|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.table.AbstractTableModel
javax.swing.table.DefaultTableModel
jsky.catalog.MemoryCatalog
public class MemoryCatalog
Used to manage tabular catalog data in memory, such as the result of a catalog query or the contents of a local catalog file. This class can be easily used with a JTable widget, since it extends the DefaultTableModel class. It can also be used as an in memory catalog for further searches.
In ASCII form, the data is represented as a tab separated table with an optional header and column headings.
The header may contain comments (starting with '#') or other text. Lines of the form "keyword: value" define properties, which are saved in a Properties object for access by client classes.
A dashed line "---" divides the column headings from the data rows. The column headings should be separated by tabs.
There is one row per line and each row should have the same number of tab separated columns as the table headings.
Field Summary | |
---|---|
static java.lang.String |
DEC_COL
|
static java.lang.String |
EQUINOX
|
static java.lang.String |
ID_COL
|
static java.lang.String |
RA_COL
|
static java.lang.String |
SYMBOL
|
static java.lang.String |
X_COL
|
static java.lang.String |
Y_COL
|
Fields inherited from class javax.swing.table.DefaultTableModel |
---|
columnIdentifiers, dataVector |
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Fields inherited from interface jsky.catalog.Catalog |
---|
ARCHIVE, CATALOG, DIRECTORY, IMAGE_SERVER, LOCAL, NAME_SERVER |
Constructor Summary | |
---|---|
protected |
MemoryCatalog()
This constructor is only for use by derived classes. |
|
MemoryCatalog(Catalog catalog,
java.io.InputStream in)
Initialize the table from the given stream. |
|
MemoryCatalog(Catalog catalog,
java.io.InputStream in,
int maxRows)
Initialize the table from the given stream by reading up to maxRows of the data (in tab separated table format). |
|
MemoryCatalog(Catalog catalog,
java.io.InputStream in,
QueryArgs queryArgs)
Initialize the table from the given stream by reading up to maxRows of the data. |
|
MemoryCatalog(Catalog catalog,
java.lang.String filename)
Initialize the table from the given file. |
|
MemoryCatalog(FieldDesc[] fields,
java.util.Vector dataVector)
Create a MemoryCatalog with the given information. |
|
MemoryCatalog(MemoryCatalog table,
FieldDesc[] fields,
java.util.Vector dataRows)
Construct a new MemoryCatalog with the given column fields and data rows (For internal use only). |
|
MemoryCatalog(java.lang.String filename)
Initialize the table from the given file |
Method Summary | |
---|---|
protected void |
_checkColumnClass(int col,
java.lang.Object o)
Check the class type for the given column to see if all of the items are the same type and update the _columnClasses vector, setting the correct lowest common class for each column. |
protected void |
_init(java.io.InputStream in,
int maxRows)
Initialize the table from the given stream, reading at most maxRows data rows. |
protected void |
_initColumnClasses()
Determine the best class to use for each column by scanning the table items. |
protected void |
_initFields()
Initialize the fields array, which describes the table columns |
protected java.util.Vector |
_parseHeading(java.lang.String s)
Parse the given line looking for tab separated column heading strings and return a vector containing the strings found. |
protected java.lang.Object |
_parseItem(java.lang.String s)
Parse the given string and return a Double or String object, depending on the format of the string. |
protected void |
_parseProperty(java.lang.String s)
Check for a "keyword: value" pair in the given string and, if found, save it as a property. |
protected java.util.Vector |
_parseRow(java.lang.String lineStr)
Parse the given table row looking for tab separated items. |
protected void |
_saveHeader(java.io.PrintStream out)
Save the table header (part before the column headings) to the given PrintStream. |
protected void |
_saveProperties(java.io.PrintStream out)
Save the table header (part before the column headings) to the given PrintStream. |
java.lang.Object |
clone()
Implementation of the clone method (makes a shallow copy). |
protected boolean |
compareRow(java.util.Vector row,
java.lang.String objectId,
CoordinateRadius region,
SearchCondition[] conditions,
int[] searchCols)
Return true if the given row satisfies the given query arguments. |
Catalog |
getCatalog()
Return the catalog used to create this table, or null if not known. |
java.lang.Class |
getColumnClass(int columnIndex)
Returns the lowest common denominator Class in the column. |
FieldDesc |
getColumnDesc(int i)
Return a description of the ith table column parameter. |
java.util.Vector |
getColumnIdentifiers()
Allow access to this inherited member variable in a subclass |
int |
getColumnIndex(java.lang.String name)
Return the table column index for the given column name |
java.lang.String |
getColumnName(int index)
Return the table column name for the given column index |
Coordinates |
getCoordinates(int rowIndex)
Return a Coordinates object based on the appropriate columns in the given row, or null if there are no coordinates available for the row. |
java.lang.String |
getDescription()
Return a description of the catalog, or null if not available |
java.net.URL |
getDocURL()
Return the documentation URL for the catalog |
FieldDesc[] |
getFields()
Return an array of objects describing the table columns |
java.lang.String |
getFilename()
Return the filename of the local catalog, if known |
java.lang.String |
getId()
Return the id or short name of the catalog |
java.lang.String |
getName()
Return the name of the catalog |
int |
getNumColumns()
Return the number of table columns.. |
int |
getNumParams()
Return the number of query parameters that this catalog accepts. |
FieldDesc |
getParamDesc(int i)
Return a description of the ith query parameter. |
FieldDesc |
getParamDesc(java.lang.String name)
Return a description of the named query parameter. |
CatalogDirectory |
getParent()
Return a reference to the parent catalog directory, or null if not known. |
Catalog[] |
getPath()
Return an array of Catalog or CatalogDirectory objects representing the path from the root catalog directory to this catalog. |
java.util.Properties |
getProperties()
Return the properties defined in the table header |
java.lang.String |
getProperty(java.lang.String key)
Return the value of the named property as a String |
QueryArgs |
getQueryArgs()
Return the object representing the arguments to the query that resulted in this table, if known, otherwise null. |
RowCoordinates |
getRowCoordinates()
Return an object storing the column indexes where RA and Dec are found, using the first plot symbol definition found. |
java.lang.String |
getTitle()
Return the title for the catalog |
java.lang.String |
getType()
Return the catalog type (normally one of the Catalog constants: CATALOG, ARCHIVE, DIRECTORY, LOCAL, IMAGE_SERVER) |
java.lang.Object |
getValueAt(int row,
java.lang.String name)
Return the value at the given row and columm name |
WorldCoordinates |
getWCSCenter()
Return the center coordinates for this table from the query arguments, if known, otherwise return the coordinates of the first row, or null if there are no world coordinates available. |
boolean |
hasCol(java.lang.String name)
return true if the table contains the given column |
boolean |
hasCoordinates()
Return true if the table has coordinate columns, such as (ra, dec) |
boolean |
isCellEditable(int rowIndex,
int columnIndex)
Returns true if the cell at rowIndex and columnIndex is editable. |
boolean |
isImageServer()
Return true if this object represents an image server. |
boolean |
isLocal()
Return true if this is a local catalog, and false if it requires network access or if a query could hang. |
boolean |
isMore()
Return true if the query result was truncated and more data would have been available |
boolean |
isReadOnly()
Return true if the table is read-only and should not be editable |
static void |
main(java.lang.String[] args)
Test cases |
protected java.util.Vector |
makeColumnIdentifiers(FieldDesc[] fields)
Create and return a vector of table column identifiers (column headings) based on the given fields. |
protected MemoryCatalog |
makeQueryResult(FieldDesc[] fields,
java.util.Vector dataRows)
Return a new MemoryCatalog with the given column fields and data rows. |
void |
print()
|
QueryResult |
query(QueryArgs queryArgs)
Query the catalog using the given argument and return the result. |
void |
saveAs(java.io.OutputStream os)
Save the table to the given stream |
void |
saveAs(java.lang.String filename)
Save the table to the given filename format. |
void |
saveAsHTML(java.lang.String filename)
Save the table to the given filename in HTML format |
void |
setCatalog(Catalog cat)
Set a reference to the catalog used to create this table. |
void |
setColumnClasses(java.lang.Class[] ar)
Set the data types for column values. |
void |
setColumnClasses(java.util.List l)
Set the data types for column values. |
void |
setColumnIdentifiers(java.util.Vector columnIdentifiers)
Set the table column headings with a Vector of Strings |
void |
setDescription(java.lang.String description)
Set the description of the catalog |
void |
setDocURL(java.net.URL docURL)
Set the doc URL for the catalog |
void |
setFields(FieldDesc[] fields)
Set the array of objects describing the table columns. |
void |
setFilename(java.lang.String filename)
Set the filename of the local catalog |
void |
setId(java.lang.String id)
Set the id or short name for the catalog |
void |
setMore(boolean more)
Called to indicate if the result was truncated and more rows would have been available |
void |
setName(java.lang.String name)
Set the name for the catalog |
void |
setParent(CatalogDirectory catDir)
Set the parent catalog directory |
void |
setProperties(java.util.Properties p)
Replace the table properties |
void |
setProperty(java.lang.String key,
java.lang.String value)
Set the value of the named property |
void |
setQueryArgs(QueryArgs queryArgs)
Set the object representing the arguments to the query that resulted in this table. |
void |
setReadOnly(boolean b)
Set to true if the table is read-only and should not be editable |
void |
setRegionArgs(QueryArgs queryArgs,
CoordinateRadius region)
This method is required to implement the Catalog interface, but currently does nothing here. |
void |
setRowCoordinates(RowCoordinates rowCoordinates)
Set the RowCoordinates object for this catalog |
void |
setTitle(java.lang.String title)
Set the title for the catalog |
void |
sort(java.lang.String[] sortCols,
java.lang.String sortOrder)
Sort the contents of the table by the given sort columns and in the given order. |
java.lang.String |
toString()
Format and return the contents of the table as a String |
Methods inherited from class javax.swing.table.DefaultTableModel |
---|
addColumn, addColumn, addColumn, addRow, addRow, convertToVector, convertToVector, getColumnCount, getDataVector, getRowCount, getValueAt, insertRow, insertRow, moveRow, newDataAvailable, newRowsAdded, removeRow, rowsRemoved, setColumnCount, setColumnIdentifiers, setDataVector, setDataVector, setNumRows, setRowCount, setValueAt |
Methods inherited from class javax.swing.table.AbstractTableModel |
---|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface jsky.catalog.TableQueryResult |
---|
getDataVector |
Methods inherited from interface javax.swing.table.TableModel |
---|
addTableModelListener, getColumnCount, getRowCount, getValueAt, removeTableModelListener, setValueAt |
Field Detail |
---|
public static final java.lang.String EQUINOX
public static final java.lang.String SYMBOL
public static final java.lang.String ID_COL
public static final java.lang.String RA_COL
public static final java.lang.String DEC_COL
public static final java.lang.String X_COL
public static final java.lang.String Y_COL
Constructor Detail |
---|
public MemoryCatalog(FieldDesc[] fields, java.util.Vector dataVector)
fields
- an array of objects describing the table columnsdataVector
- a vector of data rows, each of which is a vector of column values.public MemoryCatalog(Catalog catalog, java.io.InputStream in, int maxRows) throws java.io.IOException
catalog
- the catalog where the data originated, if knownin
- the stream to read the table data frommaxRows
- the maximum number of data rows to read
java.io.IOException
public MemoryCatalog(Catalog catalog, java.io.InputStream in) throws java.io.IOException
catalog
- the catalog where the data originated, if knownin
- the stream to read the catalog data from
java.io.IOException
public MemoryCatalog(Catalog catalog, java.io.InputStream in, QueryArgs queryArgs) throws java.io.IOException
catalog
- the catalog where the data originated, if knownin
- the stream to read the catalog data fromqueryArgs
- represents the arguments to the query that resulted in this table
java.io.IOException
public MemoryCatalog(Catalog catalog, java.lang.String filename) throws java.io.IOException
catalog
- the catalog where the data originated, if knownfilename
- the name of the catalog file
java.io.IOException
public MemoryCatalog(java.lang.String filename) throws java.io.IOException
filename
- the name of the catalog file
java.io.IOException
public MemoryCatalog(MemoryCatalog table, FieldDesc[] fields, java.util.Vector dataRows)
table
- the source catalog tablefields
- an array of objects describing the table columnsdataRows
- a vector of data rows, each of which is a vector of column values.protected MemoryCatalog()
Method Detail |
---|
public java.lang.Object clone()
clone
in interface Catalog
clone
in class java.lang.Object
public void setCatalog(Catalog cat)
public Catalog getCatalog()
getCatalog
in interface TableQueryResult
protected void _init(java.io.InputStream in, int maxRows) throws java.io.IOException
java.io.IOException
protected void _parseProperty(java.lang.String s)
protected java.util.Vector _parseHeading(java.lang.String s)
s
- A line containing tab separated column headings.
protected void _initFields()
protected java.util.Vector _parseRow(java.lang.String lineStr)
Item strings that look like numbers are inserted into the result as Doubles.
lineStr
- A string containing a line from the table.
protected java.lang.Object _parseItem(java.lang.String s)
s
- A String to be parsed.
protected void _checkColumnClass(int col, java.lang.Object o)
col
- The column indexo
- The item in the columnpublic java.util.Vector getColumnIdentifiers()
getColumnIdentifiers
in interface TableQueryResult
protected java.util.Vector makeColumnIdentifiers(FieldDesc[] fields)
public java.lang.String getName()
getName
in interface Catalog
public void setName(java.lang.String name)
setName
in interface Catalog
public java.lang.String getFilename()
public void setFilename(java.lang.String filename)
public java.lang.String getId()
getId
in interface Catalog
public void setId(java.lang.String id)
public java.lang.String getTitle()
getTitle
in interface Catalog
public void setTitle(java.lang.String title)
public java.lang.String getDescription()
getDescription
in interface Catalog
public void setDescription(java.lang.String description)
public java.net.URL getDocURL()
getDocURL
in interface Catalog
public void setDocURL(java.net.URL docURL)
public int getNumParams()
getNumParams
in interface Catalog
public FieldDesc getParamDesc(int i)
getParamDesc
in interface Catalog
public FieldDesc getParamDesc(java.lang.String name)
getParamDesc
in interface Catalog
public int getNumColumns()
public FieldDesc getColumnDesc(int i)
getColumnDesc
in interface TableQueryResult
public void setRegionArgs(QueryArgs queryArgs, CoordinateRadius region)
setRegionArgs
in interface Catalog
queryArgs
- (in/out) describes the query argumentsregion
- (in) describes the query region (center and radius range)public boolean isLocal()
isLocal
in interface Catalog
public boolean isImageServer()
isImageServer
in interface Catalog
public java.lang.String getType()
getType
in interface Catalog
public void setParent(CatalogDirectory catDir)
setParent
in interface Catalog
public CatalogDirectory getParent()
getParent
in interface Catalog
public Catalog[] getPath()
getPath
in interface Catalog
public QueryResult query(QueryArgs queryArgs) throws java.io.IOException
query
in interface Catalog
queryArgs
- An object describing the query arguments.
java.io.IOException
protected MemoryCatalog makeQueryResult(FieldDesc[] fields, java.util.Vector dataRows)
fields
- an array of objects describing the table columnsdataRows
- a vector of data rows, each of which is a vector of column values.public java.lang.String toString()
toString
in class java.lang.Object
protected boolean compareRow(java.util.Vector row, java.lang.String objectId, CoordinateRadius region, SearchCondition[] conditions, int[] searchCols)
row
- A vector containing the column values for a row.objectId
- If not null, search for an object with this id.region
- The region (center, radius) for a circular search, if not null.conditions
- Specifies the ranges for column values we are search for.searchCols
- An array of column indexes corresponding to the condition
argument (used for efficiency).
public boolean isMore()
isMore
in interface TableQueryResult
public void setMore(boolean more)
public void setColumnIdentifiers(java.util.Vector columnIdentifiers)
setColumnIdentifiers
in class javax.swing.table.DefaultTableModel
public boolean hasCol(java.lang.String name)
public java.lang.Object getValueAt(int row, java.lang.String name)
public int getColumnIndex(java.lang.String name)
getColumnIndex
in interface TableQueryResult
public java.lang.String getColumnName(int index)
getColumnName
in interface javax.swing.table.TableModel
getColumnName
in class javax.swing.table.DefaultTableModel
public java.lang.Class getColumnClass(int columnIndex)
getColumnClass
in interface javax.swing.table.TableModel
getColumnClass
in class javax.swing.table.AbstractTableModel
public void setColumnClasses(java.util.List l)
public void setColumnClasses(java.lang.Class[] ar)
public FieldDesc[] getFields()
public void setFields(FieldDesc[] fields)
public boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface javax.swing.table.TableModel
isCellEditable
in class javax.swing.table.DefaultTableModel
rowIndex
- the row whose value is to be looked upcolumnIndex
- the column whose value is to be looked up
DefaultTableModel.setValueAt(java.lang.Object, int, int)
public boolean isReadOnly()
public void setReadOnly(boolean b)
public void sort(java.lang.String[] sortCols, java.lang.String sortOrder)
sortCols
- an array of column names to sort bysortOrder
- if true, sort in ascending order, otherwise descending.public boolean hasCoordinates()
hasCoordinates
in interface TableQueryResult
public Coordinates getCoordinates(int rowIndex)
getCoordinates
in interface TableQueryResult
public void print()
public void saveAs(java.lang.String filename) throws java.io.IOException
saveAs
in interface Saveable
java.io.IOException
public void saveAs(java.io.OutputStream os)
protected void _saveHeader(java.io.PrintStream out)
protected void _saveProperties(java.io.PrintStream out)
public void saveAsHTML(java.lang.String filename) throws java.io.IOException
saveAsHTML
in interface SaveableAsHTML
java.io.IOException
public QueryArgs getQueryArgs()
getQueryArgs
in interface TableQueryResult
public void setQueryArgs(QueryArgs queryArgs)
setQueryArgs
in interface TableQueryResult
public RowCoordinates getRowCoordinates()
getRowCoordinates
in interface TableQueryResult
public void setRowCoordinates(RowCoordinates rowCoordinates)
public WorldCoordinates getWCSCenter()
getWCSCenter
in interface TableQueryResult
protected void _initColumnClasses()
public java.util.Properties getProperties()
public void setProperties(java.util.Properties p)
public java.lang.String getProperty(java.lang.String key)
public void setProperty(java.lang.String key, java.lang.String value)
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |