guk.editIM
Class GTRenderer

java.lang.Object
  |
  +--guk.editIM.GTRenderer

public class GTRenderer
extends java.lang.Object

The graphical user interface helpers for the GlyphTable. Implements a scroll helper and something that is almost a TableCellRenderer. Used by GlyphTable.


Field Summary
(package private)  java.awt.Color[] bgColor
          similar as fgColor, but for the background color.
(package private)  java.awt.Color[] fgColor
          The precomputed color for each glyph.
(package private)  MenuHelpers menu
           
(package private)  javax.swing.JTable myTable
          some abstraction-breaking variables that help us to remote- control the table in which we are loaded.
(package private)  javax.swing.JViewport myViewport
          knowing our own viewport allows us to scroll the table for which we are the data model.
(package private)  java.util.Hashtable usedSlots
          For efficiency, we keep an handle to the main data structure of the GlyphTable for which we are rendering.
(package private)  GTVisibility visor
          The visor objects keeps track of which internal rows are externally visible and how row numbers are mapped.
 
Constructor Summary
GTRenderer(java.util.Hashtable contents, GTVisibility visitor)
          The constructor initializes the colors.
 
Method Summary
 java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, boolean hasFocus, int row, int column, java.awt.Component renderer)
          The renderer: Take old renderer and improve the ToolTip and maybe other things before passing on the result.
 void processCommand(java.lang.String command, int modifiers, boolean checked)
          Process command strings.
 void scrollTo(int row)
          Scroll the viewport to a certain glyph / internal row.
 void setScroller(javax.swing.JViewport vp, javax.swing.JTable tab, MenuHelpers theMenu)
          Know which table we belong to and which viewport, so that we can remote control them.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

usedSlots

java.util.Hashtable usedSlots
For efficiency, we keep an handle to the main data structure of the GlyphTable for which we are rendering.

visor

GTVisibility visor
The visor objects keeps track of which internal rows are externally visible and how row numbers are mapped. Can be controlled by the processCommand() inside.

fgColor

java.awt.Color[] fgColor
The precomputed color for each glyph. (Could probably save some RAM here by using other data types!?). I assume that figuring out which Unicode character range a glyph has would be expensive, so the color is stored for each glyph!

bgColor

java.awt.Color[] bgColor
similar as fgColor, but for the background color. more important, as the fgColor is very dark and looks almost like black.

myTable

javax.swing.JTable myTable
some abstraction-breaking variables that help us to remote- control the table in which we are loaded. initialized by setScroller below.

myViewport

javax.swing.JViewport myViewport
knowing our own viewport allows us to scroll the table for which we are the data model.

menu

MenuHelpers menu
Constructor Detail

GTRenderer

public GTRenderer(java.util.Hashtable contents,
                  GTVisibility visitor)
The constructor initializes the colors. For each internal row, the Unicode range of the glyph in it is determined. For each Unicode range, a color is determined on pseudo-random basis. Background colors are very light, foreground colors are almost black.
Parameters:
contents - The hashtable from which we can read the contents of the table in native format, for highlighting.
visitor - An instance of GTVisibility, to know the mapping of visible to internal rows.
menuHelper - A MenuHelpers instance for font and color calculations.
Method Detail

setScroller

public void setScroller(javax.swing.JViewport vp,
                        javax.swing.JTable tab,
                        MenuHelpers theMenu)
Know which table we belong to and which viewport, so that we can remote control them. Gather the needed information (who are our viewport and table parents) to allow us to scroll ourselves, kind of breaking the abstraction barrier between table data model and table
Parameters:
vp - The viewport in which we can be seen, used for program controlled scrolling.
tab - The table to which we belong to (to know the layout, for scrolling).
theMenu - Can be set if you want a specific font setting.

scrollTo

public void scrollTo(int row)
Scroll the viewport to a certain glyph / internal row. Helper method that translates internal to visible row numbers and scrolls there (combined method: nothing else yet needs that translation). Yet another public method which MapTables do not have. When the requested glyph is not visible, the scrolling is to the next visible glyph in in the area.
Parameters:
row - The internal row number (glyph) to which we should scroll. You have to set a viewport or nothing will scroll.

getTableCellRendererComponent

public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table,
                                                        java.lang.Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column,
                                                        java.awt.Component renderer)
The renderer: Take old renderer and improve the ToolTip and maybe other things before passing on the result. This table model provides its own renderer, which sets the color according to which unicode range holds the affected row. Also adds some useful information about the glyph to all fields that happen to contain only one glyph. The information will end up in the ToolTip. This is a SPECIAL method but very similar to getTableCellRendererComponent(...) in AbstractTableModel. The difference is the additional renderer argument here.

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!

(Unicode needs HTML 4.0 to render, JLabels - the the used TableCellRenderers are derived from them - only render ISO-8859-1 HTML 3.2, so we see boxes for nonprintable chars when HTML highlighting is active).

Parameters:
renderer - A basis for our calculations. The real getTableCellRendererComponent method does not have this extra.
See Also:
TableCellRenderer

processCommand

public void processCommand(java.lang.String command,
                           int modifiers,
                           boolean checked)
Process command strings.

 process a command sent by e.g. the GUI menu system:

 jumpto 1234 (scrolls to that glyph).
 jumpfield CHAR (scrolls to that glyph - char may be escaped).
 

Parameters:
modifiers - Modifiers use the normal ActionEvent bit masks.
checked - Some commands use this as additional boolean input.