Class JXTree
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
- Direct Known Subclasses:
JXTreeTable.TreeTableCellRenderer
Rendering and Highlighting
As all SwingX collection views, a JXTree is a HighlighterClient (PENDING JW: formally define and implement, like in AbstractTestHighlighter), that is it provides consistent api to add and remove Highlighters which can visually decorate the rendering component.
JXTree tree = new JXTree(new FileSystemModel());
// use system file icons and name to render
tree.setCellRenderer(new DefaultTreeRenderer(IconValues.FILE_ICON,
StringValues.FILE_NAME));
// highlight condition: file modified after a date
HighlightPredicate predicate = new HighlightPredicate() {
public boolean isHighlighted(Component renderer,
ComponentAdapter adapter) {
File file = getUserObject(adapter.getValue());
return file != null ? lastWeek invalid input: '<' file.lastModified : false;
}
};
// highlight with foreground color
tree.addHighlighter(new ColorHighlighter(predicate, null, Color.RED);
Note: for full functionality, a DefaultTreeRenderer must be installed
as TreeCellRenderer. This is not done by default, because there are
unresolved issues when editing. PENDING JW: still? Check!
Note: to support the highlighting this implementation wraps the
TreeCellRenderer set by client code with a DelegatingRenderer which applies
the Highlighter after delegating the default configuration to the wrappee. As
a side-effect, getCellRenderer does return the wrapper instead of the custom
renderer. To access the latter, client code must call getWrappedCellRenderer.
Rollover
As all SwingX collection views, a JXTree supports per-cell rollover. If enabled, the component fires rollover events on enter/exit of a cell which by default is promoted to the renderer if it implements RolloverRenderer, that is simulates live behaviour. The rollover events can be used by client code as well, f.i. to decorate the rollover row using a Highlighter.
JXTree tree = new JXTree();
tree.setRolloverEnabled(true);
tree.setCellRenderer(new DefaultTreeRenderer());
tree.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW,
null, Color.RED);
Search
As all SwingX collection views, a JXTree is searchable. A search action is registered in its ActionMap under the key "find". The default behaviour is to ask the SearchFactory to open a search component on this component. The default keybinding is retrieved from the SearchFactory, typically ctrl-f (or cmd-f for Mac). Client code can register custom actions and/or bindings as appropriate.JXTree provides api to vend a renderer-controlled String representation of cell content. This allows the Searchable and Highlighters to use WYSIWYM (What-You-See-Is-What-You-Match), that is pattern matching against the actual string as seen by the user.
Miscellaneous
- Improved usability for editing: guarantees that the tree is the focusOwner if editing terminated by user gesture and guards against data corruption if focusLost while editing
- Access methods for selection colors, for consistency with JXTable, JXList
- Convenience methods and actions to expand, collapse all nodes
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classA small class which dispatches actions.classThis class tracks changes in the keyboard focus state.classA decorator for the original TreeCellRenderer.protected static classprotected classListens to the model and updates theexpandedStateaccordingly when nodes are removed, or changed.Nested classes/interfaces inherited from class JTree
JTree.AccessibleJTree, JTree.DropLocation, JTree.DynamicUtilTreeNode, JTree.EmptySelectionModel, JTree.TreeModelHandler, JTree.TreeSelectionRedirectorNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CompoundHighlighterCollection of active Highlighters.protected ComponentAdapterprivate JXTree.DelegatingRendererWrapper around the installed renderer, needed to support Highlighters.private CellEditorListenerThe CellEditorListener responsible to force the focus back to the tree after terminating edits.private JXTree.CellEditorRemoverThe propertyChangeListener responsible for terminating edits if focus lost.private static final int[]Empty int array used in getSelectedRows().private static final TreePath[]Empty TreePath used in getSelectedPath() if selection empty.private ChangeListenerListener to changes of Highlighters in collection.private TreeRolloverController<JXTree> The RolloverController used if rollover is enabled.private static final Loggerprivate booleanprivate RolloverProducerThe RolloverProducer used if rollover is enabled.private Searchableprivate ColorColor of selected background.private ColorColor of selected foreground.Fields inherited from class JTree
ANCHOR_SELECTION_PATH_PROPERTY, CELL_EDITOR_PROPERTY, CELL_RENDERER_PROPERTY, cellEditor, cellRenderer, editable, EDITABLE_PROPERTY, EXPANDS_SELECTED_PATHS_PROPERTY, INVOKES_STOP_CELL_EDITING_PROPERTY, invokesStopCellEditing, LARGE_MODEL_PROPERTY, largeModel, LEAD_SELECTION_PATH_PROPERTY, ROOT_VISIBLE_PROPERTY, rootVisible, ROW_HEIGHT_PROPERTY, rowHeight, SCROLLS_ON_EXPAND_PROPERTY, scrollsOnExpand, SELECTION_MODEL_PROPERTY, selectionModel, selectionRedirector, SHOWS_ROOT_HANDLES_PROPERTY, showsRootHandles, TOGGLE_CLICK_COUNT_PROPERTY, toggleClickCount, TREE_MODEL_PROPERTY, treeModel, treeModelListener, VISIBLE_ROW_COUNT_PROPERTY, visibleRowCountFields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionJXTree()Constructs aJXTreewith a sample model.Constructs aJXTreewith each element of the specified array as the child of a new root node which is not displayed.Constructs aJXTreecreated from a Hashtable which does not display with root.Constructs aJXTreewith each element of the specified Vector as the child of a new root node which is not displayed.Constructs an instance ofJXTreewhich displays the root node -- the tree is created using the specified data model.Constructs aJXTreewith the specified TreeNode as its root, which displays the root node.Constructs aJXTreewith the specified TreeNode as its root, which displays the root node and which decides whether a node is a leaf node in the specified manner. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHighlighter(Highlighter highlighter) Appends aHighlighterto the end of the list of usedHighlighters.protected voidThis is called from cell editor listener if edit terminated.voidCollapses all nodes in this tree.protected TreeCellRendererCreates and returns the default cell renderer to use.private ActionCreates and returns the action to invoke on a find request.protected ChangeListenerCreates and returns the ChangeListener observing Highlighters.protected TreeRolloverController<JXTree> Creates and returns a RolloverController appropriate for this tree.protected RolloverProducerCreates and returns the RolloverProducer to use with this tree.protected TreeModelListenerprotected voiddoFind()Starts a search on this Tree's visible nodes.voidExpands all nodes in this tree.private voidExpands the root path if a TreeModel has been set, does nothing if not.protected ComponentAdapterprotected ComponentAdaptergetComponentAdapter(int index) Convenience to access a configured ComponentAdapter.protected CompoundHighlighterReturns the CompoundHighlighter assigned to the table, null if none.private JXTree.DelegatingRendererprotected ChangeListenerReturns theChangeListenerto use with highlighters.Returns theHighlighters used by this table.protected TreeRolloverController<JXTree> Returns the RolloverController for this component.getNextMatch(String prefix, int startingRow, Position.Bias bias) Overridden to respect the string representation, if any.Returns a Searchable for this component, guaranteed to be not null.Returns the background color for selected cells.Returns the selection foreground color.TreePath[]int[]getStringAt(int row) Returns the string representation of the cell value at the given position.getStringAt(TreePath path) Returns the string representation of the cell value at the given position.Returns the renderer installed by client code or the default if none has been set.private voidinit()Instantiates JXTree state which is new compared to super.private voidInstalls selection colors from UIManager.voidInvalidates cell size caching in the ui delegate.private booleanReturns a boolean to indicate if the current focus owner is descending from this table.booleanReturns a boolean indicating whether the per-tree icons should be copied to the renderer on setCellRenderer.booleanReturns a boolean indicating whether or not rollover support is enabled.voidremoveHighlighter(Highlighter highlighter) Removes the given Highlighter.voidOverridden to release the CellEditorRemover, if any.voidsetCellRenderer(TreeCellRenderer renderer) voidsetClosedIcon(Icon closedIcon) Sets the Icon to use for a closed folder node.voidsetCollapsedIcon(Icon collapsedIcon) Sets the Icon to use for the handle of a collapsed node.voidsetExpandedIcon(Icon expandedIcon) Sets the Icon to use for the handle of an expanded node.voidsetHighlighters(Highlighter... highlighters) Sets theHighlighters to the table, replacing any old settings.voidsetLeafIcon(Icon leafIcon) Sets the Icon to use for a leaf node.voidvoidsetOpenIcon(Icon openIcon) Sets the Icon to use for an open folder node.voidsetOverwriteRendererIcons(boolean overwrite) Property to control whether per-tree icons should be copied to the renderer on setCellRenderer.voidsetRolloverEnabled(boolean rolloverEnabled) Sets the property to enable/disable rollover support.voidsetSearchable(Searchable searchable) Sets the Searchable for this component.voidsetSelectionBackground(Color selectionBackground) Sets the background color for selected cells.voidsetSelectionForeground(Color selectionForeground) Sets the foreground color for selected cells.voidstartEditingAtPath(TreePath path) private voidUninstalls selection colors.private voidHack to grab focus after editing.private voidLazily creates and updates the internal CellEditorRemover.protected voidUpdates highlighter afterupdateUIchanges.protected voidQuick fix for #1060-swingx: icons lost on toggling LAFvoidupdateUI()Methods inherited from class JTree
addSelectionInterval, addSelectionPath, addSelectionPaths, addSelectionRow, addSelectionRows, addTreeExpansionListener, addTreeSelectionListener, addTreeWillExpandListener, cancelEditing, clearSelection, clearToggledPaths, collapsePath, collapseRow, convertValueToText, createTreeModel, expandPath, expandRow, fireTreeCollapsed, fireTreeExpanded, fireTreeWillCollapse, fireTreeWillExpand, fireValueChanged, getAccessibleContext, getAnchorSelectionPath, getCellEditor, getClosestPathForLocation, getClosestRowForLocation, getDefaultTreeModel, getDescendantToggledPaths, getDragEnabled, getDropLocation, getDropMode, getEditingPath, getExpandedDescendants, getExpandsSelectedPaths, getInvokesStopCellEditing, getLastSelectedPathComponent, getLeadSelectionPath, getLeadSelectionRow, getMaxSelectionRow, getMinSelectionRow, getModel, getPathBetweenRows, getPathBounds, getPathForLocation, getPathForRow, getPreferredScrollableViewportSize, getRowBounds, getRowCount, getRowForLocation, getRowForPath, getRowHeight, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollsOnExpand, getSelectionCount, getSelectionModel, getSelectionPath, getShowsRootHandles, getToggleClickCount, getToolTipText, getTreeExpansionListeners, getTreeSelectionListeners, getTreeWillExpandListeners, getUI, getUIClassID, getVisibleRowCount, hasBeenExpanded, isCollapsed, isCollapsed, isEditable, isEditing, isExpanded, isExpanded, isFixedRowHeight, isLargeModel, isPathEditable, isPathSelected, isRootVisible, isRowSelected, isSelectionEmpty, isVisible, makeVisible, paramString, removeDescendantSelectedPaths, removeDescendantToggledPaths, removeSelectionInterval, removeSelectionPath, removeSelectionPaths, removeSelectionRow, removeSelectionRows, removeTreeExpansionListener, removeTreeSelectionListener, removeTreeWillExpandListener, scrollPathToVisible, scrollRowToVisible, setAnchorSelectionPath, setCellEditor, setDragEnabled, setDropMode, setEditable, setExpandedState, setExpandsSelectedPaths, setInvokesStopCellEditing, setLargeModel, setLeadSelectionPath, setRootVisible, setRowHeight, setScrollsOnExpand, setSelectionInterval, setSelectionModel, setSelectionPath, setSelectionPaths, setSelectionRow, setSelectionRows, setShowsRootHandles, setToggleClickCount, setUI, setVisibleRowCount, stopEditing, treeDidChangeMethods inherited from class JComponent
addAncestorListener, addNotify, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, 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, updateMethods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, 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, transferFocusDownCycle, validate, validateTreeMethods inherited from class 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
LOG
-
EMPTY_INT_ARRAY
private static final int[] EMPTY_INT_ARRAYEmpty int array used in getSelectedRows(). -
EMPTY_TREEPATH_ARRAY
Empty TreePath used in getSelectedPath() if selection empty. -
compoundHighlighter
Collection of active Highlighters. -
highlighterChangeListener
Listener to changes of Highlighters in collection. -
delegatingRenderer
Wrapper around the installed renderer, needed to support Highlighters. -
rolloverProducer
The RolloverProducer used if rollover is enabled. -
linkController
The RolloverController used if rollover is enabled. -
overwriteIcons
private boolean overwriteIcons -
searchable
-
editorRemover
The propertyChangeListener responsible for terminating edits if focus lost. -
editorListener
The CellEditorListener responsible to force the focus back to the tree after terminating edits. -
selectionForeground
Color of selected foreground. Added for consistent api across collection components. -
selectionBackground
Color of selected background. Added for consistent api across collection components. -
dataAdapter
-
-
Constructor Details
-
JXTree
public JXTree()Constructs aJXTreewith a sample model. The default model used by this tree defines a leaf node as any node without children. -
JXTree
Constructs aJXTreewith each element of the specified array as the child of a new root node which is not displayed. By default, this tree defines a leaf node as any node without children. This version of the constructor simply invokes the super class version with the same arguments.- Parameters:
value- an array of objects that are children of the root.
-
JXTree
Constructs aJXTreewith each element of the specified Vector as the child of a new root node which is not displayed. By default, this tree defines a leaf node as any node without children. This version of the constructor simply invokes the super class version with the same arguments.- Parameters:
value- an Vector of objects that are children of the root.
-
JXTree
Constructs aJXTreecreated from a Hashtable which does not display with root. Each value-half of the key/value pairs in the HashTable becomes a child of the new root node. By default, the tree defines a leaf node as any node without children. This version of the constructor simply invokes the super class version with the same arguments.- Parameters:
value- a Hashtable containing objects that are children of the root.
-
JXTree
Constructs aJXTreewith the specified TreeNode as its root, which displays the root node. By default, the tree defines a leaf node as any node without children. This version of the constructor simply invokes the super class version with the same arguments.- Parameters:
root- root node of this tree
-
JXTree
Constructs aJXTreewith the specified TreeNode as its root, which displays the root node and which decides whether a node is a leaf node in the specified manner. This version of the constructor simply invokes the super class version with the same arguments.- Parameters:
root- root node of this treeasksAllowsChildren- if true, only nodes that do not allow children are leaf nodes; otherwise, any node without children is a leaf node;- See Also:
-
JXTree
Constructs an instance ofJXTreewhich displays the root node -- the tree is created using the specified data model. This version of the constructor simply invokes the super class version with the same arguments.- Parameters:
newModel- theTreeModelto use as the data model
-
-
Method Details
-
init
private void init()Instantiates JXTree state which is new compared to super. Installs the Delegating renderer and editor, registers actions and keybindings. This must be called from each constructor. -
createTreeModelListener
- Overrides:
createTreeModelListenerin classJTree
-
createFindAction
Creates and returns the action to invoke on a find request.- Returns:
- the action to invoke on a find request.
-
doFind
protected void doFind()Starts a search on this Tree's visible nodes. This implementation asks the SearchFactory to open a find widget on itself. -
getSearchable
Returns a Searchable for this component, guaranteed to be not null. This implementation lazily creates a TreeSearchable if necessary.- Returns:
- a not-null Searchable for this component.
- See Also:
-
setSearchable
Sets the Searchable for this component. If null, a default Searchable will be created and used.- Parameters:
searchable- the Searchable to use for this component, may be null to indicate using the default.- See Also:
-
getStringAt
Returns the string representation of the cell value at the given position.- Parameters:
row- the row index of the cell in view coordinates- Returns:
- the string representation of the cell value as it will appear in the table.
-
getStringAt
-
getNextMatch
Overridden to respect the string representation, if any. This takes over completely (as compared to super), internally messaging the Searchable.PENDING JW: re-visit once we support deep node search.
- Overrides:
getNextMatchin classJTree
-
collapseAll
public void collapseAll()Collapses all nodes in this tree. -
expandAll
public void expandAll()Expands all nodes in this tree.Note: it's not recommended to use this method on the EDT for large/deep trees because expansion can take a considerable amount of time.
-
expandRoot
private void expandRoot()Expands the root path if a TreeModel has been set, does nothing if not. -
getSelectionRows
public int[] getSelectionRows()Overridden to always return a not-null array (following SwingX convention).
- Overrides:
getSelectionRowsin classJTree
-
getSelectionPaths
Overridden to always return a not-null array (following SwingX convention).
- Overrides:
getSelectionPathsin classJTree
-
getSelectionBackground
Returns the background color for selected cells.- Returns:
- the
Colorused for the background of selected list items - See Also:
-
getSelectionForeground
Returns the selection foreground color.- Returns:
- the
Colorobject for the foreground property - See Also:
-
setSelectionForeground
Sets the foreground color for selected cells. Cell renderers can use this color to render text and graphics for selected cells.The default value of this property is defined by the look and feel implementation.
This is a JavaBeans bound property.
- Parameters:
selectionForeground- theColorto use in the foreground for selected list items- See Also:
-
setSelectionBackground
Sets the background color for selected cells. Cell renderers can use this color to the fill selected cells.The default value of this property is defined by the look and feel implementation.
This is a JavaBeans bound property.
- Parameters:
selectionBackground- theColorto use for the background of selected cells- See Also:
-
updateUI
-
updateRendererEditorUI
protected void updateRendererEditorUI()Quick fix for #1060-swingx: icons lost on toggling LAF -
installSelectionColors
private void installSelectionColors()Installs selection colors from UIManager.Note: this should be done in the UI delegate.
-
uninstallSelectionColors
private void uninstallSelectionColors()Uninstalls selection colors.Note: this should be done in the UI delegate.
-
updateHighlighterUI
protected void updateHighlighterUI()Updates highlighter afterupdateUIchanges.- See Also:
-
setRolloverEnabled
public void setRolloverEnabled(boolean rolloverEnabled) Sets the property to enable/disable rollover support. If enabled, the list fires property changes on per-cell mouse rollover state, i.e. when the mouse enters/leaves a list cell.This can be enabled to show "live" rollover behaviour, f.i. the cursor over a cell rendered by a JXHyperlink.
The default value is false.
- Parameters:
rolloverEnabled- a boolean indicating whether or not the rollover functionality should be enabled.- See Also:
-
isRolloverEnabled
public boolean isRolloverEnabled()Returns a boolean indicating whether or not rollover support is enabled.- Returns:
- a boolean indicating whether or not rollover support is enabled.
- See Also:
-
getLinkController
Returns the RolloverController for this component. Lazyly creates the controller if necessary, that is the return value is guaranteed to be not null.PENDING JW: rename to getRolloverController
- Returns:
- the RolloverController for this tree, guaranteed to be not null.
- See Also:
-
createLinkController
Creates and returns a RolloverController appropriate for this tree.- Returns:
- a RolloverController appropriate for this tree.
- See Also:
-
createRolloverProducer
Creates and returns the RolloverProducer to use with this tree.- Returns:
RolloverProducerto use with this tree- See Also:
-
setHighlighters
Sets theHighlighters to the table, replacing any old settings. None of the given Highlighters must be null.This is a bound property.
Note: as of version #1.257 the null constraint is enforced strictly. To remove all highlighters use this method without param.
- Parameters:
highlighters- zero or more not null highlighters to use for renderer decoration.- Throws:
NullPointerException- if array is null or array contains null values.- See Also:
-
getHighlighters
Returns theHighlighters used by this table. Maybe empty, but guarantees to be never null.- Returns:
- the Highlighters used by this table, guaranteed to never null.
- See Also:
-
addHighlighter
Appends aHighlighterto the end of the list of usedHighlighters. The argument must not be null.- Parameters:
highlighter- theHighlighterto add, must not be null.- Throws:
NullPointerException- ifHighlighteris null.- See Also:
-
removeHighlighter
Removes the given Highlighter.Does nothing if the Highlighter is not contained.
- Parameters:
highlighter- the Highlighter to remove.- See Also:
-
getCompoundHighlighter
Returns the CompoundHighlighter assigned to the table, null if none. PENDING: open up for subclasses again?.- Returns:
- the CompoundHighlighter assigned to the table.
-
getHighlighterChangeListener
Returns theChangeListenerto use with highlighters. Lazily creates the listener.- Returns:
- the ChangeListener for observing changes of highlighters,
guaranteed to be
not-null
-
createHighlighterChangeListener
Creates and returns the ChangeListener observing Highlighters.Here: repaints the table on receiving a stateChanged.
- Returns:
- the ChangeListener defining the reaction to changes of highlighters.
-
setExpandedIcon
Sets the Icon to use for the handle of an expanded node.Note: this will only succeed if the current ui delegate is a BasicTreeUI otherwise it will do nothing.
PENDING JW: incomplete api (no getter) and not a bound property.
- Parameters:
expandedIcon- the Icon to use for the handle of an expanded node.
-
setCollapsedIcon
Sets the Icon to use for the handle of a collapsed node. Note: this will only succeed if the current ui delegate is a BasicTreeUI otherwise it will do nothing. PENDING JW: incomplete api (no getter) and not a bound property.- Parameters:
collapsedIcon- the Icon to use for the handle of a collapsed node.
-
setLeafIcon
Sets the Icon to use for a leaf node.Note: this will only succeed if current renderer is a DefaultTreeCellRenderer.
PENDING JW: this (all setXXIcon) is old api pulled up from the JXTreeTable. Need to review if we really want it - problematic if sharing the same renderer instance across different trees. PENDING JW: incomplete api (no getter) and not a bound property.
- Parameters:
leafIcon- the Icon to use for a leaf node.
-
setOpenIcon
Sets the Icon to use for an open folder node. Note: this will only succeed if current renderer is a DefaultTreeCellRenderer. PENDING JW: incomplete api (no getter) and not a bound property.- Parameters:
openIcon- the Icon to use for an open folder node.
-
setClosedIcon
Sets the Icon to use for a closed folder node. Note: this will only succeed if current renderer is a DefaultTreeCellRenderer. PENDING JW: incomplete api (no getter) and not a bound property.- Parameters:
closedIcon- the Icon to use for a closed folder node.
-
setOverwriteRendererIcons
public void setOverwriteRendererIcons(boolean overwrite) Property to control whether per-tree icons should be copied to the renderer on setCellRenderer.The default value is false. PENDING: should update the current renderer's icons when setting to true?
- Parameters:
overwrite- a boolean to indicate if the per-tree Icons should be copied to the new renderer on setCellRenderer.- See Also:
-
isOverwriteRendererIcons
public boolean isOverwriteRendererIcons()Returns a boolean indicating whether the per-tree icons should be copied to the renderer on setCellRenderer.- Returns:
- true if a TreeCellRenderer's icons will be overwritten with the tree's Icons, false if the renderer's icons will be unchanged.
- See Also:
-
getDelegatingRenderer
-
createDefaultCellRenderer
Creates and returns the default cell renderer to use. Subclasses may override to use a different type.This implementation returns a renderer of type
DefaultTreeCellRenderer. Note: Will be changed to return a renderer of typeDefaultTreeRenderer, once WrappingProvider is reasonably stable.- Returns:
- the default cell renderer to use with this tree.
-
getCellRenderer
Overridden to return the delegating renderer which is wrapped around the original to support highlighting. The returned renderer is of type DelegatingRenderer and guaranteed to not-null
- Overrides:
getCellRendererin classJTree- See Also:
-
getWrappedCellRenderer
Returns the renderer installed by client code or the default if none has been set.- Returns:
- the wrapped renderer.
- See Also:
-
setCellRenderer
Overridden to wrap the given renderer in a DelegatingRenderer to support highlighting.
Note: the wrapping implies that the renderer returned from the getCellRenderer is not the renderer as given here, but the wrapper. To access the original, use
getWrappedCellRenderer.- Overrides:
setCellRendererin classJTree- See Also:
-
invalidateCellSizeCache
public void invalidateCellSizeCache()Invalidates cell size caching in the ui delegate. May do nothing if there's no safe (i.e. without reflection) way to message the delegate.This implementation calls BasicTreeUI setLeftChildIndent with the old indent if available. Beware: clearing the cache is an undocumented implementation side-effect of the method. Revisit if we ever should have a custom ui delegate.
-
startEditingAtPath
Overridden to fix focus issues with editors. This method installs and updates the internal CellEditorRemover which terminates ongoing edits if appropriate. Additionally, it registers a CellEditorListener with the cell editor to grab the focus back to tree, if appropriate.
- Overrides:
startEditingAtPathin classJTree- See Also:
-
updateEditorListener
private void updateEditorListener()Hack to grab focus after editing. -
analyseFocus
protected void analyseFocus()This is called from cell editor listener if edit terminated. Trying to analyse if we should grab the focus back to the tree after. Brittle ... we assume we are the first to get the event, so we can analyse the hierarchy before the editing component is removed. -
isFocusOwnerDescending
private boolean isFocusOwnerDescending()Returns a boolean to indicate if the current focus owner is descending from this table. Returns false if not editing, otherwise walks the focusOwner hierarchy, taking popups into account.PENDING: copied from JXTable ... should be somewhere in a utility class?
- Returns:
- a boolean to indicate if the current focus owner is contained.
-
removeNotify
public void removeNotify()Overridden to release the CellEditorRemover, if any.- Overrides:
removeNotifyin classJComponent
-
updateEditorRemover
private void updateEditorRemover()Lazily creates and updates the internal CellEditorRemover. -
setModel
-
getComponentAdapter
- Returns:
- the unconfigured ComponentAdapter.
-
getComponentAdapter
Convenience to access a configured ComponentAdapter. Note: the column index of the configured adapter is always 0.- Parameters:
index- the row index in view coordinates, must be valid.- Returns:
- the configured ComponentAdapter.
-