/// <summary>
        /// Responds to action events. </summary>
        /// <param name="event"> the ActionEvent that happened. </param>
        public virtual void actionPerformed(ActionEvent @event)
        {
            string action = @event.getActionCommand();

            if (action.Equals(__BUTTON_CANCEL))
            {
                dispose();
            }
            else if (action.Equals(__BUTTON_OK))
            {
                __device.addLink(__node1ComboBox.getSelected(), __node2ComboBox.getSelected(), __linkId_JTextField.getText(), __lineStyleComboBox.getSelected(), __fromArrowStyleComboBox.getSelected(), __toArrowStyleComboBox.getSelected());
                dispose();
            }
            else
            {
                checkValidity();
            }
        }
        /// <summary>
        /// Saves the changes made in the GUI and applies them to the node in the parent GUI.
        /// </summary>
        private void applyChanges()
        {
            if (!validateData())
            {
                // if the data are not valid, don't close
                return;
            }

            HydrologyNode node = new HydrologyNode();
            PropList      p    = new PropList("");
            string        temp = null;

            temp = __textTextField.getText().Trim();
            temp = StringUtil.replaceString(temp, "\"", "'");
            p.set("Text", temp);

            temp = __xTextField.getText().Trim() + "," + __yTextField.getText().Trim();
            p.set("Point", temp);

            temp = __textPositionComboBox.getSelected();
            p.set("TextPosition", temp);

            temp = __fontNameComboBox.getSelected().Trim();
            p.set("FontName", temp);

            temp = __fontSizeTextField.getText().Trim();
            p.set("OriginalFontSize", temp);

            temp = __fontStyleComboBox.getSelected().Trim();
            p.set("FontStyle", temp);
            node.setAssociatedObject(p);

            node.setDirty(true);

            __parent.updateAnnotation(__nodeNum, node);
            __applyButton.setEnabled(false);
            __okButton.setEnabled(false);
        }
        /// <summary>
        /// Responds to action performed events. </summary>
        /// <param name="e"> the ActionEvent that happened. </param>
        public virtual void actionPerformed(ActionEvent e)
        {
            string routine = "StateMod_RunReport_JFrame.actionPerformed";
            string action  = e.getActionCommand();

            if (action.Equals(__BUTTON_RUN_REPORT))
            {
                JRadioButton cb = getSelectedJRadioButton();
                if (cb == null)
                {
                    return;
                }
                StringBuilder sb = new StringBuilder("-report ");
                sb.Append(cb.getText());

                // now check if station id is needed; if so, append it
                if (cb == __xdgJRadioButton)
                {
                    sb.Append(" -");
                    sb.Append(StringUtil.getToken(__xdgSimpleJComboBox.getSelected(), " ", 0, 0));
                }
                else if (cb == __xrgJRadioButton)
                {
                    sb.Append(" -");
                    sb.Append(StringUtil.getToken(__xrgSimpleJComboBox.getSelected(), " ", 0, 0));
                }
                else if (cb == __xwgJRadioButton)
                {
                    sb.Append(" -");
                    sb.Append(StringUtil.getToken(__xwgSimpleJComboBox.getSelected(), " ", 0, 0));
                }

                string s = sb.ToString();
                try
                {         // Run the report using the process manager dialog.
                    // Pass in the main GUI class so that the modal process
                    // manager dialog is on top of that window.
                    Message.printStatus(1, routine, "Running statemod " + "with command line options: '" + sb + "'");
                    StateMod_Util.runStateMod(__dataset, s, true, __dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_MAIN));
                }
                catch (Exception)
                {
                    Message.printWarning(1, routine, "There was an error running:  \n" + s, this);
                }
            }
            else if (action.Equals(__BUTTON_CANCEL))
            {
                if (__dataset_wm != null)
                {
                    __dataset_wm.closeWindow(StateMod_DataSet_WindowManager.WINDOW_RUN_REPORT);
                }
                else
                {
                    JGUIUtil.close(this);
                }
            }
            else if (action.Equals(__BUTTON_HELP))
            {
                // REVISIT HELP (JTS - 2003-08-21)
            }
        }
        /// <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>
        /// Called when Apply or OK is clicked.  Commits any changes to the node.
        /// </summary>
        private void applyClicked()
        {
            //TODO SAM 2007-03-01 Evaluate use
            bool   dirty         = false;
            string id            = __idTextField.getText();
            string x             = __xTextField.getText();
            string y             = __yTextField.getText();
            string desc          = __descriptionTextField.getText();
            bool   isNaturalFlow = __isNaturalFlowCheckBox.isSelected();
            bool   mport         = __isImportCheckBox.isSelected();
            string type          = __typeComboBox.getSelected();
            string dir           = __labelPositionComboBox.getSelected();
            string resDir        = __reservoirDirectionComboBox.getSelected();
            string area          = __areaTextField.getText();
            string precip        = __precipitationTextField.getText();

            __nodes[__nodeNum].setCommonID(id);
            if (!id.Equals(__origID))
            {
                dirty = true;
            }

            __nodes[__nodeNum].setX((Convert.ToDouble(x)));
            if (!x.Equals(__origX))
            {
                dirty = true;
            }

            __nodes[__nodeNum].setY((Convert.ToDouble(y)));
            if (!y.Equals(__origY))
            {
                dirty = true;
            }

            __nodes[__nodeNum].setDescription(desc);
            if (!desc.Equals(__origDesc))
            {
                dirty = true;
            }

            __nodes[__nodeNum].setIsNaturalFlow(isNaturalFlow);
            if (isNaturalFlow != __origNaturalFlow)
            {
                dirty = true;
            }

            __nodes[__nodeNum].setIsImport(mport);
            if (mport != __origImport)
            {
                dirty = true;
            }

            __nodes[__nodeNum].setPrecip((Convert.ToDouble(precip)));
            if (!precip.Equals(__origPrecipitation))
            {
                dirty = true;
            }

            __nodes[__nodeNum].setArea((Convert.ToDouble(area)));
            if (!area.Equals(__origArea))
            {
                dirty = true;
            }

            int  itype = -1;
            bool res   = false;

            if (type.Equals(__NODE_CONFLUENCE))
            {
                itype = HydrologyNode.NODE_TYPE_CONFLUENCE;
            }
            else if (type.Equals(__NODE_DIVERSION))
            {
                itype = HydrologyNode.NODE_TYPE_DIV;
            }
            else if (type.Equals(__NODE_DIVERSION_AND_WELL))
            {
                itype = HydrologyNode.NODE_TYPE_DIV_AND_WELL;
            }
            else if (type.Equals(__NODE_END))
            {
                itype = HydrologyNode.NODE_TYPE_END;
            }
            else if (type.Equals(__NODE_INSTREAM_FLOW))
            {
                itype = HydrologyNode.NODE_TYPE_ISF;
            }
            else if (type.Equals(__NODE_OTHER))
            {
                itype = HydrologyNode.NODE_TYPE_OTHER;
            }
            else if (type.Equals(__NODE_PLAN))
            {
                itype = HydrologyNode.NODE_TYPE_PLAN;
            }
            else if (type.Equals(__NODE_RESERVOIR))
            {
                itype = HydrologyNode.NODE_TYPE_RES;
                res   = true;
            }
            else if (type.Equals(__NODE_STREAMFLOW))
            {
                itype = HydrologyNode.NODE_TYPE_FLOW;
            }
            else if (type.Equals(__NODE_WELL))
            {
                itype = HydrologyNode.NODE_TYPE_WELL;
            }
            else if (type.Equals(__NODE_XCONFLUENCE))
            {
                itype = HydrologyNode.NODE_TYPE_XCONFLUENCE;
            }
            else
            {
                int index = type.IndexOf(":", StringComparison.Ordinal);
                type  = type.Substring(index + 1).Trim();
                itype = Integer.decode(type).intValue();
            }
            __nodes[__nodeNum].setType(itype);
            if (!type.Equals(__origType))
            {
                dirty = true;
            }

            int idir = -1;

            if (dir.Equals(__ABOVE_CENTER))
            {
                idir = 1;
            }
            else if (dir.Equals(__UPPER_RIGHT))
            {
                idir = 7;
            }
            else if (dir.Equals(__RIGHT))
            {
                idir = 4;
            }
            else if (dir.Equals(__LOWER_RIGHT))
            {
                idir = 8;
            }
            else if (dir.Equals(__BELOW_CENTER))
            {
                idir = 2;
            }
            else if (dir.Equals(__LOWER_LEFT))
            {
                idir = 5;
            }
            else if (dir.Equals(__LEFT))
            {
                idir = 3;
            }
            else if (dir.Equals(__UPPER_LEFT))
            {
                idir = 6;
            }
            else if (dir.Equals(__CENTER))
            {
                idir = 9;
            }
            else
            {
                int index = dir.IndexOf(":", StringComparison.Ordinal);
                dir  = dir.Substring(index + 1).Trim();
                idir = Integer.decode(dir).intValue();
            }
            int iresdir = 0;

            if (res)
            {
                if (resDir.Equals(__TOP))
                {
                    iresdir = 2;
                }
                else if (resDir.Equals(__BOTTOM))
                {
                    iresdir = 1;
                }
                else if (resDir.Equals(__LEFT))
                {
                    iresdir = 4;
                }
                else if (resDir.Equals(__RIGHT))
                {
                    iresdir = 3;
                }
                else
                {
                    int index = resDir.IndexOf(":", StringComparison.Ordinal);
                    resDir  = resDir.Substring(index + 1).Trim();
                    iresdir = Integer.decode(resDir).intValue();
                }
            }

            __nodes[__nodeNum].setLabelDirection((iresdir * 10) + idir);
            if (!resDir.Equals(__origResDir) || !dir.Equals(__origDir))
            {
                dirty = true;
            }

            // Only set the dirty flag if it was false previously because a previous edit may have marked
            // dirty and this edit may not have introduced additional changes.
            if (!__nodes[__nodeNum].isDirty())
            {
                __nodes[__nodeNum].setDirty(dirty);
            }
            __nodes[__nodeNum].setBoundsCalculated(false);

            __parent.nodePropertiesChanged();
        }