/// <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_ReservoirClimate cl = (StateMod_ReservoirClimate)_data.get(row); // necessary for table models that display climate data 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(cl.getCgoto()); case COL_STATION: return(cl.getID()); case COL_PCT_WEIGHT: return(new double?(cl.getWeight())); 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_ReservoirClimate cl = (StateMod_ReservoirClimate)_data.get(row); switch (col) { case COL_RESERVOIR_ID: return(cl.getCgoto()); case COL_STATION: return(cl.getID()); case COL_PCT_WEIGHT: return(new double?(cl.getWeight())); default: return(""); } }
/// <summary> /// Writes a list of StateMod_ReservoirClimate 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 Vector of objects to write. </param> /// <param name="componentType"> one of either StateMod_DataSet.COMP_RESERVOIR_PRECIP_STATIONS or /// StateMod_DataSet.COMP_RESERVOIR_EVAP_STATIONS. </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_ReservoirClimate> data, java.util.List<String> newComments, int componentType) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReservoirClimate> data, IList <string> newComments, int componentType) { string routine = "StateMod_ReservoirClimate.writeListFile"; int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("ReservoirID"); fields.Add("StationID"); fields.Add("PercentWeight"); 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_ReservoirClimate cli = 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. 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_RESERVOIR_STATION_EVAP_STATIONS) { newComments2.Insert(1, "StateMod reservoir evaporation station assignment as a delimited list file."); newComments2.Insert(2, "See also the associated station, account, precipitation station,"); } else if (componentType == StateMod_DataSet.COMP_RESERVOIR_STATION_PRECIP_STATIONS) { newComments2.Insert(1, "StateMod reservoir precipitation station assignment as a delimited list file."); newComments2.Insert(2, "See also the associated station, account, 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++) { if (i > 0) { buffer.Append(delimiter); } buffer.Append("\"" + names[i] + "\""); } @out.println(buffer.ToString()); for (int i = 0; i < size; i++) { cli = (StateMod_ReservoirClimate)data[i]; line[0] = StringUtil.formatString(cli.getCgoto(), formats[0]).Trim(); line[1] = StringUtil.formatString(cli.getID(), formats[1]).Trim(); line[2] = StringUtil.formatString(cli.getWeight(), formats[2]).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> /// 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(JWorksheet worksheet, string name) { string routine = "StateMod_Reservoir_Climate_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_ReservoirClimate> v = (java.util.List<StateMod_ReservoirClimate>)worksheet.getAllData(); IList <StateMod_ReservoirClimate> v = (IList <StateMod_ReservoirClimate>)worksheet.getAllData(); int size = v.Count; StateMod_ReservoirClimate acct = null; string warning = ""; string id; int fatalCount = 0; for (int i = 0; i < size; i++) { acct = (v[i]); id = acct.getID(); if (id.Length > 12) { warning += "\n" + name + " reservoir climate ID (" + id + ") is " + "longer than 12 characters."; fatalCount++; } if (id.IndexOf(" ", StringComparison.Ordinal) > -1 || id.IndexOf("-", StringComparison.Ordinal) > -1) { warning += "\n" + name + " reservoir climate ID (" + id + ") cannot " + "contain spaces or dashes."; 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); } }