|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.swt.widgets.Canvas
de.kupzog.ktable.KTable
public class KTable
Custom drawn tabel widget for SWT GUIs.
The idea of KTable is to have a flexible grid of cells to display data in it.
The class focuses on displaying data and not on collecting the data to
display. The latter is done by the KTableModel
which has to be implemented
for each specific case. Some default tasks are done by a base implementation
called KTableDefaultModel
. Look also into KTableSortedModel
that provides
a transparent sorting of cells.
The table asks the table model for the amount of
columns and rows, the sizes of columns and rows and for the content of the
cells which are currently drawn. Even if the table has a million rows, it
won’t get slower because it only requests those cells it currently draws.
Only a bad table model can influence the drawing speed negatively.
When drawing a cell, the table calls a KTableCellRenderer
to do this work.
The table model determines which cell renderer is used for which cell. A
default renderer is available (KTableCellRenderer.defaultRenderer
), but the
creation of self-written renderers for specific purposes is assumed.
Some default renderers are available in the package de.kupzog.ktable.cellrenderers.*
.
KTable allows to F columns and rows. Each column can have an individual size while the rows are all of the same height except the first row. Multiple column and row headers are possible. These "fixed" cells will not be scrolled out of sight. The column and row count always starts in the upper left corner with 0, independent of the number of column headers or row headers.
It is also possible to span cells over several rows and/or columns. The KTable
asks the model do provide this information via belongsToCell(col, row)
.
This method must return the cell the given cell should be merged with.
Changing of model values is possible by implementations of KTableCellEditor
.
Again the KTable asks the model to provide an implementation. Note that there
are multiple celleditors available in the package de.kupzog.ktable.editors
!
KTableModel
,
KTableDefaultModel
,
KTableSortedModel
,
KTableCellRenderer
,
KTableCellEditor
,
KTableCellSelectionListener
Field Summary |
---|
Fields inherited from class org.eclipse.swt.widgets.Control |
---|
handle |
Constructor Summary | |
---|---|
KTable(org.eclipse.swt.widgets.Composite parent,
int style)
Creates a new KTable. |
Method Summary | |
---|---|
void |
addCellResizeListener(KTableCellResizeListener listener)
Adds a listener that is notified when a cell is resized. |
void |
addCellSelectionListener(KTableCellSelectionListener listener)
Adds a listener that is notified when a cell is selected. |
org.eclipse.swt.graphics.Point |
calcColumnNum(int x,
int y)
Returns the number of the column that is present at position x or -1, if out of area. |
void |
clearSelection()
Clears the current selection (in all selection modes). |
void |
dispose()
|
org.eclipse.swt.graphics.Rectangle |
getCellRect(int col,
int row)
Returns the area that is occupied by the given cell. |
org.eclipse.swt.graphics.Point[] |
getCellSelection()
Returns an array of the selected cells as Point[]. |
KTableModel |
getModel()
returns the current table model |
int[] |
getRowSelection()
Returns an array of the selected row numbers. |
int |
getStyle()
|
java.lang.String |
getToolTipText()
Returns the global tooltip for the whole table. |
org.eclipse.swt.graphics.Point |
getValidCell(int colToCheck,
int rowToCheck)
Looks into the model to determine if the given cell is overlapped by a cell that spans several columns/rows. |
org.eclipse.swt.graphics.Rectangle |
getVisibleCells()
|
int |
getVisibleRowCount()
|
boolean |
isCellFullyVisible(int col,
int row)
|
boolean |
isCellSelected(int col,
int row)
Returns true, if the given cell is selected. |
boolean |
isCellVisible(int col,
int row)
|
boolean |
isFixedCell(int col,
int row)
|
boolean |
isHeaderCell(int col,
int row)
|
boolean |
isMultiSelectMode()
Returns true if in "Multi Selection Mode". |
boolean |
isRowFullyVisible(int row)
|
boolean |
isRowSelected(int row)
Returns true, if the given row is selected. |
boolean |
isRowSelectMode()
Returns true if in "Full Selection Mode". |
boolean |
isRowVisible(int row)
|
void |
openEditorInFocus()
This method activated the cell editor on the current focus cell, if the table model allows cell editing for this cell. |
void |
redraw(int firstCol,
int firstRow,
int numOfCols,
int numOfRows)
Redraws the the cells only in the given area. |
void |
redraw(org.eclipse.swt.graphics.Rectangle cellsToRedraw)
Redraws the the cells only in the given area. |
boolean |
removeCellResizeListener(KTableCellResizeListener listener)
Removes the listener if present. |
boolean |
removeCellSelectionListener(KTableCellSelectionListener listener)
Removes the listener if present. |
int |
resizeColumnOptimal(int column)
Resizes the given column to its optimal width. |
void |
setDefaultCursor(org.eclipse.swt.graphics.Cursor cursor,
org.eclipse.swt.graphics.Point size_below_hotspot)
Sets the default cursor to the given cursor. |
void |
setModel(KTableModel model)
Sets the table model. |
void |
setSelection(int col,
int row,
boolean scroll)
Selects the given cell. |
void |
setSelection(org.eclipse.swt.graphics.Point[] selections,
boolean scroll)
Selects the given cells - Point.x is column index, Point.y is row index. |
void |
setStyle(int style)
Overwrites the style bits that determine certain behavior of KTable. |
void |
setToolTipText(java.lang.String tooltip)
Sets the global tooltip for the whole table. |
void |
updateCell(int col,
int row)
Interface method to update the content of a cell. |
Methods inherited from class org.eclipse.swt.widgets.Canvas |
---|
getCaret, scroll, setCaret, setFont |
Methods inherited from class org.eclipse.swt.widgets.Composite |
---|
changed, computeSize, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setFocus, setLayout, setLayoutDeferred, setTabList |
Methods inherited from class org.eclipse.swt.widgets.Scrollable |
---|
computeTrim, getClientArea, getHorizontalBar, getVerticalBar |
Methods inherited from class org.eclipse.swt.widgets.Control |
---|
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackground, setBounds, setBounds, setCapture, setCursor, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update |
Methods inherited from class org.eclipse.swt.widgets.Widget |
---|
addDisposeListener, addListener, getData, getData, getDisplay, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, setData, setData, toString |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public KTable(org.eclipse.swt.widgets.Composite parent, int style)
Method Detail |
---|
public void dispose()
dispose
in class org.eclipse.swt.widgets.Widget
public int getVisibleRowCount()
public org.eclipse.swt.graphics.Rectangle getCellRect(int col, int row)
col
- the column indexrow
- the row index
java.lang.IllegalArgumentException
- if the given cell is not a cell
that is visible, but overlapped by a spanning cell. Call getValidCell()
first to ensure it is a visible cell.public void redraw(org.eclipse.swt.graphics.Rectangle cellsToRedraw)
cellsToRedraw
- Defines the area to redraw. The rectangles elements are not
pixels but cell numbers.public void redraw(int firstCol, int firstRow, int numOfCols, int numOfRows)
firstCol
- the first column to draw.firstRow
- the first row to draw. (Map if you use a sorted model!)numOfCols
- the number of columns to draw.numOfRows
- the number of rows to draw.public org.eclipse.swt.graphics.Point getValidCell(int colToCheck, int rowToCheck)
colToCheck
- The column index of the cell to check.rowToCheck
- The row index of the cell to check.
(as seen by the KTable. Map if you use a sorted model!)
java.lang.IllegalArgumentException
- If the model returns cells on
Model.belongsToCell()
that are on the right or below the given cell.KTableSortedModel#mapToTable(int);
public void updateCell(int col, int row)
Don't forget to map the row index if a sorted model is used.
col
- The column indexrow
- The row index.KTableSortedModel.mapRowIndexToTable(int)
public boolean isFixedCell(int col, int row)
col
- The column indexrow
- The row index
public boolean isHeaderCell(int col, int row)
col
- The column indexrow
- The row index
getFixedHeaderColumnCount()
and getFixedHeaderRowCount()
public void setDefaultCursor(org.eclipse.swt.graphics.Cursor cursor, org.eclipse.swt.graphics.Point size_below_hotspot)
The difference to setCursor is that this cursor will be preserved over action cursor changes.
cursor
- The cursor to use, or null
if the OS default
cursor should be used.size_below_hotspot
- The number of pixels that are needed to paint the
cursor below and right of the cursor hotspot (that is the actual location the cursor
is pointing to).
NOTE that this is just there to allow better positioning of tooltips.
Currently SWT does not provide an API to get the size of the cursor. So
these values are taken to calculate the position of the tooltip. The
the tooltip is placed pt.x pixels left and pt.y pixels below the mouse location.
If you don't know the size of the cursor (for example you use a default one), set
null
or new Point(-1, -1)
.
public org.eclipse.swt.graphics.Point calcColumnNum(int x, int y)
x
- the x location of an event in table coordinatesy
- The y location of an event in table coordinates
public boolean isCellVisible(int col, int row)
public boolean isCellFullyVisible(int col, int row)
public boolean isRowVisible(int row)
row
- The row index AS SEEN BY KTABLE. If you use a sorted model, don't forget
to map the index.
public boolean isRowFullyVisible(int row)
row
- the row index to check - as seen by ktable. If you use a
sorted model, don't forget to map.
public void setToolTipText(java.lang.String tooltip)
getTooltipText()
.
setToolTipText
in class org.eclipse.swt.widgets.Control
tooltip
- The global tooltip for the table.KTableModel.getTooltipAt(int, int)
,
getToolTipText()
public java.lang.String getToolTipText()
getToolTipText
in class org.eclipse.swt.widgets.Control
setToolTipText(String)
,
KTableModel.getTooltipAt(int, int)
public int resizeColumnOptimal(int column)
column
- The column to resize
public void openEditorInFocus()
public void addCellSelectionListener(KTableCellSelectionListener listener)
listener
- public void addCellResizeListener(KTableCellResizeListener listener)
listener
- public boolean removeCellSelectionListener(KTableCellSelectionListener listener)
public boolean removeCellResizeListener(KTableCellResizeListener listener)
public boolean isRowSelectMode()
setStyle()
. (style: SWT.FULL_SELECTION)
public boolean isMultiSelectMode()
getStyle()
.
public void clearSelection()
public void setSelection(int col, int row, boolean scroll)
Note that if you use a sorted model, don't forget to map the row index!
col
- row
- scroll
- public void setSelection(org.eclipse.swt.graphics.Point[] selections, boolean scroll)
Don't forget to map the row index if a sorted model is used.
selections
- The selected cells as points. If null
or an empty array, clears the selection.scroll
- Wether it is reuqested to scroll to the first cell
given as selection.KTableSortedModel.mapRowIndexToTable(int)
public boolean isCellSelected(int col, int row)
col
- the column index.row
- the row index.
public boolean isRowSelected(int row)
If you use a sorted model, don't forget to map the row index first.
row
- The row index as seen by the KTable.
public int[] getRowSelection()
NOTE: This returns the cell indices as seen by the KTable. If you use a sorting model, don't forget to map the indices properly.
KTableSortedModel.mapRowIndexToModel(int)
public org.eclipse.swt.graphics.Point[] getCellSelection()
NOTE: This returns the cell indices as seen by the KTable. If you use a sorting model, don't forget to map the indices properly.
KTableSortedModel.mapRowIndexToModel(int)
public org.eclipse.swt.graphics.Rectangle getVisibleCells()
public void setModel(KTableModel model)
model
- The KTableModel instance that provides the table with all
necessary data!for more information.
public KTableModel getModel()
public int getStyle()
getStyle
in class org.eclipse.swt.widgets.Widget
public void setStyle(int style)
style
- The updated style bits (ORed together). Possibilities:
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |