package uk.ac.leeds.ccg.cluster; /** Random Parameters Viewer * To display and modify Random Parameters */ import java.io.*; import java.awt.*; import java.awt.event.*; public class RandomParametersViewer extends ParametersViewer implements ActionListener{ // Members Container randomParametersContainer; // These Doubles and TextFields allow for the setting of // RandomParameters from the RandomParametersViewer TextField nCirclesTextField = new TextField(""+((RandomParameters)parameters).getNCircles()); TextField radMinTextField = new TextField(""+((RandomParameters)parameters).getRadMin()); TextField radMaxTextField = new TextField(""+((RandomParameters)parameters).getRadMax()); Double nCircles,radMin,radMax; // Constructors public RandomParametersViewer(Parameters parameters){ super(parameters); } // Methods public static void main(String args[]) throws IOException,FileNotFoundException{ RandomParametersViewer randomParametersViewer = new RandomParametersViewer (new RandomParameters()); randomParametersViewer.run(); } public void run(){ initComponents(); setDisplay(); } public void initComponents(){ // Parameters come first as ParametersViewer instantiates the // gridBagLayout gridBagLayout and gridBagConstraints gridBagConstraints super.initComponents(); randomParametersContainer = new Container(); randomParametersContainer.setLayout(gridBagLayout); // Random Parameter nCircles label = new Label("Number of circles"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); randomParametersContainer.add(label); nCirclesTextField.setText(""+((RandomParameters)parameters).getNCircles()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(nCirclesTextField,gridBagConstraints); randomParametersContainer.add(nCirclesTextField); // Random Parameter radMin label = new Label("Minimum circle radius"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); randomParametersContainer.add(label); radMinTextField.setText(""+((RandomParameters)parameters).getRadMin()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radMinTextField,gridBagConstraints); randomParametersContainer.add(radMinTextField); // Random Parameter radmax label = new Label("Maximum circle radius"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); randomParametersContainer.add(label); radMaxTextField.setText(""+((RandomParameters)parameters).getRadMax()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(radMaxTextField,gridBagConstraints); randomParametersContainer.add(radMaxTextField); } public void setDisplay(){ super.setDisplay(); gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(randomParametersContainer,gridBagConstraints); frame.add(randomParametersContainer,frame.getComponentCount()); frame.pack(); } public void parseValues(){ super.parseValues(); nCircles = new Double(nCirclesTextField.getText()); ((RandomParameters)parameters).setNCircles((int)nCircles.doubleValue()); radMin = new Double(radMinTextField.getText()); ((RandomParameters)parameters).setRadMin(radMin.doubleValue()); radMax = new Double(radMaxTextField.getText()); ((RandomParameters)parameters).setRadMax(radMax.doubleValue()); } public void setText(){ super.setText(); nCirclesTextField.setText(""+((RandomParameters)parameters).getNCircles()); radMinTextField.setText(""+((RandomParameters)parameters).getRadMin()); radMaxTextField.setText(""+((RandomParameters)parameters).getRadMax()); } public void actionPerformed(ActionEvent actionEvent){ actionCommand = new String(actionEvent.getActionCommand()); if(actionCommand.equals("load parameters")){ System.out.println("Load Parameters File"); fileDialog = new FileDialog(new Frame()); fileFil = new FileFil(fileDialog,".pars"); fileDialog.setTitle("Load Random Parameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} file = new File(fileDialog.getDirectory(),fileDialog.getFile()); try{ parameters = new RandomParameters(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); } } }