ucar.unidata.data.point
Class TextPointDataSource

java.lang.Object
  extended by ucar.unidata.collab.SharableImpl
      extended by ucar.unidata.data.DataSourceImpl
          extended by ucar.unidata.data.FilesDataSource
              extended by ucar.unidata.data.point.PointDataSource
                  extended by ucar.unidata.data.point.TextPointDataSource
All Implemented Interfaces:
Sharable, DataSource, DataSourceFactory, XmlPersistable
Direct Known Subclasses:
CDOGTextPointDataSource, DiamondPointDataSource, GNOMETextPointDataSource

public class TextPointDataSource
extends PointDataSource

A data source for point data from a Text file

Author:
IDV Development Team

Nested Class Summary
static class TextPointDataSource.Metadata
          Class Metadata holds the skipRows and the list of metadata items
 
Nested classes/interfaces inherited from class ucar.unidata.data.point.PointDataSource
PointDataSource.PlotModelSelectionComponent
 
Field Summary
static String BLANK_DELIM
          Blank delimiter
static String COMMA_DELIM
          Comma delimiter
static String PREF_METADATAMAP
          Where to write out the saved meta data listing
static String PROP_DATAPROPERTIES
          Property identifier for the hashtable of properties
static String PROP_HEADER_BLOB
          property id for the whole header blob, map and params
static String PROP_HEADER_EXTRA
          Property identifier for the
static String PROP_HEADER_MAP
          property id for the header map
static String PROP_HEADER_PARAMS
          property id for the header params
static String PROP_HEADER_SKIP
          property id for how many rows to skip
static String PROP_HEADER_SKIPPATTERN
          property id for how many rows to skip
static String SEMICOLON_DELIM
          Semicolon delimiter
static String TAB_DELIM
          Tab delimiter
 
Fields inherited from class ucar.unidata.data.point.PointDataSource
fieldsDescription, POINT_DATA, PROP_FIRSTGUESS, PROP_GRID_GAIN, PROP_GRID_NUMPASSES, PROP_GRID_PARAM, PROP_GRID_SEARCH_RADIUS, PROP_GRID_UNIT, PROP_GRID_X, PROP_GRID_Y, PROP_STATIONMODELNAME, STATION_DATA, STATION_PLOT
 
Fields inherited from class ucar.unidata.data.FilesDataSource
adapters, oldSourceFromBundles, sources
 
Fields inherited from class ucar.unidata.data.DataSourceImpl
changeDataPathsCbx, dataCacheKey, dataChoices, geoSelectionPanel, haveBeenUnPersisted, okToContinue, PARAM_SHOW_HIDE, PARAM_SHOW_NO, PARAM_SHOW_YES
 
Fields inherited from interface ucar.unidata.data.DataSource
DATAPATH_DATE_FORMAT, DATAPATH_DATE_PATTERN, MOST_RECENT, ordinalNames, PROP_AUTOCREATEDISPLAY, PROP_BASEDIRECTORY, PROP_CACHEABLE, PROP_DATACHOICENAME, PROP_DISPLAYPROPERTIES, PROP_DOCUMENTLINKS, PROP_FILEPATTERN, PROP_GEOLOCATION, PROP_ICON, PROP_NAME, PROP_POLLINFO, PROP_RESOLVERURL, PROP_SERVICE_HTTP, PROP_SUBPROPERTIES, PROP_TIMELABELS, PROP_TITLE
 
Constructor Summary
TextPointDataSource()
          Default constructor
TextPointDataSource(DataSourceDescriptor descriptor, List sources, Hashtable properties)
          Create a new PointDataSource
TextPointDataSource(DataSourceDescriptor descriptor, String source, Hashtable properties)
          Create a new TextPointDataSource
TextPointDataSource(DataSourceDescriptor descriptor, String source, String name, Hashtable properties)
          Create a new TextPointDataSource
TextPointDataSource(String source)
          Create a TextPointDataSource from the path name
 
