/// <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_ReservoirAreaCap ra = (StateMod_ReservoirAreaCap)_data.get(row);

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

            case COL_CAPACITY:
                return(new double?(ra.getConten()));

            case COL_AREA:
                return(new double?(ra.getSurarea()));

            case COL_SEEPAGE:
                return(new double?(ra.getSeepage()));

            default:
                return("");
            }
        }
        /// <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_ReservoirAreaCap ra = (StateMod_ReservoirAreaCap)_data.get(row);

            // necessary for worksheets that display area capacities 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(ra.getCgoto());

            case COL_CAPACITY:
                return(new double?(ra.getConten()));

            case COL_AREA:
                return(new double?(ra.getSurarea()));

            case COL_SEEPAGE:
                return(new double?(ra.getSeepage()));

            default:
                return("");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes a list of StateMod_ReservoirAreaCap 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 list of objects to write. </param>
        /// <param name="newComments"> new comments to add at the top of the file. </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_ReservoirAreaCap> data, java.util.List<String> newComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReservoirAreaCap> data, IList <string> newComments)
        {
            string routine = "StateMod_ReservoirAreaCap.writeListFile";
            int    size    = 0;

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

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

            fields.Add("ReservoirID");
            fields.Add("Content");
            fields.Add("Area");
            fields.Add("Seepage");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateMod_Util.COMP_RESERVOIR_AREA_CAP;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = (string)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_ReservoirAreaCap area = null;

            string[]       line = new string[fieldCount];
            IList <string> commentIndicators = new List <string>(1);

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

            ignoredCommentIndicators.Add("#>");
            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, "");
                newComments2.Insert(1, "StateMod reservoir content/area/seepage data as a delimited list file.");
                newComments2.Insert(2, "See also the associated station, account, precipitation station,");
                newComments2.Insert(3, "evaporation station, 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++)
                {
                    area = (StateMod_ReservoirAreaCap)data[i];

                    line[0] = StringUtil.formatString(area.getCgoto(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(area.getConten(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(area.getSurarea(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(area.getSeepage(), formats[3]).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();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Check the GUI state.  In particular, indicate whether the graph buttons should
        /// be enabled.
        /// </summary>
        private void checkGUIState()
        {
            IList <StateMod_ReservoirAreaCap> rv = __currentRes.getAreaCaps();

            if ((rv != null) && (rv.Count > 0))
            {
                bool area_ok = true, seepage_ok = true;
                // Check for data all one value...
                int size = rv.Count;
                StateMod_ReservoirAreaCap ac = null;
                double value;
                // REVISIT SAM 2006-08-20
                // JFreeChart has a problem when the values are the same as
                // the previous values.  However, for now, increment the values
                // slightly when graphing rather than disabling the graph.
                // Go ahead and disable if all values are the same.
                double area0 = 0.0, seepage0 = 0.0;
                bool   area_all_same = true, seepage_all_same = true;
                for (int i = 0; i < size; i++)
                {
                    ac    = (StateMod_ReservoirAreaCap)rv[i];
                    value = ac.getSurarea();

                    /*
                     * if ( value == value_prev ) {
                     *      area_ok = false;
                     *      break;
                     * }
                     */
                    if (i == 0)
                    {
                        area0 = value;
                    }
                    else
                    {
                        if (value != area0)
                        {
                            area_all_same = false;
                        }
                    }
                }
                for (int i = 0; i < size; i++)
                {
                    ac    = (StateMod_ReservoirAreaCap)rv[i];
                    value = ac.getSeepage();

                    /*
                     * if ( value == value_prev ) {
                     *      seepage_ok = false;
                     *      break;
                     * }
                     */
                    if (i == 0)
                    {
                        seepage0 = value;
                    }
                    else
                    {
                        if (value != seepage0)
                        {
                            seepage_all_same = false;
                        }
                    }
                }
                if (area_all_same)
                {
                    area_ok = false;
                }
                if (seepage_all_same)
                {
                    seepage_ok = false;
                }
                JGUIUtil.setEnabled(__GraphArea_JButton, area_ok);
                JGUIUtil.setEnabled(__GraphSeepage_JButton, seepage_ok);
            }
            else
            {
                JGUIUtil.setEnabled(__GraphArea_JButton, false);
                JGUIUtil.setEnabled(__GraphSeepage_JButton, false);
            }
            // Only enable the graph buttons if the new charting package is in the
            // path.  This will allow for some graceful transition to distribution
            // of the new software.
            if (!IOUtil.classCanBeLoaded("org.jfree.chart.ChartPanel"))
            {
                JGUIUtil.setEnabled(__GraphArea_JButton, false);
                JGUIUtil.setEnabled(__GraphSeepage_JButton, false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a dataset to display in the chart.  Extract the values from the
        /// StateMod_Reservoir curve data.
        /// </summary>
        private DefaultTableXYDataset createDataset()
        {
            string routine = "StateMod_Reservoir_AreaCap_Graph_JFrame.createDataSet";
            DefaultTableXYDataset dataset = new DefaultTableXYDataset();

            IList <StateMod_ReservoirAreaCap> v = __res.getAreaCaps();
            int size = 0;

            if (v != null)
            {
                size = v.Count;
            }
            XYSeries series = new XYSeries("Reservoir " + __res.getID() + " (" + __res.getName() + ") Content/" + __type + " Curve", false, false);
            StateMod_ReservoirAreaCap ac = null;
            // Speed up checks in loop...
            bool do_area = true;

            if (__type.Equals("Seepage", StringComparison.OrdinalIgnoreCase))
            {
                do_area = false;
            }
            double value_prev = -10000000.0, value = 0.0, value2 = 0.0;
            double content     = 0.0;
            int    match_count = 0;

            for (int i = 0; i < size; i++)
            {
                ac = (StateMod_ReservoirAreaCap)v[i];
                // Curves will often have a very large content to protect
                // against out of bounds for interpolation.  However, if this
                // point is graphed, it causes the other values to appear
                // miniscule.  Therefore, omit the last point if it is much
                // larger than the previous value.
                if ((size > 4) && (i == (size - 1)) && ac.getConten() > 9000000.0)
                {
                    Message.printStatus(2, routine, "Skipping last point.  Seems to be very large bounding" + " value and might skew the graph.");
                    continue;
                }
                // Add X first, then Y...
                if (do_area)
                {
                    value = ac.getSurarea();
                }
                else
                {
                    value = ac.getSeepage();
                }
                if (value == value_prev)
                {
                    // This is needed because JFreeChart will not allow
                    // adjacent X values to be the same.
                    ++match_count;
                    value2 = value + match_count * .00001;
                }
                else
                {
                    value2 = value;
                }
                content = ac.getConten();
                // REVISIT SAM 2006-08-20
                // Not sure if content needs to be checked the same way for
                // duplicates.
                Message.printStatus(2, routine, "X=" + value2 + " y=" + content);
                series.add(value2, content);
                value_prev = value;
            }
            dataset.addSeries(series);

            return(dataset);
        }