/// <summary>
	/// Constructor. </summary>
	/// <param name="title"> Title for JFrame.  If null, an appropriate default is used. </param>
	/// <param name="dataset"> dataset containing data to display </param>
	/// <param name="station"> StateCU_ClimateStation object to display </param>
	/// <param name="editable"> whether the display should be editable or not. </param>
	public StateCU_ClimateStation_JFrame(string title, StateCU_DataSet dataset, StateCU_ClimateStation station, bool editable)
	{
		if (string.ReferenceEquals(title, null))
		{
			setTitle("StateCU Climate Stations");
		}
		else
		{
			setTitle(title);
		}
		__dataset = dataset;
		__currentStationIndex = -1;

		__stationComponent = __dataset.getComponentForComponentType(StateCU_DataSet.COMP_CLIMATE_STATIONS);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateCU_ClimateStation> stationsVector0 = (java.util.List<StateCU_ClimateStation>)__stationComponent.getData();
		IList<StateCU_ClimateStation> stationsVector0 = (IList<StateCU_ClimateStation>)__stationComponent.getData();
		__stationsVector = stationsVector0;

		string id = station.getID();
		int index = StateCU_Util.IndexOf(__stationsVector, id);

		__editable = editable;

		setupGUI(index);
	}
Exemple #2
0
        /// <summary>
        /// Called when the Apply button is pressed. This commits any changes to the data
        /// objects.
        /// </summary>
        protected internal override void apply()
        {
            StateCU_ClimateStation station = null;
            int size = _data.Count;

            for (int i = 0; i < size; i++)
            {
                station = (StateCU_ClimateStation)_data[i];
                station.createBackup();
            }
        }
Exemple #3
0
        /// <summary>
        /// Called when the cancel button is pressed.  This discards any changes made to
        /// the data objects.
        /// </summary>
        protected internal override void cancel()
        {
            StateCU_ClimateStation station = null;
            int size = _data.Count;

            for (int i = 0; i < size; i++)
            {
                station = (StateCU_ClimateStation)_data[i];
                station.restoreOriginal();
            }
        }
Exemple #4
0
        /// <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];
            }

            StateCU_ClimateStation station = (StateCU_ClimateStation)_data.get(row);

            switch (col)
            {
            case __COL_ID:
                return(station.getID());

            case __COL_NAME:
                return(station.getName());

            case __COL_ELEVATION:
                return(new double?(station.getElevation()));

            case __COL_LATITUDE:
                return(new double?(station.getLatitude()));

            case __COL_REGION1:
                return(station.getRegion1());

            case __COL_REGION2:
                return(station.getRegion2());

            case __COL_ZH:
                if (StateCU_Util.isMissing(station.getZh()))
                {
                    return(null);
                }
                else
                {
                    return(new double?(station.getZh()));
                }

            case __COL_ZM:
                if (StateCU_Util.isMissing(station.getZm()))
                {
                    return(null);
                }
                else
                {
                    return(new double?(station.getZm()));
                }
            }

            return("");
        }
        /// <summary>
        /// Cancels any changes made to this object within a GUI since createBackup()
        /// was called and sets _original to null.
        /// </summary>
        public override void restoreOriginal()
        {
            StateCU_ClimateStation station = (StateCU_ClimateStation)_original;

            base.restoreOriginal();

            __latitude  = station.__latitude;
            __elevation = station.__elevation;
            __region1   = station.__region1;
            __region2   = station.__region2;
            __zh        = station.__zh;
            __zm        = station.__zm;

            _isClone  = false;
            _original = null;
        }
        /// <summary>
        /// Performs general and specific data checks on climate station data. </summary>
        /// <param name="props"> A property list for specific properties. </param>
        /// <param name="data_vector"> Vector of data to check. </param>
        private void checkClimateStationData(PropList props, System.Collections.IList data_vector)
        {
            // Create elements for the checks and check file
            string[] header = StateCU_ClimateStation.getDataHeader();
            System.Collections.IList data = new List <object>();
            string title = "Climate Station";

            // Perform the general validation using the Data Table Model
            StateCU_Data_TableModel tm;

            try
            {
                tm = new StateCU_ClimateStation_TableModel(data_vector, false);
            }
            catch (Exception e)
            {
                Message.printWarning(3, "StateCU_ComponentDataCheck.checkClimateStationData", e);
                return;
            }
            System.Collections.IList @checked = performDataValidation(tm, title);
            //String [] columnHeader = getDataTableModelColumnHeader( tm );
            string[] columnHeader = getColumnHeader(tm);

            // Do specific checks
            int size = 0;

            if (data_vector != null)
            {
                size = data_vector.Count;
            }
            data = doSpecificDataChecks(data_vector, props);
            // Add the data and checks to the check file.
            // Provides basic header information for this data check table
            string info = "The following " + title + " (" + data.Count +
                          " out of " + size + ") have no .....";

            // Create data models for Check file
            CheckFile_DataModel dm     = new CheckFile_DataModel(data, header, title, info, data.Count, tm.getRowCount());
            CheckFile_DataModel gen_dm = new CheckFile_DataModel(@checked, columnHeader, title + " Missing or Invalid Data", "", __gen_problems, tm.getRowCount());

            __check_file.addData(dm, gen_dm);
        }
Exemple #7
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)
        {
            StateCU_ClimateStation station = (StateCU_ClimateStation)_data.get(row);

            switch (col)
            {
            case __COL_ID:
                station.setID((string)value);
                break;

            case __COL_NAME:
                station.setName((string)value);
                break;

            case __COL_ELEVATION:
                station.setElevation(((double?)value).Value);
                break;

            case __COL_LATITUDE:
                station.setLatitude(((double?)value).Value);
                break;

            case __COL_REGION1:
                station.setRegion1((string)value);
                break;

            case __COL_REGION2:
                station.setRegion2((string)value);
                break;

            case __COL_ZH:
                station.setZh(((double?)value).Value);
                break;

            case __COL_ZM:
                station.setZm(((double?)value).Value);
                break;
            }

            base.setValueAt(value, row, col);
        }
	/// <summary>
	/// Saves the information associated with the currently-selected station.
	/// The user doesn't need to hit the return key for the gui to recognize changes.
	/// The info is saved each time the user selects a different station or pressed the close button.
	/// </summary>
	private void saveInformation(int record)
	{
		if (!__editable || record == -1)
		{
			return;
		}

		StateCU_ClimateStation station = __stationsVector[record];

		if (!checkInput())
		{
			return;
		}

		station.setName(__nameJTextField.getText());
		station.setID(__stationIDJTextField.getText());
		station.setLatitude((new double?(__latitudeJTextField.getText())));
		station.setElevation((new double?(__elevationJTextField.getText())));
		station.setRegion1(__region1JTextField.getText());
		station.setRegion2(__region2JTextField.getText());
	}
	/// <summary>
	/// Processes a table selection (either via a mouse press or programmatically 
	/// from selectTableIndex() by writing the old data back to the data set component
	/// and getting the next selection's data out of the data and displaying it on the form. </summary>
	/// <param name="index"> the index of the reservoir to display on the form. </param>
	private void processTableSelection(int index)
	{
		__lastStationIndex = __currentStationIndex;
		__currentStationIndex = __worksheet.getOriginalRowNumber(index);

		saveLastRecord();

		if (__worksheet.getSelectedRow() == -1)
		{
			nothingSelected();
			return;
		}

		somethingSelected();

		StateCU_ClimateStation station = __stationsVector[__currentStationIndex];

		__stationIDJTextField.setText(station.getID());
		__nameJTextField.setText(station.getName());
		StateCU_Util.checkAndSet(station.getLatitude(), __latitudeJTextField);
		StateCU_Util.checkAndSet(station.getElevation(), __elevationJTextField);
		__region1JTextField.setText(station.getRegion1());
		__region2JTextField.setText(station.getRegion2());
	}
        /// <summary>
        /// Writes a list of StateCU_ClimateStation 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 </param>
        /// header (true) or to create a new file with a new header<param name="data"> the Vector of objects to write. </param>
        /// <param name="outputComments"> Comments to add to the header, usually the command file and database information. </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<StateCU_ClimateStation> data, java.util.List<String> outputComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateCU_ClimateStation> data, IList <string> outputComments)
        {
            int size = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("ID");
            fields.Add("Name");
            fields.Add("Latitude");
            fields.Add("Elevation");
            fields.Add("Region1");
            fields.Add("Region2");
            fields.Add("HeightHumidity");
            fields.Add("HeightWind");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateCU_DataSet.COMP_CLIMATE_STATIONS;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = fields[i];
                names[i]   = StateCU_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateCU_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int                    j             = 0;
            PrintWriter            @out          = null;
            StateCU_ClimateStation cli           = null;
            IList <string>         commentString = new List <string>(1);

            commentString.Add("#");
            IList <string> ignoreCommentString = new List <string>(1);

            ignoreCommentString.Add("#>");
            string[]      line   = new string[fieldCount];
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  However, do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (outputComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(outputComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateCU climate stations as a delimited list file.");
                newComments2.Insert(2, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentString, ignoreCommentString, 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++)
                {
                    cli = data[i];

                    line[0] = StringUtil.formatString(cli.getID(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(cli.getName(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(cli.getLatitude(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(cli.getElevation(), formats[3]).Trim();
                    line[4] = StringUtil.formatString(cli.getRegion1(), formats[4]).Trim();
                    line[5] = StringUtil.formatString(cli.getRegion2(), formats[5]).Trim();
                    line[6] = StringUtil.formatString(cli.getZh(), formats[6]).Trim();
                    line[7] = StringUtil.formatString(cli.getZm(), formats[7]).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 a list of StateCU_ClimateStation to an opened file. </summary>
        /// <param name="dataList"> A list of StateCU_ClimateStation to write. </param>
        /// <param name="out"> output PrintWriter. </param>
        /// <exception cref="IOException"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void writeStateCUFile(java.util.List<StateCU_ClimateStation> dataList, java.io.PrintWriter out) throws java.io.IOException
        private static void writeStateCUFile(IList <StateCU_ClimateStation> dataList, PrintWriter @out)
        {
            int    i;
            string iline;
            string cmnt = "#>";
            // Missing data handled by formatting all as strings...
            string         format = "%-12.12s%6.6s%9.9s  %-20.20s%-8.8s  %-24.24s%8.8s%8.8s";
            IList <object> v      = new List <object>(8); // Reuse for all output lines.

            @out.println(cmnt);
            @out.println(cmnt + "  StateCU Climate Stations File");
            @out.println(cmnt);
            @out.println(cmnt + "  Record format (a12,f6.2,f9.2,2x,a20,a8,2x,a24,8.2f,2.2f)");
            @out.println(cmnt);
            @out.println(cmnt + "  StationID:  Station identifier (e.g., 3951)");
            @out.println(cmnt + "        Lat:  Latitude (decimal degrees)");
            @out.println(cmnt + "       Elev:  Elevation (feet)");
            @out.println(cmnt + "    Region1:  Region1 (e.g., County)");
            @out.println(cmnt + "    Region2:  Region2 (e.g., Hydrologic Unit Code, HUC)");
            @out.println(cmnt + "StationName:  Station name");
            @out.println(cmnt + "     zHumid:  Height of humidity and temperature measurements (feet, daily analysis only)");
            @out.println(cmnt + "      zWind:  Height of wind speed measurement (feet, daily analysis only)");
            @out.println(cmnt);
            @out.println(cmnt + " StationID  Lat   Elev            Region1      Region2        StationName         zHumid  zWind");
            @out.println(cmnt + "---------eb----eb-------exxb------------------eb------exxb----------------------eb------eb------e");
            @out.println(cmnt + "EndHeader");

            int num = 0;

            if (dataList != null)
            {
                num = dataList.Count;
            }
            StateCU_ClimateStation sta = null;

            for (i = 0; i < num; i++)
            {
                sta = dataList[i];
                if (sta == null)
                {
                    continue;
                }

                v.Clear();
                v.Add(sta._id);
                // Latitude...
                if (StateCU_Util.isMissing(sta.__latitude))
                {
                    v.Add("");
                }
                else
                {
                    v.Add(StringUtil.formatString(sta.__latitude, "%6.2f"));
                }
                // Elevation...
                if (StateCU_Util.isMissing(sta.__elevation))
                {
                    v.Add("");
                }
                else
                {
                    v.Add(StringUtil.formatString(sta.__elevation, "%9.2f"));
                }
                v.Add(sta.__region1);
                v.Add(sta.__region2);
                v.Add(sta._name);
                // zh...
                if (StateCU_Util.isMissing(sta.__zh))
                {
                    v.Add("");
                }
                else
                {
                    v.Add(StringUtil.formatString(sta.__zh, "%8.2f"));
                }
                // zm...
                if (StateCU_Util.isMissing(sta.__zm))
                {
                    v.Add("");
                }
                else
                {
                    v.Add(StringUtil.formatString(sta.__zm, "%8.2f"));
                }

                iline = StringUtil.formatString(v, format);
                @out.println(iline);
            }
        }
        /// <summary>
        /// Read the StateCU climate stations file and return as a list of CUClimateStation. </summary>
        /// <param name="filename"> filename containing CLI records. </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static java.util.List<StateCU_ClimateStation> readStateCUFile(String filename) throws java.io.IOException
        public static IList <StateCU_ClimateStation> readStateCUFile(string filename)
        {
            string         rtn   = "StateCU_ClimateStation.readStateCUFile";
            string         iline = null;
            IList <object> v     = new List <object> (10);
            IList <StateCU_ClimateStation> sta_Vector = new List <StateCU_ClimateStation> (100);   // Data to return.

            int[] format_0 = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING };

            int[] format_0w            = new int[] { 12, 6, 9, 2, 20, 8, 2, 24, 8, 8 };
            StateCU_ClimateStation sta = null;
            StreamReader           @in = null;

            try
            {
                Message.printStatus(2, rtn, "Reading StateCU climate station file: \"" + filename + "\"");
                // The following throws an IOException if the file cannot be opened...
                @in = new StreamReader(filename);
                string @string;
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    // check for comments
                    if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0)
                    {
                        continue;
                    }

                    // allocate new StateCU_ClimateStation instance...
                    sta = new StateCU_ClimateStation();

                    StringUtil.fixedRead(iline, format_0, format_0w, v);
                    sta.setID(((string)v[0]).Trim());
                    @string = ((string)v[1]).Trim();
                    if ((@string.Length != 0) && StringUtil.isDouble(@string))
                    {
                        sta.setLatitude(StringUtil.atod(@string));
                    }
                    @string = ((string)v[2]).Trim();
                    if ((@string.Length != 0) && StringUtil.isDouble(@string))
                    {
                        sta.setElevation(StringUtil.atod(@string));
                    }
                    sta.setRegion1(((string)v[3]).Trim());
                    sta.setRegion2(((string)v[4]).Trim());
                    sta.setName(((string)v[5]).Trim());
                    @string = ((string)v[6]).Trim();
                    if ((@string.Length != 0) && StringUtil.isDouble(@string))
                    {
                        sta.setZh(double.Parse(@string));
                    }
                    @string = ((string)v[7]).Trim();
                    if ((@string.Length != 0) && StringUtil.isDouble(@string))
                    {
                        sta.setZm(double.Parse(@string));
                    }

                    // add the StateCU_ClimateStation to the list...
                    sta_Vector.Add(sta);
                }
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            return(sta_Vector);
        }
Exemple #13
0
 /// <summary>
 /// Sets the parent well under which the right and return flow data is stored. </summary>
 /// <param name="parent"> the parent well. </param>
 public virtual void setParentClimateStation(StateCU_ClimateStation parent)
 {
     // TODO SAM 2007-03-01 Evaluate use
     //__parentStation = parent;
 }
	/// <summary>
	/// Display the time series. </summary>
	/// <param name="action"> Event action that initiated the display. </param>
	private void displayTSViewJFrame(string action)
	{
		string routine = "displayTSViewJFrame";

		// Initialize the display...

		PropList display_props = new PropList("ClimateStation");
		if (action.Equals(__BUTTON_GRAPH))
		{
			display_props.set("InitialView", "Graph");
		}
		else if (action.Equals(__BUTTON_TABLE))
		{
			display_props.set("InitialView", "Table");
		}
		else if (action.Equals(__BUTTON_SUMMARY))
		{
			display_props.set("InitialView", "Summary");
		}
		// display_props.set("HelpKey", "TSTool.ExportMenu");
		display_props.set("TotalWidth", "600");
		display_props.set("TotalHeight", "400");
		display_props.set("Title", "Demand");
		display_props.set("DisplayFont", "Courier");
		display_props.set("DisplaySize", "11");
		display_props.set("PrintFont", "Courier");
		display_props.set("PrintSize", "7");
		display_props.set("PageLength", "100");

		PropList props = new PropList("ClimateStation");

		IList<TS> tslist = new List<TS>();

		// Get the time series to display and set plot properties if graphing.
		// For now need to find in the lists because references to time series
		// are not implemented...

		IList<TS> v = null;
		TS ts = null;
		int sub = 0;
		int pos;
		StateCU_ClimateStation station = __stationsVector[__currentStationIndex];
		if (__precipitationCheckBox.isSelected())
		{
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<RTi.TS.TS> v0 = (java.util.List<RTi.TS.TS>)__dataset.getComponentForComponentType(StateCU_DataSet.COMP_PRECIPITATION_TS_MONTHLY).getData();
			IList<TS> v0 = (IList<TS>)__dataset.getComponentForComponentType(StateCU_DataSet.COMP_PRECIPITATION_TS_MONTHLY).getData();
			v = v0;
			pos = TSUtil.IndexOf(v, station.getID(), "Location", 1);
			if (pos >= 0)
			{
				ts = (TS)v[pos];
			}
			if (ts != null)
			{
				// Add a graph for precipitation...
				++sub;
				ts.setDataType("Precipitation");
				props.set("SubProduct " + sub + ".GraphType=Bar");
				props.set("SubProduct " + sub + ".SubTitleString=Monthly Precipitation");
				props.set("Data " + sub + ".1.TSID=" + ts.getIdentifierString());
				tslist.Add(ts);
			}
		}
		if (__temperatureCheckBox.isSelected())
		{
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<RTi.TS.TS> v0 = (java.util.List<RTi.TS.TS>)__dataset.getComponentForComponentType(StateCU_DataSet.COMP_TEMPERATURE_TS_MONTHLY_AVERAGE).getData();
			IList<TS> v0 = (IList<TS>)__dataset.getComponentForComponentType(StateCU_DataSet.COMP_TEMPERATURE_TS_MONTHLY_AVERAGE).getData();
			v = v0;
			pos = TSUtil.IndexOf(v, station.getID(), "Location", 1);
			if (pos >= 0)
			{
				ts = (TS)v[pos];
			}
			if (ts != null)
			{
				// Add a graph for temperature...
				++sub;
				ts.setDataType("Temperature");
				props.set("SubProduct " + sub + ".GraphType=Line");
				props.set("SubProduct " + sub + ".SubTitleString=Monthly Average Temperature");
				props.set("Data " + sub + ".1.TSID=" + ts.getIdentifierString());
				tslist.Add(ts);
			}
		}
		if (__frostDatesCheckBox.isSelected())
		{
			// REVISIT - no way to graph currently
		}

		// Display the time series...

		try
		{
			TSProduct tsproduct = new TSProduct(props, display_props);
			tsproduct.setTSList(tslist);
			new TSViewJFrame(tsproduct);
		}
		catch (Exception e)
		{
			Message.printWarning(1,routine,"Error displaying time series.");
			Message.printWarning(2, routine, e);
		}
	}