Esempio n. 1
0
        /// <summary>
        /// Clones the data object. </summary>
        /// <returns> a cloned object. </returns>
        public override object clone()
        {
            StateMod_ReservoirRight right = (StateMod_ReservoirRight)base.clone();

            right._isClone = true;
            return(right);
        }
        /// <summary>
        /// Performs data checks on reservoir right data. </summary>
        /// <param name="props"> A property list for specific properties
        /// on checking this data. </param>
        /// <param name="data_vector"> Vector of data to check. </param>
        private void checkReservoirRightData(PropList props, System.Collections.IList data_vector)
        {
            //	 Create elements for the checks and check file
            string[] header = StateMod_ReservoirRight.getDataHeader();
            System.Collections.IList data = new List <object>();
            string title = "Reservoir Right";

            // Perform the general validation using the Data Table Model
            StateMod_Data_TableModel tm = new StateMod_ReservoirRight_Data_TableModel(data_vector, false);

            System.Collections.IList @checked = performDataValidation(tm, title);
            //String [] columnHeader = getDataTableModelColumnHeader( tm );
            string[] columnHeader = getColumnHeader(tm);

            // Do specific checks
            int size = 0;

            if (data_vector != null)
            {
                size = data_vector.Count;
            }
            data = doSpecificDataChecks(data_vector, props);
            // Add the data and checks to the check file.
            // Provides basic header information for this data check table
            string info = "The following " + title + " (" + data.Count +
                          " out of " + size + ") have no .....";

            // Create data models for Check file
            CheckFile_DataModel dm     = new CheckFile_DataModel(data, header, title, info, data.Count, size);
            CheckFile_DataModel gen_dm = new CheckFile_DataModel(@checked, columnHeader, title + " Missing or Invalid Data", "", __gen_problems, size);

            __check_file.addData(dm, gen_dm);
        }
        /// <summary>
        /// Read reservoir right information in and store in a list. </summary>
        /// <param name="filename"> Name of file to read. </param>
        /// <returns> list of reservoir right data </returns>
        /// <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_ReservoirRight> readStateModFile(String filename) throws Exception
        public static IList <StateMod_ReservoirRight> readStateModFile(string filename)
        {
            string routine = "StateMod_ReservoirRight.readStateModFile";
            IList <StateMod_ReservoirRight> theRights = new List <StateMod_ReservoirRight>();

            int[]                   format_0  = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_STRING };
            int[]                   format_0w = new int[] { 12, 24, 12, 16, 8, 8, 8, 8, 8, 12 };
            string                  iline     = null;
            IList <object>          v         = new List <object>(10);
            StreamReader            @in       = null;
            StateMod_ReservoirRight aRight    = null;

            Message.printStatus(2, routine, "Reading reservoir rights file: " + filename);

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

                    aRight = new StateMod_ReservoirRight();

                    StringUtil.fixedRead(iline, format_0, format_0w, v);
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "iline: " + iline);
                    }
                    aRight.setID(((string)v[0]).Trim());
                    aRight.setName(((string)v[1]).Trim());
                    aRight.setCgoto(((string)v[2]).Trim());
                    aRight.setRtem(((string)v[3]).Trim());
                    aRight.setDcrres((double?)v[4]);
                    aRight.setSwitch((int?)v[5]);
                    aRight.setIresco((int?)v[6]);
                    aRight.setItyrstr((int?)v[7]);
                    aRight.setN2fill((int?)v[8]);
                    aRight.setCopid(((string)v[9]).Trim());
                    theRights.Add(aRight);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            return(theRights);
        }
Esempio n. 4
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("");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Compares this object to another StateMod_Data object based on the sorted
        /// order from the StateMod_Data variables, and then by rtem, dcrres, iresco,
        /// ityrstr, n2fill and copid, 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_ReservoirRight right = (StateMod_ReservoirRight)data;

            res = _rtem.CompareTo(right.getRtem());
            if (res != 0)
            {
                return(res);
            }

            if (_dcrres < right._dcrres)
            {
                return(-1);
            }
            else if (_dcrres > right._dcrres)
            {
                return(1);
            }

            if (_iresco < right._iresco)
            {
                return(-1);
            }
            else if (_iresco > right._iresco)
            {
                return(1);
            }

            if (_ityrstr < right._ityrstr)
            {
                return(-1);
            }
            else if (_ityrstr > right._ityrstr)
            {
                return(1);
            }

            if (_n2fill < right._n2fill)
            {
                return(-1);
            }
            else if (_n2fill > right._n2fill)
            {
                return(1);
            }

            res = _copid.CompareTo(right._copid);
            return(res);
        }
        /// <summary>
        /// Called when the cancel button is pressed.  This discards any changes made to
        /// the data objects.
        /// </summary>
        protected internal override void cancel()
        {
            StateMod_ReservoirRight right = null;
            int size = _data.Count;

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

            for (int i = 0; i < size; i++)
            {
                right = (StateMod_ReservoirRight)_data[i];
                right.createBackup();
            }
        }
        /// <summary>
        /// Clones the data object. </summary>
        /// <returns> a cloned object. </returns>
        //public override object clone()
        //{
        //	StateMod_ReservoirRight right = (StateMod_ReservoirRight)base.clone();
        //	right._isClone = true;
        //	return right;
        //}

        /// <summary>
        /// Compares this object to another StateMod_Data object based on the sorted
        /// order from the StateMod_Data variables, and then by rtem, dcrres, iresco,
        /// ityrstr, n2fill and copid, 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_ReservoirRight right = (StateMod_ReservoirRight)data;

        //	res = _rtem.CompareTo(right.getRtem());
        //	if (res != 0)
        //	{
        //		return res;
        //	}

        //	if (_dcrres < right._dcrres)
        //	{
        //		return -1;
        //	}
        //	else if (_dcrres > right._dcrres)
        //	{
        //		return 1;
        //	}

        //	if (_iresco < right._iresco)
        //	{
        //		return -1;
        //	}
        //	else if (_iresco > right._iresco)
        //	{
        //		return 1;
        //	}

        //	if (_ityrstr < right._ityrstr)
        //	{
        //		return -1;
        //	}
        //	else if (_ityrstr > right._ityrstr)
        //	{
        //		return 1;
        //	}

        //	if (_n2fill < right._n2fill)
        //	{
        //		return -1;
        //	}
        //	else if (_n2fill > right._n2fill)
        //	{
        //		return 1;
        //	}

        //	res = _copid.CompareTo(right._copid);
        //	return res;
        //}

        /// <summary>
        /// Creates a backup of the current data object and stores it in _original,
        /// for use in determining if an object was changed inside of a GUI.
        /// </summary>
        //public virtual void createBackup()
        //{
        //	_original = (StateMod_ReservoirRight)clone();
        //	((StateMod_ReservoirRight)_original)._isClone = false;
        //	_isClone = true;
        //}

        /// <summary>
        /// Compare two rights lists and see if they are the same. </summary>
        /// <param name="v1"> the first list of StateMod_ReservoirRight s to check.  Cannot be null. </param>
        /// <param name="v2"> the second list of StateMod_ReservoirRight s to check.  Cannot be null. </param>
        /// <returns> true if they are the same, false if not. </returns>
        //public static bool Equals(IList<StateMod_ReservoirRight> v1, IList<StateMod_ReservoirRight> v2)
        //{
        //	StateMod_ReservoirRight r1;
        //	StateMod_ReservoirRight r2;
        //	if (v1.Count != v2.Count)
        //	{
        //		//Message.printStatus(2, routine, "Lists are different sizes");
        //		return false;
        //	}
        //	else
        //	{
        //		// sort the lists and compare item-by-item.  Any differences
        //		// and data will need to be saved back into the dataset.
        //		int size = v1.Count;
        //		//Message.printStatus(2, routine, "Lists are of size: " + size);
        //		IList<StateMod_ReservoirRight> v1Sort = StateMod_Util.sortStateMod_DataVector(v1);
        //		IList<StateMod_ReservoirRight> v2Sort = StateMod_Util.sortStateMod_DataVector(v2);
        //		//Message.printStatus(2, routine, "Lists have been sorted");

        //		for (int i = 0; i < size; i++)
        //		{
        //			r1 = v1Sort[i];
        //			r2 = v2Sort[i];
        //			//Message.printStatus(2, routine, r1.toString());
        //			//Message.printStatus(2, routine, r2.toString());
        //			//Message.printStatus(2, routine, "Element " + i + " comparison: " + r1.compareTo(r2));
        //			if (r1.CompareTo(r2) != 0)
        //			{
        //				return false;
        //			}
        //		}
        //	}
        //	return true;
        //}

        /// <summary>
        /// Tests to see if two reservoir rights are equal.  Strings are compared with case sensitivity. </summary>
        /// <param name="right"> the right to compare. </param>
        /// <returns> true if they are equal, false otherwise. </returns>
        public virtual bool Equals(StateMod_ReservoirRight right)
        {
            if (!base.Equals(right))
            {
                return(false);
            }

            if (right._rtem.Equals(_rtem) && right._dcrres == _dcrres && right._iresco == _iresco && right._ityrstr == _ityrstr && right._n2fill == _n2fill && right._copid.Equals(_copid))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 9
0
        /// <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_ReservoirRight r = (StateMod_ReservoirRight)_original;

            base.restoreOriginal();
            _rtem     = r._rtem;
            _dcrres   = r._dcrres;
            _iresco   = r._iresco;
            _ityrstr  = r._ityrstr;
            _n2fill   = r._n2fill;
            _copid    = r._copid;
            _isClone  = false;
            _original = null;
        }
        /// <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);
            }
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void saveComponent(RTi.Util.IO.DataSetComponent comp, String oldFilename,String newFilename, java.util.List<String> comments) throws Exception
        private void saveComponent(DataSetComponent comp, string oldFilename, string newFilename, IList <string> comments)
        {
            bool   daily = false;
            int    type  = comp.getComponentType();
            object data  = comp.getData();
            string name  = null;

            switch (type)
            {
            ////////////////////////////////////////////////////////
            // StateMod_* classes
            case StateMod_DataSet.COMP_CONTROL:
                StateMod_DataSet.writeStateModControlFile(__dataset, oldFilename, newFilename, comments);
                name = "Control";
                break;

            case StateMod_DataSet.COMP_DELAY_TABLES_DAILY:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_DelayTable> delayTablesDaily = (java.util.List<StateMod_DelayTable>)data;
                IList <StateMod_DelayTable> delayTablesDaily = (IList <StateMod_DelayTable>)data;
                StateMod_DelayTable.writeStateModFile(oldFilename, newFilename, delayTablesDaily, comments, __dataset.getInterv(), -1);
                name = "Delay Tables Daily";
                break;

            case StateMod_DataSet.COMP_DELAY_TABLES_MONTHLY:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_DelayTable> delayTablesMonthly = (java.util.List<StateMod_DelayTable>)data;
                IList <StateMod_DelayTable> delayTablesMonthly = (IList <StateMod_DelayTable>)data;
                StateMod_DelayTable.writeStateModFile(oldFilename, newFilename, delayTablesMonthly, comments, __dataset.getInterv(), -1);
                name = "Delay Tables Monthly";
                break;

            case StateMod_DataSet.COMP_DIVERSION_STATIONS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Diversion> diversionStations = (java.util.List<StateMod_Diversion>)data;
                IList <StateMod_Diversion> diversionStations = (IList <StateMod_Diversion>)data;
                StateMod_Diversion.writeStateModFile(oldFilename, newFilename, diversionStations, comments, daily);
                name = "Diversion";
                break;

            case StateMod_DataSet.COMP_DIVERSION_RIGHTS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_DiversionRight> diversionRights = (java.util.List<StateMod_DiversionRight>)data;
                IList <StateMod_DiversionRight> diversionRights = (IList <StateMod_DiversionRight>)data;
                StateMod_DiversionRight.writeStateModFile(oldFilename, newFilename, diversionRights, comments, daily);
                name = "Diversion Rights";
                break;

            case StateMod_DataSet.COMP_INSTREAM_STATIONS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_InstreamFlow> instreamFlow = (java.util.List<StateMod_InstreamFlow>)data;
                IList <StateMod_InstreamFlow> instreamFlow = (IList <StateMod_InstreamFlow>)data;
                StateMod_InstreamFlow.writeStateModFile(oldFilename, newFilename, instreamFlow, comments, daily);
                name = "Instream";
                break;

            case StateMod_DataSet.COMP_INSTREAM_RIGHTS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_InstreamFlowRight> instreamFlowRights = (java.util.List<StateMod_InstreamFlowRight>)data;
                IList <StateMod_InstreamFlowRight> instreamFlowRights = (IList <StateMod_InstreamFlowRight>)data;
                StateMod_InstreamFlowRight.writeStateModFile(oldFilename, newFilename, instreamFlowRights, comments);
                name = "Instream Rights";
                break;

            case StateMod_DataSet.COMP_OPERATION_RIGHTS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_OperationalRight> operationalRights = (java.util.List<StateMod_OperationalRight>)data;
                IList <StateMod_OperationalRight> operationalRights = (IList <StateMod_OperationalRight>)data;
                // 2 is the file version (introduced for StateMod version 12 change)
                StateMod_OperationalRight.writeStateModFile(oldFilename, newFilename, 2, operationalRights, comments, __dataset);
                name = "Operational Rights";
                break;

            case StateMod_DataSet.COMP_PLANS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Plan> planStations = (java.util.List<StateMod_Plan>)data;
                IList <StateMod_Plan> planStations = (IList <StateMod_Plan>)data;
                StateMod_Plan.writeStateModFile(oldFilename, newFilename, planStations, comments);
                name = "Plan";
                break;

            case StateMod_DataSet.COMP_RESERVOIR_STATIONS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Reservoir> reservoirStations = (java.util.List<StateMod_Reservoir>)data;
                IList <StateMod_Reservoir> reservoirStations = (IList <StateMod_Reservoir>)data;
                StateMod_Reservoir.writeStateModFile(oldFilename, newFilename, reservoirStations, comments, daily);
                name = "Reservoir";
                break;

            case StateMod_DataSet.COMP_RESERVOIR_RIGHTS:
//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> reservoirRights = (java.util.List<StateMod_ReservoirRight>)data;
                IList <StateMod_ReservoirRight> reservoirRights = (IList <StateMod_ReservoirRight>)data;
                StateMod_ReservoirRight.writeStateModFile(oldFilename, newFilename, reservoirRights, comments);
                name = "Reservoir Rights";
                break;

            case StateMod_DataSet.COMP_RESPONSE:
                StateMod_DataSet.writeStateModFile(__dataset, oldFilename, newFilename, comments);
                name = "Response";
                break;

            case StateMod_DataSet.COMP_RIVER_NETWORK:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_RiverNetworkNode> riverNodes = (java.util.List<StateMod_RiverNetworkNode>)data;
                IList <StateMod_RiverNetworkNode> riverNodes = (IList <StateMod_RiverNetworkNode>)data;
                StateMod_RiverNetworkNode.writeStateModFile(oldFilename, newFilename, riverNodes, comments, true);
                name = "River Network";
                break;

            case StateMod_DataSet.COMP_STREAMESTIMATE_STATIONS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_StreamEstimate> streamEstimateStations = (java.util.List<StateMod_StreamEstimate>)data;
                IList <StateMod_StreamEstimate> streamEstimateStations = (IList <StateMod_StreamEstimate>)data;
                StateMod_StreamEstimate.writeStateModFile(oldFilename, newFilename, streamEstimateStations, comments, daily);
                name = "Stream Estimate";
                break;

            case StateMod_DataSet.COMP_STREAMESTIMATE_COEFFICIENTS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_StreamEstimate_Coefficients> streamEstimateCoefficients = (java.util.List<StateMod_StreamEstimate_Coefficients>)data;
                IList <StateMod_StreamEstimate_Coefficients> streamEstimateCoefficients = (IList <StateMod_StreamEstimate_Coefficients>)data;
                StateMod_StreamEstimate_Coefficients.writeStateModFile(oldFilename, newFilename, streamEstimateCoefficients, comments);
                name = "Stream Estimate Coefficients";
                break;

            case StateMod_DataSet.COMP_STREAMGAGE_STATIONS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_StreamGage> streamGageStations = (java.util.List<StateMod_StreamGage>)data;
                IList <StateMod_StreamGage> streamGageStations = (IList <StateMod_StreamGage>)data;
                StateMod_StreamGage.writeStateModFile(oldFilename, newFilename, streamGageStations, comments, daily);
                name = "Streamgage Stations";
                break;

            case StateMod_DataSet.COMP_WELL_STATIONS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Well> wellStations = (java.util.List<StateMod_Well>)data;
                IList <StateMod_Well> wellStations = (IList <StateMod_Well>)data;
                StateMod_Well.writeStateModFile(oldFilename, newFilename, wellStations, comments);
                name = "Well";
                break;

            case StateMod_DataSet.COMP_WELL_RIGHTS:
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_WellRight> wellRights = (java.util.List<StateMod_WellRight>)data;
                IList <StateMod_WellRight> wellRights = (IList <StateMod_WellRight>)data;
                StateMod_WellRight.writeStateModFile(oldFilename, newFilename, wellRights, comments, (PropList)null);
                name = "Well Rights";
                break;

            //////////////////////////////////////////////////////
            // StateMod Time Series
            case StateMod_DataSet.COMP_CONSUMPTIVE_WATER_REQUIREMENT_TS_DAILY:
            case StateMod_DataSet.COMP_CONSUMPTIVE_WATER_REQUIREMENT_TS_MONTHLY:
            case StateMod_DataSet.COMP_DEMAND_TS_DAILY:
            case StateMod_DataSet.COMP_DEMAND_TS_AVERAGE_MONTHLY:
            case StateMod_DataSet.COMP_DEMAND_TS_MONTHLY:
            case StateMod_DataSet.COMP_DEMAND_TS_OVERRIDE_MONTHLY:
            case StateMod_DataSet.COMP_DIVERSION_TS_DAILY:
            case StateMod_DataSet.COMP_DIVERSION_TS_MONTHLY:
            case StateMod_DataSet.COMP_EVAPORATION_TS_MONTHLY:
            case StateMod_DataSet.COMP_INSTREAM_DEMAND_TS_AVERAGE_MONTHLY:
            case StateMod_DataSet.COMP_INSTREAM_DEMAND_TS_DAILY:
            case StateMod_DataSet.COMP_INSTREAM_DEMAND_TS_MONTHLY:
            case StateMod_DataSet.COMP_PRECIPITATION_TS_MONTHLY:
            case StateMod_DataSet.COMP_RESERVOIR_CONTENT_TS_DAILY:
            case StateMod_DataSet.COMP_RESERVOIR_CONTENT_TS_MONTHLY:
            case StateMod_DataSet.COMP_RESERVOIR_TARGET_TS_DAILY:
            case StateMod_DataSet.COMP_RESERVOIR_TARGET_TS_MONTHLY:
            case StateMod_DataSet.COMP_STREAMESTIMATE_NATURAL_FLOW_TS_DAILY:
            case StateMod_DataSet.COMP_STREAMESTIMATE_NATURAL_FLOW_TS_MONTHLY:
            case StateMod_DataSet.COMP_STREAMGAGE_NATURAL_FLOW_TS_DAILY:
            case StateMod_DataSet.COMP_STREAMGAGE_NATURAL_FLOW_TS_MONTHLY:
            case StateMod_DataSet.COMP_STREAMGAGE_HISTORICAL_TS_DAILY:
            case StateMod_DataSet.COMP_STREAMGAGE_HISTORICAL_TS_MONTHLY:
            case StateMod_DataSet.COMP_WELL_DEMAND_TS_DAILY:
            case StateMod_DataSet.COMP_WELL_DEMAND_TS_MONTHLY:
            case StateMod_DataSet.COMP_WELL_PUMPING_TS_DAILY:
            case StateMod_DataSet.COMP_WELL_PUMPING_TS_MONTHLY:
                double   missing  = -999.0;
                YearType yearType = null;
                if (__dataset.getCyrl() == YearType.CALENDAR)
                {
                    yearType = YearType.CALENDAR;
                }
                else if (__dataset.getCyrl() == YearType.WATER)
                {
                    yearType = YearType.WATER;
                }
                else if (__dataset.getCyrl() == YearType.NOV_TO_OCT)
                {
                    yearType = YearType.NOV_TO_OCT;
                }
                int precision = 2;

                // Do the following to avoid warnings
                IList <TS> tslist = null;
                if (data != null)
                {
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<RTi.TS.TS> tslist0 = (java.util.List<RTi.TS.TS>)data;
                    IList <TS> tslist0 = (IList <TS>)data;
                    if (tslist0.Count > 0)
                    {
                        TS ts = tslist0[0];
                        missing = ts.getMissing();
                    }
                    tslist = tslist0;
                }

                StateMod_TS.writeTimeSeriesList(oldFilename, newFilename, comments, tslist, null, null, yearType, missing, precision);
                name = "TS (" + type + ")";
                break;

            default:
                name = "(something: " + type + ")";
                break;
            }
            comp.setDirty(false);
            Message.printStatus(1, "", "Component '" + name + "' written");
        }
Esempio n. 13
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;
            int    ival;
            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:
                rr.setCgoto((string)value);
                break;

            case COL_RIGHT_ID:
                rr.setID((string)value);
                break;

            case COL_RIGHT_NAME:
                rr.setName((string)value);
                break;

            case COL_STRUCT_ID:
                rr.setCgoto((string)value);
                break;

            case COL_ADMIN_NUM:
                rr.setRtem((string)value);
                break;

            case COL_DCR_AMT:
                dval = ((double?)value).Value;
                rr.setDcrres(dval);
                break;

            case COL_ON_OFF:
                if (value is int?)
                {
                    ival = ((int?)value).Value;
                    rr.setSwitch(ival);
                }
                else if (value is string)
                {
                    string onOff = (string)value;
                    int    index = onOff.IndexOf(" -", StringComparison.Ordinal);
                    ival = (Convert.ToInt32(onOff.Substring(0, index)));
                    rr.setSwitch(ival);
                }
                break;

            case COL_ACCOUNT_DIST:
                if (value is int?)
                {
                    ival = ((int?)value).Value;
                    rr.setIresco(ival);
                }
                else if (value is string)
                {
                    string acct  = (string)value;
                    int    index = acct.IndexOf(" -", StringComparison.Ordinal);
                    ival = (Convert.ToInt32(acct.Substring(0, index)));
                    rr.setIresco(ival);
                }
                break;

            case COL_RIGHT_TYPE:
                if (value is int?)
                {
                    ival = ((int?)value).Value;
                    rr.setItyrstr(ival);
                }
                else if (value is string)
                {
                    string right = (string)value;
                    int    index = right.IndexOf(" -", StringComparison.Ordinal);
                    ival = (Convert.ToInt32(right.Substring(0, index)));
                    rr.setItyrstr(ival);
                }
                break;

            case COL_FILL_TYPE:
                if (value is int?)
                {
                    ival = ((int?)value).Value;
                    rr.setN2fill(ival);
                }
                else if (value is string)
                {
                    string fill  = (string)value;
                    int    index = fill.IndexOf(" -", StringComparison.Ordinal);
                    ival = (Convert.ToInt32(fill.Substring(0, index)));
                    rr.setN2fill(ival);
                }
                break;

            case COL_OOP_RIGHT:
                rr.setCopid((string)value);
                break;
            }

            if (!__singleReservoir)
            {
                col++;
            }

            base.setValueAt(value, row, col);
        }
Esempio n. 14
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();
                }
            }
        }
        /// <summary>
        /// Sets up the GUI.
        /// </summary>
        public virtual void setupGUI()
        {
            string routine = "setupGUI";

            addWindowListener(this);

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

            p.add("JWorksheet.AllowCopy=true");
            p.add("JWorksheet.CellFont=Courier");
            p.add("JWorksheet.CellStyle=Plain");
            p.add("JWorksheet.CellSize=11");
            p.add("JWorksheet.HeaderFont=Arial");
            p.add("JWorksheet.HeaderStyle=Plain");
            p.add("JWorksheet.HeaderSize=11");
            p.add("JWorksheet.HeaderBackground=LightGray");
            p.add("JWorksheet.RowColumnPresent=false");
            p.add("JWorksheet.ShowPopupMenu=true");
            p.add("JWorksheet.SelectionMode=SingleRowSelection");

            int[]            widths = null;
            JScrollWorksheet jsw    = null;

            try
            {
                IList <StateMod_ReservoirAccount> accounts = __currentRes.getAccounts();
                IList <string>            v3   = new List <string>();
                int                       size = accounts.Count;
                StateMod_ReservoirAccount ra   = null;
                for (int i = 0; i < size; i++)
                {
                    ra = accounts[i];
                    v3.Add("" + ra.getID() + " - " + ra.getName());
                }
                for (int i = 1; i < size; i++)
                {
                    v3.Add("-" + (i + 1) + " - Fill first " + (i + 1) + " accounts");
                }

                IList <StateMod_ReservoirRight> v  = new List <StateMod_ReservoirRight>();
                IList <StateMod_ReservoirRight> v2 = __currentRes.getRights();
                StateMod_ReservoirRight         rr;
                for (int i = 0; i < v2.Count; i++)
                {
                    rr = (StateMod_ReservoirRight)v2[i].clone();
                    v.Add(rr);
                }
                StateMod_ReservoirRight_TableModel   tmr = new StateMod_ReservoirRight_TableModel(v, __editable);
                StateMod_ReservoirRight_CellRenderer crr = new StateMod_ReservoirRight_CellRenderer(tmr);

                jsw         = new JScrollWorksheet(crr, tmr, p);
                __worksheet = jsw.getJWorksheet();

                IList <string> onOff = StateMod_ReservoirRight.getIrsrswChoices(true);
                __worksheet.setColumnJComboBoxValues(StateMod_ReservoirRight_TableModel.COL_ON_OFF, onOff, false);
                __worksheet.setColumnJComboBoxValues(StateMod_ReservoirRight_TableModel.COL_ACCOUNT_DIST, v3, false);
                IList <string> rightTypes = StateMod_ReservoirRight.getItyrsrChoices(true);
                __worksheet.setColumnJComboBoxValues(StateMod_ReservoirRight_TableModel.COL_RIGHT_TYPE, rightTypes, false);
                IList <string> fillTypes = StateMod_ReservoirRight.getN2fillChoices(true);
                __worksheet.setColumnJComboBoxValues(StateMod_ReservoirRight_TableModel.COL_FILL_TYPE, fillTypes, false);

                widths = crr.getColumnWidths();
            }
            catch (Exception e)
            {
                Message.printWarning(2, routine, e);
                jsw         = new JScrollWorksheet(0, 0, p);
                __worksheet = jsw.getJWorksheet();
            }
            __worksheet.setPreferredScrollableViewportSize(null);

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

            __addRight    = new JButton(__BUTTON_ADD_RIGHT);
            __deleteRight = new JButton(__BUTTON_DEL_RIGHT);
            __deleteRight.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(__addRight);
                p1.add(__deleteRight);
            }
            p1.add(applyJButton);
            p1.add(cancelJButton);
            //	p1.add(__helpJButton);
            p1.add(__closeJButton);

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

            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);
            __addRight.addActionListener(this);
            __deleteRight.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(760, 400);
            JGUIUtil.center(this);
            setVisible(true);
            if (widths != null)
            {
                __worksheet.setColumnWidths(widths);
            }
        }
        /// <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)
            }
        }
Esempio n. 17
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();
                }
            }
        }
        /// <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;
            int    ival;
            StateMod_ReservoirRight rr = (StateMod_ReservoirRight)_data.get(row);

            switch (col)
            {
            case COL_RIGHT_ID:
                rr.setID((string)value);
                break;

            case COL_RIGHT_NAME:
                rr.setName((string)value);
                break;

            case COL_STRUCT_ID:
                rr.setCgoto((string)value);
                break;

            case COL_ADMIN_NUM:
                rr.setRtem((string)value);
                break;

            case COL_DCR_AMT:
                dval = ((double?)value).Value;
                rr.setDcrres(dval);
                break;

            case COL_ON_OFF:
                if (value is int?)
                {
                    ival = ((int?)value).Value;
                    rr.setSwitch(ival);
                }
                else if (value is string)
                {
                    string onOff = (string)value;
                    int    index = onOff.IndexOf(" -", StringComparison.Ordinal);
                    ival = (Convert.ToInt32(onOff.Substring(0, index)));
                    rr.setSwitch(ival);
                }
                break;

            case COL_ACCOUNT_DIST:
                if (value is int?)
                {
                    ival = ((int?)value).Value;
                    rr.setIresco(ival);
                }
                else if (value is string)
                {
                    string acct  = (string)value;
                    int    index = acct.IndexOf(" -", StringComparison.Ordinal);
                    ival = (Convert.ToInt32(acct.Substring(0, index)));
                    rr.setIresco(ival);
                }
                break;

            case COL_RIGHT_TYPE:
                if (value is int?)
                {
                    ival = ((int?)value).Value;
                    rr.setItyrstr(ival);
                }
                else if (value is string)
                {
                    string right = (string)value;
                    int    index = right.IndexOf(" -", StringComparison.Ordinal);
                    ival = (Convert.ToInt32(right.Substring(0, index)));
                    rr.setItyrstr(ival);
                }
                break;

            case COL_FILL_TYPE:
                if (value is int?)
                {
                    ival = ((int?)value).Value;
                    rr.setN2fill(ival);
                }
                else if (value is string)
                {
                    string fill  = (string)value;
                    int    index = fill.IndexOf(" -", StringComparison.Ordinal);
                    ival = (Convert.ToInt32(fill.Substring(0, index)));
                    rr.setN2fill(ival);
                }
                break;

            case COL_OOP_RIGHT:
                rr.setCopid((string)value);
                break;
            }

            base.setValueAt(value, row, col);
        }
        /// <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_Right_JFrame.saveData";

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

            if (checkInput() > 0)
            {
                return(false);
            }

            // now only save data if any are different.
            bool needToSave = 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_ReservoirRight> wv = (java.util.List<StateMod_ReservoirRight>)__worksheet.getAllData();
            IList <StateMod_ReservoirRight> wv = (IList <StateMod_ReservoirRight>)__worksheet.getAllData(); // w for worksheet
            IList <StateMod_ReservoirRight> rv = __currentRes.getRights();                                  // i for reservoir

            needToSave = !(StateMod_ReservoirRight.Equals(wv, rv));

            Message.printStatus(1, routine, "Saving? .........[" + needToSave + "]");

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

            // at this point, remove the old diversion rights from the original
            // component list
