/// <summary> /// Sets up the GUI. /// </summary> private void setupGUI() { addWindowListener(this); __descriptionTextField = new JTextField(25); __origDesc = __nodes[__nodeNum].getDescription(); __descriptionTextField.setText(__origDesc); __idTextField = new JTextField(10); __origID = __nodes[__nodeNum].getCommonID(); __idTextField.setText(__origID); __idTextField.addKeyListener(this); __xTextField = new JTextField(10); __origX = StringUtil.formatString(__nodes[__nodeNum].getX(), "%13.6f").Trim(); __xTextField.setText(__origX); __xTextField.addKeyListener(this); __yTextField = new JTextField(10); __origY = StringUtil.formatString(__nodes[__nodeNum].getY(), "%13.6f").Trim(); __yTextField.setText(__origY); __yTextField.addKeyListener(this); __areaTextField = new JTextField(10); __origArea = StringUtil.formatString(__nodes[__nodeNum].getArea(), "%13.6f").Trim(); __areaTextField.setText(__origArea); __areaTextField.addKeyListener(this); __precipitationTextField = new JTextField(10); __origPrecipitation = StringUtil.formatString(__nodes[__nodeNum].getPrecip(), "%13.6f").Trim(); __precipitationTextField.setText(__origPrecipitation); __precipitationTextField.addKeyListener(this); __typeComboBox = new SimpleJComboBox(false); __typeComboBox.add(__NODE_DIVERSION); __typeComboBox.add(__NODE_DIVERSION_AND_WELL); __typeComboBox.add(__NODE_INSTREAM_FLOW); __typeComboBox.add(__NODE_OTHER); __typeComboBox.add(__NODE_PLAN); __typeComboBox.add(__NODE_RESERVOIR); __typeComboBox.add(__NODE_STREAMFLOW); __typeComboBox.add(__NODE_WELL); int type = __nodes[__nodeNum].getType(); if (type == HydrologyNode.NODE_TYPE_CONFLUENCE) { __typeComboBox.select(__NODE_CONFLUENCE); } else if (type == HydrologyNode.NODE_TYPE_DIV) { __typeComboBox.select(__NODE_DIVERSION); } else if (type == HydrologyNode.NODE_TYPE_DIV_AND_WELL) { __typeComboBox.select(__NODE_DIVERSION_AND_WELL); } else if (type == HydrologyNode.NODE_TYPE_END) { __typeComboBox.removeAll(); __typeComboBox.add(__NODE_END); } else if (type == HydrologyNode.NODE_TYPE_ISF) { __typeComboBox.select(__NODE_INSTREAM_FLOW); } else if (type == HydrologyNode.NODE_TYPE_OTHER) { __typeComboBox.select(__NODE_OTHER); } else if (type == HydrologyNode.NODE_TYPE_PLAN) { __typeComboBox.select(__NODE_PLAN); } else if (type == HydrologyNode.NODE_TYPE_RES) { __typeComboBox.select(__NODE_RESERVOIR); } else if (type == HydrologyNode.NODE_TYPE_FLOW) { __typeComboBox.select(__NODE_STREAMFLOW); } else if (type == HydrologyNode.NODE_TYPE_WELL) { __typeComboBox.select(__NODE_WELL); } else if (type == HydrologyNode.NODE_TYPE_XCONFLUENCE) { __typeComboBox.select(__NODE_XCONFLUENCE); } else { __typeComboBox.removeAll(); __typeComboBox.add("Unknown Type: " + type); } __typeComboBox.setMaximumRowCount(__typeComboBox.getItemCount()); __origIType = type; __origType = __typeComboBox.getSelected(); __labelPositionComboBox = new SimpleJComboBox(false); __labelPositionComboBox.add(__ABOVE_CENTER); __labelPositionComboBox.add(__UPPER_RIGHT); __labelPositionComboBox.add(__RIGHT); __labelPositionComboBox.add(__LOWER_RIGHT); __labelPositionComboBox.add(__BELOW_CENTER); __labelPositionComboBox.add(__LOWER_LEFT); __labelPositionComboBox.add(__LEFT); __labelPositionComboBox.add(__UPPER_LEFT); __labelPositionComboBox.add(__CENTER); __labelPositionComboBox.setMaximumRowCount(__labelPositionComboBox.getItemCount()); int dir = __nodes[__nodeNum].getLabelDirection() % 10; if (dir == 2) { __labelPositionComboBox.select(__BELOW_CENTER); } else if (dir == 1) { __labelPositionComboBox.select(__ABOVE_CENTER); } else if (dir == 4) { __labelPositionComboBox.select(__RIGHT); } else if (dir == 3) { __labelPositionComboBox.select(__LEFT); } else if (dir == 7) { __labelPositionComboBox.select(__UPPER_RIGHT); } else if (dir == 8) { __labelPositionComboBox.select(__LOWER_RIGHT); } else if (dir == 5) { __labelPositionComboBox.select(__LOWER_LEFT); } else if (dir == 6) { __labelPositionComboBox.select(__UPPER_LEFT); } else if (dir == 9) { __labelPositionComboBox.select(__CENTER); } else { __labelPositionComboBox.removeAll(); __labelPositionComboBox.add("Unknown Position: " + dir); } __origIDir = dir; __origDir = __labelPositionComboBox.getSelected(); __isNaturalFlowCheckBox = new JCheckBox(); __isImportCheckBox = new JCheckBox(); __origDirty = __nodes[__nodeNum].isDirty(); __reservoirDirectionLabel = new JLabel("Reservoir Direction: "); __reservoirDirectionComboBox = new SimpleJComboBox(false); __reservoirDirectionComboBox.setToolTipText("Reservoir body is to the indicated direction " + "(downstream follows the arrow)."); __reservoirDirectionComboBox.add(__TOP); __reservoirDirectionComboBox.add(__BOTTOM); __reservoirDirectionComboBox.add(__LEFT); __reservoirDirectionComboBox.add(__RIGHT); int resDir = __nodes[__nodeNum].getLabelDirection() / 10; if (resDir == 1) { __reservoirDirectionComboBox.select(__BOTTOM); } else if (resDir == 2) { __reservoirDirectionComboBox.select(__TOP); } else if (resDir == 3) { __reservoirDirectionComboBox.select(__RIGHT); } else if (resDir == 4) { __reservoirDirectionComboBox.select(__LEFT); } else if (resDir == 0) { } else { __reservoirDirectionComboBox.removeAll(); __reservoirDirectionComboBox.add("Unknown direction: " + resDir); } __origResIDir = resDir; __origResDir = __reservoirDirectionComboBox.getSelected(); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); int y = 0; JGUIUtil.addComponent(panel, new JLabel("ID: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __idTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; JGUIUtil.addComponent(panel, new JLabel("Type: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __typeComboBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; JGUIUtil.addComponent(panel, new JLabel("Description: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __descriptionTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; JGUIUtil.addComponent(panel, new JLabel("X: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __xTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; JGUIUtil.addComponent(panel, new JLabel("Y: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __yTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; JGUIUtil.addComponent(panel, new JLabel("Is natural flow?: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __isNaturalFlowCheckBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; JGUIUtil.addComponent(panel, new JLabel("Is import?: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __isImportCheckBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; JGUIUtil.addComponent(panel, new JLabel("Area: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __areaTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; JGUIUtil.addComponent(panel, new JLabel("Precipitation: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __precipitationTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); if (__nodes[__nodeNum].getIsNaturalFlow()) { __isNaturalFlowCheckBox.setSelected(true); } else { __isNaturalFlowCheckBox.setSelected(false); __areaTextField.setEnabled(false); __precipitationTextField.setEnabled(false); } __isNaturalFlowCheckBox.addActionListener(this); if (__nodes[__nodeNum].getIsImport()) { __isImportCheckBox.setSelected(true); } else { __isImportCheckBox.setSelected(false); } __isImportCheckBox.addActionListener(this); __origNaturalFlow = __isNaturalFlowCheckBox.isSelected(); __origImport = __isImportCheckBox.isSelected(); y++; JGUIUtil.addComponent(panel, new JLabel("Label Position: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __labelPositionComboBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; JGUIUtil.addComponent(panel, __reservoirDirectionLabel, 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(panel, __reservoirDirectionComboBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); y++; y = addUpstreamNodesToPanel(panel, y); addDownstreamNodeToPanel(panel, y); getContentPane().add(panel); JPanel southPanel = new JPanel(); southPanel.setLayout(new GridBagLayout()); __applyButton = new JButton(__BUTTON_APPLY); __applyButton.addActionListener(this); __okButton = new JButton(__BUTTON_OK); __okButton.addActionListener(this); JButton cancelButton = new JButton(__BUTTON_CANCEL); cancelButton.addActionListener(this); JGUIUtil.addComponent(southPanel, __applyButton, 0, 0, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(southPanel, __okButton, 2, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); JGUIUtil.addComponent(southPanel, cancelButton, 3, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); getContentPane().add(southPanel, "South"); pack(); if (__origIType != HydrologyNode.NODE_TYPE_RES) { __reservoirDirectionLabel.setVisible(false); __reservoirDirectionComboBox.setVisible(false); } __typeComboBox.addActionListener(this); if (__parent.inStateModGUI()) { __typeComboBox.setEnabled(false); __precipitationTextField.setEditable(false); __precipitationTextField.removeKeyListener(this); __descriptionTextField.setEditable(false); __descriptionTextField.removeKeyListener(this); __areaTextField.removeKeyListener(this); __areaTextField.setEditable(false); __idTextField.removeKeyListener(this); __idTextField.setEditable(false); __isNaturalFlowCheckBox.setEnabled(false); __isImportCheckBox.setEnabled(false); } JGUIUtil.center(this); setVisible(true); }
/// <summary> /// Responds to action performed events. </summary> /// <param name="ae"> the ActionEvent that happened. </param> public virtual void actionPerformed(ActionEvent ae) { string routine = "StateMod_OutputControl_JFrame.actionPerformed"; string action = ae.getActionCommand(); if (action.Equals(__BUTTON_ADD_ROW)) { if (!__tableModel.canAddNewRow()) { return; } __dirty = true; int row = __worksheet.getRowCount(); StateMod_GraphNode n = new StateMod_GraphNode(); __worksheet.addRow(n); n.setType(""); n.setID(""); n.setSwitch(-1); __tableModel.setDirty(true); // when a row is added, mark the second and third columns // as uneditable. They will be set to editable as soon as // the user enters a value in the first column __worksheet.setCellEditable(row, 1, false); __worksheet.setCellEditable(row, 2, false); } else if (action.Equals(__BUTTON_CLEAR_LIST)) { __dirty = true; __worksheet.clear(); setMessages("Add station to list.", "Ready"); __tableModel.setDirty(true); } else if (action.Equals(__BUTTON_CLOSE)) { closeWindow(); } else if (action.Equals(__BUTTON_DELETE_ROW)) { int[] rows = __worksheet.getSelectedRows(); int length = rows.Length; __tableModel.setDirty(true); if (length == 0) { return; } for (int i = (length - 1); i >= 0; i--) { __worksheet.deleteRow(rows[i]); } __dirty = true; setMessages("Time series list has changed.", "Ready"); } else if (action.Equals(__BUTTON_HELP)) { // REVISIT HELP (JTS - 2003-07-09) } else if (action.Equals(__BUTTON_SAVE_FILE)) { JGUIUtil.setWaitCursor(this, true); string lastDirectorySelected = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = null; if (!string.ReferenceEquals(lastDirectorySelected, null)) { fc = new JFileChooser(lastDirectorySelected); } else { fc = new JFileChooser(); } fc.setDialogTitle("Select Output Control File"); SimpleFileFilter @out = new SimpleFileFilter("out", "StateMod Output Control Files"); fc.addChoosableFileFilter(@out); SimpleFileFilter tpl = new SimpleFileFilter("tpo", "StateMod Output Control Files"); fc.addChoosableFileFilter(tpl); SimpleFileFilter xou = new SimpleFileFilter("xou", "StateMod Output Control Files"); fc.addChoosableFileFilter(xou); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(tpl); fc.setDialogType(JFileChooser.SAVE_DIALOG); JGUIUtil.setWaitCursor(this, false); int retVal = fc.showSaveDialog(this); if (retVal != JFileChooser.APPROVE_OPTION) { return; } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(lastDirectorySelected, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getName(); FileFilter ff = fc.getFileFilter(); if (ff == @out) { filename = IOUtil.enforceFileExtension(filename, "out"); } else if (ff == tpl) { filename = IOUtil.enforceFileExtension(filename, "tpo"); } else if (ff == xou) { filename = IOUtil.enforceFileExtension(filename, "xou"); } __dirty = false; __tableModel.setDirty(false); System.Collections.IList theGraphNodes = __worksheet.getAllData(); try { StateMod_GraphNode.writeStateModOutputControlFile(null, currDir + File.separator + filename, theGraphNodes, null); } catch (Exception e) { Message.printWarning(1, routine, "Error saving output control file\n" + "\"" + currDir + File.separator + filename + "\"", this); Message.printWarning(2, routine, e); } } else if (action.Equals(__BUTTON_LOAD_FILE)) { JGUIUtil.setWaitCursor(this, true); string lastDirectorySelected = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = null; if (!string.ReferenceEquals(lastDirectorySelected, null)) { fc = new JFileChooser(lastDirectorySelected); } else { fc = new JFileChooser(); } fc.setDialogTitle("Select Output Control File"); SimpleFileFilter @out = new SimpleFileFilter("out", "StateMod Output Control Files"); fc.addChoosableFileFilter(@out); SimpleFileFilter tpl = new SimpleFileFilter("tpo", "StateMod Output Control Files"); fc.addChoosableFileFilter(tpl); SimpleFileFilter xou = new SimpleFileFilter("xou", "StateMod Output Control Files"); fc.addChoosableFileFilter(xou); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(tpl); fc.setDialogType(JFileChooser.OPEN_DIALOG); JGUIUtil.setWaitCursor(this, false); int retVal = fc.showOpenDialog(this); if (retVal != JFileChooser.APPROVE_OPTION) { return; } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(lastDirectorySelected, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getName(); JGUIUtil.setWaitCursor(this, true); __dirty = false; System.Collections.IList theGraphNodes = new List <object>(20, 1); try { __worksheet.clear(); __tableModel.setDirty(false); StateMod_GraphNode.readStateModOutputControlFile(theGraphNodes, currDir + File.separator + filename); int size = theGraphNodes.Count; StateMod_GraphNode g = null; int row = 0; for (int i = 0; i < size; i++) { row = __worksheet.getRowCount(); g = (StateMod_GraphNode)theGraphNodes[i]; if (i == 0) { if (g.getID().Equals("All")) { __useAllJCheckBox.setSelected(true); } else { __useAllJCheckBox.setSelected(false); } } __worksheet.addRow(g); __tableModel.fillIDColumn(row, g.getType()); } __worksheet.setData(theGraphNodes); } catch (Exception e) { Message.printWarning(1, routine, "Error loading output control file\n" + "\"" + currDir + File.separator + filename + "\"", this); Message.printWarning(2, routine, e); } JGUIUtil.setWaitCursor(this, false); } else if (action.Equals(__CHECKBOX_USE_ALL)) { // if the use all checkbox is selected, subtle changes from the // default functionality are made. The buttons to add and // delete rows are disabled, and the ID of the only record // in the worksheet is set to "All". This ID value is used // in the table model to determine when the checkbox is // selected. In addition, the ComboBox functionality of the // first and third data columns is turned off. if (__useAllJCheckBox.isSelected()) { __addRowButton.setEnabled(false); __deleteRowButton.setEnabled(false); __worksheet.setColumnJComboBoxValues(0, null); __worksheet.setColumnJComboBoxValues(2, null); __worksheet.clear(); StateMod_GraphNode g = new StateMod_GraphNode(); g.setID("All"); __worksheet.setCellEditable(0, 0, false); __worksheet.setCellEditable(0, 1, false); __worksheet.setCellEditable(0, 2, false); __worksheet.addRow(g); } else { __addRowButton.setEnabled(true); __deleteRowButton.setEnabled(true); System.Collections.IList v = StateMod_Util.arrayToList(StateMod_GraphNode.node_types); v.Add("Other"); __worksheet.setColumnJComboBoxValues(0, v); __worksheet.clear(); System.Collections.IList offOn = new List <object>(); offOn.Add("Off"); offOn.Add("On"); __worksheet.setCellEditable(0, 0, true); __worksheet.setColumnJComboBoxValues(2, offOn); } } }