guk.editIM
Class MapTable

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--guk.editIM.MapTable
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableCellRenderer, javax.swing.table.TableModel
Direct Known Subclasses:
GlyphTable, StringTable

public abstract class MapTable
extends javax.swing.table.AbstractTableModel
implements javax.swing.table.TableCellRenderer

An abstract implementation of the data model for the unicode keymap editor tables in terms of an AbstractTableModel. Contains additional methods for controlling the data and importing and exporting it in form of AssignObject objects. Also contains renderer and editor code, note the unusual place! Allowing them to access internal data that way.

See Also:
Serialized Form

Field Summary
protected  java.util.Vector assignments
          The table data, can grow on demand using our addRow() method.
protected  boolean changedFlag
           
protected  javax.swing.table.DefaultTableCellRenderer tcRenderer
          A standard renderer which we tune below.
protected  int transferFormat
          Format to be used by getValueAt and setValueAt (and therefore by Cell Editors, too!).
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
MapTable()
          The default constructor does not do much.
 
Method Summary
 boolean addEntry(AssignObject ao)
          Merges an entry into the table, returns false on failure Normally, merge succeeds, but in the GlyphTable implementation, further constraints have to be followed.
 void addRow()
          Add a row to the table.
 void clearChanged()
          Clear change flag.
 boolean flushTable()
          Removes all entries, returns false on failure
 java.lang.Class getColumnClass(int col)
          Fetches the column data types, which Java uses to select a renderer component for the column.
 int getColumnCount()
          Checks how many columns the table contains.
 java.lang.String getColumnName(int col)
          Fetches the column names for the headers and for finding columns.
 int getRowCount()
          Checks how many rows the table contains.
 java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, boolean hasFocus, int row, int column)
          Returns a component that renders the given cell.
 java.lang.Object getValueAt(int row, int col)
          Fetch the contents of a certain table cell.
 boolean isCellEditable(int row, int col)
          Tells whether a certain cell can be edited.
 boolean isChanged()
          Checks if the table contains unsaved changes.
 void processCommand(java.lang.String command, int modifiers, boolean checked)
          The generic MapTable does not process any commands yet: Implementing classes are likely to override this method, so that you can send them commands.
 java.util.Collection readTable()
          Returns the Collection with all entries (for saving them).
 boolean removeEntry(AssignObject ao)
          Finds and removes an entry from the table, returns false on failure
 void setValueAt(java.lang.Object val, int row, int col)
          Update a cell value.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

tcRenderer

protected javax.swing.table.DefaultTableCellRenderer tcRenderer
A standard renderer which we tune below.

transferFormat

protected final int transferFormat
Format to be used by getValueAt and setValueAt (and therefore by Cell Editors, too!).

assignments

protected java.util.Vector assignments
The table data, can grow on demand using our addRow() method. A flag tells when setValueAt modified the data (other kinds of modfication do not change the flag).

changedFlag

protected boolean changedFlag
Constructor Detail

MapTable

public MapTable()
The default constructor does not do much.
Method Detail

flushTable

public boolean flushTable()
Removes all entries, returns false on failure
Returns:
The standard implementation always succeeds, but implementing classes can obviously override that behaviour.

readTable

public java.util.Collection readTable()
Returns the Collection with all entries (for saving them).
Returns:
A Collection of AssignObject objects. It is not recommended to modify the returned objects or remove some of them, although some implementations may be able to handle that.

addEntry

public boolean addEntry(AssignObject ao)
Merges an entry into the table, returns false on failure Normally, merge succeeds, but in the GlyphTable implementation, further constraints have to be followed.

removeEntry

public boolean removeEntry(AssignObject ao)
Finds and removes an entry from the table, returns false on failure
Returns:
True if removal succeeded. Failure is usually because the object that you tried to remove was not found in the table.

isChanged

public boolean isChanged()
Checks if the table contains unsaved changes.
Returns:
True if the table has been modified by setValueAt

clearChanged

public void clearChanged()
Clear change flag. Tells the table that there are no unsaved changes (anymore).

getRowCount

public int getRowCount()
Checks how many rows the table contains. This must be efficient as Java calls it often.
Overrides:
getRowCount in class javax.swing.table.AbstractTableModel
Returns:
The number of rows in the table.

getColumnCount

public int getColumnCount()
Checks how many columns the table contains. Always 3: Glyphs, keys and comments.
Overrides:
getColumnCount in class javax.swing.table.AbstractTableModel
Returns:
The value 3.

getValueAt

public java.lang.Object getValueAt(int row,
                                   int col)
Fetch the contents of a certain table cell. Contents will be converted into a strings for easier use. The transferFormat object variable determines the format of the string (usually human readable Unicode).
Overrides:
getValueAt in class javax.swing.table.AbstractTableModel
Parameters:
row - The table row, selecting an AssignObject.
col - The column, selecting the part of the AssignObject.
Returns:
The object found at the given place in the table, which will be something that can be displayed.

getColumnName

public java.lang.String getColumnName(int col)
Fetches the column names for the headers and for finding columns.
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
col - The column for which you want to know the name.
Returns:
"Glyph Strings", "Key Sequences" or "Comments" for columns 0, 1 and 2 respectively.

getColumnClass

public java.lang.Class getColumnClass(int col)
Fetches the column data types, which Java uses to select a renderer component for the column.
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
col - The column for which you want to know the type.
Returns:
String (all columns return String type data when you call getValueAt).

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Tells whether a certain cell can be edited.
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Parameters:
row - The affected row (not likely to matter)
col - The affected column: implementing classes may return false for columns where they do not want Java to allow the user to activate the editor component.

setValueAt

public void setValueAt(java.lang.Object val,
                       int row,
                       int col)
Update a cell value. Sets the changedFlag. This is where all editing results come in. The user can edit cells, and when he commits the results, they end up here. Notice that this cannot fail, apart from ignoring senseless updates. The user will notice the non-change and try the edit again, but the erroneous value is lost.
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel
Parameters:
val - Usually a string with the new value for that cell.
row - The row where the value is to be stored.
col - The column where the value is to be stored.

addRow

public void addRow()
Add a row to the table. This special MapTable method adds a row to the current end of the table. The row will contain some empty AssignObject.

getTableCellRendererComponent

public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table,
                                                        java.lang.Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column)
Returns a component that renders the given cell. Note that table models usually do NOT care for the related looks, but MapTable objects provide this method, which you can hand over to the table that renders the MapTable.

This table model provides its own renderer, which sets the color according to which unicode range holds the affected row

WARNING: TableModels normally do not implement TableCellRenderer and this exception (activated via table.setDefaultRenderer(...)) means that we have to be CAREFUL with coordinates: JTable and renderer stuff uses VIEW coordinates, but the Model uses MODEL coordinates. The user may have swapped (by dragging) the columns!

Specified by:
getTableCellRendererComponent in interface javax.swing.table.TableCellRenderer
See Also:
TableCellRenderer

processCommand

public void processCommand(java.lang.String command,
                           int modifiers,
                           boolean checked)
The generic MapTable does not process any commands yet: Implementing classes are likely to override this method, so that you can send them commands.
Parameters:
command - A textual representation of something that should happen with the table data.
modifiers - ActionEvent modifiers which may affect the command.
checked - A boolean value that may affect the command.