/// <summary> /// Sets up the data to be displayed in the table. /// </summary> private void setupData() { int num = 0; int size = _data.size(); StateMod_Well well = null; string id = null; double total = 0; int rowCount = 0; __data = new System.Collections.IList[__COLUMNS]; for (int i = 0; i < __COLUMNS; i++) { __data[i] = new List <object>(); } __rowMap = new List <object>(); StateMod_ReturnFlow rf = null; System.Collections.IList returnFlows = null; for (int i = 0; i < size; i++) { total = 0; well = (StateMod_Well)_data.get(i); id = well.getID(); if (__isDepletion) { num = well.getNrtnw2(); returnFlows = well.getDepletions(); } else { num = well.getNrtnw(); returnFlows = well.getReturnFlows(); } for (int j = 0; j < num; j++) { rf = (StateMod_ReturnFlow)returnFlows[j]; __data[__COL_ID].Add(id); __data[__COL_NODE_ID].Add(rf.getCrtnid()); __data[__COL_PERCENT].Add(new double?(rf.getPcttot())); __data[__COL_DELAY_ID].Add("" + rf.getIrtndl()); total += rf.getPcttot(); __rowMap.Add(new int?(rowCount)); rowCount++; } __data[__COL_ID].Add(id); __data[__COL_NODE_ID].Add("TOTAL"); __data[__COL_PERCENT].Add(new double?(total)); __data[__COL_DELAY_ID].Add(""); rowCount++; } _rows = rowCount; }
/// <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_ReturnFlow rf = (StateMod_ReturnFlow)_data.get(row); switch (col) { case COL_PLAN_ID: return(rf.getID()); case COL_RIVER_NODE_ID: return(rf.getCrtnid()); case COL_PERCENT_RETURN: return(rf.getPcttot()); case COL_DELAY_TABLE_ID: return(rf.getIrtndl()); case COL_COMMENT: return(rf.getComment()); default: return(""); } /* * if (!__showTotals) { * row = ((Integer)__rowMap.get(row)).intValue(); * } * return __data[col].get(row); */ }
/// <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_ReturnFlow rf = (StateMod_ReturnFlow)_data.get(row); switch (col) { case COL_RIVER_NODE: return(rf.getCrtnid()); case COL_RETURN_PCT: return(new double?(rf.getPcttot())); case COL_RETURN_ID: return(new int?(rf.getIrtndl())); 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_Plan_Return_JFrame.checkInput"; System.Collections.IList v = __worksheet.getAllData(); int size = v.Count; StateMod_ReturnFlow aReturn = null; string warning = ""; string id; string riverNodeID; double percent; string tableID; int fatalCount = 0; string comment; for (int i = 0; i < size; i++) { aReturn = (StateMod_ReturnFlow)(v[i]); id = aReturn.getID(); riverNodeID = aReturn.getCrtnid(); percent = aReturn.getPcttot(); tableID = "" + aReturn.getIrtndl(); comment = aReturn.getComment(); // TODO SAM 2011-01-02 Need to implement validators if (id.Length > 12) { warning += "\nPlan ID (" + id + ") is longer than 12 characters."; fatalCount++; } if (id.IndexOf(" ", StringComparison.Ordinal) > -1 || id.IndexOf("-", StringComparison.Ordinal) > -1) { warning += "\nPlan ID (" + id + ") cannot contain spaces or dashes."; fatalCount++; } if (riverNodeID.Length > 12) { warning += "River node ID (" + riverNodeID + ") is longer than 12 characters."; } } 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(2, routine, "Returning 0 from checkInput()"); return(0); } }
/// <summary> /// Write return flow information to a StateMod file. History header information /// is also maintained by calling this routine. </summary> /// <param name="instrfile"> input file from which previous history should be taken </param> /// <param name="outstrfile"> output file to which to write </param> /// <param name="stationType"> the station type, for the file header (e.g., "Plan", "Reservoir"). </param> /// <param name="theReturns"> list of plans to write. </param> /// <param name="newComments"> addition comments which should be included in history </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 instrfile, String outstrfile, String stationType, java.util.List<StateMod_ReturnFlow> theReturns, java.util.List<String> newComments) throws Exception public static void writeStateModFile(string instrfile, string outstrfile, string stationType, IList <StateMod_ReturnFlow> theReturns, IList <string> newComments) { string routine = "StateMod_ReturnFlow.writeStateModFile"; IList <string> commentIndicators = new List <string>(1); commentIndicators.Add("#"); IList <string> ignoredCommentIndicators = new List <string>(1); ignoredCommentIndicators.Add("#>"); PrintWriter @out = null; string comment; try { @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(instrfile), IOUtil.getPathUsingWorkingDir(outstrfile), newComments, commentIndicators, ignoredCommentIndicators, 0); int i; string iline; string cmnt = "#>"; // This format follows historical conventions found in example files, limited by StateMod ID lengths string formatLine1 = "%-12.12s %-12.12s %8.2f %-12.12s"; // Comment only written if not blank StateMod_ReturnFlow rf = null; IList <object> v = new List <object>(11); // Reuse for all output lines. @out.println(cmnt); @out.println(cmnt + "*************************************************"); @out.println(cmnt + " StateMod " + stationType + " Return Flows"); @out.println(cmnt); @out.println(cmnt + " Free format; however historical format based on StateMod"); @out.println(cmnt + " identifier string lengths is used for consistency."); @out.println(cmnt); @out.println(cmnt + " ID : " + stationType + " ID"); @out.println(cmnt + " River Node crtnid: River node identifier receiving return flow"); @out.println(cmnt + " Ret % pcttot*: Percent of return flow the the river node"); @out.println(cmnt + " Table ID irtndl*: Delay (return flow) table identifier for return"); @out.println(cmnt + " Comment : Optional (e.g., return type, name)"); @out.println(cmnt + " Double quote to faciliate free-format processing."); @out.println(cmnt); @out.println(cmnt + " ID River Node Ret % Table ID Comment"); @out.println(cmnt + "---------exb----------exb------exb----------exb-------------------------------e"); @out.println(cmnt + "EndHeader"); int num = 0; if (theReturns != null) { num = theReturns.Count; } for (i = 0; i < num; i++) { rf = theReturns[i]; if (rf == null) { continue; } // line 1 v.Clear(); v.Add(rf.getID()); v.Add(rf.getCrtnid()); v.Add(rf.getPcttot()); v.Add("" + rf.getIrtndl()); // Format as string comment = rf.getComment().Trim(); if (comment.Length > 0) { comment = " \"" + comment + "\""; } iline = StringUtil.formatString(v, formatLine1) + comment; @out.println(iline); } } catch (Exception e) { Message.printWarning(3, routine, e); throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }
/// <summary> /// Writes a list of StateMod_ReturnFlow 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 header (e.g., command file, HydroBase version). </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_ReturnFlow> data, int componentType, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReturnFlow> data, int componentType, IList <string> newComments) { int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("ID"); fields.Add("RiverNodeID"); if (componentType == StateMod_DataSet.COMP_WELL_STATION_DEPLETION_TABLES) { fields.Add("DepletionPercent"); } else { fields.Add("ReturnPercent"); } fields.Add("DelayTableID"); fields.Add("Comment"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = componentType; 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_ReturnFlow rf = 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(); try { // Add some basic comments at the top of the file. However, 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, ""); if (componentType == StateMod_DataSet.COMP_DIVERSION_STATION_DELAY_TABLES) { newComments2.Insert(1, "StateMod diversion delay (return) file."); newComments2.Insert(2, "See also the associated diversion station file."); } else if (componentType == StateMod_DataSet.COMP_WELL_STATION_DEPLETION_TABLES) { newComments2.Insert(1, "StateMod well depletion file."); newComments2.Insert(2, "See also the associated well station and return files."); } else if (componentType == StateMod_DataSet.COMP_WELL_STATION_DELAY_TABLES) { newComments2.Insert(1, "StateMod well delay (return) file."); newComments2.Insert(2, "See also the associated well station and depletion files."); } newComments2.Insert(3, ""); @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++) { rf = data[i]; line[0] = StringUtil.formatString(rf.getID(), formats[0]).Trim(); line[1] = StringUtil.formatString(rf.getCrtnid(), formats[1]).Trim(); line[2] = StringUtil.formatString(rf.getPcttot(), formats[2]).Trim(); line[3] = StringUtil.formatString(rf.getIrtndl(), formats[3]).Trim(); line[4] = StringUtil.formatString(rf.getComment(), formats[4]).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()); } } finally { if (@out != null) { @out.flush(); @out.close(); } } }