/// <summary>
        /// Clones the data object. </summary>
        /// <returns> a cloned object. </returns>
        public override object clone()
        {
            StateMod_ReservoirClimate rc = (StateMod_ReservoirClimate)base.clone();

            rc._isClone = true;
            return(rc);
        }
        /// <summary>
        /// Compares this object to another StateMod_Data object based on the sorted
        /// order from the StateMod_Data variables, and then by _type and _weight, in that order. </summary>
        /// <param name="data"> the object to compare against. </param>
        /// <returns> 0 if they are the same, 1 if this object is greater than the other object, or -1 if it is less. </returns>
        public virtual int CompareTo(StateMod_Data data)
        {
            int res = base.CompareTo(data);

            if (res != 0)
            {
                return(res);
            }

            StateMod_ReservoirClimate rc = (StateMod_ReservoirClimate)data;

            if (_type < rc._type)
            {
                return(-1);
            }
            else if (_type > rc._type)
            {
                return(1);
            }

            if (_weight < rc._weight)
            {
                return(-1);
            }
            else if (_weight > rc._weight)
            {
                return(1);
            }

            return(0);
        }
        /// <summary>
        /// Sets the value at the specified position to the specified value. </summary>
        /// <param name="value"> the value to set the cell to. </param>
        /// <param name="row"> the row of the cell for which to set the value. </param>
        /// <param name="col"> the col of the cell for which to set the value. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }
            double dval;
            StateMod_ReservoirClimate cl = (StateMod_ReservoirClimate)_data.get(row);

            switch (col)
            {
            case COL_RESERVOIR_ID:
                cl.setCgoto((string)value);
                break;

            case COL_STATION:
                string s     = (string)value;
                int    index = s.IndexOf(" - ", StringComparison.Ordinal);
                if (index > -1)
                {
                    s = s.Substring(0, index);
                }
                cl.setID(s);
                break;

            case COL_PCT_WEIGHT:
                dval = ((double?)value).Value;
                cl.setWeight(dval);
                break;
            }

            base.setValueAt(value, row, col);
        }
        /// <summary>
        /// Returns the data that should be placed in the JTable at the given row and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            StateMod_ReservoirClimate cl = (StateMod_ReservoirClimate)_data.get(row);

            // necessary for table models that display climate data for 1+
            // reservoirs, so that the -1st column (ID) can also be displayed.
            // By doing it this way, code can be shared between the two kinds of
            // table models and less maintenance is necessary.
            if (!__singleReservoir)
            {
                col--;
            }

            switch (col)
            {
            case COL_RESERVOIR_ID:
                return(cl.getCgoto());

            case COL_STATION:
                return(cl.getID());

            case COL_PCT_WEIGHT:
                return(new double?(cl.getWeight()));

            default:
                return("");
            }
        }
        /// <summary>
        /// Called when the cancel button is pressed.  This discards any changes made to the data objects.
        /// </summary>
        protected internal override void cancel()
        {
            StateMod_ReservoirClimate clim = null;
            int size = _data.Count;

            for (int i = 0; i < size; i++)
            {
                clim = (StateMod_ReservoirClimate)_data[i];
                clim.restoreOriginal();
            }
        }
        /// <summary>
        /// Called when the Apply button is pressed. This commits any changes to the data objects.
        /// </summary>
        protected internal override void apply()
        {
            StateMod_ReservoirClimate clim = null;
            int size = _data.Count;

            for (int i = 0; i < size; i++)
            {
                clim = (StateMod_ReservoirClimate)_data[i];
                clim.createBackup();
            }
        }
        /// <summary>
        /// Cancels any changes made to this object within a GUI since createBackup()
        /// was called and sets _original to null.
        /// </summary>
        public override void restoreOriginal()
        {
            StateMod_ReservoirClimate clim = (StateMod_ReservoirClimate)_original;

            base.restoreOriginal();

            _type     = clim._type;
            _weight   = clim._weight;
            _isClone  = false;
            _original = null;
        }
 /// <summary>
 /// Add climate. </summary>
 /// <param name="climate"> StateMod_ReservoirClimate to add. </param>
 public virtual void addClimate(StateMod_ReservoirClimate climate)
 {
     if (climate != null)
     {
         _climate_Vector.Add(climate);
         setDirty(true);
         if (!_isClone && _dataset != null)
         {
             _dataset.setDirty(StateMod_DataSet.COMP_RESERVOIR_STATIONS, true);
         }
     }
 }
        /// <summary>
        /// Tests to see if two diversion rights are equal.  Strings are compared with case sensitivity. </summary>
        /// <param name="rc"> the rc to compare. </param>
        /// <returns> true if they are equal, false otherwise. </returns>
        public virtual bool Equals(StateMod_ReservoirClimate rc)
        {
            if (!base.Equals(rc))
            {
                return(false);
            }

            if (_type == rc._type && _weight == rc._weight)
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Creates backups of all the data objects in the Vector so that changes can later be cancelled if necessary.
        /// </summary>
        protected internal override void createDataBackup()
        {
            StateMod_ReservoirClimate clim = null;
            int size = _data.Count;

            for (int i = 0; i < size; i++)
            {
                Message.printStatus(1, "", "climate1: " + _data[i]);
                Message.printStatus(1, "", "climate2: " + _data[i].GetType());
                clim = (StateMod_ReservoirClimate)_data[i];
                clim.createBackup();
            }
        }
        /// <summary>
        /// Constructor. </summary>
        /// <param name="data"> the data to display in the worksheet.  Can be null or empty, in
        /// which case an empty worksheet is shown. </param>
        /// <param name="titleString"> the String to display in the title of the GUI. </param>
        /// <param name="editable"> whether the data in the JFrame can be edited or not.  If true
        /// the data can be edited, if false they can not. </param>
        /// <param name="precip"> if true, then the climate stations to view are precip stations.
        /// If false, they are evap stations. </param>
        /// <exception cref="Exception"> if there is an error building the worksheet. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public StateMod_ReservoirClimate_Data_JFrame(java.util.List data, String titleString, boolean editable, boolean precip) throws Exception
        public StateMod_ReservoirClimate_Data_JFrame(System.Collections.IList data, string titleString, bool editable, bool precip) : base()
        {
            int j     = 0;
            int size  = 0;
            int size2 = 0;
            StateMod_Reservoir        r = null;
            StateMod_ReservoirClimate c = null;

            System.Collections.IList climates = null;
            System.Collections.IList v        = new List <object>();

            if (data != null)
            {
                size = data.Count;
            }

            for (int i = 0; i < size; i++)
            {
                r        = (StateMod_Reservoir)data[i];
                climates = r.getClimates();
                if (climates == null)
                {
                    continue;
                }

                size2 = climates.Count;

                for (j = 0; j < size2; j++)
                {
                    c = (StateMod_ReservoirClimate)climates[j];
                    if (c == null)
                    {
                        // skip
                    }
                    else if (!precip && c.getType() == StateMod_ReservoirClimate.CLIMATE_EVAP)
                    {
                        c.setCgoto(r.getID());
                        v.Add(c);
                    }
                    else if (precip && c.getType() == StateMod_ReservoirClimate.CLIMATE_PTPX)
                    {
                        c.setCgoto(r.getID());
                        v.Add(c);
                    }
                }
            }

            initialize(v, titleString, editable);
            setSize(377, getHeight());
        }
        private IList <StateMod_ReservoirClimate> getEvaporationStations(IList <StateMod_ReservoirClimate> stations)
        {
            IList <StateMod_ReservoirClimate> v = new List <StateMod_ReservoirClimate>();
            StateMod_ReservoirClimate         s = null;

            for (int i = 0; i < stations.Count; i++)
            {
                s = stations[i];
                if (s.getType() == StateMod_ReservoirClimate.CLIMATE_EVAP)
                {
                    v.Add(s);
                }
            }
            return(v);
        }
        /// <summary>
        /// Sets the value at the specified position to the specified value. </summary>
        /// <param name="value"> the value to set the cell to. </param>
        /// <param name="row"> the row of the cell for which to set the value. </param>
        /// <param name="col"> the col of the cell for which to set the value. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }
            double dval;
            StateMod_ReservoirClimate cl = (StateMod_ReservoirClimate)_data.get(row);

            // necessary for table models that display climate data for 1+
            // reservoirs, so that the -1st column (ID) can also be displayed.
            // By doing it this way, code can be shared between the two kinds of
            // table models and less maintenance is necessary.
            if (!__singleReservoir)
            {
                col--;
            }

            switch (col)
            {
            case COL_RESERVOIR_ID:
                cl.setCgoto((string)value);
                break;

            case COL_STATION:
                string s     = (string)value;
                int    index = s.IndexOf(" - ", StringComparison.Ordinal);
                if (index > -1)
                {
                    s = s.Substring(0, index);
                }
                cl.setID(s);
                break;

            case COL_PCT_WEIGHT:
                dval = ((double?)value).Value;
                cl.setWeight(dval);
                break;
            }

            if (!__singleReservoir)
            {
                col++;
            }

            base.setValueAt(value, row, col);
        }
        /// <summary>
        /// Returns the data that should be placed in the JTable
        /// at the given row and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            StateMod_ReservoirClimate cl = (StateMod_ReservoirClimate)_data.get(row);

            switch (col)
            {
            case COL_RESERVOIR_ID:
                return(cl.getCgoto());

            case COL_STATION:
                return(cl.getID());

            case COL_PCT_WEIGHT:
                return(new double?(cl.getWeight()));

            default:
                return("");
            }
        }
        /// <summary>
        /// Reponds to action performed events. </summary>
        /// <param name="e"> the ActionEvent that happened. </param>
        public virtual void actionPerformed(ActionEvent e)
        {
            string action = e.getActionCommand();

            if (action.Equals(__BUTTON_ADD_PRECIPITATION_STATION))
            {
                StateMod_ReservoirClimate aClimateNode = new StateMod_ReservoirClimate();
                aClimateNode._isClone = true;
                aClimateNode.setType(StateMod_ReservoirClimate.CLIMATE_PTPX);
                __worksheetP.addRow(aClimateNode);
                __worksheetP.scrollToLastRow();
                __worksheetP.selectLastRow();
                checkDeleteStationButton();
            }
            else if (action.Equals(__BUTTON_ADD_EVAPORATION_STATION))
            {
                StateMod_ReservoirClimate aClimateNode = new StateMod_ReservoirClimate();
                aClimateNode._isClone = true;
                aClimateNode.setType(StateMod_ReservoirClimate.CLIMATE_EVAP);
                __worksheetE.addRow(aClimateNode);
                __worksheetE.scrollToLastRow();
                __worksheetE.selectLastRow();
                checkDeleteStationButton();
            }
            else if (action.Equals(__BUTTON_DELETE_PRECIPITATION_STATION))
            {
                int rowP  = __worksheetP.getSelectedRow();
                int rowE  = __worksheetE.getSelectedRow();
                int count = 0;
                if (rowP > -1)
                {
                    count++;
                }
                if (rowE > -1)
                {
                    count++;
                }
                if (count > 0)
                {
                    string plural = "s";
                    if (count == 1)
                    {
                        plural = "";
                    }
                    int x = (new ResponseJDialog(this, "Delete climate station" + plural, "Delete climate station" + plural + "?", ResponseJDialog.YES | ResponseJDialog.NO)).response();
                    if (x == ResponseJDialog.NO)
                    {
                        return;
                    }
                    if (rowP > -1)
                    {
                        __worksheetP.deleteRow(rowP);
                        __deleteStation.setEnabled(false);
                        __worksheetP.scrollToLastRow();
                    }
                    if (rowE > -1)
                    {
                        __worksheetE.deleteRow(rowE);
                        __deleteStation.setEnabled(false);
                        __worksheetE.scrollToLastRow();
                    }
                }
            }
            else if (action.Equals(__BUTTON_CLOSE))
            {
                if (saveData())
                {
                    setVisible(false);
                    dispose();
                }
            }
            else if (action.Equals(__BUTTON_APPLY))
            {
                saveData();
            }
            else if (action.Equals(__BUTTON_CANCEL))
            {
                setVisible(false);
                dispose();
            }
            else if (action.Equals(__BUTTON_HELP))
            {
                // REVISIT HELP (JTS - 2003-06-09)
            }
        }
        /// <summary>
        /// Sets up the GUI.
        /// </summary>
        public virtual void setupGUI()
        {
            string routine = "setupGUI";

            addWindowListener(this);

            __addPrecip     = new JButton(__BUTTON_ADD_PRECIPITATION_STATION);
            __addEvap       = new JButton(__BUTTON_ADD_EVAPORATION_STATION);
            __deleteStation = new JButton(__BUTTON_DELETE_PRECIPITATION_STATION);
            __deleteStation.setEnabled(false);
            __helpJButton = new JButton(__BUTTON_HELP);
            __helpJButton.setEnabled(false);
            __closeJButton = new JButton(__BUTTON_CLOSE);
            JButton cancelJButton = new JButton(__BUTTON_CANCEL);
            JButton applyJButton  = new JButton(__BUTTON_APPLY);

            GridBagLayout gb       = new GridBagLayout();
            JPanel        bigPanel = new JPanel();

            bigPanel.setLayout(gb);

            FlowLayout fl = new FlowLayout(FlowLayout.RIGHT);
            JPanel     p1 = new JPanel();

            p1.setLayout(fl);

            GridLayout gl         = new GridLayout(2, 2, 1, 1);
            JPanel     info_panel = new JPanel();

            info_panel.setLayout(gl);

            JPanel main_panel = new JPanel();

            main_panel.setLayout(new BorderLayout());

            info_panel.add(new JLabel("Reservoir:"));
            info_panel.add(new JLabel(__currentRes.getID()));
            info_panel.add(new JLabel("Reservoir name:"));
            info_panel.add(new JLabel(__currentRes.getName()));

            if (__editable)
            {
                p1.add(__addPrecip);
                p1.add(__addEvap);
                p1.add(__deleteStation);
            }
            p1.add(applyJButton);
            p1.add(cancelJButton);
            //	p1.add(__helpJButton);
            p1.add(__closeJButton);

            PropList p = new PropList("StateMod_Reservoir_Climate_JFrame.JWorksheet");

            p.add("JWorksheet.ShowPopupMenu=true");
            p.add("JWorksheet.AllowCopy=true");
            p.add("JWorksheet.SelectionMode=SingleRowSelection");

            int[]            widthsP = null;
            JScrollWorksheet jswP    = null;
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<String> stations = StateMod_Util.createIdentifierListFromTS(combineData((java.util.List<RTi.TS.MonthTS>)__dataset.getComponentForComponentType(StateMod_DataSet.COMP_PRECIPITATION_TS_MONTHLY).getData(), (java.util.List<RTi.TS.MonthTS>)__dataset.getComponentForComponentType(StateMod_DataSet.COMP_EVAPORATION_TS_MONTHLY).getData()), true, null);
            IList <string> stations = StateMod_Util.createIdentifierListFromTS(combineData((IList <MonthTS>)__dataset.getComponentForComponentType(StateMod_DataSet.COMP_PRECIPITATION_TS_MONTHLY).getData(), (IList <MonthTS>)__dataset.getComponentForComponentType(StateMod_DataSet.COMP_EVAPORATION_TS_MONTHLY).getData()), true, null);

            try
            {
                IList <StateMod_ReservoirClimate> temp   = getPrecipitationStations(__currentRes.getClimates());
                IList <StateMod_ReservoirClimate> clones = new List <StateMod_ReservoirClimate>();
                StateMod_ReservoirClimate         r      = null;
                int size = temp.Count;
                for (int i = 0; i < size; i++)
                {
                    r = temp[i];
                    clones.Add((StateMod_ReservoirClimate)r.clone());
                }

                __tableModelP = new StateMod_ReservoirClimate_TableModel(clones, __editable, true);
                StateMod_ReservoirClimate_CellRenderer crr = new StateMod_ReservoirClimate_CellRenderer(__tableModelP);

                jswP         = new JScrollWorksheet(crr, __tableModelP, p);
                __worksheetP = jswP.getJWorksheet();

                __worksheetP.setColumnJComboBoxValues(StateMod_ReservoirClimate_TableModel.COL_STATION, stations, true);

                widthsP = crr.getColumnWidths();
            }
            catch (Exception e)
            {
                Message.printWarning(1, routine, "Error building worksheet.", this);
                Message.printWarning(2, routine, e);
                jswP         = new JScrollWorksheet(0, 0, p);
                __worksheetP = jswP.getJWorksheet();
            }
            __worksheetP.setPreferredScrollableViewportSize(null);

            __worksheetP.setHourglassJFrame(this);
            __worksheetP.addMouseListener(this);
            __worksheetP.addKeyListener(this);

            int[]            widthsE = null;
            JScrollWorksheet jswE    = null;

            try
            {
                IList <StateMod_ReservoirClimate> temp   = getEvaporationStations(__currentRes.getClimates());
                IList <StateMod_ReservoirClimate> clones = new List <StateMod_ReservoirClimate>();
                StateMod_ReservoirClimate         r      = null;
                int size = temp.Count;
                for (int i = 0; i < size; i++)
                {
                    r = temp[i];
                    clones.Add((StateMod_ReservoirClimate)r.clone());
                }

                __tableModelE = new StateMod_ReservoirClimate_TableModel(clones, __editable, true);
                StateMod_ReservoirClimate_CellRenderer crr = new StateMod_ReservoirClimate_CellRenderer(__tableModelE);

                jswE         = new JScrollWorksheet(crr, __tableModelE, p);
                __worksheetE = jswE.getJWorksheet();

                __worksheetE.setColumnJComboBoxValues(StateMod_ReservoirClimate_TableModel.COL_STATION, stations, true);
                widthsE = crr.getColumnWidths();
            }
            catch (Exception e)
            {
                Message.printWarning(1, routine, "Error building worksheet.", this);
                Message.printWarning(2, routine, e);
                jswE         = new JScrollWorksheet(0, 0, p);
                __worksheetE = jswE.getJWorksheet();
            }
            __worksheetE.setPreferredScrollableViewportSize(null);

            __worksheetE.setHourglassJFrame(this);
            __worksheetE.addMouseListener(this);
            __worksheetE.addKeyListener(this);

            JPanel worksheets = new JPanel();

            worksheets.setLayout(gb);

            JPanel panelP = new JPanel();

            panelP.setLayout(gb);
            panelP.setBorder(BorderFactory.createTitledBorder("Precipitation Stations"));
            JGUIUtil.addComponent(panelP, jswP, 0, 0, 1, 1, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);

            JPanel panelE = new JPanel();

            panelE.setLayout(gb);
            panelE.setBorder(BorderFactory.createTitledBorder("Evaporation Stations"));
            JGUIUtil.addComponent(panelE, jswE, 0, 0, 1, 1, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);

            JGUIUtil.addComponent(worksheets, panelP, 0, 0, 1, 1, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);
            JGUIUtil.addComponent(worksheets, panelE, 0, 1, 1, 1, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);

            main_panel.add(worksheets, "Center");
            main_panel.add(p1, "South");

            // assemble parts
            JGUIUtil.addComponent(bigPanel, info_panel, 0, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);

            JGUIUtil.addComponent(bigPanel, main_panel, 0, 1, 10, 10, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.SOUTH);
            __addEvap.addActionListener(this);
            __addPrecip.addActionListener(this);
            __deleteStation.addActionListener(this);
            __helpJButton.addActionListener(this);
            __closeJButton.addActionListener(this);
            applyJButton.addActionListener(this);
            cancelJButton.addActionListener(this);

            getContentPane().add(bigPanel);

            JPanel bottomJPanel = new JPanel();

            bottomJPanel.setLayout(gb);
            __messageJTextField = new JTextField();
            __messageJTextField.setEditable(false);
            JGUIUtil.addComponent(bottomJPanel, __messageJTextField, 0, 0, 7, 1, 1.0, 0.0, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
            __statusJTextField = new JTextField(5);
            __statusJTextField.setEditable(false);
            JGUIUtil.addComponent(bottomJPanel, __statusJTextField, 7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NONE, GridBagConstraints.WEST);
            getContentPane().add("South", bottomJPanel);

            pack();
            setSize(650, 400);
            JGUIUtil.center(this);
            setVisible(true);

            if (widthsP != null)
            {
                __worksheetP.setColumnWidths(widthsP);
            }
            if (widthsE != null)
            {
                __worksheetE.setColumnWidths(widthsE);
            }
        }
        /// <summary>
        /// Saves the input back into the dataset. </summary>
        /// <returns> true if the data was saved successfuly.  False if not. </returns>
        private bool saveData()
        {
            string routine = "StateMod_Reservoir_Climate_JFrame.saveData";

            if (!__worksheetP.stopEditing())
            {
                // don't save if there are errors.
                Message.printWarning(1, routine, "There are errors in the " + "precipitation data " + "that must be corrected before data can be saved.", this);
                return(false);
            }
            if (!__worksheetE.stopEditing())
            {
                // don't save if there are errors.
                Message.printWarning(1, routine, "There are errors in the " + "evaporation data " + "that must be corrected before data can be saved.", this);
                return(false);
            }

            if (checkInput(__worksheetP, "Precipitation") > 0)
            {
                return(false);
            }
            if (checkInput(__worksheetE, "Evaporation") > 0)
            {
                return(false);
            }

            // if the Vectors are differently-sized, they're different
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_ReservoirClimate> wv1 = (java.util.List<StateMod_ReservoirClimate>)__worksheetP.getAllData();
            IList <StateMod_ReservoirClimate> wv1 = (IList <StateMod_ReservoirClimate>)__worksheetP.getAllData();   // w for worksheet
            IList <StateMod_ReservoirClimate> rv1 = getPrecipitationStations(__currentRes.getClimates());
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_ReservoirClimate> wv2 = (java.util.List<StateMod_ReservoirClimate>)__worksheetE.getAllData();
            IList <StateMod_ReservoirClimate> wv2 = (IList <StateMod_ReservoirClimate>)__worksheetE.getAllData();   // w for worksheet
            IList <StateMod_ReservoirClimate> rv2 = getEvaporationStations(__currentRes.getClimates());

            bool needToSave1 = !(StateMod_ReservoirClimate.Equals(wv1, rv1));
            bool needToSave2 = !(StateMod_ReservoirClimate.Equals(wv2, rv2));

            Message.printStatus(1, routine, "Saving Precip? .......[" + needToSave1 + "]");
            Message.printStatus(1, routine, "Saving Evap? .........[" + needToSave2 + "]");

            if (!needToSave1 && !needToSave2)
            {
                // there's nothing different -- users may even have deleted
                // some rights and added back in identical values
                return(true);
            }

            int size = wv1.Count;
            IList <StateMod_ReservoirClimate> clone = new List <StateMod_ReservoirClimate>();
            StateMod_ReservoirClimate         r     = null;
            StateMod_ReservoirClimate         cr    = null;

            for (int i = 0; i < size; i++)
            {
                r           = wv1[i];
                cr          = (StateMod_ReservoirClimate)r.clone();
                cr._isClone = false;
                clone.Add(cr);
            }

            size = wv2.Count;
            for (int i = 0; i < size; i++)
            {
                r           = wv2[i];
                cr          = (StateMod_ReservoirClimate)r.clone();
                cr._isClone = false;
                clone.Add(cr);
            }

            __currentRes.setClimates(clone);
            __dataset.setDirty(StateMod_DataSet.COMP_DIVERSION_STATIONS, true);
            return(true);
        }
        /// <summary>
        /// Writes a list of StateMod_ReservoirClimate objects to a list file.  A header
        /// is printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the Vector of objects to write. </param>
        /// <param name="componentType"> one of either StateMod_DataSet.COMP_RESERVOIR_PRECIP_STATIONS or
        /// StateMod_DataSet.COMP_RESERVOIR_EVAP_STATIONS. </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateMod_ReservoirClimate> data, java.util.List<String> newComments, int componentType) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReservoirClimate> data, IList <string> newComments, int componentType)
        {
            string routine = "StateMod_ReservoirClimate.writeListFile";
            int    size    = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("ReservoirID");
            fields.Add("StationID");
            fields.Add("PercentWeight");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = componentType;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = fields[i];
                names[i]   = StateMod_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateMod_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int         j    = 0;
            PrintWriter @out = null;
            StateMod_ReservoirClimate cli = null;
            IList <string>            commentIndicators = new List <string>(1);

            commentIndicators.Add("#");
            IList <string> ignoredCommentIndicators = new List <string>(1);

            ignoredCommentIndicators.Add("#>");
            string[]      line   = new string[fieldCount];
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  Do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (newComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(newComments);
                }
                newComments2.Insert(0, "");
                if (componentType == StateMod_DataSet.COMP_RESERVOIR_STATION_EVAP_STATIONS)
                {
                    newComments2.Insert(1, "StateMod reservoir evaporation station assignment as a delimited list file.");
                    newComments2.Insert(2, "See also the associated station, account, precipitation station,");
                }
                else if (componentType == StateMod_DataSet.COMP_RESERVOIR_STATION_PRECIP_STATIONS)
                {
                    newComments2.Insert(1, "StateMod reservoir precipitation station assignment as a delimited list file.");
                    newComments2.Insert(2, "See also the associated station, account, evaporation station,");
                }
                newComments2.Insert(3, "content/area/seepage, and collection files.");
                newComments2.Insert(4, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    if (i > 0)
                    {
                        buffer.Append(delimiter);
                    }
                    buffer.Append("\"" + names[i] + "\"");
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    cli = (StateMod_ReservoirClimate)data[i];

                    line[0] = StringUtil.formatString(cli.getCgoto(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(cli.getID(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(cli.getWeight(), formats[2]).Trim();

                    buffer = new StringBuilder();
                    for (j = 0; j < fieldCount; j++)
                    {
                        if (j > 0)
                        {
                            buffer.Append(delimiter);
                        }
                        if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                        {
                            line[j] = "\"" + line[j] + "\"";
                        }
                        buffer.Append(line[j]);
                    }

                    @out.println(buffer.ToString());
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
        /// <summary>
        /// Read reservoir information in and store in a Vector. </summary>
        /// <param name="filename"> Name of file to read. </param>
        /// <exception cref="Exception"> if there is an error reading the file. </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public static java.util.List<StateMod_Reservoir> readStateModFile(String filename) throws Exception
        public static IList <StateMod_Reservoir> readStateModFile(string filename)
        {
            string routine = "StateMod_Reservoir.readStateModFile";
            IList <StateMod_Reservoir> theReservoirs = new List <StateMod_Reservoir>();
            string         iline = null;
            IList <object> v     = new List <object>(9);

            int[]                     format_0   = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING };
            int[]                     format_0w  = new int[] { 12, 24, 12, 8, 8, 1, 12 };
            int[]                     format_1   = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER };
            int[]                     format_1w  = new int[] { 24, 8, 8, 8, 8, 8, 8, 8, 8 };
            int[]                     format_2   = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER };
            int[]                     format_2w  = new int[] { 12, 12, 8, 8, 8, 8 };
            int[]                     format_3   = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE };
            int[]                     format_3w  = new int[] { 24, 12, 8 };
            int[]                     format_4   = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE };
            int[]                     format_4w  = new int[] { 24, 8, 8, 8 };
            StreamReader              @in        = null;
            StateMod_Reservoir        aReservoir = null;
            StateMod_ReservoirAccount anAccount  = null;
            StateMod_ReservoirClimate anEvap     = null;
            StateMod_ReservoirClimate aPtpx      = null;
            int i = 0;

            if (Message.isDebugOn)
            {
                Message.printDebug(10, routine, "in SMParseResFile reading file: " + filename);
            }
            int line_count = 0;

            try
            {
                @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename));
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    ++line_count;
                    // check for comments
                    if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0)
                    {
                        continue;
                    }

                    // allocate new reservoir node
                    aReservoir = new StateMod_Reservoir();

                    // line 1
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line 1: " + iline);
                    }
                    StringUtil.fixedRead(iline, format_0, format_0w, v);
                    aReservoir.setID(((string)v[0]).Trim());
                    aReservoir.setName(((string)v[1]).Trim());
                    aReservoir.setCgoto(((string)v[2]).Trim());
                    aReservoir.setSwitch((int?)v[3]);
                    aReservoir.setRdate((double?)v[4]);
                    aReservoir.setCresdy(((string)v[5]).Trim());

                    // line 2
                    iline = @in.ReadLine();
                    ++line_count;
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line 2: " + iline);
                    }
                    StringUtil.fixedRead(iline, format_1, format_1w, v);
                    aReservoir.setVolmin(((double?)v[0]));
                    aReservoir.setVolmax(((double?)v[1]));
                    aReservoir.setFlomax(((double?)v[2]));
                    aReservoir.setDeadst(((double?)v[3]));
                    int nowner = ((int?)v[4]).Value;
                    int nevap  = ((int?)v[5]).Value;
                    int nptpx  = ((int?)v[6]).Value;
                    int nrange = ((int?)v[7]).Value;

                    // get the owner's information
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "Number of owners: " + nowner);
                    }
                    for (i = 0; i < nowner; i++)
                    {
                        iline = @in.ReadLine();
                        ++line_count;
                        StringUtil.fixedRead(iline, format_2, format_2w, v);
                        anAccount = new StateMod_ReservoirAccount();
                        // Account ID is set to the numerical count (StateMod uses the number)
                        anAccount.setID("" + (i + 1));
                        anAccount.setName(((string)v[0]).Trim());
                        anAccount.setOwnmax(((double?)v[1]));
                        anAccount.setCurown(((double?)v[2]));
                        anAccount.setPcteva(((double?)v[3]));
                        anAccount.setN2own(((int?)v[4]));
                        aReservoir.addAccount(anAccount);
                    }

                    // get the evaporation information
                    for (i = 0; i < nevap; i++)
                    {
                        iline = @in.ReadLine();
                        ++line_count;
                        StringUtil.fixedRead(iline, format_3, format_3w, v);
                        anEvap = new StateMod_ReservoirClimate();
                        anEvap.setID(((string)v[0]).Trim());
                        anEvap.setType(StateMod_ReservoirClimate.CLIMATE_EVAP);
                        anEvap.setWeight(((double?)v[1]));
                        aReservoir.addClimate(anEvap);
                    }

                    // get the precipitation information
                    for (i = 0; i < nptpx; i++)
                    {
                        iline = @in.ReadLine();
                        ++line_count;
                        StringUtil.fixedRead(iline, format_3, format_3w, v);
                        aPtpx = new StateMod_ReservoirClimate();
                        aPtpx.setID(((string)v[0]).Trim());
                        aPtpx.setType(StateMod_ReservoirClimate.CLIMATE_PTPX);
                        aPtpx.setWeight(((double?)v[1]));
                        aReservoir.addClimate(aPtpx);
                    }

                    // get the area capacity information
                    for (i = 0; i < nrange; i++)
                    {
                        iline = @in.ReadLine();
                        ++line_count;
                        StringUtil.fixedRead(iline, format_4, format_4w, v);
                        StateMod_ReservoirAreaCap anAreaCap = new StateMod_ReservoirAreaCap();
                        anAreaCap.setConten(((double?)v[0]));
                        anAreaCap.setSurarea(((double?)v[1]));
                        anAreaCap.setSeepage(((double?)v[2]));
                        aReservoir.addAreaCap(anAreaCap);
                    }

                    // add the reservoir to the vector of reservoirs
                    theReservoirs.Add(aReservoir);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, "Error reading reservoir stations in line " + line_count);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            return(theReservoirs);
        }
