/// <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> /// 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> /// 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 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); } }