/// <summary> /// Responds to action performed events. </summary> /// <param name="e"> the ActionEvent that occurred. </param> public virtual void actionPerformed(ActionEvent e) { string action = e.getActionCommand(); if (action.Equals(__BUTTON_ADD_OWNER)) { StateMod_ReservoirAccount anAccount = new StateMod_ReservoirAccount(); anAccount._isClone = true; int rowCount = __worksheet.getRowCount(); if (rowCount == 0) { anAccount.setID(1); } else { StateMod_ReservoirAccount lastAccount = (StateMod_ReservoirAccount)__worksheet.getLastRowData(); string id = lastAccount.getID(); anAccount.setID("" + ((Convert.ToInt32(id)) + 1)); } __worksheet.addRow(anAccount); __worksheet.scrollToLastRow(); __worksheet.selectLastRow(); __deleteOwner.setEnabled(true); } else if (action.Equals(__BUTTON_DEL_OWNER)) { int row = __worksheet.getSelectedRow(); if (row != -1) { int x = (new ResponseJDialog(this, "Delete owner", "Delete owner?", ResponseJDialog.YES | ResponseJDialog.NO)).response(); if (x == ResponseJDialog.NO) { return; } __worksheet.deleteRow(row); __deleteOwner.setEnabled(false); } } else if (action.Equals(__BUTTON_CLOSE)) { if (saveData()) { setVisible(false); dispose(); } } else if (action.Equals(__BUTTON_APPLY)) { saveData(); } else if (action.Equals(__BUTTON_CANCEL)) { setVisible(false); dispose(); } else if (action.Equals(__BUTTON_HELP)) { // REVISIT HELP (JTS - 2003-06-09) } }
/// <summary> /// Clones the data object. </summary> /// <returns> a cloned object. </returns> public override object clone() { StateMod_ReservoirAccount acct = (StateMod_ReservoirAccount)base.clone(); acct._isClone = true; return(acct); }
/// <summary> /// Creates backups of all the data objects in the Vector so that changes can later be cancelled if necessary. /// </summary> protected internal override void createDataBackup() { StateMod_ReservoirAccount acct = null; int size = _data.Count; for (int i = 0; i < size; i++) { acct = (StateMod_ReservoirAccount)_data[i]; acct.createBackup(); } }
/// <summary> /// Called when the cancel button is pressed. This discards any changes made to the data objects. /// </summary> protected internal override void cancel() { StateMod_ReservoirAccount acct = null; int size = _data.Count; for (int i = 0; i < size; i++) { acct = (StateMod_ReservoirAccount)_data[i]; acct.restoreOriginal(); } }
/// <summary> /// Add owner (account). </summary> /// <param name="owner"> StateMod_ReservoirAccount to add. </param> public virtual void addAccount(StateMod_ReservoirAccount owner) { if (owner != null) { _owners.Add(owner); setDirty(true); if (!_isClone && _dataset != null) { _dataset.setDirty(StateMod_DataSet.COMP_RESERVOIR_STATIONS, true); } } }
/// <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_Owner_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_ReservoirAccount> wv = (java.util.List<StateMod_ReservoirAccount>)__worksheet.getAllData(); IList <StateMod_ReservoirAccount> wv = (IList <StateMod_ReservoirAccount>)__worksheet.getAllData(); // w for worksheet IList <StateMod_ReservoirAccount> rv = __currentRes.getAccounts(); // i for instream flow needToSave = !(StateMod_ReservoirAccount.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); } // now add the elements from the new Vector to the reservoirRights // Vector. int size = wv.Count; IList <StateMod_ReservoirAccount> clone = new List <StateMod_ReservoirAccount>(); StateMod_ReservoirAccount ra; for (int i = 0; i < size; i++) { ra = (StateMod_ReservoirAccount)wv[i].clone(); clone.Add(ra); } __currentRes.setAccounts(clone); __dataset.setDirty(StateMod_DataSet.COMP_RESERVOIR_STATIONS, true); return(true); }
/// <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_ReservoirAccount acct = (StateMod_ReservoirAccount)_original; base.restoreOriginal(); _ownmax = acct._ownmax; _curown = acct._curown; _pcteva = acct._pcteva; _n2own = acct._n2own; _isClone = false; _original = null; }
/// <summary> /// Clones the data object. </summary> /// <returns> a cloned object. </returns> //public override object clone() //{ // StateMod_ReservoirAccount acct = (StateMod_ReservoirAccount)base.clone(); // acct._isClone = true; // return acct; //} /// <summary> /// Compares this object to another StateMod_Data object based on the sorted /// order from the StateMod_Data variables, and then by _ownmax, _curown, /// _pcteva, and _n2own, 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_ReservoirAccount acct = (StateMod_ReservoirAccount)data; // if (_ownmax < acct._ownmax) // { // return -1; // } // else if (_ownmax > acct._ownmax) // { // return 1; // } // if (_curown < acct._curown) // { // return -1; // } // else if (_curown > acct._curown) // { // return 1; // } // if (_pcteva < acct._pcteva) // { // return -1; // } // else if (_pcteva > acct._pcteva) // { // return 1; // } // if (_n2own < acct._n2own) // { // return -1; // } // else if (_n2own > acct._n2own) // { // return 1; // } // return 0; //} /// <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_ReservoirAccount)clone(); // ((StateMod_ReservoirAccount)_original)._isClone = false; // _isClone = true; //} /// <summary> /// Compare two rights Vectors and see if they are the same. </summary> /// <param name="v1"> the first Vector of StateMod_ReservoirAccounts to check. Cannot be null. </param> /// <param name="v2"> the second Vector of StateMod_ReservoirAccounts to check. Cannot be null. </param> /// <returns> true if they are the same, false if not. </returns> //public static bool Equals(IList<StateMod_ReservoirAccount> v1, IList<StateMod_ReservoirAccount> v2) //{ // string routine = "StateMod_ReservoirAccount.equals(List,List)"; // StateMod_ReservoirAccount r1; // StateMod_ReservoirAccount r2; // if (v1.Count != v2.Count) // { // Message.printStatus(1, routine, "Lists are different sizes"); // return false; // } // else // { // // sort the Vectors and compare item-by-item. Any differences // // and data will need to be saved back into the dataset. // int size = v1.Count; // Message.printStatus(1, routine, "Lists are of size: " + size); // IList<StateMod_ReservoirAccount> v1Sort = StateMod_Util.sortStateMod_DataVector(v1); // IList<StateMod_ReservoirAccount> v2Sort = StateMod_Util.sortStateMod_DataVector(v2); // Message.printStatus(1, routine, "Lists have been sorted"); // for (int i = 0; i < size; i++) // { // r1 = (StateMod_ReservoirAccount)v1Sort[i]; // r2 = (StateMod_ReservoirAccount)v2Sort[i]; // Message.printStatus(1, routine, r1.ToString()); // Message.printStatus(1, routine, r2.ToString()); // Message.printStatus(1, routine, "Element " + i + " comparison: " + r1.CompareTo(r2)); // if (r1.CompareTo(r2) != 0) // { // return false; // } // } // } // return true; //} /// <summary> /// Tests to see if two diversion rights are equal. Strings are compared with case sensitivity. </summary> /// <param name="acct"> the account to compare. </param> /// <returns> true if they are equal, false otherwise. </returns> public virtual bool Equals(StateMod_ReservoirAccount acct) { if (!base.Equals(acct)) { return(false); } if (_ownmax == acct._ownmax && _curown == acct._curown && _pcteva == acct._pcteva && _n2own == acct._n2own) { return(true); } return(false); }
/// <summary> /// Compares this object to another StateMod_Data object based on the sorted /// order from the StateMod_Data variables, and then by _ownmax, _curown, /// _pcteva, and _n2own, 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_ReservoirAccount acct = (StateMod_ReservoirAccount)data; if (_ownmax < acct._ownmax) { return(-1); } else if (_ownmax > acct._ownmax) { return(1); } if (_curown < acct._curown) { return(-1); } else if (_curown > acct._curown) { return(1); } if (_pcteva < acct._pcteva) { return(-1); } else if (_pcteva > acct._pcteva) { return(1); } if (_n2own < acct._n2own) { return(-1); } else if (_n2own > acct._n2own) { return(1); } return(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_ReservoirAccount rac = (StateMod_ReservoirAccount)_data.get(row); // necessary for table models that display accounts 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(rac.getCgoto()); case COL_OWNER_ID: return(rac.getID()); case COL_OWNER_ACCOUNT: return(rac.getName()); case COL_MAX_STORAGE: return(new double?(rac.getOwnmax())); case COL_INITIAL_STORAGE: return(new double?(rac.getCurown())); case COL_PRORATE_EVAP: return(new double?(rac.getPcteva())); case COL_OWNERSHIP_TIE: return(new int?(rac.getN2own())); default: return(""); } }
/// <summary> /// Constructor. </summary> /// <param name="data"> the data to display in the worksheet. Can be null or empty, in /// which case an empty worksheet is shown. </param> /// <param name="titleString"> the String to display as the GUI title. </param> /// <param name="editable"> whether the data in the JFrame can be edited or not. If true /// the data can be edited, if false they can not. </param> /// <exception cref="Exception"> if there is an error building the worksheet. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public StateMod_ReservoirAccount_Data_JFrame(java.util.List data, String titleString, boolean editable) throws Exception public StateMod_ReservoirAccount_Data_JFrame(System.Collections.IList data, string titleString, bool editable) : base() { int j = 0; int size = 0; int size2 = 0; StateMod_Reservoir r = null; StateMod_ReservoirAccount a = null; System.Collections.IList accounts = null; System.Collections.IList v = new List <object>(); if (data != null) { size = data.Count; } for (int i = 0; i < size; i++) { r = (StateMod_Reservoir)data[i]; accounts = r.getAccounts(); if (accounts == null) { continue; } size2 = accounts.Count; for (j = 0; j < size2; j++) { a = (StateMod_ReservoirAccount)accounts[j]; a.setCgoto(r.getID()); v.Add(a); } } initialize(v, titleString, editable); setSize(691, getHeight()); }
/// <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_ReservoirAccount rac = (StateMod_ReservoirAccount)_data.get(row); switch (col) { case COL_RESERVOIR_ID: return(rac.getCgoto()); case COL_OWNER_ID: return(rac.getID()); case COL_OWNER_ACCOUNT: return(rac.getName()); case COL_MAX_STORAGE: return(new double?(rac.getOwnmax())); case COL_INITIAL_STORAGE: return(new double?(rac.getCurown())); case COL_PRORATE_EVAP: return(new double?(rac.getPcteva())); case COL_OWNERSHIP_TIE: return(new int?(rac.getN2own())); 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_Owner_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_ReservoirAccount> v = (java.util.List<StateMod_ReservoirAccount>)__worksheet.getAllData(); IList <StateMod_ReservoirAccount> v = (IList <StateMod_ReservoirAccount>)__worksheet.getAllData(); int size = v.Count; StateMod_ReservoirAccount acct = null; string warning = ""; string id; string name; int fatalCount = 0; int lastID = 0; int currID = 0; if (size > 0) { acct = v[0]; id = acct.getID(); if (!id.Trim().Equals("1")) { warning += "\nThe first reservoir account must have " + "an ID of '1', not '" + id + "'"; fatalCount++; } } for (int i = 0; i < size; i++) { acct = v[i]; id = acct.getID(); if (i == 0) { lastID = (Convert.ToInt32(id)); } else { currID = (Convert.ToInt32(id)); if (currID > (lastID + 1)) { warning += "\nOwner ID values must be " + "consecutive (row #" + (i) + " is " + lastID + ", row #" + (i + 1) + " is " + currID + ")"; fatalCount++; } lastID = currID; } name = acct.getName(); if (id.Length > 12) { warning += "\nReservoir acct ID (" + id + ") is " + "longer than 12 characters."; fatalCount++; } if (id.IndexOf(" ", StringComparison.Ordinal) > -1 || id.IndexOf("-", StringComparison.Ordinal) > -1) { warning += "\nReservoir acct ID (" + id + ") cannot " + "contain spaces or dashes."; fatalCount++; } if (name.Length > 24) { warning += "\nReservoir name (" + name + ") is " + "longer than 24 characters."; fatalCount++; } /* REVISIT SAM 2004-10-29 should be enforced by the table * model since it is a choice * ownerTie = acct.getN2owns(); * if (ownerTie == null) { * warning += "\nMust fill in Ownership Tie."; * fatalCount++; * } */ // the rest are handled automatically by the worksheet } // REVISIT - if daily time series are supplied, check for time series // and allow creation if not available. if (warning.Length > 0) { warning += "\nCorrect or Cancel."; Message.printWarning(1, routine, warning, this); if (fatalCount > 0) { // Fatal errors... Message.printStatus(1, routine, "Returning 1 from checkInput()"); return(1); } else { // Nonfatal errors... Message.printStatus(1, routine, "Returning -1 from checkInput()"); return(-1); } } else { // No errors... Message.printStatus(1, routine, "Returning 0 from checkInput()"); return(0); } }
/// <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> /// Writes a list of StateMod_ReservoirAccount objects to a list file. A header /// is printed to the top of the file, containing the commands used to generate the /// file. Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary> /// <param name="filename"> the name of the file to which the data will be written. </param> /// <param name="delimiter"> the delimiter to use for separating field values. </param> /// <param name="update"> whether to update an existing file, retaining the current /// header (true) or to create a new file with a new header. </param> /// <param name="data"> the list of objects to write. </param> /// <param name="newComments"> new comments to add 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 data, java.util.List newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, System.Collections.IList data, System.Collections.IList newComments) { string routine = "StateMod_ReservoirAccount.writeListFile"; int size = 0; if (data != null) { size = data.Count; } System.Collections.IList fields = new List <object>(); fields.Add("ReservoirID"); fields.Add("OwnerID"); fields.Add("OwnerAccount"); fields.Add("MaxStorage"); fields.Add("InitialStorage"); fields.Add("ProrateEvap"); fields.Add("OwnershipTie"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = StateMod_DataSet.COMP_RESERVOIR_STATION_ACCOUNTS; string s = null; for (int i = 0; i < fieldCount; i++) { s = (string)fields[i]; names[i] = StateMod_Util.lookupPropValue(comp, "FieldName", s); formats[i] = StateMod_Util.lookupPropValue(comp, "Format", s); } string oldFile = null; if (update) { oldFile = IOUtil.getPathUsingWorkingDir(filename); } int j = 0; StateMod_ReservoirAccount acct = null; System.Collections.IList commentIndicators = new List <object>(1); commentIndicators.Add("#"); System.Collections.IList ignoredCommentIndicators = new List <object>(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. System.Collections.IList newComments2 = null; if (newComments == null) { newComments2 = new List <object>(); } else { newComments2 = new List <object>(newComments); } newComments2.Insert(0, ""); newComments2.Insert(1, "StateMod reservoir station accounts as a delimited list file."); newComments2.Insert(2, "See also the associated station, precipitation station, evaporation station,"); newComments2.Insert(3, "content/area/seepage, and collection files."); newComments2.Insert(4, ""); @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 0); for (int i = 0; i < fieldCount; i++) { buffer.Append("\"" + names[i] + "\""); if (i < (fieldCount - 1)) { buffer.Append(delimiter); } } @out.println(buffer.ToString()); for (int i = 0; i < size; i++) { acct = (StateMod_ReservoirAccount)data[i]; line[0] = StringUtil.formatString(acct.getCgoto(), formats[0]).Trim(); line[1] = StringUtil.formatString(acct.getID(), formats[1]).Trim(); line[2] = StringUtil.formatString(acct.getName(), formats[2]).Trim(); line[3] = StringUtil.formatString(acct.getOwnmax(), formats[3]).Trim(); line[4] = StringUtil.formatString(acct.getCurown(), formats[4]).Trim(); line[5] = StringUtil.formatString(acct.getPcteva(), formats[5]).Trim(); line[6] = StringUtil.formatString(acct.getN2own(), formats[6]).Trim(); buffer = new StringBuilder(); for (j = 0; j < fieldCount; j++) { if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1) { line[j] = "\"" + line[j] + "\""; } buffer.Append(line[j]); if (j < (fieldCount - 1)) { buffer.Append(delimiter); } } @out.println(buffer.ToString()); } } 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_ReservoirAccount rac = (StateMod_ReservoirAccount)_data.get(row); // necessary for table models that display accounts 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: rac.setCgoto((string)value); break; case COL_OWNER_ID: rac.setID((string)value); break; case COL_OWNER_ACCOUNT: rac.setName((string)value); break; case COL_MAX_STORAGE: dval = ((double?)value).Value; rac.setOwnmax(dval); break; case COL_INITIAL_STORAGE: dval = ((double?)value).Value; rac.setCurown(dval); break; case COL_PRORATE_EVAP: if (value is double?) { dval = ((double?)value).Value; rac.setPcteva(dval); } else if (value is string) { int index = ((string)value).IndexOf(" -", StringComparison.Ordinal); string s = ((string)value).Substring(0, index); dval = (Convert.ToDouble(s)); rac.setPcteva(dval); } break; case COL_OWNERSHIP_TIE: if (value is int?) { ival = ((int?)value).Value; rac.setN2own(ival); } else if (value is string) { string n2owns = (string)value; int index = n2owns.IndexOf(" -", StringComparison.Ordinal); ival = (Convert.ToInt32(n2owns.Substring(0, index))); rac.setN2own(ival); } break; } if (!__singleReservoir) { col++; } base.setValueAt(value, row, col); }
/// <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_ReservoirAccount rac = (StateMod_ReservoirAccount)_data.get(row); switch (col) { case COL_RESERVOIR_ID: rac.setCgoto((string)value); break; case COL_OWNER_ID: rac.setID((string)value); break; case COL_OWNER_ACCOUNT: rac.setName((string)value); break; case COL_MAX_STORAGE: dval = ((double?)value).Value; rac.setOwnmax(dval); break; case COL_INITIAL_STORAGE: dval = ((double?)value).Value; rac.setCurown(dval); break; case COL_PRORATE_EVAP: if (value is double?) { dval = ((double?)value).Value; rac.setPcteva(dval); } else if (value is string) { int index = ((string)value).IndexOf(" -", StringComparison.Ordinal); string s = ((string)value).Substring(0, index); dval = (Convert.ToDouble(s)); rac.setPcteva(dval); } break; case COL_OWNERSHIP_TIE: if (value is int?) { ival = ((int?)value).Value; rac.setN2own(ival); } else if (value is string) { string n2owns = (string)value; int index = n2owns.IndexOf(" -", StringComparison.Ordinal); ival = (Convert.ToInt32(n2owns.Substring(0, index))); rac.setN2own(ival); } break; } base.setValueAt(value, row, col); }
/// <summary> /// Sets up the GUI. /// </summary> private void setupGUI() { string routine = "setupGUI"; addWindowListener(this); __addOwner = new JButton(__BUTTON_ADD_OWNER); __deleteOwner = new JButton(__BUTTON_DEL_OWNER); __deleteOwner.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 ID:")); 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(__addOwner); p1.add(__deleteOwner); } p1.add(applyJButton); p1.add(cancelJButton); // p1.add(__helpJButton); p1.add(__closeJButton); PropList p = new PropList("StateMod_Reservoir_JFrame.JWorksheet"); p.add("JWorksheet.ShowPopupMenu=true"); p.add("JWorksheet.AllowCopy=true"); p.add("JWorksheet.SelectionMode=SingleRowSelection"); int[] widths = null; JScrollWorksheet jsw = null; try { IList <StateMod_ReservoirAccount> v = new List <StateMod_ReservoirAccount>(); IList <StateMod_ReservoirAccount> v2 = __currentRes.getAccounts(); StateMod_ReservoirAccount ra; for (int i = 0; i < v2.Count; i++) { ra = (StateMod_ReservoirAccount)v2[i].clone(); v.Add(ra); } StateMod_ReservoirAccount_TableModel tmr = new StateMod_ReservoirAccount_TableModel(v, __editable, true); StateMod_ReservoirAccount_CellRenderer crr = new StateMod_ReservoirAccount_CellRenderer(tmr); jsw = new JScrollWorksheet(crr, tmr, p); __worksheet = jsw.getJWorksheet(); IList <string> owner = StateMod_ReservoirAccount.getN2ownChoices(true); __worksheet.setColumnJComboBoxValues(StateMod_ReservoirAccount_TableModel.COL_OWNERSHIP_TIE, owner, 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); 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); __addOwner.addActionListener(this); __deleteOwner.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(700, 400); JGUIUtil.center(this); setVisible(true); if (widths != null) { __worksheet.setColumnWidths(widths); } }
/// <summary> /// Read reservoir information in and store in a Vector. </summary> /// <param name="filename"> Name of file to read. </param> /// <exception cref="Exception"> if there is an error reading the file. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static java.util.List<StateMod_Reservoir> readStateModFile(String filename) throws Exception public static IList <StateMod_Reservoir> readStateModFile(string filename) { string routine = "StateMod_Reservoir.readStateModFile"; IList <StateMod_Reservoir> theReservoirs = new List <StateMod_Reservoir>(); string iline = null; IList <object> v = new List <object>(9); int[] format_0 = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING }; int[] format_0w = new int[] { 12, 24, 12, 8, 8, 1, 12 }; int[] format_1 = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER }; int[] format_1w = new int[] { 24, 8, 8, 8, 8, 8, 8, 8, 8 }; int[] format_2 = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER }; int[] format_2w = new int[] { 12, 12, 8, 8, 8, 8 }; int[] format_3 = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE }; int[] format_3w = new int[] { 24, 12, 8 }; int[] format_4 = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE }; int[] format_4w = new int[] { 24, 8, 8, 8 }; StreamReader @in = null; StateMod_Reservoir aReservoir = null; StateMod_ReservoirAccount anAccount = null; StateMod_ReservoirClimate anEvap = null; StateMod_ReservoirClimate aPtpx = null; int i = 0; if (Message.isDebugOn) { Message.printDebug(10, routine, "in SMParseResFile reading file: " + filename); } int line_count = 0; try { @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename)); while (!string.ReferenceEquals((iline = @in.ReadLine()), null)) { ++line_count; // check for comments if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0) { continue; } // allocate new reservoir node aReservoir = new StateMod_Reservoir(); // line 1 if (Message.isDebugOn) { Message.printDebug(50, routine, "line 1: " + iline); } StringUtil.fixedRead(iline, format_0, format_0w, v); aReservoir.setID(((string)v[0]).Trim()); aReservoir.setName(((string)v[1]).Trim()); aReservoir.setCgoto(((string)v[2]).Trim()); aReservoir.setSwitch((int?)v[3]); aReservoir.setRdate((double?)v[4]); aReservoir.setCresdy(((string)v[5]).Trim()); // line 2 iline = @in.ReadLine(); ++line_count; if (Message.isDebugOn) { Message.printDebug(50, routine, "line 2: " + iline); } StringUtil.fixedRead(iline, format_1, format_1w, v); aReservoir.setVolmin(((double?)v[0])); aReservoir.setVolmax(((double?)v[1])); aReservoir.setFlomax(((double?)v[2])); aReservoir.setDeadst(((double?)v[3])); int nowner = ((int?)v[4]).Value; int nevap = ((int?)v[5]).Value; int nptpx = ((int?)v[6]).Value; int nrange = ((int?)v[7]).Value; // get the owner's information if (Message.isDebugOn) { Message.printDebug(50, routine, "Number of owners: " + nowner); } for (i = 0; i < nowner; i++) { iline = @in.ReadLine(); ++line_count; StringUtil.fixedRead(iline, format_2, format_2w, v); anAccount = new StateMod_ReservoirAccount(); // Account ID is set to the numerical count (StateMod uses the number) anAccount.setID("" + (i + 1)); anAccount.setName(((string)v[0]).Trim()); anAccount.setOwnmax(((double?)v[1])); anAccount.setCurown(((double?)v[2])); anAccount.setPcteva(((double?)v[3])); anAccount.setN2own(((int?)v[4])); aReservoir.addAccount(anAccount); } // get the evaporation information for (i = 0; i < nevap; i++) { iline = @in.ReadLine(); ++line_count; StringUtil.fixedRead(iline, format_3, format_3w, v); anEvap = new StateMod_ReservoirClimate(); anEvap.setID(((string)v[0]).Trim()); anEvap.setType(StateMod_ReservoirClimate.CLIMATE_EVAP); anEvap.setWeight(((double?)v[1])); aReservoir.addClimate(anEvap); } // get the precipitation information for (i = 0; i < nptpx; i++) { iline = @in.ReadLine(); ++line_count; StringUtil.fixedRead(iline, format_3, format_3w, v); aPtpx = new StateMod_ReservoirClimate(); aPtpx.setID(((string)v[0]).Trim()); aPtpx.setType(StateMod_ReservoirClimate.CLIMATE_PTPX); aPtpx.setWeight(((double?)v[1])); aReservoir.addClimate(aPtpx); } // get the area capacity information for (i = 0; i < nrange; i++) { iline = @in.ReadLine(); ++line_count; StringUtil.fixedRead(iline, format_4, format_4w, v); StateMod_ReservoirAreaCap anAreaCap = new StateMod_ReservoirAreaCap(); anAreaCap.setConten(((double?)v[0])); anAreaCap.setSurarea(((double?)v[1])); anAreaCap.setSeepage(((double?)v[2])); aReservoir.addAreaCap(anAreaCap); } // add the reservoir to the vector of reservoirs theReservoirs.Add(aReservoir); } } catch (Exception e) { Message.printWarning(3, routine, "Error reading reservoir stations in line " + line_count); throw e; } finally { if (@in != null) { @in.Close(); } } return(theReservoirs); }