|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTree
org.jdesktop.swingx.JXTree
public class JXTree
Enhanced Tree component with support for SwingX rendering, highlighting, rollover and search functionality.
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 < 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.
JXTree tree = new JXTree();
tree.setRolloverEnabled(true);
tree.setCellRenderer(new DefaultTreeRenderer());
tree.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW,
null, Color.RED);
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.
DefaultTreeRenderer
,
ComponentProvider
,
Highlighter
,
HighlightPredicate
,
SearchFactory
,
Searchable
,
Serialized FormNested Class Summary | |
---|---|
class |
JXTree.CellEditorRemover
This class tracks changes in the keyboard focus state. |
class |
JXTree.DelegatingRenderer
A decorator for the original TreeCellRenderer. |
protected static class |
JXTree.TreeAdapter
|
protected class |
JXTree.XTreeModelHandler
Listens to the model and updates the expandedState accordingly
when nodes are removed, or changed. |
Nested classes/interfaces inherited from class javax.swing.JTree |
---|
JTree.AccessibleJTree, JTree.DynamicUtilTreeNode, JTree.EmptySelectionModel, JTree.TreeModelHandler, JTree.TreeSelectionRedirector |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected CompoundHighlighter |
compoundHighlighter
Collection of active Highlighters. |
protected ComponentAdapter |
dataAdapter
|
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 | |
---|---|
JXTree()
Constructs a JXTree with a sample model. |
|
JXTree(Hashtable value)
Constructs a JXTree created from a Hashtable which does not
display with root. |
|
JXTree(Object[] value)
Constructs a JXTree with each element of the specified array
as the child of a new root node which is not displayed. |
|
JXTree(TreeModel newModel)
Constructs an instance of JXTree which displays the root
node -- the tree is created using the specified data model. |
|
JXTree(TreeNode root)
Constructs a JXTree with the specified TreeNode as its root,
which displays the root node. |
|
JXTree(TreeNode root,
boolean asksAllowsChildren)
Constructs a JXTree with 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. |
|
JXTree(Vector value)
Constructs a JXTree with each element of the specified
Vector as the child of a new root node which is not displayed. |
Method Summary | |
---|---|
void |
addHighlighter(Highlighter highlighter)
Appends a Highlighter to the end of the list of used
Highlighter s. |
protected void |
analyseFocus()
This is called from cell editor listener if edit terminated. |
void |
collapseAll()
Collapses all nodes in this tree. |
protected TreeCellRenderer |
createDefaultCellRenderer()
Creates and returns the default cell renderer to use. |
protected ChangeListener |
createHighlighterChangeListener()
Creates and returns the ChangeListener observing Highlighters. |
protected TreeRolloverController<JXTree> |
createLinkController()
Creates and returns a RolloverController appropriate for this tree. |
protected RolloverProducer |
createRolloverProducer()
Creates and returns the RolloverProducer to use with this tree. |
protected TreeModelListener |
createTreeModelListener()
Creates and returns an instance of TreeModelHandler . |
protected void |
doFind()
Starts a search on this Tree's visible nodes. |
void |
expandAll()
Expands all nodes in this tree. |
TreeCellRenderer |
getCellRenderer()
Returns the current TreeCellRenderer
that is rendering each cell. |
protected ComponentAdapter |
getComponentAdapter()
|
protected ComponentAdapter |
getComponentAdapter(int index)
Convenience to access a configured ComponentAdapter. |
protected CompoundHighlighter |
getCompoundHighlighter()
Returns the CompoundHighlighter assigned to the table, null if none. |
protected ChangeListener |
getHighlighterChangeListener()
Returns the ChangeListener to use with highlighters. |
Highlighter[] |
getHighlighters()
Returns the Highlighter s used by this table. |
protected TreeRolloverController<JXTree> |
getLinkController()
Returns the RolloverController for this component. |
Searchable |
getSearchable()
Returns a Searchable for this component, guaranteed to be not null. |
Color |
getSelectionBackground()
Returns the background color for selected cells. |
Color |
getSelectionForeground()
Returns the selection foreground color. |
TreePath[] |
getSelectionPaths()
Returns the paths of all selected values. |
int[] |
getSelectionRows()
Returns all of the currently selected rows. |
String |
getStringAt(int row)
Returns the string representation of the cell value at the given position. |
String |
getStringAt(TreePath path)
Returns the string representation of the cell value at the given position. |
TreeCellRenderer |
getWrappedCellRenderer()
Returns the renderer installed by client code or the default if none has been set. |
boolean |
isOverwriteRendererIcons()
Returns a boolean indicating whether the per-tree icons should be copied to the renderer on setCellRenderer. |
boolean |
isRolloverEnabled()
Returns a boolean indicating whether or not rollover support is enabled. |
void |
removeHighlighter(Highlighter highlighter)
Removes the given Highlighter. |
void |
removeNotify()
Overridden to release the CellEditorRemover, if any. |
void |
setCellRenderer(TreeCellRenderer renderer)
Sets the TreeCellRenderer that will be used to
draw each cell. |
void |
setClosedIcon(Icon closedIcon)
Sets the Icon to use for a closed folder node. |
void |
setCollapsedIcon(Icon collapsedIcon)
Sets the Icon to use for the handle of a collapsed node. |
void |
setExpandedIcon(Icon expandedIcon)
Sets the Icon to use for the handle of an expanded node. |
void |
setHighlighters(Highlighter... highlighters)
Sets the Highlighter s to the table, replacing any old settings. |
void |
setLeafIcon(Icon leafIcon)
Sets the Icon to use for a leaf node. |
void |
setModel(TreeModel newModel)
Sets the TreeModel that will provide the data. |
void |
setOpenIcon(Icon openIcon)
Sets the Icon to use for an open folder node. |
void |
setOverwriteRendererIcons(boolean overwrite)
Property to control whether per-tree icons should be copied to the renderer on setCellRenderer. |
void |
setRolloverEnabled(boolean rolloverEnabled)
Sets the property to enable/disable rollover support. |
void |
setSearchable(Searchable searchable)
Sets the Searchable for this component. |
void |
setSelectionBackground(Color selectionBackground)
Sets the background color for selected cells. |
void |
setSelectionForeground(Color selectionForeground)
Sets the foreground color for selected cells. |
void |
startEditingAtPath(TreePath path)
Selects the node identified by the specified path and initiates editing. |
protected void |
updateHighlighterUI()
Updates highlighter after updateUI changes. |
protected void |
updateRendererEditorUI()
Quick fix for #1060-swingx: icons lost on toggling LAF |
void |
updateUI()
Notification from the UIManager that the L&F has changed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected CompoundHighlighter compoundHighlighter
protected ComponentAdapter dataAdapter
Constructor Detail |
---|
public JXTree()
JXTree
with a sample model. The default model
used by this tree defines a leaf node as any node without children.
public JXTree(Object[] value)
JXTree
with 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.
value
- an array of objects that are children of the root.public JXTree(Vector value)
JXTree
with 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.
value
- an Vector of objects that are children of the root.public JXTree(Hashtable value)
JXTree
created 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.
value
- a Hashtable containing objects that are children of the root.public JXTree(TreeNode root)
JXTree
with 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.
root
- root node of this treepublic JXTree(TreeNode root, boolean asksAllowsChildren)
JXTree
with 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.
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;DefaultTreeModel.asksAllowsChildren
public JXTree(TreeModel newModel)
JXTree
which 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.
newModel
- the TreeModel
to use as the data modelMethod Detail |
---|
protected TreeModelListener createTreeModelListener()
TreeModelHandler
.
The returned
object is responsible for updating the expanded state when the
TreeModel
changes.
For more information on what expanded state means, see the JTree description above.
createTreeModelListener
in class JTree
protected void doFind()
public Searchable getSearchable()
setSearchable(Searchable)
,
TreeSearchable
public void setSearchable(Searchable searchable)
searchable
- the Searchable to use for this component, may be null to
indicate using the default.getSearchable()
public String getStringAt(int row)
row
- the row index of the cell in view coordinates
public String getStringAt(TreePath path)
path
- the TreePath representing the node.
public void collapseAll()
public void expandAll()
public int[] getSelectionRows()
TreeSelectionModel
.
If nothing is selected null
or an empty array will
be returned, based on the TreeSelectionModel
implementation.
Overridden to always return a not-null array (following SwingX convention).
getSelectionRows
in class JTree
public TreePath[] getSelectionPaths()
Overridden to always return a not-null array (following SwingX convention).
getSelectionPaths
in class JTree
TreePath
objects indicating the selected
nodes, or null
if nothing is currently selectedpublic Color getSelectionBackground()
Color
used for the background of
selected list itemssetSelectionBackground(java.awt.Color)
,
setSelectionForeground(java.awt.Color)
public Color getSelectionForeground()
Color
object for the foreground propertysetSelectionForeground(java.awt.Color)
,
setSelectionBackground(java.awt.Color)
public void setSelectionForeground(Color selectionForeground)
The default value of this property is defined by the look and feel implementation.
This is a JavaBeans bound property.
selectionForeground
- the Color
to use in the foreground
for selected list itemsgetSelectionForeground()
,
setSelectionBackground(java.awt.Color)
,
JComponent.setForeground(java.awt.Color)
,
JComponent.setBackground(java.awt.Color)
,
JComponent.setFont(java.awt.Font)
public void setSelectionBackground(Color selectionBackground)
The default value of this property is defined by the look and feel implementation.
This is a JavaBeans bound property.
selectionBackground
- the Color
to use for the
background of selected cellsgetSelectionBackground()
,
setSelectionForeground(java.awt.Color)
,
JComponent.setForeground(java.awt.Color)
,
JComponent.setBackground(java.awt.Color)
,
JComponent.setFont(java.awt.Font)
public void updateUI()
UIManager
that the L&F has changed.
Replaces the current UI object with the latest version from the
UIManager
. Overridden to update selection background/foreground. Mimicking behaviour of ui-delegates for JTable, JList.
updateUI
in class JTree
JComponent.updateUI()
protected void updateRendererEditorUI()
protected void updateHighlighterUI()
updateUI
changes.
UIDependent
public void setRolloverEnabled(boolean rolloverEnabled)
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.
rolloverEnabled
- a boolean indicating whether or not the rollover
functionality should be enabled.isRolloverEnabled()
,
getLinkController()
,
createRolloverProducer()
,
RolloverRenderer
public boolean isRolloverEnabled()
setRolloverEnabled(boolean)
protected TreeRolloverController<JXTree> getLinkController()
PENDING JW: rename to getRolloverController
setRolloverEnabled(boolean)
,
createLinkController()
,
RolloverController
protected TreeRolloverController<JXTree> createLinkController()
getLinkController()
,
RolloverController
protected RolloverProducer createRolloverProducer()
RolloverProducer
to use with this treesetRolloverEnabled(boolean)
public void setHighlighters(Highlighter... highlighters)
Highlighter
s 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.
highlighters
- zero or more not null highlighters to use for renderer decoration.
NullPointerException
- if array is null or array contains null values.getHighlighters()
,
addHighlighter(Highlighter)
,
removeHighlighter(Highlighter)
public Highlighter[] getHighlighters()
Highlighter
s used by this table.
Maybe empty, but guarantees to be never null.
setHighlighters(Highlighter[])
public void addHighlighter(Highlighter highlighter)
Highlighter
to the end of the list of used
Highlighter
s. The argument must not be null.
highlighter
- the Highlighter
to add, must not be null.
NullPointerException
- if Highlighter
is null.removeHighlighter(Highlighter)
,
setHighlighters(Highlighter[])
public void removeHighlighter(Highlighter highlighter)
Does nothing if the Highlighter is not contained.
highlighter
- the Highlighter to remove.addHighlighter(Highlighter)
,
setHighlighters(Highlighter...)
protected CompoundHighlighter getCompoundHighlighter()
protected ChangeListener getHighlighterChangeListener()
ChangeListener
to use with highlighters. Lazily
creates the listener.
not-null
protected ChangeListener createHighlighterChangeListener()
Here: repaints the table on receiving a stateChanged.
public void setExpandedIcon(Icon expandedIcon)
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.
expandedIcon
- the Icon to use for the handle of an expanded node.public void setCollapsedIcon(Icon collapsedIcon)
collapsedIcon
- the Icon to use for the handle of a collapsed node.public void setLeafIcon(Icon leafIcon)
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.
leafIcon
- the Icon to use for a leaf node.public void setOpenIcon(Icon openIcon)
openIcon
- the Icon to use for an open folder node.public void setClosedIcon(Icon closedIcon)
closedIcon
- the Icon to use for a closed folder node.public void setOverwriteRendererIcons(boolean overwrite)
The default value is false. PENDING: should update the current renderer's icons when setting to true?
overwrite
- a boolean to indicate if the per-tree Icons should
be copied to the new renderer on setCellRenderer.isOverwriteRendererIcons()
,
setLeafIcon(Icon)
,
setOpenIcon(Icon)
,
setClosedIcon(Icon)
public boolean isOverwriteRendererIcons()
setOverwriteRendererIcons(boolean)
,
setLeafIcon(Icon)
,
setOpenIcon(Icon)
,
setClosedIcon(Icon)
protected TreeCellRenderer createDefaultCellRenderer()
This implementation returns a renderer of type
DefaultTreeCellRenderer
. Note: Will be changed to
return a renderer of type DefaultTreeRenderer
,
once WrappingProvider is reasonably stable.
public TreeCellRenderer getCellRenderer()
TreeCellRenderer
that is rendering each cell. 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
getCellRenderer
in class JTree
TreeCellRenderer
that is rendering each cellsetCellRenderer(TreeCellRenderer)
,
JXTree.DelegatingRenderer
public TreeCellRenderer getWrappedCellRenderer()
setCellRenderer(TreeCellRenderer)
public void setCellRenderer(TreeCellRenderer renderer)
TreeCellRenderer
that will be used to
draw each cell. 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
.
setCellRenderer
in class JTree
renderer
- the TreeCellRenderer
that is to render each cellgetWrappedCellRenderer()
,
getCellRenderer()
public void startEditingAtPath(TreePath path)
CellEditor
does not allow
editing for the specified item. 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.
startEditingAtPath
in class JTree
path
- the TreePath
identifying a nodeupdateEditorRemover()
protected void analyseFocus()
public void removeNotify()
removeNotify
in class JComponent
JComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)
public void setModel(TreeModel newModel)
TreeModel
that will provide the data. Overridden to initialize the String conversion method of the model, if any.
PENDING JW: remove - that is an outdated approach?
setModel
in class JTree
newModel
- the TreeModel
that is to provide the dataprotected ComponentAdapter getComponentAdapter()
protected ComponentAdapter getComponentAdapter(int index)
index
- the row index in view coordinates, must be valid.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |