package uk.ac.leeds.ccg.cluster; /** Class: SpaceTimeParametersViewer * Function: To display and modify SpaceTimeParameters */ import java.io.*; import java.awt.*; import java.awt.event.*; import uk.ac.leeds.ccg.geotools.misc.*; public class SpaceTimeParametersViewer extends ParametersViewer implements ActionListener{ // Members File file; //FilenameFilter filenameFilter; FileFil fileFil; FileDialog fileDialog; SpaceTimeParameters parameters; Label label; // These Textfield, Double Choice and checkboxes allow for the // setting of SpaceTimeParameters from the SpaceTimeParametersViewer Double thresh,numRuns; TextField threshTextField,numRunsTextField; Checkbox animateCheckbox; MenuBar menuBar; Menu fileMenu; MenuItem loadSpaceTimeParametersMenuItem,saveSpaceTimeParametersMenuItem,closeMenuItem; Container parametersContainer,buttonContainer; GridBagLayout gridBagLayout; GridBagConstraints gridBagConstraints; Button applyButton,defaultButton,significanceTestSpaceTimeParametersButton; Frame frame; String actionCommand; boolean alternator=true; // Constructors public SpaceTimeParametersViewer(SpaceTimeParameters parameters){ this.parameters = parameters; animateCheckbox = new Checkbox(); animateCheckbox.setState(parameters.getAnimate()); animateCheckbox.setLabel("Animate"); //threshTextField = new TextField(""+parameters.getSignificanceThreshold()); threshTextField = new TextField(""+FormatedString.format(""+parameters.getSignificanceThreshold(),4).trim()); numRunsTextField = new TextField(""+parameters.getNumRuns()); } // Methods public static void main(String args[]) throws IOException,FileNotFoundException{ SpaceTimeParametersViewer pv = new SpaceTimeParametersViewer(new SpaceTimeParameters()); pv.run(); } public void run(){ initComponents(); setDisplay(); } public void initComponents(){ // Set menu bar menuBar = new MenuBar(); fileMenu = new Menu(); fileMenu.setLabel("File"); loadSpaceTimeParametersMenuItem = new MenuItem(); loadSpaceTimeParametersMenuItem.addActionListener(this); loadSpaceTimeParametersMenuItem.setActionCommand("load parameters"); loadSpaceTimeParametersMenuItem.setLabel("Load SpaceTimeParameters"); fileMenu.add(loadSpaceTimeParametersMenuItem); saveSpaceTimeParametersMenuItem = new MenuItem(); saveSpaceTimeParametersMenuItem.addActionListener(this); saveSpaceTimeParametersMenuItem.setActionCommand("save parameters"); saveSpaceTimeParametersMenuItem.setLabel("Save SpaceTimeParameters"); fileMenu.add(saveSpaceTimeParametersMenuItem); 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); // SpaceTimeParameter 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); // SpaceTimeParameter numRuns label = new Label("Number of runs"); gridBagConstraints.anchor=GridBagConstraints.EAST; gridBagConstraints.gridwidth=GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(label,gridBagConstraints); parametersContainer.add(label); numRunsTextField.setText(""+parameters.getNumRuns()); gridBagConstraints.anchor=GridBagConstraints.WEST; gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(numRunsTextField,gridBagConstraints); parametersContainer.add(numRunsTextField); // 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); // significanceTestSpaceTimeParametersButton = new Button(); // significanceTestSpaceTimeParametersButton.setLabel("SpaceTime Series Parameters"); // significanceTestSpaceTimeParametersButton.addActionListener(this); // significanceTestSpaceTimeParametersButton.setActionCommand("significance test parameters"); // buttonContainer.add(significanceTestSpaceTimeParametersButton); animateCheckbox.setState(parameters.getAnimate()); buttonContainer.add(animateCheckbox); } public void setDisplay(){ // Set frame frame = new Frame("SpaceTimeParameters"); frame.setMenuBar(getMenuBar()); frame.setLayout(gridBagLayout); // Add buttonContainer gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(buttonContainer,gridBagConstraints); frame.add(buttonContainer,frame.getComponentCount()); gridBagConstraints.gridwidth=GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(parametersContainer,gridBagConstraints ); frame.add(parametersContainer); frame.pack(); frame.setVisible(true); } public MenuBar getMenuBar(){return menuBar;} public void parseValues(){ parameters.setAnimate(animateCheckbox.getState()); thresh = new Double(threshTextField.getText()); parameters.setSignificanceThreshold(thresh.doubleValue()); numRuns = new Double(numRunsTextField.getText()); parameters.setNumRuns((int)numRuns.doubleValue()); } public void setText(){ animateCheckbox.setState(parameters.getAnimate()); threshTextField.setText(""+FormatedString.format(""+parameters.getSignificanceThreshold(),4).trim()); numRunsTextField.setText(""+parameters.getNumRuns()); } public void actionPerformed(ActionEvent actionEvent){ actionCommand = new String(actionEvent.getActionCommand()); // Action command name // Menu actions if(actionCommand.equals("load parameters")){ System.out.println("Load SpaceTimeParameters File"); fileDialog = new FileDialog(new Frame()); fileFil = new FileFil(fileDialog,".parameters"); fileDialog.setTitle("Load SpaceTimeParameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} file = new File(fileDialog.getDirectory(),fileDialog.getFile()); try{ parameters = new SpaceTimeParameters(file); System.out.println(parameters.getAnimate()); setText(); parseValues(); //dbase.load(file); } catch(IOException error){ System.err.println("Error "+error+ "loading file "+file); return; } } if(actionCommand.equals("save parameters")){ System.out.println("Save SpaceTimeParameters File"); fileDialog = new FileDialog(new Frame()); fileFil = new FileFil(fileDialog,".parameters"); fileDialog.setTitle("Save SpaceTimeParameters File"); fileDialog.setFilenameFilter(fileFil); fileDialog.setVisible(true); if (fileDialog.getFile()==null) {return;} file = new File(fileDialog.getDirectory(),fileDialog.getFile()); try{ parameters.writeSpaceTimeParameters(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("SpaceTimeParameters\n"+parameters); } if(actionCommand.equals("default")){ parameters.setDefaultSpaceTimeParameters(); setText(); System.out.println("SpaceTimeParameters\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; } } } }