Example #1
0
        /// <summary>
        /// Inserts the specified value into the table at the given position. </summary>
        /// <param name="value"> the object to store in the table cell. </param>
        /// <param name="row"> the row of the cell in which to place the object. </param>
        /// <param name="col"> the column of the cell in which to place the object. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }
            setDirty(true);
            StateMod_GraphNode gn = (StateMod_GraphNode)_data.get(row);

            switch (col)
            {
            case COL_TYPE:
                string type = gn.getType();
                if (type.Equals((string)value))
                {
                    break;
                }
                gn.setType((string)value);
                gn.setID("");
                gn.setSwitch(-1);
                setValueAt("", row, 1);
                setValueAt("", row, 2);
                fireTableDataChanged();
                overrideCellEdit(row, 1, true);
                overrideCellEdit(row, 2, false);
                fillIDColumn(row, (string)value);
                break;

            case COL_ID:
                gn.setID((string)value);
                gn.setSwitch(-1);
                setValueAt("", row, 2);
                fireTableDataChanged();
                overrideCellEdit(row, 2, true);
                break;

            case COL_SWITCH:
                string offOn = (string)value;
                if (offOn.Equals("Off"))
                {
                    gn.setSwitch(0);
                }
                else if (offOn.Equals("On"))
                {
                    gn.setSwitch(1);
                }
                else
                {
                    gn.setSwitch(-1);
                }
                break;
            }

            base.setValueAt(value, row, col);
        }
Example #2
0
        /// <summary>
        /// Inserts the specified value into the table at the given position. </summary>
        /// <param name="value"> the object to store in the table cell. </param>
        /// <param name="row"> the row of the cell in which to place the object. </param>
        /// <param name="col"> the column of the cell in which to place the object. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            if (row >= _data.size())
            {
                // this is probably happening as a result of an edit that did not end in time.
            }

            StateMod_GraphNode gn = (StateMod_GraphNode)_data.get(row);

            //Message.printStatus(1, "", "Set value at: " + row + ", " + col + " '" + value + "'");
            switch (col)
            {
            case COL_FILE:
                string filename    = (string)value;
                string oldFilename = (string)(getValueAt(row, col));
                if (filename.Equals(oldFilename))
                {
                    return;
                }

                if (filename.Equals(StateMod_RunSmDelta_JFrame.OPTION_BROWSE, StringComparison.OrdinalIgnoreCase))
                {
                    string newfile = browseForFile();
                    gn.setFileName(newfile);
                    if (row == 0)
                    {
                        if (newfile.Trim().Equals(""))
                        {
                            setCellAttributes(row, col, true);
                        }
                        else
                        {
                            setCellAttributes(row, col, false);
                        }
                    }
                    base.setValueAt(newfile, row, col);
                    return;
                }
                else
                {
                    gn.setFileName(filename);
                }
                if (row == 0)
                {
                    if (filename.Trim().Equals(""))
                    {
                        setCellAttributes(row, col, true);
                    }
                    else
                    {
                        setCellAttributes(row, col, false);
                    }
                }
                break;

            case COL_TYPE:
                string type    = (string)value;
                string oldType = (string)(getValueAt(row, col));

                if (type.Equals(oldType))
                {
                    return;
                }

                gn.setType(type);

                if (type.Equals(""))
                {
                    if (row == 0)
                    {
                        setCellAttributes(row, col, true);
                        emptyParmIDComboBoxes(0);
                    }
                    else
                    {
                        string aboveType = getNearestType(row);
                        if (aboveType.Equals(""))
                        {
                            // error!
                            emptyParmIDComboBoxes(row);
                        }
                        else
                        {
                            setParmIDComboBoxes(row, aboveType);
                        }
                    }
                }
                else
                {
                    if (row == 0)
                    {
                        setCellAttributes(row, col, false);
                    }
                    string aboveType = getNearestType(row);
                    if (!type.Equals(aboveType))
                    {
                        setCellAttributes(row, COL_PARM, true);
                        setParmIDComboBoxes(row, type);
                    }
                    else
                    {
                        setCellAttributes(row, COL_PARM, false);
                    }
                }

                break;

            case COL_PARM:
                string dtype = ((string)value).Trim();
                // FIXME SAM 2008-03-24 No need to do this with newer StateMod
                // since binary file uses underscores for data types.
                //dtype = dtype.replace(' ', '_');
                string oldDtype = (string)(getValueAt(row, col));
                if (dtype.Equals(oldDtype))
                {
                    return;
                }
                gn.setDtype(dtype);
                if (row == 0)
                {
                    if (dtype.Trim().Equals(""))
                    {
                        setCellAttributes(row, col, true);
                    }
                    else
                    {
                        setCellAttributes(row, col, false);
                    }
                }
                else if (!dtype.Trim().Equals(""))
                {
                    setCellAttributes(row, col, false);
                }
                break;

            case COL_YEAR:
                string year    = ((string)value).Trim();
                string oldYear = (string)(getValueAt(row, col));
                if (year.Equals(oldYear))
                {
                    return;
                }
                gn.setYrAve(year);
                if (row == 0)
                {
                    if (year.Trim().Equals(""))
                    {
                        setCellAttributes(row, col, true);
                    }
                    else
                    {
                        setCellAttributes(row, col, false);
                    }
                }
                break;

            case COL_ID:
                string id    = (string)value;
                string oldID = (string)(getValueAt(row, col));
                if (id.Equals(oldID))
                {
                    return;
                }

                /*
                 * int index = id.indexOf("(");
                 * if (index > -1) {
                 *      id = id.substring(0, index);
                 * }
                 * id = id.trim();
                 */
                gn.setID(id);
                if (id.Trim().Equals(""))
                {
                    setCellAttributes(row, col, true);
                }
                else
                {
                    setCellAttributes(row, col, false);
                }
                break;
            }
            base.setValueAt(value, row, col);
        }
Example #3
0
        /// <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);
                }
            }
        }