ewe.ui
Class GridTableModel

java.lang.Object
  extended byewe.ui.TableModel
      extended byewe.ui.GridTableModel
All Implemented Interfaces:
CellConstants, ControlConstants, EventListener, UIConstants
Direct Known Subclasses:
RegistryTableModel

public class GridTableModel
extends TableModel

This is a table model which displays a Grid of data. It also has the capability to correctly display Control objects.

To use this you do the following:

  1. Create a Grid containing the data, and optionally create Vectors to hold the row and column headers.
  2. Call setDataAndHeaders(Grid data, Vector columnHeaders, Vector rowHeaders) to set the data and headers. Either of the columnHeaders or rowHeaders can be null.
  3. Get a FontMetrics object for the Font that you intend to use in the TableControl. The easiest way is to call getFontMetrics() on the TableControl you intend to use (after you have optionally changed the "font" variable in the TableControl).
  4. Call calculateSizes(fontMetrics) on the GridTableModel so that it calculates the correct width and heights for the cells for that Font.
  5. Optionally set "hasPreferredSize" to true if you want to TableControl to calculate its preferredSize to be the size of the entire table. For large tables you may not want to do this, but rather set the preferredSize explicitly using setPreferredSize().
  6. Call setTableModel(myGridTableModel) on the TableControl you want to use.
Here is an example use:
import ewe.ui.*;
import ewe.util.*;

//##################################################################
public class TestGridTableModel extends Editor{
//##################################################################

//===================================================================
public TestGridTableModel()
//===================================================================
{
        TableControl t = new TableControl();
        //
        // Create the data Grid and header Vector.
        //
        Grid g = new Grid();
        Vector headers = new Vector();
        //
        for (int row = -1; row != 10; row++){
                for (int col = 0; col != 5; col++){
                        if (row == -1)
                                headers.add("Header: "+col);
                        else
                                g.add("Cell("+row+", "+col+")",false);
                }
                g.endRow();
        }
        //
        // Create the GridTableModel.
        //
        GridTableModel gtm = new GridTableModel();
        //
        // Set the data and the headers.
        // We won't use row headers in our example.
        //
        gtm.setDataAndHeaders(g,headers,null);
        //
        // Call this to correctly calculate the size of the each cell
        // given the Font that you intend to use.
        // If you intend to use the default font of this Editor then
        // you can use this.getFontMetrics() instead of t.getFontMetrics().
        //
        t.font = mApp.findFont("fixed",true);
        gtm.calculateSizes(t.getFontMetrics());
        //
        // If this is not true the Table will not have a preferred size
        // and will be initially displayed very small.
        //
        gtm.hasPreferredSize = true;
        //
        t.setTableModel(gtm);
        addLast(new ScrollBarPanel(t));
}
//##################################################################
}
//##################################################################


Nested Class Summary
 
Nested classes inherited from class ewe.ui.TableModel
TableModel.CellControl, TableModel.ControlProxy
 
Field Summary
protected  Vector columnHeaders
          The column headers if any.
protected  Grid data
          The data to be displayed.
protected  int[] heights
           
protected  Vector rowHeaders
          The row headers if any.
protected  int[] widths
          The widths of the cells as used by calculateColWidth().
 
Fields inherited from class ewe.ui.TableModel
activeCellControl, allColumnsSameSize, allRowsSameSize, canHScroll, canVScroll, cellInsets, charHeight, charWidth, clipData, controlProxy, cursorSize, fillToEqualHeights, fillToEqualWidths, gap, hasColumnHeaders, hasPreferredSize, hasRowHeaders, hasSpanningColumns, hasSpanningRows, horizontalScrollUnit, insets, numCols, numRows, preferredCols, preferredRows, rect, selectRowWhenEditing, shadeAlternateRows, table, tca, verticalScrollUnit
 
Fields inherited from interface ewe.ui.UIConstants
BDR_DOTTED, BDR_INNER, BDR_NOBORDER, BDR_OUTER, BDR_OUTLINE, BDR_RAISEDINNER, BDR_RAISEDOUTER, BDR_SUNKENINNER, BDR_SUNKENOUTER, BF_BOTTOM, BF_BOTTOMLEFT, BF_BOTTOMRIGHT, BF_BUTTON, BF_DIAGONAL, BF_DIAGONAL_ENDBOTTOMLEFT, BF_DIAGONAL_ENDBOTTOMRIGHT, BF_DIAGONAL_ENDTOPLEFT, BF_DIAGONAL_ENDTOPRIGHT, BF_EXACT, BF_FLAT, BF_LEFT, BF_MIDDLE, BF_MONO, BF_PALM, BF_RECT, BF_RIGHT, BF_SOFT, BF_SQUARE, BF_TOP, BF_TOPLEFT, BF_TOPRIGHT, EDGE_BUMP, EDGE_ETCHED, EDGE_RAISED, EDGE_SUNKEN
 