Method Summary
 void addPropertiesTabs(JTabbedPane tabbedPane)
          add to properties tab
 void applyNames(String line)
          update the gui
 boolean applyProperties()
          apply properties
 void applySavedMetaData(TextPointDataSource.Metadata metadata)
          Init the widgets
 void applySavedMetaDataFromUI(TextPointDataSource.Metadata metadata)
          THis gets called from the Preferences menu and sets the metadata and also updates the skipRows
 void applySavedMetaDataFromUIInner(TextPointDataSource.Metadata metadata)
          This gets called in a thread from the applySavedMetaDataFromUI method
 boolean canDoGeoSelection()
          Can this datasource do the geoselection subsetting and decimation
protected  boolean canDoGeoSelectionStride()
          Used for the geo subsetting property gui as to whether to show the stride or not
 boolean canSaveDataToLocalDisk()
          Can we save locally
 void changeMetadata()
          Show the metadata gui
 void deleteMetaData(String key)
          Remove the given key from the saved mapping.
 void doMakeDataChoices()
          Make the data choices
 boolean equals(Object o)
          Check to see if this TextPointDataSource is equal to the object in question.
static int[] findLatLonAltIndices(TupleType type)
          Find the lat/lon/alt indicides
protected  String getContents(String sourceFile)
          Get the contents of the file as a string
protected  String getContents(String sourceFile, boolean sampleIt)
          Read the given source file and return the text contents of it.
protected  Data getDataInner(DataChoice dataChoice, DataCategory category, DataSelection dataSelection, Hashtable requestProperties)
          Get the data represented by this class.
 String getDelimiter()
          Get the delimiter used in the text file
protected  String getDelimiter(String source)
          Get the delimiter to use for the given file.
 String getGroupVarName()
          Get the GroupVarName property.
 String getMap()
          Get the Map property.
 List getMetaDataFields()
          Get the MetaDataFields property.
 String getParams()
          Get the Params property.
 void getPropertiesComponents(List comps)
          Add to properties gui
protected  FieldImpl getSample(DataChoice dataChoice)
          Read a sample of the data.
 int getSkipRows()
          Get the SkipRows property.
protected  String getSource(DataChoice dataChoice)
          the data choice
 int hashCode()
          Get the hashcode for this object
static void main(String[] args)
          main
static void main2(String[] args)
          test
 FieldImpl makeObs(DataChoice dataChoice, DataSelection subset, ucar.unidata.geoloc.LatLonRect bbox)
          Make PointObs from the raw VisAD data
 FieldImpl makeObs(DataChoice dataChoice, DataSelection subset, ucar.unidata.geoloc.LatLonRect bbox, String trackParam, boolean sampleIt, boolean showAttributeGuiIfNeeded)
          make the observations from the given datachoice
 FieldImpl makeObs(String contents, String delimiter, DataSelection subset, ucar.unidata.geoloc.LatLonRect bbox, String trackParam, boolean sampleIt, boolean showAttributeGuiIfNeeded)
          make the observations from the given datachoice
 void popupMetaDataMenu(JComponent near)
          Show the metadata preference menu
 void saveMetaDataMap()
          Save the meta data
 void setDelimiter(String delim)
          Get the delimiter used in the text file
 void setGroupVarName(String value)
          Set the GroupVarName property.
 void setMap(String value)
          Set the Map property.
 void setMetaDataFields(List value)
          Set the MetaDataFields property.
 void setParams(String value)
          Set the Params property.
 void setSkipRows(int value)
          Set the SkipRows property.
 void setStreamProcessor(TextAdapter.StreamProcessor streamProcessor)
          Set the stream processor to use
 void writeHeader()
          write the header text to a file
 void writePlugin()
          write the plugin
 
Methods inherited from class ucar.unidata.data.point.PointDataSource
canAddCurrentName, canCreateGrid, doRemove, getBinRoundTo, getBinWidth, getDataName, getDefaultLevels, getDescriptionDataChoice, getFullDescription, getGridGain, getGridSearchRadius, getGridUnit, getGridX, getGridY, getMakeGridFields, getNumGridPasses, getPointCategories, init, initDataSelectionComponents, initGridParameters, makeDerivedDataChoices, makeFieldDescription, reloadData, setBinRoundTo, setBinWidth, setGridGain, setGridSearchRadius, setGridUnit, setGridX, setGridY, setMakeGridFields, setNumGridPasses, setRoundToFromComboBox, setSource, setWidthFromComboBox, shouldCache
 
