package uk.ac.leeds.ccg.cluster; /** Class: ParametersViewer * Function: To display and modify Parameters */ import java.io.*; import java.awt.*; import java.awt.event.*; import uk.ac.leeds.ccg.geotools.misc.*; public class ParametersViewer extends Panel implements ActionListener{ // Members File file; //FilenameFilter filenameFilter; FileFil fileFil; FileDialog fileDialog; Parameters parameters; Label label; // These Textfield, Double Choice and checkboxes allow for the // setting of Parameters from the ParametersViewer Double thresh,popMin,canMin,hH,meas,minPnt,maxSam,maxMC,maxRep; TextField threshTextField,popMinTextField,canMinTextField,hHTextField; TextField minPntTextField,maxSamTextField,maxMCTextField,maxRepTextField; Choice measChoice; Checkbox animateCheckbox, excessCheckbox; MenuBar menuBar; Menu fileMenu; MenuItem loadParametersMenuItem,saveParametersMenuItem,closeMenuItem; Container parametersContainer,buttonContainer; GridBagLayout gridBagLayout; GridBagConstraints gridBagConstraints; Button applyButton,defaultButton,significanceTestParametersButton; Frame frame; String actionCommand; boolean alternator=true; public ParametersViewer(){} public ParametersViewer(Parameters parameters){ this.parameters = parameters; excessCheckbox = new Checkbox(); excessCheckbox.setState( parameters.getExcess() ); excessCheckbox.setLabel("Excess"); animateCheckbox = new Checkbox(); animateCheckbox.setState(parameters.getAnimate()); animateCheckbox.setLabel("Animate"); //threshTextField = new TextField(""+parameters.getSignificanceThreshold()); threshTextField = new TextField(""+FormatedString.format(""+parameters.getSignificanceThreshold(),4).trim()); popMinTextField = new TextField(""+parameters.getMinPopSize()); canMinTextField = new TextField(""+parameters.getMinIncidenceCount()); hHTextField = new TextField(""+parameters.getMonteCarloRejectionCount()); measChoice = new Choice(); measChoice.add("observed - expected"); measChoice.add("observed / expected"); measChoice.add("1 - probability of result"); measChoice.select(parameters.getStatType()-1); minPntTextField = new TextField(""+parameters.getMinPointCount()); maxSamTextField = new TextField(""+parameters.getBootstrapSampleSize()); maxMCTextField = new TextField(""+parameters.getMonteCarloSampleSize()); maxRepTextField = new TextField(""+parameters.getMultipleTestReruns()); } // Methods public static void main(String args[]) throws IOException,FileNotFoundException{ ParametersViewer pv = new ParametersViewer(new Parameters()); pv.run(); } public void run(){ initComponents(); setDisplay(); } public void initComponents(){ // Set menu bar menuBar = new MenuBar(); fileMenu = new Menu(); fileMenu.setLabel("File"); loadParametersMenuItem = new MenuItem(); loadParametersMenuItem.addActionListener(this); loadParametersMenuItem.setActionCommand("load parameters"); loadParametersMenuItem.setLabel("Load Parameters"); fileMenu.add(loadParametersMenuItem); saveParametersMenuItem = new MenuItem(); saveParametersMenuItem.addActionListener(this); saveParametersMenuItem.setActionCommand("save parameters"); saveParametersMenuItem.setLabel("Save Parameters"); fileMenu.add(saveParametersMenuItem); closeMenuItem = new MenuItem(); closeMenuItem.addActionListener(this); closeMenuItem.setActionCommand("close"); closeMenuItem.setLabel("Close"); fileMenu.add(closeMenuItem); menuBar.add(fileMenu); // Display parametersContainer gridBagLayout = new GridBagLayout(); gridBagConstraints = new GridBagConstraints(); parametersContainer = new Container(); parametersContainer.setLayout(gridBagLayout); // Parameter thresh label = new Label("Significance Threshold"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); threshTextField.setText(""+FormatedString.format(""+parameters.getSignificanceThreshold(),4)); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(threshTextField,gridBagConstraints); parametersContainer.add(threshTextField); // Parameter popMin label = new Label("Minimum Population Size"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); popMinTextField.setText(""+parameters.getMinPopSize()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(popMinTextField,gridBagConstraints); parametersContainer.add(popMinTextField); // Parameter canMin label = new Label("Minimum Incidence Count"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); canMinTextField.setText(""+parameters.getMinIncidenceCount()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(canMinTextField,gridBagConstraints); parametersContainer.add(canMinTextField); // Parameter hH label = new Label("Monte Carlo Rejection Count"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); hHTextField.setText(""+parameters.getMonteCarloRejectionCount()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(hHTextField,gridBagConstraints); parametersContainer.add(hHTextField); // Parameter meas label = new Label("Type of Result"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); measChoice.select(parameters.getStatType()-1); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(measChoice,gridBagConstraints); parametersContainer.add(measChoice); // Parameter minPnt label = new Label("Minimum Point Count"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); minPntTextField.setText(""+parameters.getMinPointCount()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(minPntTextField,gridBagConstraints); parametersContainer.add(minPntTextField); // Parameter maxSam label = new Label("Number of Bootstrap Samples"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); maxSamTextField.setText(""+parameters.getBootstrapSampleSize()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(maxSamTextField,gridBagConstraints); parametersContainer.add(maxSamTextField); // Parameter maxMC label = new Label("Number of Monte Carlo Samples"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); maxMCTextField.setText(""+parameters.getMonteCarloSampleSize()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(maxMCTextField,gridBagConstraints); parametersContainer.add(maxMCTextField); // Parameter maxRep label = new Label("Number of Multiple Test Reruns"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); maxRepTextField.setText(""+parameters.getMultipleTestReruns()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(maxRepTextField,gridBagConstraints); parametersContainer.add(maxRepTextField); // Set buttonContainer and checkbox buttonContainer = new Container(); buttonContainer.setLayout(gridBagLayout); applyButton = new Button(); applyButton.setLabel("Apply"); applyButton.addActionListener(this); applyButton.setActionCommand("apply"); buttonContainer.add(applyButton); defaultButton = new Button(); defaultButton.setLabel("Default"); defaultButton.addActionListener(this); defaultButton.setActionCommand("default"); buttonContainer.add(defaultButton); significanceTestParametersButton = new Button(); significanceTestParametersButton.setLabel("Significance Test Parameters"); significanceTestParametersButton.addActionListener(this); significanceTestParametersButton.setActionCommand("significance test parameters"); buttonContainer.add(significanceTestParametersButton); animateCheckbox.setState(parameters.getAnimate()); buttonContainer.add(animateCheckbox); excessCheckbox.setState( parameters.getExcess() ); buttonContainer.add( excessCheckbox ); } public void setDisplay(){ // Set frame frame = new Frame("Parameters"); frame.setMenuBar(getMenuBar()); frame.setLayout(gridBagLayout); // Add buttonContainer gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(buttonContainer,gridBagConstraints); frame.add(buttonContainer,frame.getComponentCount()); frame.pack(); frame.setVisible(true); } public MenuBar getMenuBar(){return menuBar;} public void parseValues(){ parameters.setAnimate(animateCheckbox.getState()); parameters.setExcess(excessCheckbox.getState()); thresh = new Double(threshTextField.getText()); parameters.setSignificanceThreshold(thresh.doubleValue()); popMin = new Double(popMinTextField.getText()); parameters.setMinPopSize(popMin.doubleValue()); canMin = new Double(canMinTextField.getText()); parameters.setMinIncidenceCount(canMin.doubleValue()); hH = new Double(hHTextField.getText()); parameters.setMonteCarloRejectionCount(hH.doubleValue()); meas = new Double(measChoice.getSelectedIndex()+1); parameters.setStatType((int)meas.doubleValue()); minPnt = new Double(minPntTextField.getText()); parameters.setMinPointCount((int)minPnt.doubleValue()); maxSam = new Double(maxSamTextField.getText()); parameters.setBootstrapSampleSize((int)maxSam.doubleValue()); maxMC = new Double(maxMCTextField.getText()); parameters.setMonteCarloSampleSize((int)maxMC.doubleValue()); maxRep = new Double(maxRepTextField.getText()); parameters.setMultipleTestReruns((int)maxRep.doubleValue()); } public void setText(){ animateCheckbox.setState(parameters.getAnimate()); excessCheckbox.setState( parameters.getExcess() ); threshTextField.setText(""+FormatedString.format(""+parameters.getSignificanceThreshold(),4).trim()); popMinTextField.setText(""+parameters.getMinPopSize()); canMinTextField.setText(""+parameters.getMinIncidenceCount()); hHTextField.setText(""+parameters.getMonteCarloRejectionCount()); measChoice.select(parameters.getStatType()-1); minPntTextField.setText(""+parameters.getMinPointCount()); maxSamTextField.setText(""+parameters.getBootstrapSampleSize()); maxMCTextField.setText(""+parameters.getMonteCarloSampleSize()); maxRepTextField.setText(""+parameters.getMultipleTestReruns()); } public void actionPerformed(ActionEvent actionEvent){ actionCommand = new String(actionEvent.getActionCommand()); // Action command name // Menu actions if(actionCommand.equals("load parameters")){ System.out.println("Load Parameters File"); fileDialog = new FileDialog(new Frame()); fileFil = new FileFil(fileDialog,".parameters"); fileDialog.setTitle("Load Parameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} file = new File(fileDialog.getDirectory(),fileDialog.getFile()); parameters = new Parameters(file); System.out.println(parameters.getAnimate()); setText(); parseValues(); } if(actionCommand.equals("save parameters")){ System.out.println("Save Parameters File"); fileDialog = new FileDialog(new Frame()); fileFil = new FileFil(fileDialog,".parameters"); fileDialog.setTitle("Save Parameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} file = new File(fileDialog.getDirectory(),fileDialog.getFile()); try{ parameters.writeParameters(file); //dbase.save(file); } catch(IOException error){ System.err.println("Error saving file "+error); return; } } if(actionCommand.equals("close")){ frame.dispose(); } // Button actions if(actionCommand.equals("apply")){ parseValues(); setText(); System.out.println("Parameters\n"+parameters); } if(actionCommand.equals("default")){ parameters.setDefaultParameters(); setText(); System.out.println("Parameters\n"+parameters); } if(actionCommand.equals("significance test parameters")){ if(alternator==true){ gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(parametersContainer,gridBagConstraints); frame.add(parametersContainer); frame.pack(); alternator=false; } else{ frame.remove(parametersContainer); frame.pack(); alternator=true; } } } }