## com.bbn.openmap.dataAccess.shape
Class DbfTableModel

    java.lang.Object
      javax.swing.table.AbstractTableModel
          com.bbn.openmap.dataAccess.shape.DbfTableModel

All Implemented Interfaces:
  java.util.EventListener, java.io.Serializable, ShapeConstants, javax.swing.table.TableModel, javax.swing.event.TableModelListener

Direct Known Subclasses:
  DbfFile, MetaDbfTableModel

public class DbfTableModel
extends javax.swing.table.AbstractTableModel
implements ShapeConstants, javax.swing.event.TableModelListener

An implemention of TableModel that manages tabular data read from a dbf file and enables the user to stored data store herein to be saved to a file conforming to the DBF III file format specification. To create a three one column model:

     DbfTableModel model = new DbfTableModel(1);

     model.setDecimalCount(0, (byte) 0);
     model.setLength(0, (byte) 10);
     model.setColumnName(0, "Column1");
     model.setType(0, (byte) DbfTableModel.TYPE_CHARACTER);

     model.setDecimalCount(1, (byte) 0);
     model.setLength(1, (byte) 10);
     model.setColumnName(1, "Column1");
     model.setType(1, (byte) DbfTableModel.TYPE_NUMERIC);

     model.setDecimalCount(2, (byte) 0);
     model.setLength(2, (byte) 10);
     model.setColumnName(2, "Column1");
     model.setType(2, (byte) DbfTableModel.TYPE_CHARACTER);

     esriLayer.setModel(model);

Author:
  Doug Van Auken
See Also:
  Serialized Form

Field Summary
`protected int` `_columnCount` Class scope variable for the number of columns that exist in the model
`protected byte[]` `_decimalCounts` An array of bytes that contain the number of decimal places for each column
`protected int[]` `_lengths` An array of bytes that contain the character lengths for each column
`protected java.lang.String[]` `_names` An array of bytes that contain the names for each column
`protected java.util.ArrayList` `_records` Class scope reference to a list of data formatted by row
`protected byte[]` `_types` An array of bytes that contain the column types for each column
`protected boolean` `DEBUG`
`protected boolean` `dirty`
`static int` `DONE_MASK` Button mask to drop the frame quietly, with the modifications to the table complete.
`protected boolean` `exitOnClose`
`protected java.lang.StringBuffer` `filePath`
`protected javax.swing.JFrame` `frame`
`static int` `MODIFY_COLUMN_MASK` Edit button mask, to allow adding/removing columns in the attribute table.
`static int` `MODIFY_ROW_MASK` Edit button mask, to allow adding/removing rows.
`protected DbfTableModel` `parent`
`static int` `SAVE_MASK` Button mask to show a save button to write out any changes.
`protected javax.swing.JTable` `table`
`static int` `TYPE_CHARACTER`
`static int` `TYPE_DATE`
`static int` `TYPE_LOGICAL`
`static int` `TYPE_MEMO`
`static int` `TYPE_NUMERIC`
`protected boolean` `writable`

Fields inherited from class javax.swing.table.AbstractTableModel
`listenerList`

Fields inherited from interface com.bbn.openmap.dataAccess.shape.ShapeConstants

`DBF_ATTRIBUTE, DBF_CHARACTER, DBF_DATE, DBF_LOGICAL, DBF_MEMO, DBF_NUMERIC, DBF_TYPE_CHARACTER, DBF_TYPE_DATE, DBF_TYPE_LOGICAL, DBF_TYPE_MEMO, DBF_TYPE_NUMERIC, PARAM_DBF, PARAM_SHP, PARAM_SHX, SHAPE_BOUNDS_ATTRIBUTE, SHAPE_DBF_DASHPATTERN, SHAPE_DBF_DASHPHASE, SHAPE_DBF_DESCRIPTION, SHAPE_DBF_FILLCOLOR, SHAPE_DBF_INFO_ATTRIBUTE, SHAPE_DBF_LINECOLOR, SHAPE_DBF_LINEWIDTH, SHAPE_DBF_SELECTCOLOR, SHAPE_FILE_HEADER_LENGTH, SHAPE_FILE_RECORD_HEADER_LENGTH, SHAPE_INDEX_ATTRIBUTE, SHAPE_MAX_MEASURE_ATTRIBUTE, SHAPE_MAX_Z_ATTRIBUTE, SHAPE_MEASURE_ATTRIBUTE, SHAPE_MIN_MEASURE_ATTRIBUTE, SHAPE_MIN_Z_ATTRIBUTE, SHAPE_TYPE_ARC, SHAPE_TYPE_MULTIPATCH, SHAPE_TYPE_MULTIPOINT, SHAPE_TYPE_MULTIPOINTM, SHAPE_TYPE_MULTIPOINTZ, SHAPE_TYPE_NULL, SHAPE_TYPE_POINT, SHAPE_TYPE_POINTM, SHAPE_TYPE_POINTZ, SHAPE_TYPE_POLYGON, SHAPE_TYPE_POLYGONM, SHAPE_TYPE_POLYGONZ, SHAPE_TYPE_POLYLINE, SHAPE_TYPE_POLYLINEM, SHAPE_TYPE_POLYLINEZ, SHAPE_Z_ATTRIBUTE`

