package uk.ac.leeds.ccg.cluster; import java.io.*; import java.awt.*; import java.awt.event.*; /** Class: SpattimescanParametersViewer * Function: To display and modify SpattimescanParametersViewer */ public class SpattimescanParametersViewer extends ParametersViewer implements ActionListener { // Members // GUI variables Container spattimescanParametersContainer; // These Doubles and TextFields allow for the setting of // SpattimescanParametersViewer from the SpattimescanParametersViewer TextField radMinTextField = new TextField(""+((SpattimescanParameters)parameters).getRadMin()); TextField radMaxTextField = new TextField(""+((SpattimescanParameters)parameters).getRadMax()); TextField radIncTextField = new TextField(""+((SpattimescanParameters)parameters).getRadInc()); TextField timeMinTextField = new TextField(""+((SpattimescanParameters)parameters).getTimeMin()); TextField timeMaxTextField = new TextField(""+((SpattimescanParameters)parameters).getTimeMax()); TextField timeIncTextField = new TextField(""+((SpattimescanParameters)parameters).getTimeInc()); TextField numRunsTextField = new TextField(""+((SpattimescanParameters)parameters).getNumRuns()); Double radMin,radMax,radInc, timeMin,timeMax,timeInc,numRuns; // Constructors public SpattimescanParametersViewer(Parameters p){ super(p); } // Methods public static void main(String args[]) throws IOException,FileNotFoundException{ SpattimescanParametersViewer spattimescanParametersViewer = new SpattimescanParametersViewer (new SpattimescanParameters()); spattimescanParametersViewer.run(); } public void run(){ initComponents(); setDisplay(); } public void initComponents(){ // Parameters come first as ParametersViewer instantiates the // gridBagLayout gridBagLayout and gridBagConstraints gridBagConstraints super.initComponents(); spattimescanParametersContainer = new Container(); spattimescanParametersContainer.setLayout(gridBagLayout); // SpattimescanParameter RadMin label = new Label("Minimum circle radius"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spattimescanParametersContainer.add(label); radMinTextField.setText(""+((SpattimescanParameters)parameters).getRadMin()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radMinTextField,gridBagConstraints); spattimescanParametersContainer.add(radMinTextField); // SpattimescanParameter RadMax label = new Label("Maximum circle radius"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spattimescanParametersContainer.add(label); radMaxTextField.setText(""+((SpattimescanParameters)parameters).getRadMax()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radMaxTextField,gridBagConstraints); spattimescanParametersContainer.add(radMaxTextField); // SpattimescanParameter RadInc label = new Label("Radius Increment"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spattimescanParametersContainer.add(label); radIncTextField.setText(""+((SpattimescanParameters)parameters).getRadInc()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radIncTextField,gridBagConstraints); spattimescanParametersContainer.add(radIncTextField); // SpattimescanParameter TimeMin label = new Label("Earliest time"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spattimescanParametersContainer.add(label); timeMinTextField.setText(""+((SpattimescanParameters)parameters).getTimeMin()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(timeMinTextField,gridBagConstraints); spattimescanParametersContainer.add(timeMinTextField); // SpattimescanParameter TimeMax label = new Label("Latest time"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spattimescanParametersContainer.add(label); timeMaxTextField.setText(""+((SpattimescanParameters)parameters).getTimeMax()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(timeMaxTextField,gridBagConstraints); spattimescanParametersContainer.add(timeMaxTextField); // SpattimescanParameter TimeInc label = new Label("Time Increment "); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spattimescanParametersContainer.add(label); timeIncTextField.setText(""+((SpattimescanParameters)parameters).getTimeInc()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(timeIncTextField,gridBagConstraints); spattimescanParametersContainer.add(timeIncTextField); // SpattimescanParameter NumRuns label = new Label("Number of Runs"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); spattimescanParametersContainer.add(label); numRunsTextField.setText(""+((SpattimescanParameters)parameters).getNumRuns()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(numRunsTextField,gridBagConstraints); spattimescanParametersContainer.add(numRunsTextField); } public void setDisplay(){ super.setDisplay(); gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(spattimescanParametersContainer,gridBagConstraints); frame.add(spattimescanParametersContainer,frame.getComponentCount()); frame.pack(); } public void parseValues(){ super.parseValues(); radMin = new Double(radMinTextField.getText()); ((SpattimescanParameters)parameters).setRadMin(radMin.doubleValue()); radMax = new Double(radMaxTextField.getText()); ((SpattimescanParameters)parameters).setRadMax(radMax.doubleValue()); radInc = new Double(radIncTextField.getText()); ((SpattimescanParameters)parameters).setRadInc(radInc.doubleValue()); timeMin = new Double(timeMinTextField.getText()); ((SpattimescanParameters)parameters).setTimeMin(timeMin.doubleValue()); timeMax = new Double(timeMaxTextField.getText()); ((SpattimescanParameters)parameters).setTimeMax(timeMax.doubleValue()); timeInc = new Double(timeIncTextField.getText()); ((SpattimescanParameters)parameters).setTimeInc(timeInc.doubleValue()); numRuns = new Double(numRunsTextField.getText()); ((SpattimescanParameters)parameters).setNumRuns((int)numRuns.doubleValue()); } public void setText(){ super.setText(); radMinTextField.setText(""+((SpattimescanParameters)parameters).getRadMin()); radMaxTextField.setText(""+((SpattimescanParameters)parameters).getRadMax()); radIncTextField.setText(""+((SpattimescanParameters)parameters).getRadInc()); timeMinTextField.setText(""+((SpattimescanParameters)parameters).getTimeMin()); timeMaxTextField.setText(""+((SpattimescanParameters)parameters).getTimeMax()); timeIncTextField.setText(""+((SpattimescanParameters)parameters).getTimeInc()); numRunsTextField.setText(""+((SpattimescanParameters)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 SpattimescanParameters(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); } } }