JComponentPack 1.5.0

com.zfqjava.swing
Class XTree

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTree
                  extended by com.zfqjava.swing.XTree
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class XTree
extends JTree
implements Accessible

XTree provides a JTree expends component, provides inheritance selection mode.
Note:
Since XTree is compitable with JTree at API level, use it just replace JTree with XTree.

Since:
JDirChooser 1.2
See Also:
Serialized Form

Nested Class Summary
protected  class XTree.AccessibleXTree
          This class implements accessibility support for the XTree class.
 
Nested classes/interfaces inherited from class javax.swing.JTree
JTree.AccessibleJTree, JTree.DropLocation, 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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int CONTIGUOUS_TREE_SELECTION
          Selection can only be contiguous.
static int DISCONTIGUOUS_TREE_SELECTION
          Selection can contain any number of items that are not necessarily contiguous.
static int INHERITANCE_TREE_SELECTION
          Selection can inherited from parent node.
static int SINGLE_TREE_SELECTION
          Selection can only contain one path at a time.
 
Fields inherited from class javax.swing.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, visibleRowCount
 
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
XTree()
          Returns a XTree with a sample model.
XTree(Hashtable value)
          Returns a XTree created from a Hashtable which does not display with root.
XTree(Object[] value)
          Returns a XTree with each element of the specified array as the child of a new root node which is not displayed.
XTree(TreeModel newModel)
          Returns an instance of XTree which displays the root node -- the tree is created using the specified data model.
XTree(TreeNode root)
          Returns a XTree with the specified TreeNode as its root, which displays the root node.
XTree(TreeNode root, boolean asksAllowsChildren)
          Returns a XTree 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.
XTree(Vector value)
          Returns a XTree with each element of the specified Vector as the child of a new root node which is not displayed.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Adds a ChangeListener to this cardpane.
 void clearSelection()
          Clears the selection.
protected  void fireStateChanged()
          Sends a ChangeEvent, whose source is this cardpane, to each listener.
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this XTree.
 ChangeListener[] getChangeListeners()
          Returns an array of all the ChangeListeners added to this JCardpane with addChangeListener.
 TreeCellEditor getRealCellEditor()
          Returns the real cell editor.
 TreeCellRenderer getRealCellRenderer()
          Returns the real cell renderer.
 TreePath[] getSelection()
          Returns the paths of all selected values.
 int getSelectionMode()
          Returns the tree selection mode.
 Point getToolTipLocation(MouseEvent event)
           
 String getToolTipText(MouseEvent event)
           
 boolean isSelectionEmpty()
          Returns true if the selection is currently empty.
protected  String paramString()
          Returns a string representation of this XTree.
 void removeChangeListener(ChangeListener l)
          Removes a ChangeListener from this cardpane.
 void setRealCellEditor(TreeCellEditor cellEditor)
          Sets the cell editor.
 void setRealCellRenderer(TreeCellRenderer x)
          Sets the TreeCellRenderer that will be used to draw each cell.
 void setSelection(TreePath[] paths)
          Selects the nodes identified by the specified array of paths.
 void setSelectionMode(int mode)
          Sets the tree selection mode.
 
Methods inherited from class javax.swing.JTree
addSelectionInterval, addSelectionPath, addSelectionPaths, addSelectionRow, addSelectionRows, addTreeExpansionListener, addTreeSelectionListener, addTreeWillExpandListener, cancelEditing, clearToggledPaths, collapsePath, collapseRow, convertValueToText, createTreeModel, createTreeModelListener, expandPath, expandRow, fireTreeCollapsed, fireTreeExpanded, fireTreeWillCollapse, fireTreeWillExpand, fireValueChanged, getAnchorSelectionPath, getCellEditor, getCellRenderer, getClosestPathForLocation, getClosestRowForLocation, getDefaultTreeModel, getDescendantToggledPaths, getDragEnabled, getDropLocation, getDropMode, getEditingPath, getExpandedDescendants, getExpandsSelectedPaths, getInvokesStopCellEditing, getLastSelectedPathComponent, getLeadSelectionPath, getLeadSelectionRow, getMaxSelectionRow, getMinSelectionRow, getModel, getNextMatch, getPathBetweenRows, getPathBounds, getPathForLocation, getPathForRow, getPreferredScrollableViewportSize, getRowBounds, getRowCount, getRowForLocation, getRowForPath, getRowHeight, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollsOnExpand, getSelectionCount, getSelectionModel, getSelectionPath, getSelectionPaths, getSelectionRows, getShowsRootHandles, getToggleClickCount, getTreeExpansionListeners, getTreeSelectionListeners, getTreeWillExpandListeners, getUI, getUIClassID, getVisibleRowCount, hasBeenExpanded, isCollapsed, isCollapsed, isEditable, isEditing, isExpanded, isExpanded, isFixedRowHeight, isLargeModel, isPathEditable, isPathSelected, isRootVisible, isRowSelected, isVisible, makeVisible, removeDescendantSelectedPaths, removeDescendantToggledPaths, removeSelectionInterval, removeSelectionPath, removeSelectionPaths, removeSelectionRow, removeSelectionRows, removeTreeExpansionListener, removeTreeSelectionListener, removeTreeWillExpandListener, scrollPathToVisible, scrollRowToVisible, setAnchorSelectionPath, setCellEditor, setCellRenderer, setDragEnabled, setDropMode, setEditable, setExpandedState, setExpandsSelectedPaths, setInvokesStopCellEditing, setLargeModel, setLeadSelectionPath, setModel, setRootVisible, setRowHeight, setScrollsOnExpand, setSelectionInterval, setSelectionModel, setSelectionPath, setSelectionPaths, setSelectionRow, setSelectionRows, setShowsRootHandles, setToggleClickCount, setUI, setVisibleRowCount, startEditingAtPath, stopEditing, treeDidChange, updateUI
 
Methods inherited from class javax.swing.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, 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, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, 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, 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

SINGLE_TREE_SELECTION

public static final int SINGLE_TREE_SELECTION
Selection can only contain one path at a time.

See Also:
Constant Field Values

CONTIGUOUS_TREE_SELECTION

public static final int CONTIGUOUS_TREE_SELECTION
Selection can only be contiguous. This will only be enforced if a RowMapper instance is provided. That is, if no RowMapper is set this behaves the same as DISCONTIGUOUS_TREE_SELECTION.

See Also:
Constant Field Values

DISCONTIGUOUS_TREE_SELECTION

public static final int DISCONTIGUOUS_TREE_SELECTION
Selection can contain any number of items that are not necessarily contiguous.

See Also:
Constant Field Values

INHERITANCE_TREE_SELECTION

public static final int INHERITANCE_TREE_SELECTION
Selection can inherited from parent node. Use JTree.getSelectionPaths() gets current selection.

See Also:
Constant Field Values
Constructor Detail

XTree

public XTree()
Returns a XTree with a sample model. The default model used by the tree defines a leaf node as any node without children.

See Also:
DefaultTreeModel.asksAllowsChildren

XTree

public XTree(Object[] value)
Returns a XTree with each element of the specified array as the child of a new root node which is not displayed. By default, the tree defines a leaf node as any node without children.

Parameters:
value - an array of Objects
See Also:
DefaultTreeModel.asksAllowsChildren

XTree

public XTree(Vector value)
Returns a XTree with each element of the specified Vector as the child of a new root node which is not displayed. By default, the tree defines a leaf node as any node without children.

Parameters:
value - a Vector
See Also:
DefaultTreeModel.asksAllowsChildren

XTree

public XTree(Hashtable value)
Returns a XTree 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.

Parameters:
value - a Hashtable
See Also:
DefaultTreeModel.asksAllowsChildren

XTree

public XTree(TreeNode root)
Returns a XTree 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.

Parameters:
root - a TreeNode object
See Also:
DefaultTreeModel.asksAllowsChildren

XTree

public XTree(TreeNode root,
             boolean asksAllowsChildren)
Returns a XTree 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.

Parameters:
root - a TreeNode object
asksAllowsChildren - if false, any node without children is a leaf node; if true, only nodes that do not allow children are leaf nodes
See Also:
DefaultTreeModel.asksAllowsChildren