Constructor Summary
`protected` `DbfTableModel()`
`` `DbfTableModel(DbfInputStream is)` Creates a DbfTableModel based on an InputStream
`` `DbfTableModel(int columnCount)` Creates a blank DbfTableModel

Method Summary
`protected byte[]` `add(byte[] current, byte nb)`
`protected int[]` `add(int[] current, byte nb)`
`protected java.lang.String[]` `add(java.lang.String[] current, java.lang.String string)`
`void` `addBlankRecord()`
`protected void` `addColumn(java.util.ArrayList recordColumn)` The types in the ArrayList are set - String, Byte, Integer, Integer - to match the format of the header.
`void` `addRecord(java.util.ArrayList columns)` Adds a row of data to the the model
`void` `cleanupChanges()`
`protected void` `commitEvents(DbfTableModel model)`
`protected void` `deleteColumn(int columnIndex)` Delete a column, iterating through all the records and deleting that part of each record.
`void` `exitWindowClosed()`
`java.lang.Class` `getColumnClass(int c)` Retrieves the column class for the passed in column index
`int` `getColumnCount()` Retrieves the number of columns that exist in the model
`int` `getColumnIndexForName(java.lang.String columnName)` Find the column index of the column with the given name.
`java.lang.String` `getColumnName(int column)` Retrieves the column name for the passed in column index
`static DbfTableModel` `getDbfTableModel(java.net.URL dbf)` Creates a DbfTableModel for a given .dbf file
`byte` `getDecimalCount(int column)` Retrieves the number of decimal places for the passed in column index
`java.lang.Object` `getEmptyDefaultForType(byte type)`
`java.awt.Component` `getGUI(java.lang.String filename, int actionMask)`
`int` `getLength(int column)` Retrieves the character length for the passed in column index
`java.lang.Object` `getRecord(int recordnumber)` Retrieves the record array list for the passed record number
`java.util.Iterator` `getRecords()` Get an iterator over the records.
`int` `getRowCount()` Retrieves the number of columns that exist in the model
`protected javax.swing.JTable` `getTable()`
`javax.swing.JTable` `getTable(javax.swing.ListSelectionModel lsm)` Needs to be called before displaying the DbfTableModel.
`byte` `getType(int column)` Retrieves the column type for the passed in column index
`java.lang.Object` `getValueAt(int row, int column)` Retrieves a value for a specific column and row index
`boolean` `getWritable()`
`DbfTableModel` `headerClone()` Create another DbfTableModel with the same structure as this one (number of columns, column names, lengths and decimal counts).
`void` `hideGUI()`
`boolean` `isCellEditable(int rowIndex, int columnIndex)`
`static void` `main(java.lang.String[] args)`
`protected byte[]` `remove(byte[] current, int index)`
`java.util.ArrayList` `remove(int index)` Remove the record at the index.
`protected int[]` `remove(int[] current, int index)`
`protected java.lang.String[]` `remove(java.lang.String[] current, int index)`
`void` `setColumnName(int column, java.lang.String name)` Sets the column name for the passed-in field index
`void` `setDecimalCount(int column, byte decimalCount)` Sets the decimal count for the passed in field index
`void` `setLength(int column, int length)` Set the character length fro the passed-in field index
`void` `setType(int column, byte type)` Sets the column type for the passed-in field index
`void` `setValueAt(java.lang.Object object, int row, int column)`
`void` `setWritable(boolean set)`
`void` `showGUI(java.lang.String filename, int actionMask)`
`void` `tableChanged(javax.swing.event.TableModelEvent e)`

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
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### TYPE_CHARACTER

    public static final int TYPE_CHARACTER

See Also:
  Constant Field Values

### TYPE_DATE

    public static final int TYPE_DATE

See Also:
  Constant Field Values

### TYPE_NUMERIC

    public static final int TYPE_NUMERIC

See Also:
  Constant Field Values

### TYPE_LOGICAL

    public static final int TYPE_LOGICAL

See Also:
  Constant Field Values

### TYPE_MEMO

    public static final int TYPE_MEMO

See Also:
  Constant Field Values

### MODIFY_ROW_MASK

    public static final int MODIFY_ROW_MASK

  Edit button mask, to allow adding/removing rows. Be very careful with this option if you plan on using this file with a shape file - the number of records has to match the number of graphics in a shape file, so if you add or delete, you should add/delete the graphic in the shape file, too.

  See Also:
    Constant Field Values

### MODIFY_COLUMN_MASK

    public static final int MODIFY_COLUMN_MASK

  Edit button mask, to allow adding/removing columns in the attribute table.

  See Also:
    Constant Field Values

### DONE_MASK

    public static final int DONE_MASK

  Button mask to drop the frame quietly, with the modifications to the table complete.

  See Also:
    Constant Field Values

### SAVE_MASK

    public static final int SAVE_MASK

  Button mask to show a save button to write out any changes.

  See Also:
    Constant Field Values

### _lengths

    protected int[] _lengths

  An array of bytes that contain the character lengths for each column

### _decimalCounts

    protected byte[] _decimalCounts

  An array of bytes that contain the number of decimal places for each column

### _types

    protected byte[] _types

  An array of bytes that contain the column types for each column

### _names

    protected java.lang.String[] _names

  An array of bytes that contain the names for each column

### _records

    protected java.util.ArrayList _records

  Class scope reference to a list of data formatted by row

### _columnCount

    protected int _columnCount

  Class scope variable for the number of columns that exist in the model

### writable

    protected boolean writable

### table

    protected javax.swing.JTable table

### parent

    protected final DbfTableModel parent

### dirty

    protected boolean dirty

### exitOnClose

    protected boolean exitOnClose

### DEBUG

    protected boolean DEBUG

### filePath

    protected final java.lang.StringBuffer filePath

### frame

    protected javax.swing.JFrame frame

Constructor Detail

### DbfTableModel

    protected DbfTableModel()

### DbfTableModel

    public DbfTableModel(int columnCount)

  Creates a blank DbfTableModel

Parameters:
  `columnCount` - The number of columns this model will manage

### DbfTableModel

    public DbfTableModel(DbfInputStream is)

  Creates a DbfTableModel based on an InputStream

Parameters:
  `is` - The dbf file

Method Detail

### addRecord

    public void addRecord(java.util.ArrayList columns)

  Adds a row of data to the the model

  Parameters:
    `columns` - A collection of columns that comprise the row of data
  Throws:
    `An` - exception is thrown if the number of elements in the passed in collection does not match the number of columns in the model

### remove

    public java.util.ArrayList remove(int index)

  Remove the record at the index.

### addBlankRecord

    public void addBlankRecord()

### getEmptyDefaultForType

    public java.lang.Object getEmptyDefaultForType(byte type)

### getRecord

    public java.lang.Object getRecord(int recordnumber)

  Retrieves the record array list for the passed record number

  Parameters:
    `recordnumber` - The record number
  Returns:
    An ArrayList for the given record number

### getRecords

    public java.util.Iterator getRecords()

  Get an iterator over the records.

### getColumnClass

    public java.lang.Class getColumnClass(int c)

  Retrieves the column class for the passed in column index

  Specified by:
    `getColumnClass` in interface `javax.swing.table.TableModel`
  Parameters:
    `c` - The column index
  Returns:
    The column class for the given column index

### getColumnCount

    public int getColumnCount()

  Retrieves the number of columns that exist in the model

  Specified by:
    `getColumnCount` in interface `javax.swing.table.TableModel`
  Returns:
    The number of columns that exist in the model

### getDecimalCount

    public byte getDecimalCount(int column)

  Retrieves the number of decimal places for the passed in column index

  Parameters:
    `column` - The column index
  Returns:
    The number of decimal places for the given column index

### getColumnName

    public java.lang.String getColumnName(int column)

  Retrieves the column name for the passed in column index

  Specified by:
    `getColumnName` in interface `javax.swing.table.TableModel`
  Parameters:
    `column` - The column index
  Returns:
    The column name for the given column index