Methods inherited from class ucar.unidata.data.FilesDataSource
getDataFileExtension, getDataPaths, getFilePath, getInputStreams, getLocationsForPolling, getPartialDescription, getSource, getSources, haveSources, initAfterCreation, initAfterUnpersistence, initWithPollingInfo, isFileBased, newFilesFromPolling, processDataFilename, propertiesChanged, reloadData, saveDataToLocalDisk, setNewFiles, setSources, sourcesChanged, updateState
 
Methods inherited from class ucar.unidata.data.DataSourceImpl
addActions, addDataChangeListener, addDataChoice, addReloadTab, applyFieldMask, beginWritingDataToLocalDisk, canCacheDataToDisk, canChangeData, canDoFieldMask, canDoGeoSelectionMap, canPoll, canShowParameter, checkForInitAfterUnPersistence, clearCachedData, clearFileCache, clearTimes, convertSourceFile, convertToFilesIfDirectory, createAutoDisplay, createCacheKey, createElement, decrOutstandingGetDataCalls, doDirectory, doMakeDateTimes, doMakeGeoSelectionPanel, doMakeGeoSelectionPanel, doMakeGeoSelectionPanel, doMakeGeoSubsetPropertiesComponent, endWritingDataToLocalDisk, expandIfNeeded, findDataChoice, findDataChoices, flushCache, getAbsoluteDateTimes, getActions, getAlias, getAllDateTimes, getAllDateTimes, getAllLevels, getAllLevels, getAllTimesForTimeDriver, getCache, getCache, getCacheClearDelay, getCacheDataToDisk, getCompositeDataChoices, getData, getData, getDataCachePath, getDataChangeListeners, getDataChoices, getDataContext, getDataInner, getDataIsEditable, getDataPrefix, getDataSelection, getDataSelectionComponents, getDataSource, getDateTimes, getDateTimeSelection, getDescription, getDescriptor, getErrorMessage, getEverChangedName, getExtraGeoSelectionComponent, getExtraTimesComponent, getFileFilterForPolling, getid, getIdv, getInError, getLocalDirectory, getLocationForPolling, getMostRecentFiles, getName, getNameForDataSource, getNeedToShowErrorToUser, getNextId, getOutstandingGetDataCalls, getPassword, getPathsThatCanBeRelative, getPollingInfo, getProperties, getPropertiesHeader, getProperty, getProperty, getProperty, getProperty, getProperty, getProperty, getProperty, getRelativePaths, getSampleDataProjection, getSaveDataFileLabel, getSelectedDateTimes, getSelectedDateTimes, getTimesFromDataSelection, getTmpPaths, getTypeName, getUserName, handlePropertiesAction, hasPollingInfo, holdsDateTimes, holdsIndices, identifiedBy, identifiedByName, incrOutstandingGetDataCalls, initAfter, initDataChoice, initFromXml, isPolling, loadFieldMask, loadFieldMask, loadLatestFile, logException, logException, makeSaveLocalActions, newFileFromPolling, notifyDataChange, putCache, putCache, reloadProperties, removeCache, removeDataChangeListener, removeDataChoice, removeProperty, replaceDataChoice, resetTmpState, saveDataToLocalDisk, saveDataToLocalDisk, selectTimesFromList, setAlias, setAskToUpdate, setCacheClearDelay, setCacheDataToDisk, setDataEditableStrings, setDataIsEditable, setDataIsRelative, setDataRelativeStrings, setDataSelection, setDateTimeSelection, setDescription, setDescriptor, setDirectory, setEverChangedName, setInError, setInError, setInError, setName, setObjectProperties, setObjectProperty, setPassword, setPollingInfo, setPollLocation, setProperties, setProperty, setProperty, setRelativePaths, setTemplateName, setTmpPaths, setUserName, shouldCache, showPasswordDialog, showPropertiesDialog, showPropertiesDialog, showPropertiesDialog, showWaitDialog, tick, toString, toStringTruncated, updateDetailsText, writeFieldMaskFile, writeFieldMaskFile
 