//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> reservoirRights = (java.util.List<StateMod_ReservoirRight>)(__dataset.getComponentForComponentType(StateMod_DataSet.COMP_RESERVOIR_RIGHTS)).getData();
            IList <StateMod_ReservoirRight> reservoirRights = (IList <StateMod_ReservoirRight>)(__dataset.getComponentForComponentType(StateMod_DataSet.COMP_RESERVOIR_RIGHTS)).getData();
            int size = rv.Count;
            StateMod_ReservoirRight ir;

            for (int i = 0; i < size; i++)
            {
                ir = (StateMod_ReservoirRight)rv[i];
                StateMod_Util.removeFromVector(reservoirRights, ir);
            }

            // now add the elements from the new Vector to the reservoirRights
            // Vector.
            size = wv.Count;
            StateMod_ReservoirRight cdr = null;

            for (int i = 0; i < size; i++)
            {
                ir           = (StateMod_ReservoirRight)wv[i];
                cdr          = (StateMod_ReservoirRight)ir.clone();
                cdr._isClone = false;
                reservoirRights.Add(cdr);
            }

            // sort the reservoirRights Vector
            // REVISIT (JTS - 2003-10-10)
            // here we are sorting the full data array -- may be a performance
            // issue
            IList <StateMod_ReservoirRight> sorted = StateMod_Util.sortStateMod_DataVector(reservoirRights);

            __dataset.getComponentForComponentType(StateMod_DataSet.COMP_RESERVOIR_RIGHTS).setData(sorted);
            __currentRes.disconnectRights();
            __currentRes.connectRights(sorted);
            __dataset.setDirty(StateMod_DataSet.COMP_RESERVOIR_RIGHTS, true);
            return(true);
        }