All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class COM.taligent.util.FileTable

java.lang.Object
   |
   +----COM.taligent.util.TableModel
           |
           +----COM.taligent.util.FileTable

public class FileTable
extends TableModel
A file based table model. The data source for the table is a file which is set via its filename. The data can be stored in a TEXT format or BINARY format.

The TEXT file format consists of lines of data that represent row elements. The first row of the text file are the column information for the columns and all following rows contain the actual row data. Each row element is separated by a field separator that is set and queried using the set/getSeparator methods. Because the text file cannot contain binary data, the toString method of each element is used to store the actual data.

The BINARY file format contains a binary representation of the table. This format is dictated by the FileTable implementation as follows:

Even though the file is the data source of the table model, you can modify the table elements and re-write the data using the writeTable method. Also, you can refresh the contents of the table by calling the readTable method.

Version:
1.0
Author:
Andy Clark, Taligent Inc.

Variable Index

 o BINARY
Binary mode.
 o DEFAULT_FILENAME
Default filename (table.txt).
 o DEFAULT_MODE
Default file mode (TEXT).
 o DEFAULT_SEPARATOR
Default text mode field separator (',').
 o TEXT
Text mode.

Constructor Index

 o FileTable()
Constructs an empty table with the default filename and file mode.
 o FileTable(String)
Constructs a table from the specified filename with the default file mode.
 o FileTable(String, int)
Constructs a table from the specified filename and with the specified file mode.

Method Index

 o addColumn(Object[], Object)
Adds a column.
 o addRow(Object[], Object)
Adds a row.
 o addTableListener(TableListener)
Adds a table listener.
 o getColumnCount()
Returns the number of columns in the table.
 o getColumnIndex(Object)
Returns the index of the first column information that equals the specified information or -1 if no column information matches.
 o getColumnInfo(int)
Returns the specified column's information.
 o getElement(int, int)
Returns the element at the specified <row, col>.
 o getFilename()
Returns the current filename.
 o getMode()
Returns the current file mode.
 o getRowCount()
Returns the number of rows in the table.
 o getRowIndex(Object)
Returns the index of the first row information that equals the specified information or -1 if no column information matches.
 o getRowInfo(int)
Returns the specified row's information.
 o getSeparator()
Returns the current field separator for TEXT file mode.
 o insertColumn(Object[], Object, int)
Inserts a column at the specified index.
 o insertRow(Object[], Object, int)
Insert a row at the specified index.
 o isFirstLineColumnNames()
Returns whether the first line of the file contains the column names.
 o readTable()
Loads the data from the file.
 o removeAllColumns()
Removes all of the columns in the table.
 o removeAllRows()
Removes all of the rows in the table.
 o removeColumn(int)
Removes the specified column.
 o removeRow(int)
Removes specified row.
 o removeTableListener(TableListener)
Removes the specified table listener.
 o replaceColumn(Object[], Object, int)
Replace the column at the specified index.
 o replaceRow(Object[], Object, int)
Replaces the row at the specified index.
 o setColumnInfo(Object, int)
Sets the specified column's information.
 o setElement(Object, int, int)
Sets the element at the specified <row, col>.
 o setFilename(String)
Sets the filename.
 o setFirstLineColumnNames(boolean)
Sets whether the first line of the file contains the column names.
 o setMode(int)
Sets the file mode.
 o setRowInfo(Object, int)
Sets the specified row's information.
 o setSeparator(char)
Sets the field separator for TEXT file mode.
 o writeTable()
Writes the data to the file.

Variables

 o TEXT
 public static final int TEXT
Text mode.

 o BINARY
 public static final int BINARY
Binary mode.

 o DEFAULT_MODE
 public static final int DEFAULT_MODE
Default file mode (TEXT).

 o DEFAULT_FILENAME
 public static final String DEFAULT_FILENAME
Default filename (table.txt).

 o DEFAULT_SEPARATOR
 public static final char DEFAULT_SEPARATOR
Default text mode field separator (',').

Constructors

 o FileTable
 public FileTable()
Constructs an empty table with the default filename and file mode.

See Also:
DEFAULT_FILENAME, DEFAULT_MODE
 o FileTable
 public FileTable(String filename)
Constructs a table from the specified filename with the default file mode.

If the file exists at object construction time, the contents are loaded.

Parameters:
filename - The file.
See Also:
DEFAULT_MODE
 o FileTable
 public FileTable(String filename,
                  int mode)
Constructs a table from the specified filename and with the specified file mode.

If the file exists at object construction time, the contents are loaded.

Parameters:
filename - The file.
mode - The file mode.
See Also:
setFilename, setMode

Methods

 o readTable
 public void readTable()
Loads the data from the file.

See Also:
writeTable
 o writeTable
 public synchronized void writeTable()
Writes the data to the file.

See Also:
readTable
 o setFilename
 public synchronized void setFilename(String filename)
Sets the filename.

Parameters:
filename - The new filename.
See Also:
getFilename, DEFAULT_FILENAME
 o getFilename
 public String getFilename()
Returns the current filename.

See Also:
setFilename
 o setMode
 public synchronized void setMode(int mode)
Sets the file mode.

Parameters:
mode - The new mode.
See Also:
getMode, DEFAULT_MODE, TEXT, BINARY
 o getMode
 public int getMode()
Returns the current file mode.

See Also:
setMode
 o setFirstLineColumnNames
 public synchronized void setFirstLineColumnNames(boolean contains)
Sets whether the first line of the file contains the column names. This setting only applies to the TEXT file mode.

Parameters:
contains - True if first line contains column names, false otherwise.
See Also:
isFirstLineColumnNames
 o isFirstLineColumnNames
 public boolean isFirstLineColumnNames()
