com.yospace.yae.yogi
Class YogiTable

java.lang.Object
  |
  +--com.yospace.yae.yogi.YogiComponent
        |
        +--com.yospace.yae.yogi.AbstractTable
              |
              +--com.yospace.yae.yogi.YogiTable

public class YogiTable
extends AbstractTable

A Table component. Extends AbstractTable and provides a two-dimensional view of the data model contained in the superclass.


Field Summary
static int PROPERTY_CELL_SELECTABLE
          cell selectable property
static int PROPERTY_COLUMN_COUNT
          column count property
static int PROPERTY_COLUMN_WIDTH
          column width property
protected  RendererFactory[] rendererFactory
          The RendererFactory objects used to customise the appearance of a YogiTable column
 
Fields inherited from class com.yospace.yae.yogi.AbstractTable
fixedCellHeight, initialSelected, model, PROPERTY_CELL_BORDERS, PROPERTY_FIXED_CELL_HEIGHT, PROPERTY_ITEMS, PROPERTY_RENDERER, PROPERTY_SELECTED_INDEX, PROPERTY_SELECTION_MODE, PROPERTY_TOGGLEABLE, selectionModel
 
Fields inherited from class com.yospace.yae.yogi.YogiComponent
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, BORDER_DOTTED, BORDER_NONE, BORDER_PLAIN, BORDER_ROUNDED, BORDER_SOLID, COLOR_BACKGROUND, COLOR_BORDER, COLOR_FOREGROUND, FOCUS_DEFAULT, FOCUS_OFF, FOCUS_ON, PROPERTY_ALIGN, PROPERTY_BORDER_STYLE, PROPERTY_BOUNDS, PROPERTY_COLOR, PROPERTY_CONTEXT_ENABLED, PROPERTY_ENABLED, PROPERTY_FOCUS, PROPERTY_FOCUS_INDEX, PROPERTY_FOCUS_TRAVERSABLE, PROPERTY_FONT, PROPERTY_HOTKEY, PROPERTY_LOCATION, PROPERTY_OPAQUE, PROPERTY_SIZE, PROPERTY_VISIBLE, PROPERTY_X_INSET, PROPERTY_Y_INSET
 
Constructor Summary
YogiTable()
          Default constructor which creates a DefaultDataModel to store the YogiTable's data items and has a default of 1 column.
YogiTable(DataModel model, int columnCount)
          Constructor taking a DefaultDataModel object to comprise the data for the table, and the total number of columns.
 
Method Summary
 int getCellHeight()
          Convenience method for getting the cell height of a table cell.
 Rectangle getCellRect(int x, int y)
          Returns a Rectangle denoting the bounds of the specifed YogiTable cell.
 int getColumnCount()
          This method gets the number of columns in the table.
 int getColumnWidth(int index)
          Returns the width in pixels of a given column.
 java.lang.String getColumnWidths()
          Utility method which concatenates the currently set column widths into a readable, ';'-separated string.
 java.lang.Object getItem(int xIndex, int yIndex)
          Convenience method for extracting a value from the model.
 RendererFactory getRenderer(int column)
          Returns the RendererFactory object used to provide custom rendered cells for the specified column of the table.
 java.lang.String getRenderers()
          Returns a semi-colon delimited String containing the classnames of the renderers set for this YogiTable.
 int getRowCount()
          This method gets the number of rows in the table.
 int getSelectedColumn()
          Returns an int which is the index of the first selected column.
 int[] getSelectedColumns()
          Returns an array of ints containing the indices of each selected column.
 int getSelectedRow()
          Returns an int which is the index of the first selected row.
 int[] getSelectedRows()
          Returns an array of ints containing the indices of each selected row.
 boolean isCellSelectable()
          Returns the state of the cellSelectable flag.
 boolean isSelected(int xIndex, int yIndex)
          Returns the selection state of a given cell.
 void removeItem(int xIndex, int yIndex)
          Removes an item from the table.
 void removeRowInterval(int start, int end)
          Removes the specified range of rows from the Table.