Beispiel #20
0
        /// <summary>
        /// Returns the data that should be placed in the JTable at the given row and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            StateMod_Reservoir r = (StateMod_Reservoir)_data.get(row);

            switch (col)
            {
            case COL_ID:
                return(r.getID());

            case COL_NAME:
                return(r.getName());

            case COL_NODE_ID:
                return(r.getCgoto());

            case COL_SWITCH:
                return(new int?(r.getSwitch()));

            case COL_ONE_FILL_DATE:
                return(new int?((int)r.getRdate()));

            case COL_MIN_CONTENT:
                return(new double?(r.getVolmin()));

            case COL_MAX_CONTENT:
                return(new double?(r.getVolmax()));

            case COL_MAX_RELEASE:
                return(new double?(r.getFlomax()));

            case COL_DEAD_STORAGE:
                return(new double?(r.getDeadst()));

            case COL_DAILY_ID:
                return(r.getCresdy());

            case COL_NUM_OWNERS:
                return(new int?(r.getNowner()));

            case COL_NUM_PRECIP_STA:
                int nptpx = StateMod_ReservoirClimate.getNumPrecip(r.getClimates());
                return(new int?(nptpx));

            case COL_NUM_EVAP_STA:
                int nevap = StateMod_ReservoirClimate.getNumEvap(r.getClimates());
                return(new int?(nevap));

            case COL_NUM_CURVE_ROWS:
                System.Collections.IList v = r.getAreaCaps();
                if (v == null)
                {
                    return(new int?(0));
                }
                else
                {
                    return(new int?(v.Count));
                }

            default:
                return("");
            }
        }
        /// <summary>
        /// Checks the data to make sure that all the data are valid. </summary>
        /// <returns> 0 if the data are valid, 1 if errors exist and -1 if non-fatal errors
        /// exist. </returns>
        private int checkInput(JWorksheet worksheet, string name)
        {
            string routine = "StateMod_Reservoir_Climate_JFrame.checkInput";
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_ReservoirClimate> v = (java.util.List<StateMod_ReservoirClimate>)worksheet.getAllData();
            IList <StateMod_ReservoirClimate> v = (IList <StateMod_ReservoirClimate>)worksheet.getAllData();

            int size = v.Count;
            StateMod_ReservoirClimate acct = null;
            string warning = "";
            string id;
            int    fatalCount = 0;

            for (int i = 0; i < size; i++)
            {
                acct = (v[i]);

                id = acct.getID();

                if (id.Length > 12)
                {
                    warning += "\n" + name + " reservoir climate ID ("
                               + id + ") is "
                               + "longer than 12 characters.";
                    fatalCount++;
                }

                if (id.IndexOf(" ", StringComparison.Ordinal) > -1 || id.IndexOf("-", StringComparison.Ordinal) > -1)
                {
                    warning += "\n" + name + " reservoir climate ID ("
                               + id + ") cannot "
                               + "contain spaces or dashes.";
                    fatalCount++;
                }

                // the rest are handled automatically by the worksheet
            }
            // REVISIT - if daily time series are supplied, check for time series
            // and allow creation if not available.
            if (warning.Length > 0)
            {
                warning += "\nCorrect or Cancel.";
                Message.printWarning(1, routine, warning, this);
                if (fatalCount > 0)
                {
                    // Fatal errors...
                    Message.printStatus(1, routine, "Returning 1 from checkInput()");
                    return(1);
                }
                else
                {         // Nonfatal errors...
                    Message.printStatus(1, routine, "Returning -1 from checkInput()");
                    return(-1);
                }
            }
            else
            {     // No errors...
                Message.printStatus(1, routine, "Returning 0 from checkInput()");
                return(0);
            }
        }