de.kupzog.examples
Class PaletteExampleModel

java.lang.Object
  extended by de.kupzog.examples.PaletteExampleModel
All Implemented Interfaces:
KTableModel

public class PaletteExampleModel
extends java.lang.Object
implements KTableModel

Author:
Friederich Kupzog

Constructor Summary
PaletteExampleModel()
           
 
Method Summary
 org.eclipse.swt.graphics.Point belongsToCell(int col, int row)
          Allows cells to merge with other cells.
 KTableCellEditor getCellEditor(int col, int row)
          A table cell will be "in place editable" if this method returns a valid cell editor for the given cell.
 KTableCellRenderer getCellRenderer(int col, int row)
          Returns the cell renderer for the given cell.
 int getColumnCount()
          This function tells the KTable how many columns have to be displayed.
 int getColumnWidth(int col)
          Each column can have its individual width.
 java.lang.Object getContentAt(int col, int row)
          This method should return the content at the given position.
 int getFixedHeaderColumnCount()
          This function tells the KTable how many columns form the "column header".
 int getFixedHeaderRowCount()
          This function tells the KTable how many rows form the "row header".
 int getFixedSelectableColumnCount()
          This functon tells the KTable how many columns form a fixed region that is not scrolled.
 int getFixedSelectableRowCount()
          This functon tells the KTable how many rows form a fixed region that is not scrolled.
 int getRowCount()
          This function tells the KTable how many rows have to be displayed.
 int getRowHeight(int row)
          All rows except the first row have the same height.
 int getRowHeightMinimum()
          This function should return the minimum height of the rows.
 java.lang.String getTooltipAt(int col, int row)
          This method allows the model to set a tooltip for a given cell.
 boolean isColumnResizable(int col)
          This function should return true if the user should be allowed to resize the given column.
 boolean isRowResizable(int row)
          This function should return true if the user should be allowed to resize the rows.
 void setColumnWidth(int col, int value)
          Each column can have its individual width.
 void setContentAt(int col, int row, java.lang.Object value)
          If getCellEditor() does return any editor instead of null, the table will use this method to set the changed cell values.
 void setFirstRowHeight(int value)
           
 void setRowHeight(int row, int value)
          If the user resizes a row, the model has to keep track of these changes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PaletteExampleModel

public PaletteExampleModel()
Method Detail

getContentAt

public java.lang.Object getContentAt(int col,
                                     int row)
Description copied from interface: KTableModel
This method should return the content at the given position. The content is an Object, that means it can be everything.

The returned Object is handed over to the KTableCellRenderer. You can decide which renderer is used in getCellRenderer. Usually, the renderer expects the content being of a certain type.

Specified by:
getContentAt in interface KTableModel

getCellEditor

public KTableCellEditor getCellEditor(int col,
                                      int row)
Description copied from interface: KTableModel
A table cell will be "in place editable" if this method returns a valid cell editor for the given cell. For no edit functionalitity return null.

Specified by:
getCellEditor in interface KTableModel
Parameters:
col - The column index
row - The row index
Returns:
Returns an instance of KTableCellEditor that will be responsible of showing an editor control and writing back the changed value by calling setContentAt().

setContentAt

public void setContentAt(int col,
                         int row,
                         java.lang.Object value)
Description copied from interface: KTableModel
If getCellEditor() does return any editor instead of null, the table will use this method to set the changed cell values.

Specified by:
setContentAt in interface KTableModel
Parameters:
col - The column index.
row - The row index.

getRowCount

public int getRowCount()
Description copied from interface: KTableModel
This function tells the KTable how many rows have to be displayed.

KTable counts header rows as normal rows, so the number of header rows has to be added to the number of data rows. The function must at least return the number of fixed (header + selectable) rows.

Specified by:
getRowCount in interface KTableModel
Returns:
The number of rows in the table, including the fixed rows.

getFixedHeaderRowCount

public int getFixedHeaderRowCount()
Description copied from interface: KTableModel
This function tells the KTable how many rows form the "row header".

These rows are always displayed and not scrolled. Note that the total number of fixed columns is the sum of header and selectable fixed columns.

Specified by:
getFixedHeaderRowCount in interface KTableModel
Returns:
int The number of fixed rows.

getColumnCount

public int getColumnCount()
Description copied from interface: KTableModel
This function tells the KTable how many columns have to be displayed.

It must at least return the number of fixed and fixed selectable Columns.

Specified by:
getColumnCount in interface KTableModel
Returns:
Returns the number of columns in the table, including all fixed columns.

getFixedHeaderColumnCount

public int getFixedHeaderColumnCount()
Description copied from interface: KTableModel
This function tells the KTable how many columns form the "column header". These columns are always displayed and not scrolled - that means they are fixed. Note that cells in that region cannot be selected! The total of all fixed cells is formed by selectable and header cells.

