Example #1
0
        /// <summary>
        /// Sets the value at the specified position to the specified value. </summary>
        /// <param name="value"> the value to set the cell to. </param>
        /// <param name="row"> the row of the cell for which to set the value. </param>
        /// <param name="col"> the col of the cell for which to set the value. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }
            switch (col)
            {
            case COL_NAME:             // File name...
                string s   = ((string)value).Trim();
                string dir = __dataset.getDataSetDirectory();
                try
                {
                    s = IOUtil.toRelativePath(dir, s);
                }
                catch (Exception e)
                {
                    string routine = "StateMod_Response_TableModel"
                                     + ".setValue";
                    Message.printWarning(2, routine, "Error converting to relative path (" + dir + ", " + s + "):");
                    Message.printWarning(2, routine, e);
                }

                if (s.Equals(((string)getValueAt(row, col)).Trim()))
                {
                    return;
                }

                __dataset.getComponentForComponentType(__data[row]).setDataFileName(s);
                __dataset.getComponentForComponentType(__data[row]).setDirty(true);
                goto default;

            default:
                break;
            }

            base.setValueAt(value, row, col);
        }
        /// <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];
            }

            /*
             * Message.printStatus(1, "", "---------------------------------------");
             * Message.printStatus(1, "", "SET VALUE AT: " + row + ", " +col);
             * JWorksheet.except(1, 3);
             * Message.printStatus(1, "", "---------------------------------------");
             */

            TSIdent tsident = (TSIdent)_data.get(row);

            switch (col)
            {
            case _COL_STATION_TYPE:
                string type = tsident.getAlias();
                if (type.Equals((string)value))
                {
                    break;
                }
                tsident.setAlias((string)value);
                tsident.setLocation("");
                setValueAt("", row, _COL_INTERVAL);
                // this next line wouldn't seem to make any sense, but leave it in!!
                setValueAt(getValueAt(row, _COL_DATA_TYPE), row, _COL_DATA_TYPE);
                fireTableDataChanged();
                overrideCellEdit(row, _COL_ID, true);
                fillIDColumn(row, (string)value);
                // Since the ID is filled, select the first item by
                // default to force something to be displayed...
                if (__worksheet != null)
                {
                    System.Collections.IList ids = __worksheet.getCellSpecificJComboBoxValues(row, _COL_ID);
                    if (ids.Count > 0)
                    {
                        setValueAt(ids[0], row, _COL_ID);
                    }
                    else
                    {
                        setValueAt("", row, _COL_ID);
                    }
                }
                break;

            case _COL_ID:
                string id = (string)value;
                tsident.setLocation(id);
                bool   outputOnly = false;
                string staType    = (string)getValueAt(row, _COL_STATION_TYPE);
                if (staType.Equals(StateMod_Util.STATION_TYPE_RESERVOIR))
                {
                    if (id.IndexOf("-", StringComparison.Ordinal) > -1)
                    {
                        outputOnly = true;
                    }
                }
                overrideCellEdit(row, _COL_DATA_TYPE, true);
                // Fill the interval cell, given the station type and identifier...
                if (((string)value).Length == 0)
                {
                    fireTableDataChanged();
                }
                fillIntervalColumn(row, (string)getValueAt(row, _COL_STATION_TYPE), (string)value);
                if (outputOnly)
                {
                    fillDataTypeColumn(row, true, (string)getValueAt(row, _COL_STATION_TYPE), (string)getValueAt(row, _COL_ID), (string)value);
                }
                else
                {
                    fillDataTypeColumn(row, false, (string)getValueAt(row, _COL_STATION_TYPE), (string)getValueAt(row, _COL_ID), (string)value);
                }
                fireTableDataChanged();
                break;

            case _COL_INTERVAL:
                try
                {
                    tsident.setInterval((string)value);
                }
                catch (Exception)
                {
                    // Should not happen.
                }
                bool   ioutputOnly = false;
                string istaType    = (string)getValueAt(row, _COL_STATION_TYPE);
                string iid         = (string)getValueAt(row, _COL_ID);
                if (istaType.Equals(StateMod_Util.STATION_TYPE_RESERVOIR))
                {
                    if (iid.IndexOf("-", StringComparison.Ordinal) > -1)
                    {
                        ioutputOnly = true;
                    }
                }
                if (ioutputOnly)
                {
                    fillDataTypeColumn(row, true, (string)getValueAt(row, _COL_STATION_TYPE), (string)getValueAt(row, _COL_ID), (string)value);
                }
                else
                {
                    fillDataTypeColumn(row, false, (string)getValueAt(row, _COL_STATION_TYPE), (string)getValueAt(row, _COL_ID), (string)value);
                }
                // this next line wouldn't seem to make any sense, but leave it in!!
                setValueAt(getValueAt(row, _COL_DATA_TYPE), row, _COL_DATA_TYPE);
                fireTableDataChanged();
                break;

            case _COL_DATA_TYPE:
                tsident.setType((string)value);
                // Fill the input type cell, given the station type, identifier, and interval...
                fillInputTypeColumn(row, (string)getValueAt(row, _COL_STATION_TYPE), (string)getValueAt(row, _COL_ID), (string)getValueAt(row, _COL_INTERVAL), (string)value);
                fireTableDataChanged();
                break;

            case _COL_INPUT_TYPE:
                tsident.setInputType((string)value);
                // Fill the input name with defaults...
                fillInputNameColumn(row, (string)getValueAt(row, _COL_STATION_TYPE), (string)getValueAt(row, _COL_ID), (string)getValueAt(row, _COL_INTERVAL), (string)getValueAt(row, _COL_DATA_TYPE), (string)value);
                break;

            case _COL_INPUT_NAME:
                string s = (string)value;
                if (s.Equals(__BROWSE_INPUT_NAME_ABSOLUTE))
                {
                    s = browseForFile();
                }
                else if (s.Equals(__BROWSE_INPUT_NAME_RELATIVE))
                {
                    string file = browseForFile();
                    if (!string.ReferenceEquals(file, null))
                    {
                        try
                        {
                            int    index      = file.LastIndexOf(File.separator);
                            string workingDir = __dataset.getDataSetDirectory();
                            string dir        = IOUtil.toRelativePath(workingDir, file.Substring(0, index));
                            s = dir + File.separator + file.Substring(index + 1, file.Length - (index + 1));
                        }
                        catch (Exception)
                        {
                            // TODO (JTS - 2003-11-05)  maybe handle this better.  Right now just defaults to the absolute filename
                            s = file;
                        }
                    }
                }
                tsident.setInputName(s);
                // don't go through the super.setValueAt() at the end of the method ...
                base.setValueAt(s, row, col);
                return;
            }

            base.setValueAt(value, row, col);
        }
