package uk.ac.leeds.ccg.cluster; import java.io.*; import java.awt.*; import java.awt.event.*; /** Class: ScanTimeParametersViewer * Function: To display and modify ScanTimeParameters */ public class ScanTimeParametersViewer extends TimeParametersViewer implements ActionListener { // Members Container scanTimeParametersContainer; // These Doubles and TextFields allow for the setting of // ScanTimeParameters from the ScanTimeParametersViewer Double w; TextField wTextField = new TextField(""+((ScanTimeParameters)parameters).getW()); Checkbox filterCheckbox = new Checkbox(); // filterCheckbox.setState(((ScanTimeParameters)parameters).getFilter()); // filterCheckbox.setLabel("Filter"); Double filt_step; TextField filt_stepTextField = new TextField(""+((ScanTimeParameters)parameters).getFilt_step()); // Constructors public ScanTimeParametersViewer(TimeParameters p){ super(p); } // Methods public static void main(String args[]) throws IOException,FileNotFoundException{ ScanTimeParametersViewer scanTimeParametersViewer = new ScanTimeParametersViewer (new ScanTimeParameters()); scanTimeParametersViewer.run(); } public void run(){ initComponents(); setDisplay(); } public void initComponents(){ // TimeParameters come first as TimeParametersViewer instantiates the // gridBagLayout gridBagLayout and gridBagConstraints gridBagConstraints super.initComponents(); scanTimeParametersContainer = new Container(); scanTimeParametersContainer.setLayout(gridBagLayout); // ScanTimeParameter w label = new Label("Width of window"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); scanTimeParametersContainer.add(label); wTextField.setText(""+((ScanTimeParameters)parameters).getW()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(wTextField,gridBagConstraints); scanTimeParametersContainer.add(wTextField); // Filter // label = new Label("Filter "); // gridBagConstraints.anchor=GridBagConstraints.EAST; // gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; // gridBagLayout.setConstraints(label,gridBagConstraints); // scanTimeParametersContainer.add(label); filterCheckbox.setState(((ScanTimeParameters)parameters).getFilter()); filterCheckbox.setLabel("Filter"); // gridBagConstraints.anchor=GridBagConstraints.WEST; // gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; // gridBagLayout.setConstraints(filterCheckbox,gridBagConstraints); scanTimeParametersContainer.add(filterCheckbox); // ScanTimeParameter filt_step label = new Label("Filter step "); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); scanTimeParametersContainer.add(label); filt_stepTextField.setText(""+((ScanTimeParameters)parameters).getFilt_step()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(filt_stepTextField,gridBagConstraints); scanTimeParametersContainer.add(filt_stepTextField); } public void setDisplay(){ super.setDisplay(); gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(scanTimeParametersContainer,gridBagConstraints); frame.add(scanTimeParametersContainer,frame.getComponentCount()); frame.setTitle("TimeParameters - Scan"); frame.pack(); } public void parseValues(){ super.parseValues(); w = new Double(wTextField.getText()); ((ScanTimeParameters)parameters).setW((int)w.doubleValue()); ((ScanTimeParameters)parameters).setFilter(filterCheckbox.getState()); filt_step = new Double(filt_stepTextField.getText()); ((ScanTimeParameters)parameters).setFilt_step((int)filt_step.doubleValue()); } public void setText(){ super.setText(); wTextField.setText(""+((ScanTimeParameters)parameters).getW()); filterCheckbox.setState(((ScanTimeParameters)parameters).getFilter()); filt_stepTextField.setText(""+((ScanTimeParameters)parameters).getFilt_step()); } public void actionPerformed(ActionEvent actionEvent){ String actionCommand = new String(actionEvent.getActionCommand()); if(actionCommand.equals("load parameters")){ System.out.println("Load TimeParameters File"); fileDialog = new FileDialog(new Frame()); fileFil = new FileFil(fileDialog,".pars"); fileDialog.setTitle("Load Scan TimeParameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} file = new File(fileDialog.getDirectory(),fileDialog.getFile()); try{ parameters = new ScanTimeParameters(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); } } }