### getColumnIndexForName

    public int getColumnIndexForName(java.lang.String columnName)

  Find the column index of the column with the given name.

  Parameters:
    `columnName` -
  Returns:
    If the columnName is valid, some number between 0-column count. Otherwise, -1 for non-valid names.

### getLength

    public int getLength(int column)

  Retrieves the character length for the passed in column index

  Parameters:
    `column` - The column index
  Returns:
    The charcter length for the given column index

### getRowCount

    public int getRowCount()

  Retrieves the number of columns that exist in the model

  Specified by:
    `getRowCount` in interface `javax.swing.table.TableModel`
  Returns:
    The number column that exist in the model

### getType

    public byte getType(int column)

  Retrieves the column type for the passed in column index

  Parameters:
    `column` - The column index
  Returns:
    The column type for the given column index

### getValueAt

    public java.lang.Object getValueAt(int row,
                                       int column)

  Retrieves a value for a specific column and row index

  Specified by:
    `getValueAt` in interface `javax.swing.table.TableModel`
  Returns:
    Object A value for a specific column and row index

### setColumnName

    public void setColumnName(int column,
                              java.lang.String name)

  Sets the column name for the passed-in field index

  Parameters:
    `column` - The column index
    `name` - The name to assign for the passed-in column index

### setDecimalCount

    public void setDecimalCount(int column,
                                byte decimalCount)

  Sets the decimal count for the passed in field index

  Parameters:
    `column` - The index to the column
    `decimalCount` - The number of decimals places to assign to the passed in column

### setLength

    public void setLength(int column,
                          int length)

  Set the character length fro the passed-in field index

  Parameters:
    `column` - The column index
    `length` - The character length to assign for the passed-in column index

### setType

    public void setType(int column,
                        byte type)

  Sets the column type for the passed-in field index

  Parameters:
    `column` - The column index
    `type` - The type of column to assign for the passed-in column index

### setValueAt

    public void setValueAt(java.lang.Object object,
                           int row,
                           int column)

  Specified by:
    `setValueAt` in interface `javax.swing.table.TableModel`

### isCellEditable

    public boolean isCellEditable(int rowIndex,
                                  int columnIndex)

  Specified by:
    `isCellEditable` in interface `javax.swing.table.TableModel`

### setWritable

    public void setWritable(boolean set)

### getWritable

    public boolean getWritable()

### getTable

    public javax.swing.JTable getTable(javax.swing.ListSelectionModel lsm)

  Needs to be called before displaying the DbfTableModel.

### getTable

    protected javax.swing.JTable getTable()

### getGUI

    public java.awt.Component getGUI(java.lang.String filename,
                                     int actionMask)

### hideGUI

    public void hideGUI()

### showGUI

    public void showGUI(java.lang.String filename,
                        int actionMask)

### exitWindowClosed

    public void exitWindowClosed()

### tableChanged

    public void tableChanged(javax.swing.event.TableModelEvent e)

  Specified by:
    `tableChanged` in interface `javax.swing.event.TableModelListener`

### commitEvents

    protected void commitEvents(DbfTableModel model)

### deleteColumn

    protected void deleteColumn(int columnIndex)

  Delete a column, iterating through all the records and deleting that part of each record.

### remove

    protected int[] remove(int[] current,
                           int index)

### remove

    protected byte[] remove(byte[] current,
                            int index)

### remove

    protected java.lang.String[] remove(java.lang.String[] current,
                                        int index)

### addColumn

    protected void addColumn(java.util.ArrayList recordColumn)

  The types in the ArrayList are set - String, Byte, Integer, Integer - to match the format of the header.

### add

    protected int[] add(int[] current,
                        byte nb)

### add

    protected byte[] add(byte[] current,
                         byte nb)

### add

    protected java.lang.String[] add(java.lang.String[] current,
                                     java.lang.String string)

### cleanupChanges

    public void cleanupChanges()

### headerClone

    public DbfTableModel headerClone()

  Create another DbfTableModel with the same structure as this one (number of columns, column names, lengths and decimal counts).

### getDbfTableModel

    public static DbfTableModel getDbfTableModel(java.net.URL dbf)

  Creates a DbfTableModel for a given .dbf file

  Parameters:
    `dbf` - The url of the file to retrieve.
  Returns:
    The DbfTableModel, null if there is a problem.

### main

    public static void main(java.lang.String[] args)

Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details