Methods inherited from class ucar.unidata.collab.SharableImpl
applySharableProperties, doShare, doShare, doShareExternal, doShareInternal, getReceiveShareTime, getSharablePropertiesComponent, getShareGroup, getSharing, getUniqueId, initSharable, receiveShareData, removeSharable, setReceiveShareTime, setShareGroup, setSharing, setUniqueId, showSharableDialog
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ucar.unidata.data.DataSource
getUniqueId
 

Field Detail

PROP_HEADER_MAP

public static final String PROP_HEADER_MAP
property id for the header map

See Also:
Constant Field Values

PROP_DATAPROPERTIES

public static final String PROP_DATAPROPERTIES
Property identifier for the hashtable of properties

See Also:
Constant Field Values

PROP_HEADER_EXTRA

public static final String PROP_HEADER_EXTRA
Property identifier for the

See Also:
Constant Field Values

PROP_HEADER_PARAMS

public static final String PROP_HEADER_PARAMS
property id for the header params

See Also:
Constant Field Values

PROP_HEADER_SKIP

public static final String PROP_HEADER_SKIP
property id for how many rows to skip

See Also:
Constant Field Values

PROP_HEADER_SKIPPATTERN

public static final String PROP_HEADER_SKIPPATTERN
property id for how many rows to skip

See Also:
Constant Field Values

PROP_HEADER_BLOB

public static final String PROP_HEADER_BLOB
property id for the whole header blob, map and params

See Also:
Constant Field Values

PREF_METADATAMAP

public static final String PREF_METADATAMAP
Where to write out the saved meta data listing

See Also:
Constant Field Values

COMMA_DELIM

public static final String COMMA_DELIM
Comma delimiter

See Also:
Constant Field Values

SEMICOLON_DELIM

public static final String SEMICOLON_DELIM
Semicolon delimiter

See Also:
Constant Field Values

TAB_DELIM

public static final String TAB_DELIM
Tab delimiter

See Also:
Constant Field Values

BLANK_DELIM

public static final String BLANK_DELIM
Blank delimiter

See Also:
Constant Field Values
Constructor Detail

TextPointDataSource

public TextPointDataSource()
                    throws VisADException
Default constructor

Throws:
VisADException - problem creating the object

TextPointDataSource

public TextPointDataSource(String source)
                    throws VisADException
Create a TextPointDataSource from the path name

Parameters:
source - path to source data
Throws:
VisADException - problem creating the file

TextPointDataSource

public TextPointDataSource(DataSourceDescriptor descriptor,
                           List sources,
                           Hashtable properties)
                    throws VisADException
Create a new PointDataSource

Parameters:
descriptor - data source descriptor
sources - List of sources of data (filename/URL)
properties - extra properties for initialization
Throws:
VisADException - problem creating the data

TextPointDataSource

public TextPointDataSource(DataSourceDescriptor descriptor,
                           String source,
                           Hashtable properties)
                    throws VisADException
Create a new TextPointDataSource

Parameters:
descriptor - data source descriptor
source - source of data (filename/URL)
properties - extra properties for initialization
Throws:
VisADException - problem creating the data

TextPointDataSource

public TextPointDataSource(DataSourceDescriptor descriptor,
                           String source,
                           String name,
                           Hashtable properties)
                    throws VisADException
Create a new TextPointDataSource

Parameters:
descriptor - data source descriptor
source - source of data (filename/URL)
name - the name of the dataset
properties - extra properties for initialization
Throws:
VisADException - problem creating the data
Method Detail

canSaveDataToLocalDisk

public boolean canSaveDataToLocalDisk()
Can we save locally

Specified by:
canSaveDataToLocalDisk in interface DataSource
Overrides:
canSaveDataToLocalDisk in class DataSourceImpl
Returns:
true if we can

setStreamProcessor

public void setStreamProcessor(TextAdapter.StreamProcessor streamProcessor)
Set the stream processor to use

Parameters:
streamProcessor - the StreamProcessor

canDoGeoSelection

public boolean canDoGeoSelection()
Can this datasource do the geoselection subsetting and decimation

Specified by:
canDoGeoSelection in interface DataSource
Overrides:
canDoGeoSelection in class DataSourceImpl
Returns:
treu if can do geo subsetting

canDoGeoSelectionStride

protected boolean canDoGeoSelectionStride()
Used for the geo subsetting property gui as to whether to show the stride or not

Overrides:
canDoGeoSelectionStride in class DataSourceImpl
Returns:
default is true

makeObs

public FieldImpl makeObs(DataChoice dataChoice,
                         DataSelection subset,
                         ucar.unidata.geoloc.LatLonRect bbox)
                  throws Exception
Make PointObs from the raw VisAD data

Specified by:
makeObs in class PointDataSource
Parameters:
dataChoice - choice for data (source of data)
subset - subsetting parameters
bbox - The area subset. May be null.
Returns:
data of the form index -> (EarthLocation, Time, value_tuple)
Throws:
Exception - problem creating data

getSource

protected String getSource(DataChoice dataChoice)
the data choice

Overrides:
getSource in class PointDataSource
Parameters:
dataChoice - the data choice
Returns:
the file or url this data choice refers to

makeObs

public FieldImpl makeObs(DataChoice dataChoice,
                         DataSelection subset,
                         ucar.unidata.geoloc.LatLonRect bbox,
                         String trackParam,
                         boolean sampleIt,
                         boolean showAttributeGuiIfNeeded)
                  throws Exception
make the observations from the given datachoice

Parameters:
dataChoice - the data choice
subset - data selection to subset with
bbox - bounding box to subset
trackParam - the parameter to use for thetrack
sampleIt - do we just sample or do we read the full set of obs
showAttributeGuiIfNeeded - popup the gui if we have a problem
Returns:
the field
Throws:
Exception - On badness

getDelimiter

protected String getDelimiter(String source)
Get the delimiter to use for the given file. If its xls then use ','

Parameters:
source - source file
Returns:
delimiter to use

getContents

protected final String getContents(String sourceFile)
                            throws Exception
Get the contents of the file as a string

Parameters:
sourceFile - the contents
Returns:
the contents as a string
Throws:
Exception - probably an IOException

getContents

protected String getContents(String sourceFile,
                             boolean sampleIt)
                      throws Exception
Read the given source file and return the text contents of it. If the source file is a xls file then convert to csv text

Parameters:
sourceFile - The source file (or url)
sampleIt - if true, then just read on ob
Returns:
The contents
Throws:
Exception - On badness

makeObs

public FieldImpl makeObs(String contents,
                         String delimiter,
                         DataSelection subset,
                         ucar.unidata.geoloc.LatLonRect bbox,
                         String trackParam,
                         boolean sampleIt,
                         boolean showAttributeGuiIfNeeded)
                  throws Exception
make the observations from the given datachoice

Parameters:
contents - The text contents
delimiter - The delimiter
subset - data selection to subset with
bbox - bounding box to subset
trackParam - the parameter to use for thetrack
sampleIt - do we just sample or do we read the full set of obs
showAttributeGuiIfNeeded - popup the gui if we have a problem
Returns:
the field
Throws:
Exception - On badness

changeMetadata

public void changeMetadata()
                    throws IOException
Show the metadata gui

Throws:
IOException - On badness

getDelimiter

public String getDelimiter()
Get the delimiter used in the text file

Returns:
delimiter

setDelimiter

public void setDelimiter(String delim)
Get the delimiter used in the text file

Parameters:
delim - delimiter

applyNames

public void applyNames(String line)
update the gui

Parameters:
line - the sampled text line

deleteMetaData

public void deleteMetaData(String key)
Remove the given key from the saved mapping. Write out the file

Parameters:
key - key

writePlugin

public void writePlugin()
write the plugin


writeHeader

public void writeHeader()
write the header text to a file


popupMetaDataMenu

public void popupMetaDataMenu(JComponent near)
Show the metadata preference menu

Parameters:
near - The component to show the menu near

saveMetaDataMap

public void saveMetaDataMap()
Save the meta data


applyProperties

public boolean applyProperties()
apply properties

Overrides:
applyProperties in class PointDataSource
Returns:
ok

addPropertiesTabs

public void addPropertiesTabs(JTabbedPane tabbedPane)
add to properties tab

Overrides:
addPropertiesTabs in class PointDataSource
Parameters:
tabbedPane - tab

applySavedMetaDataFromUI

public void applySavedMetaDataFromUI(TextPointDataSource.Metadata metadata)
THis gets called from the Preferences menu and sets the metadata and also updates the skipRows

Parameters:
metadata - The metadata

applySavedMetaDataFromUIInner

public void applySavedMetaDataFromUIInner(TextPointDataSource.Metadata metadata)
This gets called in a thread from the applySavedMetaDataFromUI method

Parameters:
metadata - The metadata

applySavedMetaData

public void applySavedMetaData(TextPointDataSource.Metadata metadata)
Init the widgets

Parameters:
metadata - The metadata

equals

public boolean equals(Object o)
Check to see if this TextPointDataSource is equal to the object in question.

Overrides:
equals in class FilesDataSource
Parameters:
o - object in question
Returns:
true if they are the same or equivalent objects

hashCode

public int hashCode()
Get the hashcode for this object

Overrides:
hashCode in class Object
Returns:
hash code

findLatLonAltIndices

public static int[] findLatLonAltIndices(TupleType type)
Find the lat/lon/alt indicides

Parameters:
type - the type to search
Returns:
the indicies in the tuple

getSample

protected FieldImpl getSample(DataChoice dataChoice)
                       throws Exception
Read a sample of the data. e.g., just the first ob

Overrides:
getSample in class PointDataSource
Parameters:
dataChoice - The data choice
Returns:
The first ob
Throws:
Exception - On badness

doMakeDataChoices

public void doMakeDataChoices()
Make the data choices

Overrides:
doMakeDataChoices in class PointDataSource

getPropertiesComponents

public void getPropertiesComponents(List comps)
Add to properties gui

Overrides:
getPropertiesComponents in class PointDataSource
Parameters:
comps - properties comps

getDataInner

protected Data getDataInner(DataChoice dataChoice,
                            DataCategory category,
                            DataSelection dataSelection,
                            Hashtable requestProperties)
                     throws VisADException,
                            RemoteException
Get the data represented by this class. Calls makeObs, real work needs to be implemented there.

Overrides:
getDataInner in class PointDataSource
Parameters:
dataChoice - choice for data
category - category of data
dataSelection - subselection properties
requestProperties - additional selection properties (not used here)
Returns:
Data object representative of the choice
Throws:
RemoteException - Java RMI error
VisADException - VisAD Error

main2

public static void main2(String[] args)
                  throws Exception
test

Parameters:
args - args
Throws:
Exception - On badness

main

public static void main(String[] args)
                 throws Exception
main

Parameters:
args - args
Throws:
Exception - on badness

setMap

public void setMap(String value)
Set the Map property.

Parameters:
value - The new value for Map

getMap

public String getMap()
Get the Map property.

Returns:
The Map

setParams

public void setParams(String value)
Set the Params property.

Parameters:
value - The new value for Params

getParams

public String getParams()
Get the Params property.

Returns:
The Params

setMetaDataFields

public void setMetaDataFields(List value)
Set the MetaDataFields property.

Parameters:
value - The new value for MetaDataFields

getMetaDataFields

public List getMetaDataFields()
Get the MetaDataFields property.

Returns:
The MetaDataFields

setGroupVarName

public void setGroupVarName(String value)
Set the GroupVarName property.

Parameters:
value - The new value for GroupVarName

getGroupVarName

public String getGroupVarName()
Get the GroupVarName property.

Returns:
The GroupVarName

setSkipRows

public void setSkipRows(int value)
Set the SkipRows property.

Parameters:
value - The new value for SkipRows

getSkipRows

public int getSkipRows()
Get the SkipRows property.

Returns:
The SkipRows