package uk.ac.leeds.ccg.cluster; import java.io.*; import java.awt.*; import java.awt.event.*; /** Class: GamParametersViewer * Function: To display and modify GamParameters */ public class GamParametersViewer extends ParametersViewer implements ActionListener { // Members // GUI variables Container gamParametersContainer; // These Doubles and TextFields allow for the setting of // GamParameters from the GamParametersViewer TextField radMinTextField = new TextField(""+((GamParameters)parameters).getRadMin()); TextField radMaxTextField = new TextField(""+((GamParameters)parameters).getRadMax()); TextField radIncTextField = new TextField(""+((GamParameters)parameters).getRadInc()); TextField overlpTextField = new TextField(""+((GamParameters)parameters).getOverlp()); Double radMin,radMax,radInc,overlp; // Constructors public GamParametersViewer(Parameters p){ super(p); } // Methods public static void main(String args[]) throws IOException,FileNotFoundException{ GamParametersViewer gamParametersViewer = new GamParametersViewer (new GamParameters()); gamParametersViewer.run(); } public void run(){ initComponents(); setDisplay(); } public void initComponents(){ // Parameters come first as ParametersViewer instantiates the // gridBagLayout gridBagLayout and gridBagConstraints gridBagConstraints super.initComponents(); gamParametersContainer = new Container(); gamParametersContainer.setLayout(gridBagLayout); // GamParameter RadMin label = new Label("Minimum circle radius"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); gamParametersContainer.add(label); radMinTextField.setText(""+((GamParameters)parameters).getRadMin()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radMinTextField,gridBagConstraints); gamParametersContainer.add(radMinTextField); // GamParameter RadMax label = new Label("Maximum circle radius"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); gamParametersContainer.add(label); radMaxTextField.setText(""+((GamParameters)parameters).getRadMax()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radMaxTextField,gridBagConstraints); gamParametersContainer.add(radMaxTextField); // GamParameter RadInc label = new Label("Radius Increment"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); gamParametersContainer.add(label); radIncTextField.setText(""+((GamParameters)parameters).getRadInc()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radIncTextField,gridBagConstraints); gamParametersContainer.add(radIncTextField); // GamParameter Overlap label = new Label("Circle Overlap"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); gamParametersContainer.add(label); overlpTextField.setText(""+((GamParameters)parameters).getOverlp()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(overlpTextField,gridBagConstraints); gamParametersContainer.add(overlpTextField); } public void setDisplay(){ super.setDisplay(); gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(gamParametersContainer,gridBagConstraints); frame.add(gamParametersContainer,frame.getComponentCount()); frame.pack(); } public void parseValues(){ super.parseValues(); radMin = new Double(radMinTextField.getText()); ((GamParameters)parameters).setRadMin(radMin.doubleValue()); radMax = new Double(radMaxTextField.getText()); ((GamParameters)parameters).setRadMax(radMax.doubleValue()); radInc = new Double(radIncTextField.getText()); ((GamParameters)parameters).setRadInc(radInc.doubleValue()); overlp = new Double(overlpTextField.getText()); ((GamParameters)parameters).setOverlp(overlp.doubleValue()); } public void setText(){ super.setText(); radMinTextField.setText(""+((GamParameters)parameters).getRadMin()); radMaxTextField.setText(""+((GamParameters)parameters).getRadMax()); radIncTextField.setText(""+((GamParameters)parameters).getRadInc()); overlpTextField.setText(""+((GamParameters)parameters).getOverlp()); } 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 Gam Parameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} File file = new File(fileDialog.getDirectory(),fileDialog.getFile()); //try{ parameters = new GamParameters(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); } } }