package uk.ac.leeds.ccg.cluster; import java.io.*; import java.awt.*; import java.awt.event.*; /** Class: KnoxTimeParametersViewer * Function: To display and modify KnoxTimeParameters */ public class KnoxTimeParametersViewer extends SpaceTimeParametersViewer implements ActionListener { // Members Container knoxTimeParametersContainer; // These Doubles and TextFields allow for the setting of // KnoxTimeParameters from the KnoxTimeParametersViewer Double delta, tau; TextField deltaTextField = new TextField(""+((KnoxTimeParameters)parameters).getDelta()); TextField tauTextField = new TextField(""+((KnoxTimeParameters)parameters).getTau()); // Constructcts public KnoxTimeParametersViewer(SpaceTimeParameters p){ super(p); } // Methods public static void main(String args[]) throws IOException,FileNotFoundException{ KnoxTimeParametersViewer knoxTimeParametersViewer = new KnoxTimeParametersViewer (new KnoxTimeParameters()); knoxTimeParametersViewer.run(); } public void run(){ initComponents(); setDisplay(); } public void initComponents(){ // SpaceTimeParameters come first as SpaceTimeParametersViewer instantiates the // gridBagLayout gridBagLayout and gridBagConstraints gridBagConstraints super.initComponents(); knoxTimeParametersContainer = new Container(); knoxTimeParametersContainer.setLayout(gridBagLayout); // KnoxTimeParameter delta label = new Label("Critical space distance"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); knoxTimeParametersContainer.add(label); deltaTextField.setText(""+((KnoxTimeParameters)parameters).getDelta()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(deltaTextField,gridBagConstraints); knoxTimeParametersContainer.add(deltaTextField); // KnoxTimeParameter tau label = new Label("Critical time distance"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); knoxTimeParametersContainer.add(label); tauTextField.setText(""+((KnoxTimeParameters)parameters).getTau()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(tauTextField,gridBagConstraints); knoxTimeParametersContainer.add(tauTextField); } public void setDisplay(){ super.setDisplay(); gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(knoxTimeParametersContainer,gridBagConstraints); frame.add(knoxTimeParametersContainer,frame.getComponentCount()); frame.setTitle("SpaceTimeParameters - Knox"); frame.pack(); } public void parseValues(){ super.parseValues(); delta = new Double(deltaTextField.getText()); ((KnoxTimeParameters)parameters).setDelta((int)delta.doubleValue()); tau = new Double(tauTextField.getText()); ((KnoxTimeParameters)parameters).setTau((int)tau.doubleValue()); } public void setText(){ super.setText(); deltaTextField.setText(""+((KnoxTimeParameters)parameters).getDelta()); tauTextField.setText(""+((KnoxTimeParameters)parameters).getTau()); } public void actionPerformed(ActionEvent actionEvent){ String actionCommand = new String(actionEvent.getActionCommand()); if(actionCommand.equals("load parameters")){ System.out.println("Load SpaceTimeParameters File"); fileDialog = new FileDialog(new Frame()); fileFil = new FileFil(fileDialog,".pars"); fileDialog.setTitle("Load Knox SpaceTimeParameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} file = new File(fileDialog.getDirectory(),fileDialog.getFile()); try{ parameters = new KnoxTimeParameters(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); } } }