XTree

public XTree(TreeModel newModel)
Returns an instance of XTree which displays the root node -- the tree is created using the specified data model.

Parameters:
newModel - the TreeModel to use as the data model
Method Detail

getToolTipText

public String getToolTipText(MouseEvent event)
Overrides:
getToolTipText in class JTree

getToolTipLocation

public Point getToolTipLocation(MouseEvent event)
Overrides:
getToolTipLocation in class JComponent

setSelectionMode

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

Parameters:
mode - the tree selection mdoe, one of 4 legal values:
  • XTree.SINGLE_TREE_SELECTION
  • XTree.CONTIGUOUS_TREE_SELECTION
  • XTree.DISCONTIGUOUS_TREE_SELECTION
  • XTree.INHERITANCE_TREE_SELECTION

getSelectionMode

public int getSelectionMode()
Returns the tree selection mode.

Returns:
the tree selection mode, one of 4 legal values:
  • XTree.SINGLE_TREE_SELECTION
  • XTree.CONTIGUOUS_TREE_SELECTION
  • XTree.DISCONTIGUOUS_TREE_SELECTION
  • XTree.INHERITANCE_TREE_SELECTION

clearSelection

public void clearSelection()
Clears the selection.

Overrides:
clearSelection in class JTree

isSelectionEmpty

public boolean isSelectionEmpty()
Returns true if the selection is currently empty.

Overrides:
isSelectionEmpty in class JTree
Returns:
true if the selection is currently empty

getSelection

public TreePath[] getSelection()
Returns the paths of all selected values.

Returns:
an array of TreePath objects indicating the selected nodes, or null if nothing is currently selected

setSelection

public void setSelection(TreePath[] paths)
Selects the nodes identified by the specified array of paths. If any component in any of the paths is hidden (under a collapsed node), and getExpandsSelectedPaths is true it is exposed (made viewable).

Parameters:
paths - an array of TreePath objects that specifies the nodes to select

setRealCellRenderer

public void setRealCellRenderer(TreeCellRenderer x)
Sets the TreeCellRenderer that will be used to draw each cell.

Parameters:
x - the TreeCellRenderer that is to render each cell

getRealCellRenderer

public TreeCellRenderer getRealCellRenderer()
Returns the real cell renderer.

Returns:
the real cell renderer
See Also:
setRealCellRenderer(javax.swing.tree.TreeCellRenderer)

setRealCellEditor

public void setRealCellEditor(TreeCellEditor cellEditor)
Sets the cell editor. A null value implies that the tree cannot be edited. If this represents a change in the cellEditor, the propertyChange method is invoked on all listeners.

Parameters:
cellEditor - the TreeCellEditor to use

getRealCellEditor

public TreeCellEditor getRealCellEditor()
Returns the real cell editor.

Returns:
the real cell editor
See Also:
setRealCellEditor

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a ChangeListener to this cardpane.

Parameters:
l - the ChangeListener to add
See Also:
fireStateChanged(), removeChangeListener(javax.swing.event.ChangeListener)

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from this cardpane.

Parameters:
l - the ChangeListener to remove
See Also:
fireStateChanged(), addChangeListener(javax.swing.event.ChangeListener)

getChangeListeners

public ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners added to this JCardpane with addChangeListener.

Returns:
all of the ChangeListeners added or an empty array if no listeners have been added

fireStateChanged

protected void fireStateChanged()
Sends a ChangeEvent, whose source is this cardpane, to each listener. This method method is called each time a ChangeEvent is received from the model.

See Also:
addChangeListener(javax.swing.event.ChangeListener), EventListenerList

paramString

protected String paramString()
Returns a string representation of this XTree. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overrides:
paramString in class JTree
Returns:
a string representation of this XTree.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this XTree. For XTrees, the AccessibleContext takes the form of an AccessibleXTree. A new AccessibleXTree instance is created if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JTree
Returns:
an AccessibleXTree that serves as the AccessibleContext of this XTree

JComponentPack 1.5.0

Send your Feedback
JComponentPack 1.5.0
Copyright © 2001-2007 Extreme Component, Inc. All rights reserved.