/// <summary> /// From AbstractTableModel; 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_GraphNode gn = (StateMod_GraphNode)_data.get(row); switch (col) { case COL_FILE: return(gn.getFileName()); case COL_TYPE: return(gn.getType()); case COL_PARM: string s = gn.getDtype(); // FIXME SAM 2008-03-24 No need to do this with newer StateMod // since binary file uses underscores for data types. //s = (s.replace('_', ' ')).trim(); return(s); case COL_YEAR: return(gn.getYrAve()); case COL_ID: return(gn.getID()); default: return(""); } }
/// <summary> /// Checks to see if a row can be added to the table. Rows cannot be added if the first row is not fully /// filled out. /// TODO (JTS - 2006-03-06) /// I think this is bad code. I think the elementAt() call should return the /// last data value -- as it is, it is only checking that the first row is /// set up properly. </summary> /// <returns> true if a new row can be added, false if not. </returns> public virtual bool canAddRow() { if (_rows == 0) { return(true); } StateMod_GraphNode gn = (StateMod_GraphNode)_data.get(0); if (gn.getFileName().Trim().Equals("")) { return(false); } if (gn.getType().Trim().Equals("")) { return(false); } if (gn.getDtype().Trim().Equals("")) { return(false); } if (gn.getYrAve().Trim().Equals("")) { return(false); } if (gn.getID().Trim().Equals("")) { return(false); } return(true); }
/// <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_GraphNode gn = (StateMod_GraphNode)_data.get(row); string ID = gn.getID(); switch (col) { case COL_TYPE: string type = gn.getType(); if (type.Equals("")) { return(""); } else if (type.Equals("INS", StringComparison.OrdinalIgnoreCase) || type.Equals("Instream Flow", StringComparison.OrdinalIgnoreCase)) { return("Instream Flow"); } else if (type.Equals("DIV", StringComparison.OrdinalIgnoreCase) || type.Equals("Diversion", StringComparison.OrdinalIgnoreCase)) { return("Diversion"); } else if (type.Equals("RES", StringComparison.OrdinalIgnoreCase) || type.Equals("Reservoir", StringComparison.OrdinalIgnoreCase)) { return("Reservoir"); } else if (type.Equals("STR", StringComparison.OrdinalIgnoreCase) || type.Equals("Streamflow", StringComparison.OrdinalIgnoreCase)) { return("Streamflow"); } else if (type.Equals("WEL", StringComparison.OrdinalIgnoreCase) || type.Equals("Well", StringComparison.OrdinalIgnoreCase)) { return("Well"); } else { if (ID.Equals("All")) { return(""); } return("Other"); } case COL_ID: if (ID.Equals("All")) { return("All"); } else if (ID.Equals("")) { return(""); } return(findIDMatch(gn.getType(), gn.getID())); case COL_SWITCH: if (ID.Equals("All")) { return(""); } if (gn.getSwitch() == 0) { return("Off"); } else if (gn.getSwitch() == 1) { return("On"); } else { return(""); } default: return(""); } }
/// <summary> /// Saves form data to the data set. </summary> /// <param name="worksheetData"> the data in the worksheet to save. </param> /// <returns> a list of data objects created from the data in the worksheet. </returns> public virtual IList <StateMod_GraphNode> formSaveData(IList <StateMod_GraphNode> worksheetData) { int rows = worksheetData.Count; if (rows == 0) { return(new List <StateMod_GraphNode>()); } // gnw will be a node used to read data FROM the _W_orksheet nodes StateMod_GraphNode gnw = worksheetData[0]; string pfile = gnw.getFileName().Trim(); string ptype = gnw.getType().Trim(); string pdtype = gnw.getDtype().Trim(); string pyear = gnw.getYrAve().Trim(); string pid = gnw.getID().Trim(); string file = null; string type = null; string dtype = null; string year = null; string id = null; // gno will be a node used for creating the _O_utput nodes StateMod_GraphNode gno = new StateMod_GraphNode(); gno.setFileName(pfile); gno.setType(ptype); gno.setDtype(pdtype); gno.setYrAve(pyear); int paren = pid.IndexOf("(", StringComparison.Ordinal); if (paren > -1) { gno.addID(pid.Substring(0, paren).Trim()); } else { gno.addID(pid); } IList <StateMod_GraphNode> v = new List <StateMod_GraphNode>(); for (int i = 1; i < rows; i++) { gnw = worksheetData[i]; file = gnw.getFileName().Trim(); if (file.Equals("")) { file = pfile; } type = gnw.getType().Trim(); if (type.Equals("")) { type = ptype; } dtype = gnw.getDtype().Trim(); if (dtype.Equals("")) { dtype = pdtype; } year = gnw.getYrAve().Trim(); if (year.Equals("")) { year = pyear; } id = gnw.getID().Trim(); if (id.Equals("")) { id = pid; } if (file.Equals(pfile) && type.Equals(ptype) && dtype.Equals(pdtype) && year.Equals(pyear)) { // all the fields match, so this is a different ID // added to the Vector of IDs in the node's vector. paren = id.IndexOf("(", StringComparison.Ordinal); if (paren > -1) { gno.addID(id.Substring(0, paren).Trim()); } else { gno.addID(id); } } else { // otherwise, values other than just the ID are // different, so a new node needs created v.Add(gno); gno = new StateMod_GraphNode(); gno.setFileName(file); gno.setType(type); gno.setDtype(dtype); gno.setYrAve(year); paren = id.IndexOf("(", StringComparison.Ordinal); if (paren > -1) { gno.addID(id.Substring(0, paren).Trim()); } else { gno.addID(id); } } pfile = file; ptype = type; pdtype = dtype; pyear = year; pid = id; } v.Add(gno); return(v); }
/// <summary> /// Creates a list of objects suitable for use in the worksheet from the data /// read from a delta plot file. </summary> /// <param name="fileData"> the fileData to process. </param> /// <returns> a list of objects suitable for use within a form. </returns> public virtual IList <StateMod_GraphNode> formLoadData(IList <StateMod_GraphNode> fileData) { int rows = fileData.Count; if (rows == 0) { return(new List <StateMod_GraphNode>()); } // gnf will be a node used to read data FROM the _F_ile nodes StateMod_GraphNode gnf = fileData[0]; string pfile = ""; string ptype = ""; string pyear = ""; string file = null; string type = null; string dtype = null; string year = null; // gnw will be a node used for creating the _W_orksheet nodes StateMod_GraphNode gnw = null; IList <StateMod_GraphNode> v = new List <StateMod_GraphNode>(); int ids = 0; for (int i = 0; i < rows; i++) { gnf = fileData[i]; ids = gnf.getIDVectorSize(); file = gnf.getFileName().Trim(); type = gnf.getType().Trim(); dtype = gnf.getDtype().Trim(); year = gnf.getYrAve().Trim(); for (int j = 0; j < ids; j++) { if (j == 0) { gnw = new StateMod_GraphNode(); if (!file.Equals(pfile)) { gnw.setFileName(file); } else { gnw.setFileName(""); } if (!type.Equals(ptype)) { gnw.setType(type); } else { gnw.setType(""); } if (!dtype.Equals(dtype)) { gnw.setDtype(dtype); } else { gnw.setDtype(""); } if (!year.Equals(pyear)) { gnw.setYrAve(year); } else { gnw.setYrAve(""); } gnw.setID(gnf.getID(0).Trim()); } else { gnw.setFileName(""); gnw.setType(""); gnw.setDtype(""); gnw.setYrAve(""); gnw.setID(gnf.getID(j).Trim()); } gnw.setSwitch(gnf.getSwitch()); v.Add(gnw); } pfile = file; ptype = type; pyear = year; } return(v); }
/// <summary> /// Responds to action performed events. </summary> /// <param name="ae"> the ActionEvent that happened. </param> public virtual void actionPerformed(ActionEvent ae) { string routine = "StateMod_OutputControl_JFrame.actionPerformed"; string action = ae.getActionCommand(); if (action.Equals(__BUTTON_ADD_ROW)) { if (!__tableModel.canAddNewRow()) { return; } __dirty = true; int row = __worksheet.getRowCount(); StateMod_GraphNode n = new StateMod_GraphNode(); __worksheet.addRow(n); n.setType(""); n.setID(""); n.setSwitch(-1); __tableModel.setDirty(true); // when a row is added, mark the second and third columns // as uneditable. They will be set to editable as soon as // the user enters a value in the first column __worksheet.setCellEditable(row, 1, false); __worksheet.setCellEditable(row, 2, false); } else if (action.Equals(__BUTTON_CLEAR_LIST)) { __dirty = true; __worksheet.clear(); setMessages("Add station to list.", "Ready"); __tableModel.setDirty(true); } else if (action.Equals(__BUTTON_CLOSE)) { closeWindow(); } else if (action.Equals(__BUTTON_DELETE_ROW)) { int[] rows = __worksheet.getSelectedRows(); int length = rows.Length; __tableModel.setDirty(true); if (length == 0) { return; } for (int i = (length - 1); i >= 0; i--) { __worksheet.deleteRow(rows[i]); } __dirty = true; setMessages("Time series list has changed.", "Ready"); } else if (action.Equals(__BUTTON_HELP)) { // REVISIT HELP (JTS - 2003-07-09) } else if (action.Equals(__BUTTON_SAVE_FILE)) { JGUIUtil.setWaitCursor(this, true); string lastDirectorySelected = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = null; if (!string.ReferenceEquals(lastDirectorySelected, null)) { fc = new JFileChooser(lastDirectorySelected); } else { fc = new JFileChooser(); } fc.setDialogTitle("Select Output Control File"); SimpleFileFilter @out = new SimpleFileFilter("out", "StateMod Output Control Files"); fc.addChoosableFileFilter(@out); SimpleFileFilter tpl = new SimpleFileFilter("tpo", "StateMod Output Control Files"); fc.addChoosableFileFilter(tpl); SimpleFileFilter xou = new SimpleFileFilter("xou", "StateMod Output Control Files"); fc.addChoosableFileFilter(xou); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(tpl); fc.setDialogType(JFileChooser.SAVE_DIALOG); JGUIUtil.setWaitCursor(this, false); int retVal = fc.showSaveDialog(this); if (retVal != JFileChooser.APPROVE_OPTION) { return; } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(lastDirectorySelected, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getName(); FileFilter ff = fc.getFileFilter(); if (ff == @out) { filename = IOUtil.enforceFileExtension(filename, "out"); } else if (ff == tpl) { filename = IOUtil.enforceFileExtension(filename, "tpo"); } else if (ff == xou) { filename = IOUtil.enforceFileExtension(filename, "xou"); } __dirty = false; __tableModel.setDirty(false); System.Collections.IList theGraphNodes = __worksheet.getAllData(); try { StateMod_GraphNode.writeStateModOutputControlFile(null, currDir + File.separator + filename, theGraphNodes, null); } catch (Exception e) { Message.printWarning(1, routine, "Error saving output control file\n" + "\"" + currDir + File.separator + filename + "\"", this); Message.printWarning(2, routine, e); } } else if (action.Equals(__BUTTON_LOAD_FILE)) { JGUIUtil.setWaitCursor(this, true); string lastDirectorySelected = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = null; if (!string.ReferenceEquals(lastDirectorySelected, null)) { fc = new JFileChooser(lastDirectorySelected); } else { fc = new JFileChooser(); } fc.setDialogTitle("Select Output Control File"); SimpleFileFilter @out = new SimpleFileFilter("out", "StateMod Output Control Files"); fc.addChoosableFileFilter(@out); SimpleFileFilter tpl = new SimpleFileFilter("tpo", "StateMod Output Control Files"); fc.addChoosableFileFilter(tpl); SimpleFileFilter xou = new SimpleFileFilter("xou", "StateMod Output Control Files"); fc.addChoosableFileFilter(xou); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(tpl); fc.setDialogType(JFileChooser.OPEN_DIALOG); JGUIUtil.setWaitCursor(this, false); int retVal = fc.showOpenDialog(this); if (retVal != JFileChooser.APPROVE_OPTION) { return; } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(lastDirectorySelected, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getName(); JGUIUtil.setWaitCursor(this, true); __dirty = false; System.Collections.IList theGraphNodes = new List <object>(20, 1); try { __worksheet.clear(); __tableModel.setDirty(false); StateMod_GraphNode.readStateModOutputControlFile(theGraphNodes, currDir + File.separator + filename); int size = theGraphNodes.Count; StateMod_GraphNode g = null; int row = 0; for (int i = 0; i < size; i++) { row = __worksheet.getRowCount(); g = (StateMod_GraphNode)theGraphNodes[i]; if (i == 0) { if (g.getID().Equals("All")) { __useAllJCheckBox.setSelected(true); } else { __useAllJCheckBox.setSelected(false); } } __worksheet.addRow(g); __tableModel.fillIDColumn(row, g.getType()); } __worksheet.setData(theGraphNodes); } catch (Exception e) { Message.printWarning(1, routine, "Error loading output control file\n" + "\"" + currDir + File.separator + filename + "\"", this); Message.printWarning(2, routine, e); } JGUIUtil.setWaitCursor(this, false); } else if (action.Equals(__CHECKBOX_USE_ALL)) { // if the use all checkbox is selected, subtle changes from the // default functionality are made. The buttons to add and // delete rows are disabled, and the ID of the only record // in the worksheet is set to "All". This ID value is used // in the table model to determine when the checkbox is // selected. In addition, the ComboBox functionality of the // first and third data columns is turned off. if (__useAllJCheckBox.isSelected()) { __addRowButton.setEnabled(false); __deleteRowButton.setEnabled(false); __worksheet.setColumnJComboBoxValues(0, null); __worksheet.setColumnJComboBoxValues(2, null); __worksheet.clear(); StateMod_GraphNode g = new StateMod_GraphNode(); g.setID("All"); __worksheet.setCellEditable(0, 0, false); __worksheet.setCellEditable(0, 1, false); __worksheet.setCellEditable(0, 2, false); __worksheet.addRow(g); } else { __addRowButton.setEnabled(true); __deleteRowButton.setEnabled(true); System.Collections.IList v = StateMod_Util.arrayToList(StateMod_GraphNode.node_types); v.Add("Other"); __worksheet.setColumnJComboBoxValues(0, v); __worksheet.clear(); System.Collections.IList offOn = new List <object>(); offOn.Add("Off"); offOn.Add("On"); __worksheet.setCellEditable(0, 0, true); __worksheet.setColumnJComboBoxValues(2, offOn); } } }