Example #3
0
        /// <summary>
        /// Sets up the GUI.
        /// </summary>
        private void setupGUI()
        {
            string routine = "StateMod_Save_JDialog.setupGUI";

            addWindowListener(this);

            PropList p = new PropList("StateMod_Save_JDialog.JWorksheet");

            /*
             * p.add("JWorksheet.CellFont=Courier");
             * p.add("JWorksheet.CellStyle=Plain");
             * p.add("JWorksheet.CellSize=11");
             * p.add("JWorksheet.HeaderFont=Arial");
             * p.add("JWorksheet.HeaderStyle=Plain");
             * p.add("JWorksheet.HeaderSize=11");
             * p.add("JWorksheet.HeaderBackground=LightGray");
             * p.add("JWorksheet.RowColumnPresent=false");
             */
            p.add("JWorksheet.ShowPopupMenu=true");
            p.add("JWorksheet.SelectionMode=MultipleDiscontinuousRowSelection");

            int[]            widths = null;
            JScrollWorksheet jsw    = null;

            try
            {
                __tableModel = new StateMod_Save_TableModel(__dataset);
                StateMod_Save_CellRenderer crr = new StateMod_Save_CellRenderer(__tableModel);

                jsw         = new JScrollWorksheet(crr, __tableModel, p);
                __worksheet = jsw.getJWorksheet();

                widths = crr.getColumnWidths();
                // Select all the rows initially...
                __worksheet.selectAllRows();
            }
            catch (Exception e)
            {
                Message.printWarning(1, routine, "Error building worksheet.");
                Message.printWarning(2, routine, e);
                jsw         = new JScrollWorksheet(0, 0, p);
                __worksheet = jsw.getJWorksheet();
            }
            __worksheet.setPreferredScrollableViewportSize(null);
            __worksheet.setHourglassJFrame(__parent);

            __helpButton = new SimpleJButton(__BUTTON_HELP, this);
            __helpButton.setEnabled(false);
            __saveButton = new SimpleJButton(__BUTTON_SAVE, this);
            __saveButton.setToolTipText("Save data to file(s).");
            __cancelButton = new SimpleJButton(__BUTTON_CANCEL, this);
            __cancelButton.setToolTipText("Cancel without saving data to file(s).");

            JPanel panel = new JPanel();

            panel.setLayout(new GridBagLayout());
            JGUIUtil.addComponent(panel, new JLabel("Data from the following files have been modified."), 0, 0, 2, 1, 1, 1, 0, 0, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);
            JGUIUtil.addComponent(panel, new JLabel("Select files to be saved and press the \"Save Selected Files\" button."), 0, 1, 2, 1, 1, 1, 0, 0, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);
            JGUIUtil.addComponent(panel, new JLabel("To change the filenames, use the Data...Control...Response menu"), 0, 2, 2, 1, 1, 1, 0, 0, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);
            JGUIUtil.addComponent(panel, new JLabel("Data set base name (from *.rsp):  "), 0, 3, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHEAST);
            JGUIUtil.addComponent(panel, new JLabel(__dataset.getBaseName()), 1, 3, 1, 1, 1, 1, 0, 0, 0, 0, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);
            JGUIUtil.addComponent(panel, new JLabel("Data set directory:  "), 0, 4, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHEAST);
            JGUIUtil.addComponent(panel, new JLabel(__dataset.getDataSetDirectory()), 1, 4, 1, 1, 1, 1, 0, 0, 0, 0, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);

            __updateCheckbox = new JCheckBox((string)null, true);
            JGUIUtil.addComponent(panel, __updateCheckbox, 0, 6, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHEAST);
            JGUIUtil.addComponent(panel, new JLabel("Carry forward old file comments?"), 1, 6, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);

            getContentPane().add("North", panel);
            getContentPane().add("Center", jsw);

            JPanel button_panel = new JPanel();

            button_panel.add(__saveButton);
            button_panel.add(__cancelButton);
            //	button_panel.add(__helpButton);

            JPanel bottom_panel = new JPanel();

            bottom_panel.setLayout(new BorderLayout());
            getContentPane().add("South", bottom_panel);
            bottom_panel.add("South", button_panel);

            pack();
            setSize(700, 500);

            JGUIUtil.center(this);

            if (widths != null)
            {
                __worksheet.setColumnWidths(widths, __parent.getGraphics());
            }

            setVisible(true);
        }
Example #4
0
        /// <summary>
        /// Sets up the GUI.
        /// </summary>
        private void setupGUI()
        {
            string routine = "StateMod_Response_JFrame.setupGUI";

            addWindowListener(this);

            PropList p = new PropList("StateMod_Response_JFrame.JWorksheet");

            p.add("JWorksheet.ShowPopupMenu=true");
            p.add("JWorksheet.AllowCopy=true");
            p.add("JWorksheet.SelectionMode=SingleRowSelection");

            int[]            widths = null;
            JScrollWorksheet jsw    = null;

            try
            {
                // Operate on a copy of the table model...
                __tableModel = new StateMod_Response_TableModel(__dataset_copy);
                StateMod_Response_CellRenderer crr = new StateMod_Response_CellRenderer(__tableModel);

                jsw         = new JScrollWorksheet(crr, __tableModel, p);
                __worksheet = jsw.getJWorksheet();

                __tableModel.setWorksheet(__worksheet);

                widths = crr.getColumnWidths();
            }
            catch (Exception e)
            {
                Message.printWarning(1, routine, "Error building worksheet.");
                Message.printWarning(2, routine, e);
                jsw         = new JScrollWorksheet(0, 0, p);
                __worksheet = jsw.getJWorksheet();
            }
            __worksheet.setPreferredScrollableViewportSize(null);
            __worksheet.addMouseListener(this);
            __worksheet.addKeyListener(this);
            __worksheet.setHourglassJFrame(this);

            /* TODO SAM 2007-03-01 Evaluate logic
             * boolean renameAllowed = false;
             * if (__tableModel != null) {
             *      renameAllowed = true;
             * }
             */

            JPanel top_panel = new JPanel();

            top_panel.setLayout(new GridBagLayout());
            int y = 0;

            JGUIUtil.addComponent(top_panel, new JLabel("To rename a data set component, select a row and " + "either type a new file name or use the Browse button."), 0, y++, 2, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);

            JGUIUtil.addComponent(top_panel, new JLabel("If ARE DATA MODIFIED? is YES, data for the " + "component have been modified by the GUI but the file has not been written."), 0, y++, 2, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);

            JGUIUtil.addComponent(top_panel, new JLabel("Consequently, StateMod will not recognize the " + "changes until the data are saved with File...Save."), 0, y++, 2, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);

            JGUIUtil.addComponent(top_panel, new JLabel("If a filename is changed, the file with the original filename will remain " + "even after the new file is saved."), 0, y++, 2, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);

            JGUIUtil.addComponent(top_panel, new JLabel("Data set base name (from *.rsp):  "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHEAST);
            JGUIUtil.addComponent(top_panel, new JLabel(__dataset.getBaseName()), 1, y++, 1, 1, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);
            JGUIUtil.addComponent(top_panel, new JLabel("Data set directory:  "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHEAST);
            JGUIUtil.addComponent(top_panel, new JLabel(__dataset.getDataSetDirectory()), 1, y++, 1, 1, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);

            getContentPane().add("North", top_panel);

            getContentPane().add("Center", jsw);

            JPanel button_panel = new JPanel();

            __browse_JButton = new SimpleJButton(__BUTTON_BROWSE, this);
            __browse_JButton.setEnabled(false);
            __browse_JButton.setToolTipText("Select an existing file.");
            button_panel.add(__browse_JButton);
            __apply_JButton = new SimpleJButton(__BUTTON_APPLY, this);
            //__apply_JButton.setEnabled(false);
            __apply_JButton.setToolTipText("Set the file names.  File...Save is still required to save files.");
            button_panel.add(__apply_JButton);
            __cancel_JButton = new SimpleJButton(__BUTTON_CANCEL, this);
            __cancel_JButton.setToolTipText("Cancel file name changes.");
            button_panel.add(__cancel_JButton);
            __close_JButton = new SimpleJButton(__BUTTON_CLOSE, this);
            __close_JButton.setToolTipText("Apply file name changes and close " + "window.  File...Save is still required to save files.");
            //__close_JButton.setEnabled (false);
            button_panel.add(__close_JButton);
            //__help_JButton = new SimpleJButton(__BUTTON_HELP, this);
            //__help_JButton.setEnabled(false);
            //button_panel.add(__help_JButton);

            JPanel bottom_panel = new JPanel();

            bottom_panel.setLayout(new BorderLayout());
            getContentPane().add("South", bottom_panel);
            bottom_panel.add("South", button_panel);

            pack();

            if (__dataset_wm != null)
            {
                __dataset_wm.setWindowOpen(StateMod_DataSet_WindowManager.WINDOW_RESPONSE, this);
            }

            setSize(700, 500);
            JGUIUtil.center(this);

            setVisible(true);

            if (widths != null)
            {
                __worksheet.setColumnWidths(widths);
            }
        }