Fields inherited from interface ewe.ui.CellConstants
BORDER, BOTTOM, CELLFLAG, CELLMASK, CENTER, CONTROLMASK, DONTCHANGE, DONTFILL, DONTSTRETCH, EAST, FILL, FIXEDSIZE, GROW, HCENTER, HCONTRACT, HEXPAND, HFILL, HGROW, HSHRINK, HSTRETCH, INITIALLY_CLOSED, INITIALLY_MINIMIZED, INITIALLY_PREFERRED_SIZE, INSETS, LEFT, MAXIMUMSIZE, MINIMUMSIZE, NORTH, NORTHEAST, NORTHWEST, PREFERREDSIZE, RECT, RIGHT, SHRINK, SOUTH, SOUTHEAST, SOUTHWEST, SPAN, STRETCH, TEXTSIZE, TOP, VCENTER, VCONTRACT, VEXPAND, VFILL, VGROW, VSHRINK, VSTRETCH, WEST
 
Fields inherited from interface ewe.ui.ControlConstants
All, AlwaysEnabled, AlwaysRecalculateSizes, ByDeferredMouse, ByDeferredPen, ByFrameChange, ByKeyboard, ByMouse, ByPen, ByRequest, CalculatedSizes, Disabled, DisablePopupMenu, DisplayOnly, Down, DrawFlat, Flag, ForceResize, HasData, Invisible, KeepImage, KeepSIP, Left, MakeMenuAtLeastAsWide, Maximize, Minimize, MouseSensitive, NoFocus, NotAnEditor, NotEditable, PaintDataOnly, PaintOutsideOnly, PenTransparent, PreferredSizeOnly, Right, SendUpKeyEvents, SendUpPenEvents, ShowSIP, ShrinkToNothing, SmallControl, SpecialBackground, TakeControlEvents, TakesKeyFocus, Transparent, Up, WantDrag, WantHoldDown
 
Constructor Summary
GridTableModel()
           
 
Method Summary
 int calculateColWidth(int col)
          Returns the column width.
 int calculateRowHeight(int row)
          Returns the row height.
 void calculateSizes(FontMetrics fm)
          This calculates the correct sizes for the rows and columns.
protected  void checkCellSize(FontMetrics fm, int row, int col, Dimension d)
          This calculates the size of cell given the FontMetrics.
 Object getCellData(int row, int col)
          This returns the data in the grid and columnHeaders/rowHeaders unmodified.
 Dimension getCellPreferredSize(int row, int col, FontMetrics fm, Dimension dest)
           
 void setDataAndHeaders(Grid data, Vector columnHeaders, Vector rowHeaders)
          Set the data and the headers.
 void updateData(boolean updateTable)
          Call this method if you have changed any data in the grid for the TableModel.
 
Methods inherited from class ewe.ui.TableModel
calculateTextCharsInColumn, calculateTextLinesInRow, canScreenScroll, canSelect, checkControlFor, clearCellAdjustments, closeActiveControl, deferPaintTableCell, doHotKey, findCellsInArea, fixBorder, getCellAttributes, getCellControlFor, getCellInsets, getCellRect, getCellText, getColWidth, getControlFor, getLinesFor, getMaxColWidth, getMaxRowHeight, getMenuFor, getMenuOutsideCells, getMinColWidth, getMinRowHeight, getPreferredSize, getRowHeight, getToolTip, hasActiveControls, inset, isActiveCellControl, made, notifyDataChange, onEvent, onKeyEvent, paintTableCell, paintTableCell, paintTableCellData, paintTableCellText, penPressed, popupMenuEvent, remapColumns, resized, scrollTo, select, show, startedEditing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

data

protected Grid data
The data to be displayed.


columnHeaders

protected Vector columnHeaders
The column headers if any.


rowHeaders

protected Vector rowHeaders
The row headers if any.


widths

protected int[] widths
The widths of the cells as used by calculateColWidth(). There must be on entry for each cell


heights

protected int[] heights
Constructor Detail

GridTableModel

public GridTableModel()
Method Detail

setDataAndHeaders

public void setDataAndHeaders(Grid data,
                              Vector columnHeaders,
                              Vector rowHeaders)
Set the data and the headers. Each element in the Vectors or Grid must be either a String or an array of Strings for multiline display.


getCellData

public Object getCellData(int row,
                          int col)
This returns the data in the grid and columnHeaders/rowHeaders unmodified.

Overrides:
getCellData in class TableModel

checkCellSize

protected void checkCellSize(FontMetrics fm,
                             int row,
                             int col,
                             Dimension d)
This calculates the size of cell given the FontMetrics.


calculateRowHeight

public int calculateRowHeight(int row)
Returns the row height.

Overrides:
calculateRowHeight in class TableModel

calculateColWidth

public int calculateColWidth(int col)
Returns the column width.

Overrides:
calculateColWidth in class TableModel

calculateSizes

public void calculateSizes(FontMetrics fm)
This calculates the correct sizes for the rows and columns. Make sure you call setDataAndHeaders() first.


getCellPreferredSize

public Dimension getCellPreferredSize(int row,
                                      int col,
                                      FontMetrics fm,
                                      Dimension dest)
Overrides:
getCellPreferredSize in class TableModel

updateData

public void updateData(boolean updateTable)
Call this method if you have changed any data in the grid for the TableModel. It will recalculate the number of rows and cell sizes based on the same font metrics that was used last time.

Parameters:
updateTable - if this is true then a call to update(true) will be made on the containing TableControl.