org.openbp.swing.components.treetable
Class JTreeTable

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTable
                  extended by org.openbp.swing.components.treetable.JTreeTable
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.CellEditorListener, javax.swing.event.ListSelectionListener, javax.swing.event.RowSorterListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener, javax.swing.Scrollable

public class JTreeTable
extends javax.swing.JTable
implements java.awt.event.MouseListener

This JTreeTable is based on the same concept (placing a JTree into a column of a JTable) as the JTreeTable provided by Sun Microsystems, with the exception that the individual JTree nodes will adapt to the height of JTables row in which they have been placed. This functionality is brought about by providing a new type of TreeNode, the TreeTableNode, that contains methods that will deliver the maximum preferred height of the row to the tree and the table. Further, to enable provision of such information, it is expected that all cell objects for a row are kept inside the individual node.
As on the standard Java API, the JTreeTable requires a model for data provision, the TreeTableModel This interface actually brings the TreeModel and TableModel interfaces together in one, with a few extra added methods. In order not to have to implement the entire model, a partially implemented model, the SimpleTreeTableModel with most generic methods provided. If the user wishes not to implement the model at all, then the DefaultTreeTableModel is provided the can be used with the DefaultTreeTableNode

Author:
Erich Lauterbach
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTable
javax.swing.JTable.AccessibleJTable, javax.swing.JTable.DropLocation, javax.swing.JTable.PrintMode
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  javax.swing.ActionMap actionMap
          Action map of the tree table
static int CMD_BACKTAB
          Command: Backtab
static int CMD_BOTTOM
          Command: To the bottom
static int CMD_CODE_MASK
          Command modifier mask: Code mask
static int CMD_DOWN
          Command: Cursor down
static int CMD_END
          Command: End
static int CMD_ENTER
          Command: Enter
static int CMD_ESC
          Command: Escape
static int CMD_EXTEND_SELECTION
          Command modifier: Extend selection
static int CMD_HOME
          Command: Home
static int CMD_LEFT
          Command: Cursor left
static int CMD_MOUSE
          Command: Mouse key
static int CMD_NONE
          Command: No key
static int CMD_PGDN
          Command: Page down
static int CMD_PGUP
          Command: Page up
static int CMD_RIGHT
          Command: Cursor right
static int CMD_SELECTION_MASK
          Command modifier mask: Selection mask
static int CMD_SET_SELECTION
          Command modifier: Set selection
static int CMD_SPACE
          Command: Space
static int CMD_SWITCH_TREE
          Command modifier: Switch from tree to table and vice versa
static int CMD_TAB
          Command: Tab
static int CMD_TOGGLE_SELECTION
          Command modifier: Toggle selection
static int CMD_TOP
          Command: To the top
static int CMD_UP
          Command: Cursor up
protected  int currentCol
          Current colum
protected  int currentRow
          Current row
protected  javax.swing.InputMap focusAncestorInputMap
          Input map for ancestor-focused keys of the tree table
protected  javax.swing.InputMap focusInputMap
          Input map for focused keys of the tree table
protected  ListenerSupport listenerSupport
          Listener support object holding the listeners
static int SELECTION_MULTI
          Selection mode: Multiple selection
static int SELECTION_NONE
          Selection mode: No selection
static int SELECTION_SINGLE
          Selection mode: Single selection
 
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JTreeTable()
          Default Constructor.
JTreeTable(TreeTableModel treeTableModel)
          Constructor.
 
Method Summary
 void addTreeTableListener(TreeTableListener listener)
          Adds a tree table listener to the listener list.
 void addWeakTreeTableListener(TreeTableListener listener)
          Adds a tree table listener to the listener list as weak listener.
 void changeSelection(int newRow, int newCol, boolean toggle, boolean extend)
          JTable override.
 void collapsePath(javax.swing.tree.TreePath path)
          Ensures that the node identified by the specified path is collapsed and viewable.
 void collapseRow(int row)
          Ensures that the node in the specified row is collapsed.
 void configureSubComponent(javax.swing.JComponent comp)
          Configures a component that shall be used in a tree table cell for usage in the tree.
