package uk.ac.leeds.ccg.cluster; import java.io.*; import java.awt.*; import java.awt.event.*; /** Class: SpatscanParametersViewer * Function: To display and modify SpatscanParametersViewer */ public class SpatscanParametersViewer extends ParametersViewer implements ActionListener { // Members // GUI variables Container spatscanParametersContainer; // These Doubles and TextFields allow for the setting of // SpatscanParametersViewer from the SpatscanParametersViewer TextField radMinTextField = new TextField(""+((SpatscanParameters)parameters).getRadMin()); TextField radMaxTextField = new TextField(""+((SpatscanParameters)parameters).getRadMax()); TextField radIncTextField = new TextField(""+((SpatscanParameters)parameters).getRadInc()); TextField numRunsTextField = new TextField(""+((SpatscanParameters)parameters).getNumRuns()); Double radMin,radMax,radInc, numRuns; // Constructors public SpatscanParametersViewer(Parameters p){ super(p); } // Methods public static void main(String args[]) throws IOException,FileNotFoundException{ SpatscanParametersViewer spatscanParametersViewer = new SpatscanParametersViewer (new SpatscanParameters()); spatscanParametersViewer.run(); } public void run(){ initComponents(); setDisplay(); } public void initComponents(){ // Parameters come first as ParametersViewer instantiates the // gridBagLayout gridBagLayout and gridBagConstraints gridBagConstraints super.initComponents(); spatscanParametersContainer = new Container(); spatscanParametersContainer.setLayout(gridBagLayout); // SpatscanParameter RadMin label = new Label("Minimum circle radius"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spatscanParametersContainer.add(label); radMinTextField.setText(""+((SpatscanParameters)parameters).getRadMin()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radMinTextField,gridBagConstraints); spatscanParametersContainer.add(radMinTextField); // SpatscanParameter RadMax label = new Label("Maximum circle radius"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spatscanParametersContainer.add(label); radMaxTextField.setText(""+((SpatscanParameters)parameters).getRadMax()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radMaxTextField,gridBagConstraints); spatscanParametersContainer.add(radMaxTextField); // SpatscanParameter RadInc label = new Label("Radius Increment"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spatscanParametersContainer.add(label); radIncTextField.setText(""+((SpatscanParameters)parameters).getRadInc()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radIncTextField,gridBagConstraints); spatscanParametersContainer.add(radIncTextField); // SpatscanParameter NumRuns label = new Label("Number of Runs"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spatscanParametersContainer.add(label); numRunsTextField.setText(""+((SpatscanParameters)parameters).getNumRuns()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(numRunsTextField,gridBagConstraints); spatscanParametersContainer.add(numRunsTextField); } public void setDisplay(){ super.setDisplay(); gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(spatscanParametersContainer,gridBagConstraints); frame.add(spatscanParametersContainer,frame.getComponentCount()); frame.pack(); } public void parseValues(){ super.parseValues(); radMin = new Double(radMinTextField.getText()); ((SpatscanParameters)parameters).setRadMin(radMin.doubleValue()); radMax = new Double(radMaxTextField.getText()); ((SpatscanParameters)parameters).setRadMax(radMax.doubleValue()); radInc = new Double(radIncTextField.getText()); ((SpatscanParameters)parameters).setRadInc(radInc.doubleValue()); numRuns = new Double(numRunsTextField.getText()); ((SpatscanParameters)parameters).setNumRuns((int)numRuns.doubleValue()); } public void setText(){ super.setText(); radMinTextField.setText(""+((SpatscanParameters)parameters).getRadMin()); radMaxTextField.setText(""+((SpatscanParameters)parameters).getRadMax()); radIncTextField.setText(""+((SpatscanParameters)parameters).getRadInc()); numRunsTextField.setText(""+((SpatscanParameters)parameters).getNumRuns()); } public void actionPerformed(ActionEvent actionEvent){ String actionCommand = new String(actionEvent.getActionCommand()); if(actionCommand.equals("load parameters")){ System.out.println("Load Parameters File"); FileDialog fileDialog = new FileDialog(new Frame()); FileFil fileFil = new FileFil(fileDialog,".pars"); fileDialog.setTitle("Load Spat Scan Parameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} File file = new File(fileDialog.getDirectory(),fileDialog.getFile()); try{ parameters = new SpatscanParameters(file); setText(); parseValues(); //dbase.load(file); } catch(IOException error){ System.err.println("Error loading file "+error); return; } } else{ // This works because calling super.actionPerformed(actionEvent) from this class // uses the methods in this class first if they exist. super.actionPerformed(actionEvent); } } }