Specified by:
getFixedHeaderColumnCount in interface KTableModel
Returns:
The number of fixed columns in the table (must be smaller or equal to the total number of columns in the table.

getColumnWidth

public int getColumnWidth(int col)
Description copied from interface: KTableModel
Each column can have its individual width. The model has to manage these widths and return the values with this function.

Specified by:
getColumnWidth in interface KTableModel
Parameters:
col - The index of the column
Returns:
The width in pixels for this column.

isColumnResizable

public boolean isColumnResizable(int col)
Description copied from interface: KTableModel
This function should return true if the user should be allowed to resize the given column. (all rows have the same height except the first)

Specified by:
isColumnResizable in interface KTableModel
Parameters:
col - The column index
Returns:
Returns true if the column is resizable.

setColumnWidth

public void setColumnWidth(int col,
                           int value)
Description copied from interface: KTableModel
Each column can have its individual width. The model has to manage these widths. If the user resizes a column, the model has to keep track of these changes. The model is informed about such a resize by this method. (view updates are managed by the table)

Specified by:
setColumnWidth in interface KTableModel
Parameters:
col - the column index
value - The width in pixels to set for the given column.

getRowHeight

public int getRowHeight(int row)
Description copied from interface: KTableModel
All rows except the first row have the same height.

Specified by:
getRowHeight in interface KTableModel
Parameters:
row - The row index for the row height.
Returns:
the current height of all except the first row.

isRowResizable

public boolean isRowResizable(int row)
Description copied from interface: KTableModel
This function should return true if the user should be allowed to resize the rows.

Specified by:
isRowResizable in interface KTableModel

setFirstRowHeight

public void setFirstRowHeight(int value)

getRowHeightMinimum

public int getRowHeightMinimum()
Description copied from interface: KTableModel
This function should return the minimum height of the rows. It is only needed if the rows are resizable.

Specified by:
getRowHeightMinimum in interface KTableModel
Returns:
Returns the minimum height for the rows.

setRowHeight

public void setRowHeight(int row,
                         int value)
Description copied from interface: KTableModel
If the user resizes a row, the model has to keep track of these changes. The model is informed about such a resize by this method. (view updates are managed by the table)

Specified by:
setRowHeight in interface KTableModel
Parameters:
row - The row index.
value - The height of all except the first row.

getCellRenderer

public KTableCellRenderer getCellRenderer(int col,
                                          int row)
Description copied from interface: KTableModel
Returns the cell renderer for the given cell.

For a first approach, KTableCellRenderer.defaultRenderer can be returned. For some default renderer behavior, look at the classses in the package de.kupzog.ktable.cellrenderers .

If this does not suite your needs, you can easily derive your own cellrenderer from KTableCellRenderer. If it is some general, not too specific renderer, we would be happy to include it as a default renderer!

Specified by:
getCellRenderer in interface KTableModel
Parameters:
col - The column index
row - The row index
Returns:
Returns the cell renderer that is responsible for drawing the cell.

belongsToCell

public org.eclipse.swt.graphics.Point belongsToCell(int col,
                                                    int row)
Description copied from interface: KTableModel
Allows cells to merge with other cells.

Return the column and row index of the cell the given cell should be merged with. Note that cells can only merge with cells that have a row/col index smaller or equal than their own index.

The content of a spanned, large cell is determined by the left upper cell, a 'supercell'. Such supercells as well as cells that do not span always return their own indices. So if no cell spanning is desired, simply return the given cell location:
return new Point(col, row);

To visualize the expected return value: Normal table: Spanned table: ___________ ___________ |__|__|__|__| | |__|__| |__|__|__|__| |_____|__|__| In this case, the left upper cell (0,0) returns its own index and is responsible for the content of the whole spanned cell. The cells (0,1), (1,0) and (1,1) are overlapped and thus not visible. So they return (0,0) to signal that they belong to the cell (0,0). Note that in this case, the value of the cell (1,1) is never requested, since the large cell must always be a rectangle. Cells like ___________ | __|__|__| |__|__|__|__| are not possible.

Specified by:
belongsToCell in interface KTableModel
Parameters:
col - the column index
row - the row index
Returns:
Return the given cell, or a cell the given cell should be merged with. Point.x corresponds to column index, Point.y corresponds to row index.

getTooltipAt

public java.lang.String getTooltipAt(int col,
                                     int row)
Description copied from interface: KTableModel
This method allows the model to set a tooltip for a given cell. It is shown when the mouse stops over a cell and typically gives advanced information or shows the complete content.

Return null or "" if no tooltip should be displayed.

Specified by:
getTooltipAt in interface KTableModel
Parameters:
col - The column index
row - The row index
Returns:
Returns the text that should be displayed when the tooltip for the cell is shown to the user.

getFixedSelectableRowCount

public int getFixedSelectableRowCount()
Description copied from interface: KTableModel
This functon tells the KTable how many rows form a fixed region that is not scrolled. The clickable or selectable fixed columns start after getFixedRowCount() rows. Note that the number of fixed and fixed selectable rows must be smaller or equal to getRowCount().

Specified by:
getFixedSelectableRowCount in interface KTableModel
Returns:
Returns the number of fixed, selectable rows.

getFixedSelectableColumnCount

public int getFixedSelectableColumnCount()
Description copied from interface: KTableModel
This functon tells the KTable how many columns form a fixed region that is not scrolled. The clickable fixed columns start after getFixedColumnCount() columns. Note that the number of fixed and fixed clickable columns must be smaller or equal to getColumnCount().

Specified by:
getFixedSelectableColumnCount in interface KTableModel
Returns:
Returns the number of fixed, selectable columns.