/// <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_RiverNetworkNode r = (StateMod_RiverNetworkNode)_data.get(row); switch (col) { case COL_ID: return(r.getID()); case COL_NAME: return(r.getName()); case COL_COMMENT: return(r.getComment()); case COL_CSTADN: return(r.getCstadn()); case COL_GWMAXR: return(new double?(r.getGwmaxr())); default: return(""); } }
/// <summary> /// Processes a table selection (either via a mouse press or programmatically /// from selectTableIndex() by writing the old data back to the data set component /// and getting the next selection's data out of the data and displaying it on the form. </summary> /// <param name="index"> the index of the reservoir to display on the form. </param> private void processTableSelection(int index) { /* * Message.printStatus(1, "", "Current: " + __currentStationIndex); * Message.printStatus(1, "", "Last: " + __lastStationIndex); * Message.printStatus(1, "", "Orig: " + __worksheet.getOriginalRowNumber(index)); * Message.printStatus(1, "", "Index: " + index); */ __lastStationIndex = __currentStationIndex; __currentStationIndex = __worksheet.getOriginalRowNumber(index); saveLastRecord(); if (__worksheet.getSelectedRow() == -1) { JGUIUtil.disableComponents(__disables, true); return; } JGUIUtil.enableComponents(__disables, __textUneditables, __editable); StateMod_RiverNetworkNode rnn = (StateMod_RiverNetworkNode)__riverNetworkNodesVector[__currentStationIndex]; __idJTextField.setText(rnn.getID()); __nameJTextField.setText(rnn.getName()); __nodeJTextField.setText(rnn.getCstadn()); __commentJTextField.setText(rnn.getComment()); checkViewButtonState(); }
/// <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_RiverNetworkNode r = (StateMod_RiverNetworkNode)_data.get(row); switch (col) { case COL_ID: return(r.getID()); case COL_NAME: return(r.getName()); default: return(""); } }
/// <summary> /// Writes a list of StateMod_RiverNetworkNode 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 file header. </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_RiverNetworkNode> data, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_RiverNetworkNode> data, IList <string> newComments) { string routine = "StateMod_RiverNetworkNode.writeListFile"; int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("ID"); fields.Add("Name"); fields.Add("DownstreamID"); fields.Add("Comment"); fields.Add("GWMaxRecharge"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = StateMod_DataSet.COMP_RIVER_NETWORK; 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; PrintWriter @out = null; StateMod_RiverNetworkNode rnn = null; string[] line = new string[fieldCount]; IList <string> commentIndicators = new List <string>(1); commentIndicators.Add("#"); IList <string> ignoredCommentIndicators = new List <string>(1); ignoredCommentIndicators.Add("#>"); StringBuilder buffer = new StringBuilder(); 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 river network as a delimited list file."); newComments2.Insert(2, "See also the generalized network file."); newComments2.Insert(3, ""); @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++) { rnn = (StateMod_RiverNetworkNode)data[i]; line[0] = StringUtil.formatString(rnn.getID(), formats[0]).Trim(); line[1] = StringUtil.formatString(rnn.getName(), formats[1]).Trim(); line[2] = StringUtil.formatString(rnn.getCstadn(), formats[2]).Trim(); line[3] = StringUtil.formatString(rnn.getComment(), formats[3]).Trim(); line[4] = StringUtil.formatString(rnn.getGwmaxr(), formats[4]).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> /// Write the new (updated) river network file to the StateMod river network /// file. If an original file is specified, then the original header is carried into the new file. </summary> /// <param name="infile"> Name of old file or null if no old file to update. </param> /// <param name="outfile"> Name of new file to create (can be the same as the old file). </param> /// <param name="theRivs"> list of StateMod_RiverNetworkNode to write. </param> /// <param name="newcomments"> New comments to write in the file header. </param> /// <param name="doWell"> Indicates whether well modeling fields should be written. </param> //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_RiverNetworkNode> theRivs, java.util.List<String> newcomments, boolean doWell) throws Exception public static void writeStateModFile(string infile, string outfile, IList <StateMod_RiverNetworkNode> theRivs, IList <string> newcomments, bool doWell) { PrintWriter @out = null; IList <string> commentIndicators = new List <string>(1); commentIndicators.Add("#"); IList <string> ignoredCommentIndicators = new List <string>(1); ignoredCommentIndicators.Add("#>"); string routine = "StateMod_RiverNetworkNode.writeStateModFile"; if (Message.isDebugOn) { Message.printDebug(2, routine, "Writing river network file \"" + outfile + "\" using \"" + infile + "\" header..."); } try { // Process the header from the old file... @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(infile), IOUtil.getPathUsingWorkingDir(outfile), newcomments, commentIndicators, ignoredCommentIndicators, 0); string cmnt = "#>"; string iline = null; string format = null; StateMod_RiverNetworkNode riv = null; @out.println(cmnt + " *******************************************************"); @out.println(cmnt + " StateMod River Network File"); @out.println(cmnt + " WARNING - if .net file is available, it should be edited and the .rin"); @out.println(cmnt + " file should be created from the .net"); @out.println(cmnt); @out.println(cmnt + " format: (a12, a24, a12, 1x, a12, 1x, f8.0)"); @out.println(cmnt); @out.println(cmnt + " ID cstaid: Station ID"); @out.println(cmnt + " Name stanam: Station name"); @out.println(cmnt + " Downstream cstadn: Downstream node ID"); @out.println(cmnt + " Comment comment: Alternate identifier/comment."); @out.println(cmnt + " GWMax gwmaxr: Max recharge limit (cfs) - see iwell in control file."); @out.println(cmnt); @out.println(cmnt + " ID Name DownStream Comment GWMax "); @out.println(cmnt + "---------eb----------------------eb----------exb----------exb------e"); if (doWell) { format = "%-12.12s%-24.24s%-12.12s %-12.12s %8.8s"; } else { format = "%-12.12s%-24.24s%-12.12s %-12.12s"; } @out.println(cmnt); @out.println(cmnt + "EndHeader"); @out.println(cmnt); int num = 0; if (theRivs != null) { num = theRivs.Count; } IList <object> v = new List <object>(5); for (int i = 0; i < num; i++) { riv = theRivs[i]; v.Clear(); v.Add(riv.getID()); v.Add(riv.getName()); v.Add(riv.getCstadn()); v.Add(riv.getComment()); if (doWell) { // Format as string since main format uses string. v.Add(StringUtil.formatString(riv.getGwmaxr(), "%8.0f")); } iline = StringUtil.formatString(v, format); @out.println(iline); } } catch (Exception e) { Message.printWarning(3, routine, e); throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }