예제 #1
0
	/// <summary>
	/// Selects the desired ID in the table and displays the appropriate data
	/// in the remainder of the window. </summary>
	/// <param name="id"> the identifier to select in the list. </param>
	public virtual void selectID(string id)
	{
		int rows = __worksheetL.getRowCount();
		StateMod_DelayTable dt = null;
		for (int i = 0; i < rows; i++)
		{
			dt = (StateMod_DelayTable)__worksheetL.getRowData(i);
			if (dt.getID().Trim().Equals(id.Trim()))
			{
				selectLeftTableIndex(i, true, true);
				return;
			}
		}
	}
        /// <summary>
        /// Selects the desired ID in the left table and displays the appropriate data
        /// in the remainder of the window. </summary>
        /// <param name="id"> the identifier to select in the list. </param>
        public virtual void selectID(string id)
        {
            int rows = __worksheet.getRowCount();
            StateMod_RiverNetworkNode rnn = null;

            for (int i = 0; i < rows; i++)
            {
                rnn = (StateMod_RiverNetworkNode)__worksheet.getRowData(i);
                if (rnn.getID().Trim().Equals(id.Trim()))
                {
                    selectTableIndex(i);
                    return;
                }
            }
        }
        /// <summary>
        /// Responds to action performed events. </summary>
        /// <param name="e"> the ActionEvent that occurred. </param>
        public virtual void actionPerformed(ActionEvent e)
        {
            string action = e.getActionCommand();

            if (action.Equals(__BUTTON_ADD_OWNER))
            {
                StateMod_ReservoirAccount anAccount = new StateMod_ReservoirAccount();
                anAccount._isClone = true;
                int rowCount = __worksheet.getRowCount();
                if (rowCount == 0)
                {
                    anAccount.setID(1);
                }
                else
                {
                    StateMod_ReservoirAccount lastAccount = (StateMod_ReservoirAccount)__worksheet.getLastRowData();
                    string id = lastAccount.getID();
                    anAccount.setID("" + ((Convert.ToInt32(id)) + 1));
                }
                __worksheet.addRow(anAccount);
                __worksheet.scrollToLastRow();
                __worksheet.selectLastRow();
                __deleteOwner.setEnabled(true);
            }
            else if (action.Equals(__BUTTON_DEL_OWNER))
            {
                int row = __worksheet.getSelectedRow();
                if (row != -1)
                {
                    int x = (new ResponseJDialog(this, "Delete owner", "Delete owner?", ResponseJDialog.YES | ResponseJDialog.NO)).response();
                    if (x == ResponseJDialog.NO)
                    {
                        return;
                    }
                    __worksheet.deleteRow(row);
                    __deleteOwner.setEnabled(false);
                }
            }
            else if (action.Equals(__BUTTON_CLOSE))
            {
                if (saveData())
                {
                    setVisible(false);
                    dispose();
                }
            }
            else if (action.Equals(__BUTTON_APPLY))
            {
                saveData();
            }
            else if (action.Equals(__BUTTON_CANCEL))
            {
                setVisible(false);
                dispose();
            }
            else if (action.Equals(__BUTTON_HELP))
            {
                // REVISIT HELP (JTS - 2003-06-09)
            }
        }
	/// <summary>
	/// Selects the desired index in the table, but also displays the appropriate data
	/// in the remainder of the window. </summary>
	/// <param name="index"> the index to select in the list. </param>
	public virtual void selectTableIndex(int index)
	{
		int rowCount = __worksheet.getRowCount();
		if (rowCount == 0)
		{
			return;
		}
		if (index > (rowCount + 1))
		{
			return;
		}
		if (index < 0)
		{
			return;
		}
		__worksheet.scrollToRow(index);
		__worksheet.selectRow(index);
		processTableSelection(index);
	}
예제 #5
0
        /// <summary>
        /// Formats the data in the worksheet into a list of Strings.  Each field in the
        /// worksheet will be separated from the next by the specified delimiter, with
        /// no trailing delimiter. </summary>
        /// <param name="delimiter"> the character String to use to separate worksheet fields. </param>
        /// <param name="quotes"> if true, then the column names will be surrounded by
        /// quotes.  In addition, if the column data has the delimiter in it, it will be
        /// surrounded by quotes.  If false, nothing will be surrounded by quotes. </param>
        /// <returns> a list of delimited strings.  Each element in the list is one
        /// row in the worksheet. </returns>
        protected internal virtual IList <string> formatOutput(string delimiter, bool trimFieldValue, bool quotes)
        {
            IList <string> v = new List <string>();

            int rows = _worksheet.getRowCount();
            int cols = _worksheet.getColumnCount();

            StringBuilder buff  = new StringBuilder();
            string        quote = "\"";

            for (int i = 0; i < cols; i++)
            {
                if (quotes)
                {
                    buff.Append(quote);
                }
                buff.Append(_worksheet.getColumnName(i, true));
                if (quotes)
                {
                    buff.Append(quote);
                }
                if (i < cols - 1)
                {
                    buff.Append(delimiter);
                }
            }

            v.Add(buff.ToString());

            int    j = 0;
            string s = null;

            for (int i = 0; i < rows; i++)
            {
                buff.Length = 0;

                for (j = 0; j < cols; j++)
                {
                    s = _worksheet.getValueAtAsString(i, j);
                    if (trimFieldValue)
                    {
                        s = s.Trim();
                    }
                    if (s.IndexOf(delimiter, StringComparison.Ordinal) > -1 && quotes)
                    {
                        buff.Append("\"" + s + "\"");
                    }
                    else
                    {
                        buff.Append(s);
                    }

                    if (j < cols - 1)
                    {
                        // do not do for the last column.
                        buff.Append(delimiter);
                    }
                }

                v.Add(buff.ToString());
            }

            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);
                }
            }
        }
예제 #7
0
	/// <summary>
	/// Responds to action performed events. </summary>
	/// <param name="e"> the ActionEvent that happened. </param>
	public virtual void actionPerformed(ActionEvent e)
	{
		string routine = "StateMod_DelayTable_JFrame"
			+ ".actionPerformed";
		if (Message.isDebugOn)
		{
			Message.printDebug(1, routine, "In actionPerformed: " + e.getActionCommand());
		}

		string action = e.getActionCommand();

		if (action.Equals(__BUTTON_HELP))
		{
			// REVISIT HELP (JTS - 2003-06-09)
		}
		else if (action.Equals(__BUTTON_CLOSE))
		{
			closeWindow();
		}
		else if (action.Equals(__BUTTON_APPLY))
		{
			saveDelayTable();
			int size = __delaysVector.Count;
			StateMod_DelayTable dt = null;
			bool changed = false;
			for (int i = 0; i < size; i++)
			{
				dt = (StateMod_DelayTable)__delaysVector[i];
				if (!changed && dt.changed())
				{
					changed = true;
				}
				dt.createBackup();
			}
			if (changed)
			{
				__dataset.setDirty(__componentType, true);
			}
		}
		else if (action.Equals(__BUTTON_CANCEL))
		{
			__worksheetR.deselectAll();
			int size = __delaysVector.Count;
			StateMod_DelayTable dt = null;
			bool changed = false;
			for (int i = 0; i < size; i++)
			{
				dt = (StateMod_DelayTable)__delaysVector[i];
				if (!changed && dt.changed())
				{
					changed = true;
				}
				dt.restoreOriginal();
			}
			if (__dataset_wm != null)
			{
				__dataset_wm.closeWindow(__window_type);
			}
			else
			{
				JGUIUtil.close(this);
			}
		}
		else if (action.Equals(__BUTTON_ADD_RETURN))
		{
			int row = __worksheetR.getSelectedRow();

			int total_num_rows = __worksheetR.getRowCount() - 1;

			if (row == -1)
			{
				row = total_num_rows;
			}

			if (row != -1)
			{
				if (row == total_num_rows)
				{
					int x = new ResponseJDialog(this, "Insert row", "Do you wish to add a new row above " + "the last row?\n" + "uniquetempvar.response();
					if (x == ResponseJDialog.CANCEL)
					{
						return;
					}
					else if (x == ResponseJDialog.NO)
					{
						row += 1;
					}
				}
				__worksheetR.insertRowAt(new double?(0), row);
				__worksheetR.scrollToRow(row);
				__worksheetR.selectRow(row);
			}
			else
			{
				__worksheetR.addRow(new double?(0));
				__worksheetR.scrollToRow(0);
				__worksheetR.selectRow(0);
			}
			__deleteReturn.setEnabled(true);
		}
		else if (action.Equals(__BUTTON_DELETE_RETURN))
		{
			int row = __worksheetR.getSelectedRow();
			if (row != -1)
			{
				int x = (new ResponseJDialog(this, "Delete Return", "Delete return?", ResponseJDialog.YES | ResponseJDialog.NO)).response();
				if (x == ResponseJDialog.NO)
				{
					return;
				}
				//StateMod_DelayTable dt = (StateMod_DelayTable)
					//__worksheetL.getRowData(
					//__worksheetL.getSelectedRow());
				__worksheetR.deleteRow(row);
				__deleteReturn.setEnabled(false);
			}
			else
			{
				Message.printWarning(1, routine, "Must select desired right to delete.");
			}
		}
		else if (e.getSource() == __findNextDelay)
		{
			searchLeftWorksheet(__worksheetL.getSelectedRow() + 1);
		}
		else if (e.getSource() == __searchID)
		{
			searchLeftWorksheet();
		}
		else
		{
			if (__worksheetL.getSelectedRow() == -1)
			{
				new ResponseJDialog(this, "You must first select a delay from the list.", ResponseJDialog.OK);
				return;
			}
			else if (e.getSource() == __graphDelayJButton)
			{
				try
				{
					__worksheetR.deselectAll();

					int index = __worksheetL.getSelectedRow();
					if (index == -1)
					{
						return;
					}

					StateMod_DelayTable currentDelay = ((StateMod_DelayTable) __delaysVector[index]);

					int j;

					DateTime date;

					TSIdent tsident = new TSIdent();
					tsident.setLocation(currentDelay.getID());
					tsident.setSource("StateMod");
					if (__monthly_data)
					{
						tsident.setInterval("Month");
					}
					else
					{
						tsident.setInterval("Day");
					}
					tsident.setType("Delay");

					DateTime date1 = null;
					DateTime date2 = null;
					int interval_base;
					if (__monthly_data)
					{
						date1 = new DateTime(DateTime.PRECISION_MONTH);
						date2 = new DateTime(DateTime.PRECISION_MONTH);
						interval_base = TimeInterval.MONTH;
					}
					else
					{
						date1 = new DateTime(DateTime.PRECISION_DAY);
						date2 = new DateTime(DateTime.PRECISION_DAY);
						interval_base = TimeInterval.DAY;
					}
					date1.setMonth(1);
					date1.setYear(1);
					date2.setMonth(1);
					date2.setYear(1);
					date2.addInterval(interval_base, (currentDelay.getNdly() - 1));

					TS ts = null;
					if (__monthly_data)
					{
						ts = new MonthTS();
					}
					else
					{
						ts = new DayTS();
					}
					ts.setDate1(date1);
					ts.setDate2(date2);
					ts.setIdentifier(tsident);
					if (__monthly_data)
					{
						ts.setDescription(ts.getLocation() + " Monthly Delay Table");
					}
					else
					{
						ts.setDescription(ts.getLocation() + " Daily Delay Table");
					}
					ts.setDataType("Delay");
					ts.setDataUnits(currentDelay.getUnits());
					ts.allocateDataSpace();

					double max = 0.0;
					for (date = new DateTime(date1), j = 0; date.lessThanOrEqualTo(date2); date.addInterval(interval_base, 1), j++)
					{
						ts.setDataValue(date, currentDelay.getRet_val(j));
						if (currentDelay.getRet_val(j) > max)
						{
							max = currentDelay.getRet_val(j);
						}
					}
					IList<TS> tslist = new List<TS>();
					tslist.Add(ts);

					PropList graphProps = new PropList("TSView");
					// If dealing with small values, use a high
					// of precision...
					if (max < 1.0)
					{
						graphProps.set("YAxisPrecision","6");
						graphProps.set("OutputPrecision","6");
					}
					else
					{
						graphProps.set("YAxisPrecision","3");
						graphProps.set("OutputPrecision","3");
					}
					graphProps.set("InitialView", "Graph");
					graphProps.set("TotalWidth", "600");
					graphProps.set("TotalHeight", "400");
					if (__monthly_data)
					{
						graphProps.set("Title", ts.getLocation() + " Monthly Delay Table");
					}
					else
					{
						graphProps.set("Title", ts.getLocation() + " Daily Delay Table");
					}
					graphProps.set("DisplayFont", "Courier");
					graphProps.set("DisplaySize", "11");
					graphProps.set("PrintFont", "Courier");
					graphProps.set("PrintSize", "7");
					graphProps.set("PageLength", "100");
					new TSViewJFrame(tslist, graphProps);
				}
				catch (Exception)
				{
					Message.printWarning(1, routine, "Unable to graph delay. ");
				}
			}
		}
	}