static java.lang.Object createDescriptionCellValue(java.lang.String text)
          Creates a text value for display in a text-only cell (e\. g\. a description cell).
 void doLayout()
          Handle the layout of the rows and columns.
 boolean editCellAt(int row, int col)
          JTable override.
 boolean editCellAt(int row, int col, java.util.EventObject e)
          Overriden method.
 void expandAll(boolean expand)
          Expands all tree nodes or collapse these.
 void expandAll(javax.swing.tree.TreePath parent, boolean expand)
          Expands all tree nodes or collapse these.
 void expandPath(javax.swing.tree.TreePath path)
          Ensures that the node identified by the specified path is expanded and viewable.
 void expandRow(int row)
          Ensures that the node in the specified row is expanded and viewable.
 void expandTreeLevels(boolean expand, int numberOfLevelThatAreNeededToBeExpanded)
          Expands all tree nodes or collapse these level by level.
 void expandTreeLevels(javax.swing.tree.TreePath parent, boolean expand, int numberOfLevelThatAreNeededToBeExpanded)
          Expands all tree nodes or collapse these level by level.
protected  boolean fireCommand(int command)
          Fires a 'command' event to all registered tree table listeners.
 int getDefaultRowHeight()
          Gets the default row height.
 int getEditingRow()
          Workaround for BasicTableUI anomaly.
 int getFirstVisibleRow()
          Gets the first row that is fully visible in the scroll pane.
 int getLastVisibleRow()
          Gets the last row that is fully visible in the scroll pane.
 TreeTableNode getNodeByPath(javax.swing.tree.TreePath path)
          Gets the tree table node by a given tree path.
 TreeTableNode getNodeByPoint(java.awt.Point point)
          Gets the tree table node located at the specified position relative to the table.
 TreeTableNode getNodeByRow(int row)
          Gets the tree node by a given row.
 javax.swing.tree.TreePath getPathByNode(javax.swing.tree.TreeNode treeNode)
          Gets the TreePath for a specified TreeTableNode in the visible tree table.
 javax.swing.tree.TreePath getPathByPoint(java.awt.Point point)
          Gets the tree path located at the specified position relative to the table.
 javax.swing.tree.TreePath getPathByRow(int row)
          Gets the tree path by a given row.
 int getRowByPath(javax.swing.tree.TreePath path)
          Determines the row by the tree path.
protected  javax.swing.JScrollPane getScrollPane()
          Gets the scroll pane that is associated with the table.
 javax.swing.tree.TreePath[] getSelection()
          Gets the selection.
 int getSelectionMode()
          Gets the selection mode.
 java.lang.String getToolTipText(java.awt.event.MouseEvent me)
          Override of the super method that takes special considerations for tree cell renderers.
 javax.swing.JTree getTree()
          Returns the tree used by the TreeTable.
 int getTreeCol()
          Gets the we assume the tree column to be column 0.
 TreeTableModel getTreeTableModel()
          Returns the TreeTableModel that provides the data displayed by this JTreeTable
 java.lang.Object getValueAt(int row, int column)
          Override to prevent NPE in default cut/copy/paste transfer handler when copying table data.
 int getVisibleRowCount()
          Gets the number of visible rows in the scroll pane.
 void handleKeyEvent(java.awt.event.KeyEvent e)
          Processses a key event.
 boolean isCellSelectable(int row, int col)
          Checks of a cell is selectable.
 void mouseClicked(java.awt.event.MouseEvent me)
          Delegates any mouse event that occurred on the tree column and was not Button 1 to the tree with new pointer coordinates relative to the tree.
 void mouseEntered(java.awt.event.MouseEvent me)
          Invoked when the mouse pointer enteres a region.
 void mouseExited(java.awt.event.MouseEvent me)
          Invoked when the mouse pointer exits a region.
 void mousePressed(java.awt.event.MouseEvent me)
          Invoked when the mouse button is pressed.
 void mouseReleased(java.awt.event.MouseEvent me)
          Invoked when the mouse button is released.
protected  void processCommand(int command)
          Handles a command.
 void removeTreeTableListener(TreeTableListener listener)
          Removes a tree table listener from the listener list.
protected  void repaintCell(int row, int col)
          Repaints the given cell.
 void restoreCurrentPosition()
          Restores the current position (i\.e\. the currently selected cell).
 void saveCurrentPosition()
          Saves the current position (i\.e\. the currently selected cell).
 void selectCell(int newRow, int newCol)
          Selects the specified cell.
 boolean selectDefaultCell()
          Selects the default cell.
 boolean selectDefaultCell(boolean treeCell)
          Selects the first cell that is selectable.
 boolean selectNode(javax.swing.tree.TreeNode node)
          Sets the selection to a specified node.
 void setColumnSizeConstraint(ColumnSizeConstraint csc)
          Set the constraint for the column size.
 void setDefaultRowHeight(int defaultRowHeight)
          Sets the default row height.
 void setModel(TreeTableModel model)
          Sets the tree table model.
 void setRootVisible(boolean visible)
          Sets the root visible in the tree.
 void setSelectionMode(int selectionMode)
          Sets the selection mode.
 void sizeColumnsToFit()
          Resizes all cells in the table to adjust to the width of the the components contained in the individual cells.
 void sizeColumnsToFit(int resizingColumn)
          Resizes all cells in the table to adjust to the width of the the components contained in the individual cells.
 void sizeRowsToFit()
          Resizes all rows in the table to adjust to the height of the the components contained in the individual cells.
 void togglePath(javax.swing.tree.TreePath path)
          Ensures that the node in the specified path is either collapsed or expanded depending on the state or the node.
 void toggleRow(int row)
          Ensures that the node in the specified row is either collapsed or expanded depending on the state or the node.
 void updateUI()
          This was overridden to message super and forward the method to the tree.
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getUI, getUIClassID, getUpdateSelectionOnSort, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, print, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setRowSorter, setSelectionBackground, setSelectionForeground, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, setValueAt, sizeColumnsToFit, sorterChanged, tableChanged, unconfigureEnclosingScrollPane, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SELECTION_NONE

public static final int SELECTION_NONE
Selection mode: No selection

See Also:
Constant Field Values

SELECTION_SINGLE

public static final int SELECTION_SINGLE
Selection mode: Single selection

See Also:
Constant Field Values

SELECTION_MULTI

public static final int SELECTION_MULTI
Selection mode: Multiple selection

See Also:
Constant Field Values

CMD_NONE

public static final int CMD_NONE
Command: No key

See Also:
Constant Field Values

CMD_MOUSE

public static final int CMD_MOUSE
Command: Mouse key

See Also:
Constant Field Values

CMD_TAB

public static final int CMD_TAB
Command: Tab

See Also:
Constant Field Values

CMD_BACKTAB

public static final int CMD_BACKTAB
Command: Backtab

See Also:
Constant Field Values

CMD_ENTER

public static final int CMD_ENTER
Command: Enter

See Also:
Constant Field Values

CMD_SPACE

public static final int CMD_SPACE
Command: Space

See Also:
Constant Field Values

CMD_LEFT

public static final int CMD_LEFT
Command: Cursor left

See Also:
Constant Field Values

CMD_RIGHT

public static final int CMD_RIGHT
Command: Cursor right

See Also:
Constant Field Values

CMD_UP

public static final int CMD_UP
Command: Cursor up

See Also:
Constant Field Values

CMD_DOWN

public static final int CMD_DOWN
Command: Cursor down

See Also:
Constant Field Values

CMD_PGUP

public static final int CMD_PGUP
Command: Page up

See Also:
Constant Field Values

CMD_PGDN

public static final int CMD_PGDN
Command: Page down

See Also:
Constant Field Values

CMD_TOP

public static final int CMD_TOP
Command: To the top

See Also:
Constant Field Values

CMD_BOTTOM

public static final int CMD_BOTTOM
Command: To the bottom

See Also:
Constant Field Values

CMD_HOME

public static final int CMD_HOME
Command: Home

See Also:
Constant Field Values

