示例#1
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>
	/// 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();
                }
            }
        }