Ejemplo n.º 1
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_ReservoirRight rr = (StateMod_ReservoirRight)_data.get(row);

            // necessary for table models that display rights 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(rr.getCgoto());

            case COL_RIGHT_ID:
                return(rr.getID());

            case COL_RIGHT_NAME:
                return(rr.getName());

            case COL_STRUCT_ID:
                return(rr.getCgoto());

            case COL_ADMIN_NUM:
                return(rr.getRtem());

            case COL_DCR_AMT:
                return(new double?(rr.getDcrres()));

            case COL_ON_OFF:
                return(new int?(rr.getSwitch()));

            case COL_ACCOUNT_DIST:
                return(new int?(rr.getIresco()));

            case COL_RIGHT_TYPE:
                return(new int?(rr.getItyrstr()));

            case COL_FILL_TYPE:
                return(new int?(rr.getN2fill()));

            case COL_OOP_RIGHT:
                return(rr.getCopid());

            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_ReservoirRight rr = (StateMod_ReservoirRight)_data.get(row);

            switch (col)
            {
            case COL_RIGHT_ID:
                return(rr.getID());

            case COL_RIGHT_NAME:
                return(rr.getName());

            case COL_STRUCT_ID:
                return(rr.getCgoto());

            case COL_ADMIN_NUM:
                return(rr.getRtem());

            case COL_DCR_AMT:
                return(new double?(rr.getDcrres()));

            case COL_ON_OFF:
                return(new int?(rr.getSwitch()));

            case COL_ACCOUNT_DIST:
                return(new int?(rr.getIresco()));

            case COL_RIGHT_TYPE:
                return(new int?(rr.getItyrstr()));

            case COL_FILL_TYPE:
                return(new int?(rr.getN2fill()));

            case COL_OOP_RIGHT:
                return(rr.getCopid());

            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()
        {
            string routine = "StateMod_Reservoir_Right_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_ReservoirRight> v = (java.util.List<StateMod_ReservoirRight>)__worksheet.getAllData();
            IList <StateMod_ReservoirRight> v = (IList <StateMod_ReservoirRight>)__worksheet.getAllData();

            int size = v.Count;
            StateMod_ReservoirRight right = null;
            string warning = "";
            string id;
            string name;
            string resID;
            string adminNum;
            int    fatalCount = 0;

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

                id       = right.getID();
                name     = right.getName();
                resID    = right.getCgoto();
                adminNum = right.getRtem();
                //copID = right.getCopid();

                if (id.Length > 12)
                {
                    warning += "\nReservoir right ID (" + id + ") is "
                               + "longer than 12 characters.";
                    fatalCount++;
                }

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

                if (name.Length > 24)
                {
                    warning += "\nReservoir name (" + name + ") is "
                               + "longer than 24 characters.";
                    fatalCount++;
                }

                if (resID.Length > 12)
                {
                    warning += "\nReservoir ID associated with right ("
                               + resID + ") is longer than 12 characters.";
                }

                if (!StringUtil.isDouble(adminNum))
                {
                    warning += "\nAdministration number (" + adminNum + ") is not a number.";
                    fatalCount++;
                }

                /* REVISIT SAM 2004-10-29 These don't need to be checked
                 * because they are enforced by the table model?
                 *
                 * switchx = right.getSwitch();
                 * iresco = right.getIresco();
                 * ityrstr = right.getItyrstr();
                 * n2fill = right.getN2fill();
                 *
                 * if (switchx == null) {
                 *      warning += "\nMust fill in On/Off switch.";
                 *      fatalCount++;
                 * }
                 * if (iresco == null) {
                 *      warning += "\nMust fill in Accounts served.";
                 *      fatalCount++;
                 * }
                 * if (ityrstr == null) {
                 *      warning += "\nMust fill in Right type.";
                 *      fatalCount++;
                 * }
                 * if (n2fill == null) {
                 *      warning += "\nMust fill in Fill type.";
                 *      fatalCount++;
                 * }
                 */

                // copid is not handled yet

                // decreed amount is not checked to be a double because that
                // is enforced by the worksheet and its table model
            }
            // 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);
            }
        }
        /// <summary>
        /// Responds to action performed events. </summary>
        /// <param name="e"> the ActionEvent that happened. </param>
        public virtual void actionPerformed(ActionEvent e)
        {
            string routine = "StateMod_Reservoir_Right_JFrame::actionPerformed";

            string action = e.getActionCommand();

            if (action.Equals(__BUTTON_ADD_RIGHT))
            {
                StateMod_ReservoirRight aRight = new StateMod_ReservoirRight();
                aRight._isClone = true;
                StateMod_ReservoirRight last = (StateMod_ReservoirRight)__worksheet.getLastRowData();

                if (last == null)
                {
                    aRight.setID(StateMod_Util.createNewID(__currentRes.getID()));
                    aRight.setCgoto(__currentRes.getID());
                }
                else
                {
                    aRight.setID(StateMod_Util.createNewID(last.getID()));
                    aRight.setCgoto(last.getCgoto());
                }
                __worksheet.scrollToLastRow();
                __worksheet.addRow(aRight);
                __worksheet.selectLastRow();
                __deleteRight.setEnabled(true);
            }
            else if (action.Equals(__BUTTON_DEL_RIGHT))
            {
                int row = __worksheet.getSelectedRow();
                if (row != -1)
                {
                    int x = (new ResponseJDialog(this, "Delete right", "Delete reservoir right?", ResponseJDialog.YES | ResponseJDialog.NO)).response();
                    if (x == ResponseJDialog.NO)
                    {
                        return;
                    }

                    __worksheet.cancelEditing();
                    __worksheet.deleteRow(row);
                    __deleteRight.setEnabled(false);
                }
                else
                {
                    Message.printWarning(1, routine, "Must select desired right to delete.");
                }
            }
            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 (e.getSource() == __helpJButton)
            {
                // REVISIT HELP (JTS - 2003-06-09)
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Write reservoir right information to output.  History header information
        /// is also maintained by calling this routine. </summary>
        /// <param name="infile"> input file from which previous history should be taken </param>
        /// <param name="outfile"> output file to which to write </param>
        /// <param name="theRights"> list of reservoir right to print </param>
        /// <param name="newComments"> addition comments which should be included in history </param>
        /// <param name="oldAdminNumFormat"> whether to use the old admin num format or not </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 writeStateModFile(String infile, String outfile, java.util.List<StateMod_ReservoirRight> theRights, java.util.List<String> newComments, boolean oldAdminNumFormat) throws Exception
        public static void writeStateModFile(string infile, string outfile, IList <StateMod_ReservoirRight> theRights, IList <string> newComments, bool oldAdminNumFormat)
        {
            IList <string> commentIndicators = new List <string>(1);

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

            ignoredCommentIndicators.Add("#>");
            string      routine = "StateMod_ReservoirRight.writeStateModFile";
            PrintWriter @out    = null;

            if (Message.isDebugOn)
            {
                Message.printDebug(2, routine, "Writing reservoir rights to file: " + outfile);
            }
            try
            {
                @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(infile), IOUtil.getPathUsingWorkingDir(outfile), newComments, commentIndicators, ignoredCommentIndicators, 0);

                string iline = null;
                string cmnt  = "#>";
                StateMod_ReservoirRight right = null;
                IList <object>          v     = new List <object>(10);
                string format_0 = null;
                string format_1 = null;
                if (oldAdminNumFormat)
                {
                    // Left justify...
                    format_0 = "%-12.12s%-24.24s%-12.12s    %-12.12s%8.0f%8d%8d%8d%8d%-12.12s";
                    format_1 = "%-12.12s%-24.24s%-12.12s    %-12.12s%8.2f%8d%8d%8d%8d%-12.12s";
                }
                else
                {
                    // Right justify...
                    format_0 = "%-12.12s%-24.24s%-12.12s    %12.12s%8.0f%8d%8d%8d%8d%-12.12s";
                    format_1 = "%-12.12s%-24.24s%-12.12s    %12.12s%8.2f%8d%8d%8d%8d%-12.12s";
                }

                @out.println(cmnt);
                @out.println(cmnt + " *******************************************************");
                @out.println(cmnt + "  StateMod Reservoir Right File");
                @out.println(cmnt);
                @out.println(cmnt + "  format:  (a12, a24, a12, F16.5, f8.0, 4i8, a12)");
                @out.println(cmnt);
                @out.println(cmnt + "  ID       cirsid:  Reservoir right ID");
                @out.println(cmnt + "  Name      namer:  Reservoir name");
                @out.println(cmnt + "  Res ID    cgoto:  Reservoir ID tied to this right");
                @out.println(cmnt + "  Admin #    rtem:  Administration number");
                @out.println(cmnt + "                    (small is senior).");
                @out.println(cmnt + "  Decree   dcrres:  Decreed amount (af)");
                @out.println(cmnt + "  On/Off   irsrsw:  Switch 0 = off,1 = on");
                @out.println(cmnt + "                    YYYY = on for years >= YYYY");
                @out.println(cmnt + "                    -YYYY = off for years > YYYY");
                @out.println(cmnt + "  Owner    iresco:  Ownership code");
                @out.println(cmnt + "                      >0, account to be filled");
                @out.println(cmnt + "                      <0, ownership go to 1st (n) accounts");
                @out.println(cmnt + "  Type     ityrsr:  Reservoir type");
                @out.println(cmnt + "                      1=Standard");
                @out.println(cmnt + "                      2=Out of priority water right");
                @out.println(cmnt + "  Fill #   n2fill:  Right type 1=1st fill, 2=2nd fill");
                @out.println(cmnt + "  Out ID    copid:  Out of priority associated operational ");
                @out.println(cmnt + "                      right  (when ityrsr=-1)");
                @out.println(cmnt);
                @out.println(cmnt + "    ID     Name                    Res ID            Admin #   Decree  On/Off  Owner   Type    Fill #  Out ID     ");
                @out.println(cmnt + "---------eb----------------------eb----------eb--------------eb------eb------eb------eb------eb------eb----------e");
                @out.println(cmnt);
                @out.println(cmnt + "EndHeader");
                @out.println(cmnt);

                int num = 0;
                if (theRights != null)
                {
                    num = theRights.Count;
                }
                for (int i = 0; i < num; i++)
                {
                    right = (StateMod_ReservoirRight)theRights[i];
                    if (right == null)
                    {
                        continue;
                    }
                    v.Clear();
                    v.Add(right.getID());
                    v.Add(right.getName());
                    v.Add(right.getCgoto());
                    v.Add(right.getRtem());
                    v.Add(new double?(right.getDcrres()));
                    v.Add(new int?(right.getSwitch()));
                    v.Add(new int?(right.getIresco()));
                    v.Add(new int?(right.getItyrstr()));
                    v.Add(new int?(right.getN2fill()));
                    v.Add(right.getCopid());
                    if (right.getDcrres() < 1.0)
                    {
                        // Use the format for a small right(8.2)...
                        iline = StringUtil.formatString(v, format_1);
                    }
                    else
                    {
                        // Default format 8.0...
                        iline = StringUtil.formatString(v, format_0);
                    }
                    @out.println(iline);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Writes a list of StateMod_ReservoirRight 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"> comments to write to 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_ReservoirRight> data, java.util.List<String> newComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReservoirRight> data, IList <string> newComments)
        {
            string routine = "StateMod_ReservoirRight.writeListFile";
            int    size    = 0;

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

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

            fields.Add("ID");
            fields.Add("Name");
            fields.Add("StructureID");
            fields.Add("AdministrationNumber");
            fields.Add("DecreedAmount");
            fields.Add("OnOff");
            fields.Add("AccountDistribution");
            fields.Add("Type");
            fields.Add("FillType");
            fields.Add("OopRight");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateMod_DataSet.COMP_RESERVOIR_RIGHTS;
            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;
            StateMod_ReservoirRight right             = 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();
            PrintWriter   @out   = null;

            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 rights as a delimited list file.");
                newComments2.Insert(2, "");
                @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++)
                {
                    right = (StateMod_ReservoirRight)data[i];

                    line[0] = StringUtil.formatString(right.getID(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(right.getName(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(right.getCgoto(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(right.getRtem(), formats[3]).Trim();
                    line[4] = StringUtil.formatString(right.getDcrres(), formats[4]).Trim();
                    line[5] = StringUtil.formatString(right.getSwitch(), formats[5]).Trim();
                    line[6] = StringUtil.formatString(right.getIresco(), formats[6]).Trim();
                    line[7] = StringUtil.formatString(right.getItyrstr(), formats[7]).Trim();
                    line[8] = StringUtil.formatString(right.getN2fill(), formats[8]).Trim();
                    line[9] = StringUtil.formatString(right.getCopid(), formats[9]).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();
                }
            }
        }