CMD_END

public static final int CMD_END
Command: End

See Also:
Constant Field Values

CMD_ESC

public static final int CMD_ESC
Command: Escape

See Also:
Constant Field Values

CMD_SET_SELECTION

public static final int CMD_SET_SELECTION
Command modifier: Set selection

See Also:
Constant Field Values

CMD_EXTEND_SELECTION

public static final int CMD_EXTEND_SELECTION
Command modifier: Extend selection

See Also:
Constant Field Values

CMD_TOGGLE_SELECTION

public static final int CMD_TOGGLE_SELECTION
Command modifier: Toggle selection

See Also:
Constant Field Values

CMD_SWITCH_TREE

public static final int CMD_SWITCH_TREE
Command modifier: Switch from tree to table and vice versa

See Also:
Constant Field Values

CMD_CODE_MASK

public static final int CMD_CODE_MASK
Command modifier mask: Code mask

See Also:
Constant Field Values

CMD_SELECTION_MASK

public static final int CMD_SELECTION_MASK
Command modifier mask: Selection mask

See Also:
Constant Field Values

focusInputMap

protected javax.swing.InputMap focusInputMap
Input map for focused keys of the tree table


focusAncestorInputMap

protected javax.swing.InputMap focusAncestorInputMap
Input map for ancestor-focused keys of the tree table


actionMap

protected javax.swing.ActionMap actionMap
Action map of the tree table


listenerSupport

protected ListenerSupport listenerSupport
Listener support object holding the listeners


currentCol

protected int currentCol
Current colum


currentRow

protected int currentRow
Current row

Constructor Detail

JTreeTable

public JTreeTable()
Default Constructor. This constructor creates a DefaultTreeTableNode for a root node, and adds this to a DefaultTreeTableModel which it registers with this JTreeTable.


JTreeTable

public JTreeTable(TreeTableModel treeTableModel)
Constructor.

Parameters:
treeTableModel - The TreeTableModel to be used with this JTreeTable
Method Detail

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)
Override to prevent NPE in default cut/copy/paste transfer handler when copying table data.

Overrides:
getValueAt in class javax.swing.JTable
See Also:
JTable.getValueAt(int, int)

updateUI

public void updateUI()
This was overridden to message super and forward the method to the tree. This is done since the tree is not actually in the component hierarchy, this it will never receive the updateUI message.

Overrides:
updateUI in class javax.swing.JTable

editCellAt

public boolean editCellAt(int row,
                          int col)
JTable override. This method has been overridden such that the selection for both the tree and the table take place.
See javax.swing.table.editCellAt (int row, int column)

Overrides:
editCellAt in class javax.swing.JTable
Parameters:
row - Row of the cell
col - Column of the cell
Returns:
true If the specified column can be edited.
false If the specified column can not be edited.

editCellAt

public boolean editCellAt(int row,
                          int col,
                          java.util.EventObject e)
Overriden method. This method has been overridden such that the selection for both the tree and the table take place.
See javax.swing.table.editCellAt (int row, int column)

Overrides:
editCellAt in class javax.swing.JTable
Parameters:
row - Row of the cell
col - Column of the cell
e - Event object of the event that caused the call
Returns:
true If the specified column can be edited.
false If the specified column can not be edited.

changeSelection

public void changeSelection(int newRow,
                            int newCol,
                            boolean toggle,
                            boolean extend)
JTable override. This is done to forward the selection to the tree, when a new row is selected. The selection method has been implemented in this manner, since it is more responsive than sharing the ListSelectionModel of the tree with the table. Updates the selection models of the table and the tree, depending on the state of the two flags: toggle and extend. All changes to the selection that are the result of keyboard or mouse events received by the UI are channeled through this method so that the behavior may be overridden by a subclass. This implementation uses the following conventions:

Overrides:
changeSelection in class javax.swing.JTable
Parameters:
newRow - Index of the row to select
newCol - Index of the column to select
toggle - See description above
extend - If true, extend the current selection

repaintCell

protected void repaintCell(int row,
                           int col)
Repaints the given cell.

