/// <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_Return_JFrame::actionPerformed";

            string action = e.getActionCommand();

            if (action.Equals(__BUTTON_ADD_RETURN))
            {
                StateMod_ReturnFlow aReturn = new StateMod_ReturnFlow(StateMod_DataSet.COMP_RESERVOIR_RETURN);
                aReturn._isClone = true;
                StateMod_ReturnFlow last = (StateMod_ReturnFlow)__worksheet.getLastRowData();

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

                    __worksheet.cancelEditing();
                    __worksheet.deleteRow(row);
                    __deleteReturn_JButton.setEnabled(false);
                }
                else
                {
                    Message.printWarning(1, routine, "Must select desired return 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() == __help_JButton)
            {
                // TODO HELP (JTS - 2003-06-09)
            }
        }
Example #2
0
        /// <summary>
        /// Read return information in and store in a list. </summary>
        /// <param name="filename"> filename containing return flow information </param>
        /// <param name="smdataCompType"> the StateMod_DataSet component type, passed to the constructor of StateMod_ReturnFlow
        /// objects. </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 java.util.List<StateMod_ReturnFlow> readStateModFile(String filename, int smdataCompType) throws Exception
        public static IList <StateMod_ReturnFlow> readStateModFile(string filename, int smdataCompType)
        {
            string         routine = "StateMod_ReturnFlow.readStateModFile";
            string         iline   = null;
            IList <string> v;
            IList <StateMod_ReturnFlow> theReturns = new List <StateMod_ReturnFlow>();
            int linecount = 0;

            StateMod_ReturnFlow aReturn = null;
            StreamReader        @in     = null;

            Message.printStatus(2, routine, "Reading return file: " + filename);
            int size       = 0;
            int errorCount = 0;

            try
            {
                @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename));
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    ++linecount;
                    // check for comments
                    if (iline.StartsWith("#", StringComparison.Ordinal) || (iline.Trim().Length == 0))
                    {
                        // Special dynamic header comments written by software and blank lines - no need to keep
                        continue;
                    }
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line: " + iline);
                    }
                    // Break the line using whitespace, while allowing for quoted strings...
                    v    = StringUtil.breakStringList(iline, " \t", StringUtil.DELIM_ALLOW_STRINGS | StringUtil.DELIM_SKIP_BLANKS);
                    size = 0;
                    if (v != null)
                    {
                        size = v.Count;
                    }
                    if (size < 4)
                    {
                        Message.printStatus(2, routine, "Ignoring line " + linecount + " not enough data values.  Have " + size + " expecting 4+");
                        ++errorCount;
                        continue;
                    }
                    // Uncomment if testing...
                    //Message.printStatus ( 2, routine, "" + v );

                    // Allocate new plan node and set the values
                    aReturn = new StateMod_ReturnFlow(smdataCompType);
                    aReturn.setID(v[0].Trim());
                    aReturn.setName(v[0].Trim());             // Same as ID
                    aReturn.setCrtnid(v[1].Trim());
                    aReturn.setCgoto(v[1].Trim());            // Redundant
                    aReturn.setPcttot(v[2].Trim());
                    aReturn.setIrtndl(v[3].Trim());
                    if (v.Count > 4)
                    {
                        aReturn.setComment(v[4].Trim());
                    }

                    // Set the return to not dirty because it was just initialized...

                    aReturn.setDirty(false);

                    // Add the return to the list of returns
                    theReturns.Add(aReturn);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, "Error reading line " + linecount + " \"" + iline + "\" uniquetempvar.");
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            if (errorCount > 0)
            {
                throw new Exception("There were " + errorCount + " errors processing the data - refer to log file.");
            }
            return(theReturns);
        }