/// <summary>
        /// Adjust the X coordinate of all the given nodes to match the X coordinate of the confluence node.
        /// The operation will only be performed if there is only one confluence node. </summary>
        /// <returns> the number of nodes that were edited </returns>
        protected internal virtual int setNodeXToConfluenceX(IList <HydrologyNode> nodeList)
        {
            // First find the confluence node
            HydrologyNode confNode      = null;
            int           confNodeCount = 0;

            foreach (HydrologyNode node in nodeList)
            {
                if (node.getType() == HydrologyNode.NODE_TYPE_CONFLUENCE)
                {
                    confNode = node;
                    ++confNodeCount;
                }
            }
            int editCount = 0;

            if (confNodeCount == 1)
            {
                foreach (HydrologyNode node in nodeList)
                {
                    if (node != confNode)
                    {
                        // Set the coordinate...
                        node.setX(confNode.getX());
                        node.setDirty(true);
                        ++editCount;
                    }
                }
            }
            return(editCount);
        }
        /// <summary>
        /// Position the nodes evenly between the end nodes. </summary>
        /// <returns> the number of nodes that were edited </returns>
        protected internal virtual int positionNodesEvenlyBetweenEndNodes(IList <HydrologyNode> nodeList)
        {
            if (nodeList.Count < 3)
            {
                return(0);
            }
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            string routine = this.GetType().FullName + "positionNodesEvenlyBetweenEndNodes";
            // First make a copy of the list so that the sort does not change the original list
            IList <HydrologyNode> nodeListSorted = null;
            // Sort the list so that it is in the order from upstream to downstream
            int editCount = 0;

            try
            {
                nodeListSorted = sortNodesSequential(nodeList);
            }
            catch (Exception e)
            {
                // Likely not in a line
                Message.printWarning(1, routine, "Error positioning nodes (" + e + ").  Make sure that nodes are in a single reach with no branches.", this.__editorJFrame);
                Message.printWarning(3, routine, e);
                return(0);
            }
            HydrologyNode firstNode = nodeListSorted[0];
            HydrologyNode lastNode  = nodeListSorted[nodeListSorted.Count - 1];
            // Compute the delta between the first node and last node
            double dx = (lastNode.getX() - firstNode.getX()) / (nodeListSorted.Count - 1);
            double dy = (lastNode.getY() - firstNode.getY()) / (nodeListSorted.Count - 1);
            // Apply the delta to the middle nodes
            HydrologyNode node;

            for (int i = 1; i < nodeListSorted.Count - 1; i++)
            {
                node = nodeListSorted[i];
                node.setX(firstNode.getX() + dx * i);
                node.setY(firstNode.getY() + dy * i);
                node.setDirty(true);
                ++editCount;
            }
            return(editCount);
        }
        /// <summary>
        /// Responds to action performed events. </summary>
        /// <param name="e"> the ActionEvent that happened. </param>
        public virtual void actionPerformed(ActionEvent e)
        {
            string routine = "StateMod_RiverNetworkNode_JFrame.actionPerformed";

            if (Message.isDebugOn)
            {
                Message.printDebug(1, routine, "In actionPerformed: " + e.getActionCommand());
            }
            object source = e.getSource();

            if (source == __closeJButton)
            {
                saveCurrentRecord();
                int size = __riverNetworkNodesVector.Count;
                StateMod_RiverNetworkNode r = null;
                bool changed = false;
                for (int i = 0; i < size; i++)
                {
                    r = __riverNetworkNodesVector[i];
                    if (!changed && r.changed())
                    {
                        changed = true;
                    }
                    r.acceptChanges();
                }
                if (changed)
                {
                    __dataset.setDirty(StateMod_DataSet.COMP_RIVER_NETWORK, true);
                }
                if (__dataset_wm != null)
                {
                    __dataset_wm.closeWindow(StateMod_DataSet_WindowManager.WINDOW_RIVER_NETWORK);
                }
                else
                {
                    JGUIUtil.close(this);
                }
            }
            else if (source == __applyJButton)
            {
                saveCurrentRecord();
                int size = __riverNetworkNodesVector.Count;
                StateMod_RiverNetworkNode r = null;
                bool changed = false;
                for (int i = 0; i < size; i++)
                {
                    r = __riverNetworkNodesVector[i];
                    if (!changed && r.changed())
                    {
                        changed = true;
                    }
                    r.createBackup();
                }
                if (changed)
                {
                    __dataset.setDirty(StateMod_DataSet.COMP_RIVER_NETWORK, true);
                }
            }
            else if (source == __cancelJButton)
            {
                int size = __riverNetworkNodesVector.Count;
                StateMod_RiverNetworkNode r = null;
                for (int i = 0; i < size; i++)
                {
                    r = __riverNetworkNodesVector[i];
                    r.restoreOriginal();
                }
                if (__dataset_wm != null)
                {
                    __dataset_wm.closeWindow(StateMod_DataSet_WindowManager.WINDOW_RIVER_NETWORK);
                }
                else
                {
                    JGUIUtil.close(this);
                }
            }
            else if (source == __helpJButton)
            {
                // REVISIT HELP (JTS - 2003-08-18)
            }
            else if (source == __searchIDJRadioButton)
            {
                __searchName.setEditable(false);
                __searchID.setEditable(true);
            }
            else if (source == __searchNameJRadioButton)
            {
                __searchName.setEditable(true);
                __searchID.setEditable(false);
            }
            else if (source == __showOnMap_JButton)
            {
                GeoRecord geoRecord = getSelectedRiverNetworkNode().getGeoRecord();
                GRShape   shape     = geoRecord.getShape();
                __dataset_wm.showOnMap(getSelectedRiverNetworkNode(), "Node: " + getSelectedRiverNetworkNode().getID() + " - " + getSelectedRiverNetworkNode().getName(), new GRLimits(shape.xmin, shape.ymin, shape.xmax, shape.ymax), geoRecord.getLayer().getProjection());
            }
            else if (source == __showOnNetwork_JButton)
            {
                StateMod_Network_JFrame networkEditor = __dataset_wm.getNetworkEditor();
                if (networkEditor != null)
                {
                    HydrologyNode node = networkEditor.getNetworkJComponent().findNode(getSelectedRiverNetworkNode().getID(), false, false);
                    if (node != null)
                    {
                        __dataset_wm.showOnNetwork(getSelectedRiverNetworkNode(), "Node: " + getSelectedRiverNetworkNode().getID() + " - " + getSelectedRiverNetworkNode().getName(), new GRLimits(node.getX(), node.getY(), node.getX(), node.getY()));
                    }
                }
            }
            else if (source == __findNext)
            {
                searchWorksheet(__worksheet.getSelectedRow() + 1);
            }
            else if (source == __searchID || source == __searchName)
            {
                searchWorksheet(0);
            }
        }