Returns whether the first line of the file contains the column names. This setting only applies to the TEXT file mode.

See Also:
setFirstLineColumnNames
 o setSeparator
 public synchronized void setSeparator(char separator)
Sets the field separator for TEXT file mode.

Parameters:
separator - The new field separator character.
See Also:
getSeparator, DEFAULT_SEPARATOR
 o getSeparator
 public char getSeparator()
Returns the current field separator for TEXT file mode.

See Also:
setSeparator
 o addTableListener
 public void addTableListener(TableListener listener)
Adds a table listener.

Overrides:
addTableListener in class TableModel
 o removeTableListener
 public void removeTableListener(TableListener listener)
Removes the specified table listener.

Overrides:
removeTableListener in class TableModel
 o setElement
 public void setElement(Object element,
                        int row,
                        int col)
Sets the element at the specified <row, col>.

Parameters:
element - The new element.
row - The row index.
col - The column index.
Overrides:
setElement in class TableModel
 o getElement
 public synchronized Object getElement(int row,
                                       int col)
Returns the element at the specified <row, col>.

Parameters:
row - The row index.
col - The column index.
Overrides:
getElement in class TableModel
 o getColumnCount
 public int getColumnCount()
Returns the number of columns in the table.

Overrides:
getColumnCount in class TableModel
 o setColumnInfo
 public void setColumnInfo(Object info,
                           int col)
Sets the specified column's information.

Parameters:
info - The column information.
col - The column index.
Overrides:
setColumnInfo in class TableModel
 o getColumnInfo
 public synchronized Object getColumnInfo(int col)
Returns the specified column's information.

Parameters:
col - The column index.
Overrides:
getColumnInfo in class TableModel
 o getColumnIndex
 public synchronized int getColumnIndex(Object info)
Returns the index of the first column information that equals the specified information or -1 if no column information matches.

Parameters:
info - The column information.
Overrides:
getColumnIndex in class TableModel
 o addColumn
 public void addColumn(Object data[],
                       Object info)
Adds a column.

Parameters:
data - The new column's data. Can be null. If the data array length is shorter than the number of rows, then null values will be added; and if the length is greater than the number of rows, the extraneous values are ignored.
info - The new column's information. Can be null.
Overrides:
addColumn in class TableModel
 o removeColumn
 public void removeColumn(int col)
Removes the specified column.

Parameters:
col - The column index.
Overrides:
removeColumn in class TableModel
 o removeAllColumns
 public void removeAllColumns()
Removes all of the columns in the table.

Overrides:
removeAllColumns in class TableModel
 o insertColumn
 public void insertColumn(Object data[],
                          Object info,
                          int col)
Inserts a column at the specified index.

Parameters:
data - The new column's data. Can be null. If the data array length is shorter than the number of rows, then null values will be added; and if the length is greater than the number of rows, the extraneous values are ignored.
info - The new column's information. Can be null.
col - The column index.
Overrides:
insertColumn in class TableModel
 o replaceColumn
 public void replaceColumn(Object data[],
                           Object info,
                           int col)
Replace the column at the specified index.

Parameters:
data - The column's new data. Can be null. If the data array length is shorter than the number of rows, then null values will be added; and if the length is greater than the number of rows, the extraneous values are ignored.
info - The column's new information. Can be null.
col - The column index.
Overrides:
replaceColumn in class TableModel
 o getRowCount
 public synchronized int getRowCount()
Returns the number of rows in the table.

Overrides:
getRowCount in class TableModel
 o setRowInfo
 public void setRowInfo(Object info,
                        int row)
Sets the specified row's information.

Parameters:
info - The row information.
row - The row index.
Overrides:
setRowInfo in class TableModel
 o getRowInfo
 public Object getRowInfo(int row)
Returns the specified row's information.

Parameters:
row - The row index.
Overrides:
getRowInfo in class TableModel
 o getRowIndex
 public synchronized int getRowIndex(Object info)
Returns the index of the first row information that equals the specified information or -1 if no column information matches.

Parameters:
info - The row information.
Overrides:
getRowIndex in class TableModel
 o addRow
 public void addRow(Object data[],
                    Object info)
Adds a row.

Parameters:
data - The new row's data. Can be null. If the data array length is shorter than the number of columns, then null values will be added; and if the length is greater than the number of columns, the extraneous values are ignored.
info - The new row's information. Can be null.
Overrides:
addRow in class TableModel
 o removeRow
 public void removeRow(int row)
Removes specified row.

Parameters:
row - The row index.
Overrides:
removeRow in class TableModel
 o removeAllRows
 public void removeAllRows()
Removes all of the rows in the table.

Overrides:
removeAllRows in class TableModel
 o insertRow
 public void insertRow(Object data[],
                       Object info,
                       int row)
Insert a row at the specified index.

Parameters:
data - The new row's data. Can be null. If the data array length is shorter than the number of columns, then null values will be added; and if the length is greater than the number of columns, the extraneous values are ignored.
info - The new row's information.
row - The row index.
Overrides:
insertRow in class TableModel
 o replaceRow
 public void replaceRow(Object data[],
                        Object info,
                        int row)
Replaces the row at the specified index. The implementer of this method should send TableEvent.ROW_CHANGED events to the registered table listeners.

Parameters:
data - The row's new data. Can be null. If the data array length is shorter than the number of columns, then null values will be added; and if the length is greater than the number of columns, the extraneous values are ignored.
info - The row's new information. Can be null.
row - The row index.
Overrides:
replaceRow in class TableModel

All Packages  Class Hierarchy  This Package  Previous  Next  Index