Parameters:
row - Row of the cell
col - Column of the cell

getEditingRow

public int getEditingRow()
Workaround for BasicTableUI anomaly. Make sure the UI never tries to paint the editor. The UI currently uses different techniques to paint the renderers and editors and overriding setBounds() below is not the right thing to do for an editor. Returning -1 for the editing row in this case, ensures the editor is never painted.

Overrides:
getEditingRow in class javax.swing.JTable
Returns:
The current row being edited

setModel

public void setModel(TreeTableModel model)
Sets the tree table model.

Parameters:
model - The model to be set for the tree table

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent me)
Override of the super method that takes special considerations for tree cell renderers.

Overrides:
getToolTipText in class javax.swing.JTable

getTree

public javax.swing.JTree getTree()
Returns the tree used by the TreeTable.

Returns:
The JTree used by the TreeTalbe

getTreeTableModel

public TreeTableModel getTreeTableModel()
Returns the TreeTableModel that provides the data displayed by this JTreeTable

Returns:
the TreeTableModel that provides the data displayed by this JTreeTable

getScrollPane

protected javax.swing.JScrollPane getScrollPane()
Gets the scroll pane that is associated with the table.

Returns:
The scroll pane or null if there is none

setRootVisible

public void setRootVisible(boolean visible)
Sets the root visible in the tree.

Parameters:
visible - true To show the root
false To hide it

getTreeCol

public int getTreeCol()
Gets the we assume the tree column to be column 0.


getDefaultRowHeight

public int getDefaultRowHeight()
Gets the default row height.


setDefaultRowHeight

public void setDefaultRowHeight(int defaultRowHeight)
Sets the default row height.


sizeRowsToFit

public void sizeRowsToFit()
Resizes all rows in the table to adjust to the height of the the components contained in the individual cells. The row height will be set to the largest preferred size of all components contained in a row.


sizeColumnsToFit

public void sizeColumnsToFit()
Resizes all cells in the table to adjust to the width of the the components contained in the individual cells. The column size will be set according to the minimum and maximum sizes that have been specified for each column and the relation of the column sizes in percent.


sizeColumnsToFit

public void sizeColumnsToFit(int resizingColumn)
Resizes all cells in the table to adjust to the width of the the components contained in the individual cells. Override of JTable.sizeColumnsToFit.
The column size will be set according to the minimum and maximum sizes that have been specified for each column and the relation of the column sizes in percent.

Overrides:
sizeColumnsToFit in class javax.swing.JTable
Parameters:
resizingColumn - Column index of the column that has been resized if the request originates from a column header being dragged. If this value is != -1, the request will be delegated to the super method.

setColumnSizeConstraint

public void setColumnSizeConstraint(ColumnSizeConstraint csc)
Set the constraint for the column size.

Parameters:
csc - The constraint class

doLayout

public void doLayout()
Handle the layout of the rows and columns.

Overrides:
doLayout in class javax.swing.JTable

getPathByRow

public javax.swing.tree.TreePath getPathByRow(int row)
Gets the tree path by a given row.

Parameters:
row - Row index
Returns:
The tree path or null if the row index is invalid

getPathByNode

public javax.swing.tree.TreePath getPathByNode(javax.swing.tree.TreeNode treeNode)
Gets the TreePath for a specified TreeTableNode in the visible tree table.

Parameters:
treeNode - The TreeTableNode for which the TreePath is desired
Returns:
The TreePath, if the node exists in the visible tree, else null

getPathByPoint

public javax.swing.tree.TreePath getPathByPoint(java.awt.Point point)
Gets the tree path located at the specified position relative to the table.

Parameters:
point - Location in table component coordinates
Returns:
The path or null

getNodeByRow

public TreeTableNode getNodeByRow(int row)
Gets the tree node by a given row.

Parameters:
row - Row index
Returns:
The tree node or null if the row index is invalid

getNodeByPath

public TreeTableNode getNodeByPath(javax.swing.tree.TreePath path)
Gets the tree table node by a given tree path.

Parameters:
path - Tree path or null
Returns:
The node or null if the path is null

getNodeByPoint

public TreeTableNode getNodeByPoint(java.awt.Point point)
Gets the tree table node located at the specified position relative to the table.

Parameters:
point - Location in table component coordinates
Returns:
The node or null if the point lies not within valid a column/row

getRowByPath

public int getRowByPath(javax.swing.tree.TreePath path)
Determines the row by the tree path.

Parameters:
path - Tree path
Returns:
The row or -1

getFirstVisibleRow

public int getFirstVisibleRow()
Gets the first row that is fully visible in the scroll pane.

Returns:
The row index or -1 if there are no rows

getLastVisibleRow

public int getLastVisibleRow()
Gets the last row that is fully visible in the scroll pane. If there is no scroll pane surrounding the table, the row count - 1 will be returned.

Returns:
The row index or -1 if there are no rows

getVisibleRowCount

public int getVisibleRowCount()
Gets the number of visible rows in the scroll pane.

Returns:
The number of visible rows (at least 0) or 0 if there are no rows

configureSubComponent

public void configureSubComponent(javax.swing.JComponent comp)
Configures a component that shall be used in a tree table cell for usage in the tree. Basically, this method disables the focus traversal keys in order to let the tree table control the focus traversal between the cells of the tree.

Parameters:
comp - Comp

isCellSelectable

public boolean isCellSelectable(int row,
                                int col)
Checks of a cell is selectable. The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering.

Parameters:
row - Row whose value is to be queried
col - Column whose value is to be queried

selectCell

public void selectCell(int newRow,
                       int newCol)
Selects the specified cell.

Parameters:
newRow - Index of the row to select
newCol - Index of the column to select

selectDefaultCell

public boolean selectDefaultCell()
Selects the default cell. Selects the the first valid content cell or the first tree cell if there is no content cell.

Returns:
true A cell was found we can set the focus to.
false No appropriate cell was found.

selectDefaultCell

public boolean selectDefaultCell(boolean treeCell)
Selects the first cell that is selectable. The method will start at the first row and search downwards for a cell that we can select. The columns in a row are searched from left to right.

Parameters:
treeCell - true The cell to select must be a tree cell. false The cell to select must be a content cell.
Returns:
true A cell was found we can set the focus to.
false No appropriate cell was found.

selectNode

public boolean selectNode(javax.swing.tree.TreeNode node)
Sets the selection to a specified node.

Parameters:
node - The node to set the selection to
Returns:
true if the selection was successful
false is not.

getSelection

public javax.swing.tree.TreePath[] getSelection()
Gets the selection.

Returns:
An array of tree paths that denote the selected elements or null if no element has been selected.

getSelectionMode

public int getSelectionMode()
Gets the selection mode.

Returns:
SELECTION_NONE/SELECTION_SINGLE/SELECTION_MULTI

setSelectionMode

public void setSelectionMode(int selectionMode)
Sets the selection mode.

Overrides:
setSelectionMode in class javax.swing.JTable
Parameters:
selectionMode - SELECTION_NONE/SELECTION_SINGLE/SELECTION_MULTI

saveCurrentPosition

public void saveCurrentPosition()
Saves the current position (i\.e\. the currently selected cell).


restoreCurrentPosition

public void restoreCurrentPosition()
Restores the current position (i\.e\. the currently selected cell).


expandTreeLevels

public void expandTreeLevels(boolean expand,
                             int numberOfLevelThatAreNeededToBeExpanded)
Expands all tree nodes or collapse these level by level.

Parameters:
expand - true expands all nodes in the tree
false collapses all nodes in the tree
numberOfLevelThatAreNeededToBeExpanded - The number of level that are needed to be expand. The value '-1' expands all levels.

expandAll

public void expandAll(boolean expand)
Expands all tree nodes or collapse these.

Parameters:
expand - true expands all nodes in the tree
false collapses all nodes in the tree

expandAll

public void expandAll(javax.swing.tree.TreePath parent,
                      boolean expand)
Expands all tree nodes or collapse these.

Parameters:
parent - The parent tree path
expand - true expands all nodes in the tree
false collapses all nodes in the tree

expandTreeLevels

public void expandTreeLevels(javax.swing.tree.TreePath parent,
                             boolean expand,
                             int numberOfLevelThatAreNeededToBeExpanded)
Expands all tree nodes or collapse these level by level.

Parameters:
parent - The parent tree path
expand - true expands all nodes in the tree
false collapses all nodes in the tree
numberOfLevelThatAreNeededToBeExpanded - The number of level that are needed to be expand. The value '-1' expands all levels.

toggleRow

public void toggleRow(int row)
Ensures that the node in the specified row is either collapsed or expanded depending on the state or the node.

Parameters:
row - An integer specifying a display row, where 0 is the first row in the display

togglePath

public void togglePath(javax.swing.tree.TreePath path)
Ensures that the node in the specified path is either collapsed or expanded depending on the state or the node.

Parameters:
path - the TreePath identifying a node

collapseRow

public void collapseRow(int row)
Ensures that the node in the specified row is collapsed.

If row is < 0 or >= getRowCount this will have no effect.

Parameters:
row - An integer specifying a display row, where 0 is the first row in the display

expandRow

public void expandRow(int row)
Ensures that the node in the specified row is expanded and viewable. If row is < 0 or >= getRowCount this will have no effect.

Parameters:
row - An integer specifying a display row, where 0 is the first row in the display

collapsePath

public void collapsePath(javax.swing.tree.TreePath path)
Ensures that the node identified by the specified path is collapsed and viewable.

Parameters:
path - the TreePath identifying a node

expandPath

public void expandPath(javax.swing.tree.TreePath path)
Ensures that the node identified by the specified path is expanded and viewable.

Parameters:
path - the TreePath identifying a node

handleKeyEvent

public void handleKeyEvent(java.awt.event.KeyEvent e)
Processses a key event.

Parameters:
e - Event to process

processCommand

protected void processCommand(int command)
Handles a command.

Parameters:
command - Command to process

fireCommand

protected boolean fireCommand(int command)
Fires a 'command' event to all registered tree table listeners.

Parameters:
command - Command to execute
Returns:
true The event has been consumed, no further processing desired.
false The event has not been consumed.

addTreeTableListener

public void addTreeTableListener(TreeTableListener listener)
Adds a tree table listener to the listener list.

Parameters:
listener - The listener to be added

addWeakTreeTableListener

public void addWeakTreeTableListener(TreeTableListener listener)
Adds a tree table listener to the listener list as weak listener. The listener is registered a WEAK listener, i. e. it may be garbage-collected if not referenced otherwise.
ATTENTION: Never add an automatic class (i. e new TreeTableListener () { ... }) or an inner class that is not referenced otherwise as a weak listener to the list. These objects will be cleared by the garbage collector during the next gc run!

Parameters:
listener - The listener to be added

removeTreeTableListener

public void removeTreeTableListener(TreeTableListener listener)
Removes a tree table listener from the listener list.

Parameters:
listener - The listener to be removed

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent me)
Delegates any mouse event that occurred on the tree column and was not Button 1 to the tree with new pointer coordinates relative to the tree. Invoked when the mouse has been clicked on a component.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent me)
Invoked when the mouse button is pressed.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent me)
Invoked when the mouse button is released.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent me)
Invoked when the mouse pointer enteres a region.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent me)
Invoked when the mouse pointer exits a region.

Specified by:
mouseExited in interface java.awt.event.MouseListener

createDescriptionCellValue

public static java.lang.Object createDescriptionCellValue(java.lang.String text)
Creates a text value for display in a text-only cell (e\. g\. a description cell). The method will check if the text is multi line text. If yes, the method returns an array or two strings, the first string the text to display in the cell, the second string the text that should appear as tool tip. Otherwise, the text will be returned as string.
The returned object will be recognized by the DefaultTableCellRenderer which will create a formatted tool tip from the full text.

Parameters:
text - Text to display
Returns:
A string, an array of Strings of size 2 or null


Copyright © 2011. All Rights Reserved.