/// <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_InstreamFlow isf = (StateMod_InstreamFlow)_data.get(row); switch (col) { case COL_ID: return(isf.getID()); case COL_NAME: return(isf.getName()); case COL_DAILY_ID: return(isf.getCifridy()); case COL_DOWN_NODE: return(isf.getIfrrdn()); case COL_DEMAND_TYPE: return(new int?(isf.getIifcom())); default: return(""); } }
/// <summary> /// Constructor. </summary> /// <param name="dataset"> the dataset in which the data is contained. </param> /// <param name="insf"> the InstreamFlow right to display. </param> /// <param name="editable"> whether the gui data is editable or not </param> public StateMod_InstreamFlow_Right_JFrame(StateMod_DataSet dataset, StateMod_InstreamFlow insf, bool editable) { StateMod_GUIUtil.setTitle(this, dataset, insf.getName() + " - Instream Flow Water Rights", null); JGUIUtil.setIcon(this, JGUIUtil.getIconImage()); __currentInstreamFlow = insf; __dataset = dataset; __editable = editable; setupGUI(); }
/// <summary> /// Writes a list of StateMod_InstreamFlow 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"> additional comments to write to the 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_InstreamFlow> data, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_InstreamFlow> data, IList <string> newComments) { int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("ID"); fields.Add("Name"); fields.Add("UpstreamRiverNodeID"); fields.Add("OnOff"); fields.Add("DownstreamRiverNodeID"); fields.Add("DailyID"); fields.Add("DemandType"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = StateMod_DataSet.COMP_INSTREAM_STATIONS; 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_InstreamFlow flo = 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, ""); newComments2.Insert(1, "StateMod instream flow stations as a delimited list file."); newComments2.Insert(2, ""); @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++) { flo = (StateMod_InstreamFlow)data[i]; line[0] = StringUtil.formatString(flo.getID(), formats[0]).Trim(); line[1] = StringUtil.formatString(flo.getName(), formats[1]).Trim(); line[2] = StringUtil.formatString(flo.getCgoto(), formats[2]).Trim(); line[3] = StringUtil.formatString(flo.getSwitch(), formats[3]).Trim(); line[4] = StringUtil.formatString(flo.getIfrrdn(), formats[4]).Trim(); line[5] = StringUtil.formatString(flo.getCifridy(), formats[5]).Trim(); line[6] = StringUtil.formatString(flo.getIifcom(), 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()); } } finally { if (@out != null) { @out.flush(); @out.close(); } } }
/// <summary> /// Write the instream flow objects to the StateMod file. </summary> /// <param name="infile"> input file(original file read from, can be null). </param> /// <param name="outfile"> output file(to create or update, can be same as input). </param> /// <param name="theInsf"> list of StateMod_InstreamFlow instances. </param> /// <param name="newcomments"> Comments to add at the top of the file. </param> /// <param name="useDailyData"> Indicates whether daily and extended data(cifridy, iifcom)should be used. </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 infile, String outfile, java.util.List<StateMod_InstreamFlow> theInsf, java.util.List<String> newcomments, boolean useDailyData) throws Exception public static void writeStateModFile(string infile, string outfile, IList <StateMod_InstreamFlow> theInsf, IList <string> newcomments, bool useDailyData) { string routine = "StateMod_InstreamFlow.writeStateModFile"; IList <string> commentIndicators = new List <string>(1); commentIndicators.Add("#"); IList <string> ignoredCommentIndicators = new List <string>(1); ignoredCommentIndicators.Add("#>"); PrintWriter @out = null; Message.printStatus(2, routine, "Writing instream flows to file \"" + outfile + "\" using \"" + infile + "\" header..."); // Process the header from the old file... try { @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(infile), IOUtil.getPathUsingWorkingDir(outfile), newcomments, commentIndicators, ignoredCommentIndicators, 0); int i; string iline; string cmnt = "#>"; IList <object> v = new List <object>(7); StateMod_InstreamFlow insf = null; string format_0 = "%-12.12s%-24.24s%-12.12s%8d %-12.12s %-12.12s%8d"; string format_1 = "%-12.12s%-24.24s%-12.12s%8d %-12.12s"; @out.println(cmnt); @out.println(cmnt + " ******************************************************* "); @out.println(cmnt + " StateMod Instream Flow Station File"); @out.println(cmnt); @out.println(cmnt + " Card format: (a12,a24,a12,i8,1x,a12,1x,a12,i8)"); @out.println(cmnt); @out.println(cmnt + " ID cifrid: Instream Flow ID"); @out.println(cmnt + " Name cfrnam: Instream Flow Name"); @out.println(cmnt + " Riv ID cgoto: Upstream river ID where instream flow is located"); @out.println(cmnt + " On/Off ifrrsw: Switch; 0=off, 1=on"); @out.println(cmnt + " Downstream ifrrdn: Downstream river ID where instream flow is located"); @out.println(cmnt + " (blank indicates downstream=upstream)"); @out.println(cmnt + " DailyID cifridy: Daily instream flow ID (see StateMod doc)"); @out.println(cmnt + " DemandType iifcom: Demand type switch (see StateMod doc)"); @out.println(cmnt); @out.println(cmnt + " ID Name Riv ID On/Off Downstream DailyID DemandType"); @out.println(cmnt + "---------eb----------------------eb----------eb------e-b----------exb----------eb------e"); @out.println(cmnt + "EndHeader"); @out.println(cmnt); int num = 0; if (theInsf != null) { num = theInsf.Count; } for (i = 0; i < num; i++) { insf = theInsf[i]; if (insf == null) { continue; } v.Clear(); v.Add(insf.getID()); v.Add(insf.getName()); v.Add(insf.getCgoto()); v.Add(new int?(insf.getSwitch())); v.Add(insf.getIfrrdn()); if (useDailyData) { v.Add(insf.getCifridy()); v.Add(new int?(insf.getIifcom())); iline = StringUtil.formatString(v, format_0); } else { iline = StringUtil.formatString(v, format_1); } @out.println(iline); } } catch (Exception e) { Message.printWarning(3, routine, e); throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }
/// <summary> /// Sets up the GUI. /// </summary> private void setupGUI() { string routine = "setupGUI"; addWindowListener(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("Instream flow:")); info_panel.add(new JLabel(__currentInstreamFlow.getID())); info_panel.add(new JLabel("Instream flow name:")); info_panel.add(new JLabel(__currentInstreamFlow.getName())); if (__editable) { p1.add(__addRight); p1.add(__deleteRight); } 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 { System.Collections.IList v = new List <object>(); System.Collections.IList v2 = __currentInstreamFlow.getRights(); for (int i = 0; i < v2.Count; i++) { v.Add(((StateMod_InstreamFlowRight)(v2[i])).clone()); } StateMod_InstreamFlowRight_TableModel tmi = new StateMod_InstreamFlowRight_TableModel(v, __editable, true); StateMod_InstreamFlowRight_CellRenderer cri = new StateMod_InstreamFlowRight_CellRenderer(tmi); jsw = new JScrollWorksheet(cri, tmi, p); __worksheet = jsw.getJWorksheet(); widths = cri.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); System.Collections.IList v = new List <object>(); v.Add("0 - Off"); v.Add("1 - On"); __worksheet.setColumnJComboBoxValues(StateMod_InstreamFlowRight_TableModel.COL_ON_OFF, v); 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); cancelJButton.addActionListener(this); applyJButton.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); } }