package uk.ac.leeds.ccg.cluster; import java.io.*; import java.awt.*; import java.awt.event.*; /** Class: GrimsonTimeParametersViewer * Function: To display and modify GrimsonTimeParameters */ public class GrimsonTimeParametersViewer extends TimeParametersViewer implements ActionListener { // Members Container grimsonTimeParametersContainer; // These Doubles and TextFields allow for the setting of // GrimsonTimeParameters from the GrimsonTimeParametersViewer Double highrisk; TextField hrTextField = new TextField(""+((GrimsonTimeParameters)parameters).getHR()); // Constructors public GrimsonTimeParametersViewer(TimeParameters p){ super(p); } // Methods public static void main(String args[]) throws IOException,FileNotFoundException{ GrimsonTimeParametersViewer grimsonTimeParametersViewer = new GrimsonTimeParametersViewer (new GrimsonTimeParameters()); grimsonTimeParametersViewer.run(); } public void run(){ initComponents(); setDisplay(); } public void initComponents(){ // TimeParameters come first as TimeParametersViewer instantiates the // gridBagLayout gridBagLayout and gridBagConstraints gridBagConstraints super.initComponents(); grimsonTimeParametersContainer = new Container(); grimsonTimeParametersContainer.setLayout(gridBagLayout); // GrimsonTimeParameter highrisk label = new Label("High risk threshold"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); grimsonTimeParametersContainer.add(label); hrTextField.setText(""+((GrimsonTimeParameters)parameters).getHR()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(hrTextField,gridBagConstraints); grimsonTimeParametersContainer.add(hrTextField); } public void setDisplay(){ super.setDisplay(); gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(grimsonTimeParametersContainer,gridBagConstraints); frame.add(grimsonTimeParametersContainer,frame.getComponentCount()); frame.setTitle("TimeParameters - Grimson"); frame.pack(); } public void parseValues(){ super.parseValues(); highrisk = new Double(hrTextField.getText()); ((GrimsonTimeParameters)parameters).setHR((double)highrisk.doubleValue()); } public void setText(){ super.setText(); hrTextField.setText(""+((GrimsonTimeParameters)parameters).getHR()); } 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 Grimson TimeParameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} file = new File(fileDialog.getDirectory(),fileDialog.getFile()); try{ parameters = new GrimsonTimeParameters(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); } } }