protected  void resize()
          Resizes the table.
 void setCellSelectable(boolean cellSelectable)
          Sets the cellSelectable flag.
 void setColumnCount(int columnCount)
          Sets the total number of columns in the table and resizes the table.
 void setColumnWidth(int column, int width)
          Sets the width of a given column to a specified number of pixels.
 void setColumnWidths(int width)
          Sets the width of all columns to the specified number of pixels.
 void setColumnWidths(java.lang.String widths)
          Used internally to parse a semi-colon delimited String of column widths and set the width of successive columns to the specified number of pixels.
 boolean setFocus(int x, int y)
          Sets the current x,y focus index of a YogiTable.
 void setItem(java.lang.Object item, int xIndex, int yIndex)
          Sets the item at the specified index, replacing the existing contents.
 void setRenderer(RendererFactory rendererFactory, int column)
          Sets the cell renderer to be used for a specified column in the YogiTable.
 void setRenderers(java.lang.String renderers)
          Used internally to set the column cell renderers to a semi-colon delimited String of fully-qualified classnames.
 void setRowSelectionInterval(int start, int end, boolean newState)
          Sets the specified range of rows from the table to the specified state.
 void setSelected(int xIndex, int yIndex, boolean newState)
          Sets the state of the selected index to newState.
 void toggleSelected(int xIndex, int yIndex)
          Toggles the state of the selected index if toggling is allowed, else set the state to true.
 void update(int elementOne, int elementTwo)
          Updates the table between two specified elements.
 
Methods inherited from class com.yospace.yae.yogi.AbstractTable
add, addItem, clearSelections, getFixedCellHeight, getFocusBounds, getFocusX, getFocusY, getItemCount, getModel, getSelectionMode, getSelectionModel, hasCellBorders, initializeSelectionModel, isToggleable, removeAll, setCellBorders, setFixedCellHeight, setModel, setSelectionMode, setSelectionModel, setToggleable
 
Methods inherited from class com.yospace.yae.yogi.YogiComponent
_debugPrintComponents, addPropertyChangeListener, bringForwards, bringInFrontOf, bringToFront, contains, containsComponent, ensureVisible, ensureVisible, findComponentAt, findCurrentFocus, findFirstFocus, findFocusDomainRoot, findFocusDomainRootImpl, findHotkeyComponent, findNextFocus, fireActionPerformedEvent, firePropertyChangeEvent, getAlign, getBorderStyle, getBounds, getColor, getColors, getComponent, getComponent, getComponentCount, getComponentIndex, getComponents, getFocusIndex, getFont, getGlobalLocation, getHeight, getHotkey, getId, getParent, getParent, getTreeLock, getUI, getWidth, getX, getXInset, getY, getYInset, hasFocus, isActive, isContextEnabled, isEnabled, isFocusDomainRoot, isFocusTraversable, isOpaque, isVisible, keyPressed, keyReleased, keyRepeated, paint, paintBackground, paintBorder, paintForeground, pointerDragged, pointerPressed, pointerReleased, remove, remove, removePropertyChangeListener, repaint, repaint, repaintAfterRebounding, requestFocus, requestFocus, sendBackwards, sendBehind, sendToBack, setActionListener, setActive, setAlign, setBorderStyle, setBounds, setColor, setColors, setContextEnabled, setDefaultColor, setEnabled, setFocusDomainRoot, setFocusIndex, setFocusTraversable, setFont, setHotkey, setId, setLocation, setNoFocus, setOpaque, setProperty, setSize, setUI, setVisible, setXInset, setYInset, updateUI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_COLUMN_COUNT

public static final int PROPERTY_COLUMN_COUNT
column count property

PROPERTY_COLUMN_WIDTH

public static final int PROPERTY_COLUMN_WIDTH
column width property

PROPERTY_CELL_SELECTABLE

public static final int PROPERTY_CELL_SELECTABLE
cell selectable property

rendererFactory

protected RendererFactory[] rendererFactory
The RendererFactory objects used to customise the appearance of a YogiTable column
Constructor Detail

YogiTable

public YogiTable()
Default constructor which creates a DefaultDataModel to store the YogiTable's data items and has a default of 1 column.

YogiTable

public YogiTable(DataModel model,
                 int columnCount)
Constructor taking a DefaultDataModel object to comprise the data for the table, and the total number of columns.
Parameters:
model - the list data.
columnCount - the number of columns in the table.
Method Detail

setColumnWidths

public void setColumnWidths(int width)
Sets the width of all columns to the specified number of pixels.
Parameters:
width - the width in pixels to set all columns widths to

setColumnWidth

public void setColumnWidth(int column,
                           int width)
Sets the width of a given column to a specified number of pixels.
Parameters:
column - the specified column.
width - the width for that column.

setColumnCount

public void setColumnCount(int columnCount)
Sets the total number of columns in the table and resizes the table.
Parameters:
columnCount - the total number of columns in the table.

setRenderer

public void setRenderer(RendererFactory rendererFactory,
                        int column)
Sets the cell renderer to be used for a specified column in the YogiTable.
Parameters:
rendererFactory - the factory to use for the column.
column - the specified column.

getRenderer

public RendererFactory getRenderer(int column)
Returns the RendererFactory object used to provide custom rendered cells for the specified column of the table.
Parameters:
column - the specified column.
Returns:
the renderer factory for the given column.

setCellSelectable

public void setCellSelectable(boolean cellSelectable)
Sets the cellSelectable flag.
Parameters:
cellSelectable - true if the table can have a single cell selected, false if only rows may be selected.

isCellSelectable

public boolean isCellSelectable()
Returns the state of the cellSelectable flag.
Returns:
true if the table can have a single cell selected, false if only rows may be selected.

getColumnCount

public int getColumnCount()
This method gets the number of columns in the table.
Returns:
the number of columns in the table.

getRowCount

public int getRowCount()
This method gets the number of rows in the table.
Returns:
the number of rows in the table.

getColumnWidth

public int getColumnWidth(int index)
Returns the width in pixels of a given column. If a width has been explicitly set using setColumnWidth(int, int) then this value will be returned, else the default is the average width of columns in the table.
Parameters:
index - the column.
Returns:
the width in pixels of the specified column.

removeRowInterval

public void removeRowInterval(int start,
                              int end)
Removes the specified range of rows from the Table. NB. The removal will take place from and including the first row (start) up to and including the last row (end).
Parameters:
start - the row from which to begin the removal.
end - the row at which to stop the removal.

setRowSelectionInterval

public void setRowSelectionInterval(int start,
                                    int end,
                                    boolean newState)
Sets the specified range of rows from the table to the specified state. NB. The setting will take place from and including the first row (start) up to and including the last row (end).
Parameters:
start - the row from which to begin reseting the state.
end - the row at which to stop reseting the state.
newState - the state to which to set the selected flag of each table cell.

getSelectedRows

public int[] getSelectedRows()
Returns an array of ints containing the indices of each selected row. For example, if rows 2, 4 and 6 are selected, an array of 3 ints will be returned containing 2, 4 and 6.
Returns:
the indices of the selected rows.

getSelectedColumns

public int[] getSelectedColumns()
Returns an array of ints containing the indices of each selected column. For example, if columns 2, 4 and 6 are selected, an array of 3 ints will be returned containing 2, 4 and 6.
Returns:
the indices of the selected columns.

getSelectedRow

public int getSelectedRow()
Returns an int which is the index of the first selected row.
Returns:
the index of the first selected row.

getSelectedColumn

public int getSelectedColumn()
Returns an int which is the index of the first selected column.
Returns:
the index of the first selected column.

isSelected

public boolean isSelected(int xIndex,
                          int yIndex)
Returns the selection state of a given cell.
Parameters:
xIndex - the column index of the cell.
yIndex - the row index of the cell.
Returns:
the selection status.

toggleSelected

public void toggleSelected(int xIndex,
                           int yIndex)
Toggles the state of the selected index if toggling is allowed, else set the state to true.
Parameters:
xIndex - the column index of the cell.
yIndex - the row index of the cell.

setSelected

public void setSelected(int xIndex,
                        int yIndex,
                        boolean newState)
Sets the state of the selected index to newState. Calls update method to redraw the Table by the minimal amount neccessary and fires a PropertyChangeEvent to notify listeners of the change in selection state,
Parameters:
xIndex - the column index of the cell.
yIndex - the row index of the cell.
newState - the new selection state.

getCellRect

public Rectangle getCellRect(int x,
                             int y)
Returns a Rectangle denoting the bounds of the specifed YogiTable cell.
Overrides:
getCellRect in class AbstractTable
Parameters:
x - column index of the cell.
y - row index of the cell.
Returns:
the bounds of this cell. Null if the co-ordinates supplied are invalid.

setFocus

public boolean setFocus(int x,
                        int y)
Sets the current x,y focus index of a YogiTable.
Overrides:
setFocus in class AbstractTable
Parameters:
x - horizontal focus index, must be 0.
y - vertical focus index.
Returns:
True if the focus has changed, False if the specified indexes were already those with focus.

getColumnWidths

public final java.lang.String getColumnWidths()
Utility method which concatenates the currently set column widths into a readable, ';'-separated string. Widths that have not been set explicitly are left as null entries. For example, if this table has an explicit width of 20 pixels for column 0, default width for column 1, and 30 pixels for column 2, then the String might appear as "20;;30". The returned string has no trailing ';' chars, and will return an empty string if there are no set widths.
Returns:
the table's column widths, as a string of ';'-separated ints.

update

public void update(int elementOne,
                   int elementTwo)
Updates the table between two specified elements. All the table cells falling between these elements and lying within the current clip will be updated. All selective repainting of YogiTables should be undertaken with this method, as it is considerably more efficient than calling repaint() on the entire table.
Overrides:
update in class AbstractTable
Parameters:
elementOne - the first element from which to update.
elementTwo - the last element to update.

setItem

public void setItem(java.lang.Object item,
                    int xIndex,
                    int yIndex)
Sets the item at the specified index, replacing the existing contents.
Parameters:
item - the Object to replace the specified cell in the table.
xIndex - the column index.
yIndex - the row index.

getItem

public java.lang.Object getItem(int xIndex,
                                int yIndex)
Convenience method for extracting a value from the model.
Parameters:
xIndex - the column index.
yIndex - the row index.
Returns:
the Object at the specified index.

removeItem

public void removeItem(int xIndex,
                       int yIndex)
Removes an item from the table.
Parameters:
xIndex - the column index.
yIndex - the row index.

getCellHeight

public int getCellHeight()
Convenience method for getting the cell height of a table cell.
Overrides:
getCellHeight in class AbstractTable
Returns:
the fixed cell height if this has been set, otherwise the average height of a table cell.

resize

protected void resize()
Resizes the table. Called internally after adding to or removing from the table.
Overrides:
resize in class AbstractTable

getRenderers

public final java.lang.String getRenderers()
Returns a semi-colon delimited String containing the classnames of the renderers set for this YogiTable. Only those renderers that have been explicitly defined will be returned. For example, if the first four renderers in a six-column table have been defined, a String containing the four classnames separated by semi-colons will be returned. Undefined renderers falling between defined renderers have no String representation, but the semi-colon is still appended.
Returns:
the explicitly defined renderers for this YogiTable, separated by semi-colons.

setRenderers

public final void setRenderers(java.lang.String renderers)
Used internally to set the column cell renderers to a semi-colon delimited String of fully-qualified classnames.
Parameters:
renderers - the renderers

setColumnWidths

public final void setColumnWidths(java.lang.String widths)
Used internally to parse a semi-colon delimited String of column widths and set the width of successive columns to the specified number of pixels.
Parameters:
widths - the semi-colon delimited width in pixels of a succession of columns.

Copyright 2002 Yospace Holdings Ltd. All Rights Reserved.