org.formaria.swing
Class Tree

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 org.formaria.swing.Tree
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.TreeSelectionListener, javax.swing.Scrollable, ErrorDisplay, ListenerHelper, StyleComponent

public class Tree
extends javax.swing.JTree
implements javax.swing.event.TreeSelectionListener, ListenerHelper, StyleComponent, java.awt.event.MouseListener, ErrorDisplay

A tree control, wraps JTree

Copyright (c) Formaria Ltd.,
License: see license.txt $Revision: 2.4 $

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTree
javax.swing.JTree.AccessibleJTree, javax.swing.JTree.DropLocation, javax.swing.JTree.DynamicUtilTreeNode, javax.swing.JTree.EmptySelectionModel, javax.swing.JTree.TreeModelHandler, javax.swing.JTree.TreeSelectionRedirector
 
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  java.lang.String errorMessage
           
protected  int errorStatus
           
 
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
Tree()
          Create a new JTree component
 
Method Summary
 void addHandler(java.lang.Object page, java.lang.String handlerType, java.lang.String methodName)
          Add an event handler response method to a component such that the page's response method is invoked when the event occurs
 javax.swing.JToolTip createToolTip()
           
 void expandAll(boolean expand, int levels)
          Expand the tree
 void expandAll(boolean expand, int levels, javax.swing.tree.TreeNode startNode)
          Expand the tree
 void expandAll(javax.swing.tree.TreePath parent, boolean expand, int levels)
           
 javax.swing.tree.TreePath findNearestPath(javax.swing.tree.TreePath tp)
          Find the nearest tree path in the current tree model.
 DataModel getSelectedNode()
          Get the selected model node.
 java.lang.String getStyleName()
          Get the style name
 java.lang.String getToolTip()
          Get the tooltip text
 java.lang.String getToolTipText(java.awt.event.MouseEvent me)
           
 void mouseClicked(java.awt.event.MouseEvent me)
          Allow a mouse event to trigger the event if it is the same as the last selection.
 void mouseEntered(java.awt.event.MouseEvent me)
          A mouse event
 void mouseExited(java.awt.event.MouseEvent me)
          A mouse event
 void mousePressed(java.awt.event.MouseEvent me)
          A mouse event
 void mouseReleased(java.awt.event.MouseEvent me)
          A mouse event
 void paint(java.awt.Graphics g)
          Paint the component, rendering the error badge if necessary
 void setCustomToolTip(java.lang.String clsName)
          Set the class for rendering teh tooltip
 void setDragEnabled(boolean state)
          Setup drag and drop support
 void setDrawBorder(java.lang.String value)
          Set the border style
 void setErrorMessage(java.lang.String errorMsg)
          Set the error message
 void setErrorStatus(int status)
          Set the error status
 void setRenderer(java.lang.String className)
          Set the tree cell renderer.
 void setStyle(java.lang.String style)
          Set the tree style name
 void setToolTip(java.lang.String text)
          Set the tooltip text
 void valueChanged(javax.swing.event.TreeSelectionEvent e)
          Called whenever the value of the selection changes.
 
Methods inherited from class javax.swing.JTree
addSelectionInterval, addSelectionPath, addSelectionPaths, addSelectionRow, addSelectionRows, addTreeExpansionListener, addTreeSelectionListener, addTreeWillExpandListener, cancelEditing, clearSelection, clearToggledPaths, collapsePath, collapseRow, convertValueToText, createTreeModel, createTreeModelListener, expandPath, expandRow, fireTreeCollapsed, fireTreeExpanded, fireTreeWillCollapse, fireTreeWillExpand, fireValueChanged, getAccessibleContext, 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, isSelectionEmpty, isVisible, makeVisible, paramString, removeDescendantSelectedPaths, removeDescendantToggledPaths, removeSelectionInterval, removeSelectionPath, removeSelectionPaths, removeSelectionRow, removeSelectionRows, removeTreeExpansionListener, removeTreeSelectionListener, removeTreeWillExpandListener, scrollPathToVisible, scrollRowToVisible, setAnchorSelectionPath, setCellEditor, setCellRenderer, 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, 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, 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

errorStatus

protected int errorStatus

errorMessage

protected java.lang.String errorMessage
Constructor Detail

Tree

public Tree()
Create a new JTree component

Method Detail

setToolTip

public void setToolTip(java.lang.String text)
Set the tooltip text

Parameters:
text - the new text

getToolTip

public java.lang.String getToolTip()
Get the tooltip text

Returns:
the existing text if any

setDrawBorder

public void setDrawBorder(java.lang.String value)
Set the border style

Parameters:
"0" - for no border

setRenderer

public void setRenderer(java.lang.String className)
Set the tree cell renderer. The renderer should be set prior to any rendering of the component.

Parameters:
className - the full clas name

valueChanged

public void valueChanged(javax.swing.event.TreeSelectionEvent e)
Called whenever the value of the selection changes.

Specified by:
valueChanged in interface javax.swing.event.TreeSelectionListener
Parameters:
e - the event that characterizes the change.

getSelectedNode

public DataModel getSelectedNode()
Get the selected model node.

Returns:
the selection

addHandler

public void addHandler(java.lang.Object page,
                       java.lang.String handlerType,
                       java.lang.String methodName)
                throws java.lang.NoSuchMethodException
Add an event handler response method to a component such that the page's response method is invoked when the event occurs

Specified by:
addHandler in interface ListenerHelper
Parameters:
page - the page containing the method
handlerType - the type of event handler
methodName - the method to invoke
Throws:
java.lang.NoSuchMethodException - Couldn't set the handler

setStyle

public void setStyle(java.lang.String style)
Set the tree style name

Specified by:
setStyle in interface StyleComponent
Parameters:
style - the style name

getStyleName

public java.lang.String getStyleName()
Get the style name

Returns:
the style name

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent me)
A mouse event

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
me - the mouse event

mouseExited

public void mouseExited(java.awt.event.MouseEvent me)
A mouse event

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
me - the mouse event

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent me)
Allow a mouse event to trigger the event if it is the same as the last selection. In other cases the tree selection listener will handle the event, changes the selection

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
me - teh mouse event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent me)
A mouse event

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
me - the mouse event

mousePressed

public void mousePressed(java.awt.event.MouseEvent me)
A mouse event

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
me - the mouse event

setDragEnabled

public void setDragEnabled(boolean state)
Setup drag and drop support

Overrides:
setDragEnabled in class javax.swing.JTree
Parameters:
state - true to enable drag and drop support

findNearestPath

public javax.swing.tree.TreePath findNearestPath(javax.swing.tree.TreePath tp)
Find the nearest tree path in the current tree model. The method is designed for use when a tree is refreshed with a new or updated model that references the same objects. The tree nodes and tree paths will be different in then revised model and therefore the tree methods that rely on tree paths saved prior to the update will fail to find the equivalent objects. This method descends the tree attempting to find the new paths that reference the same (equals) objects. The search will stop if when the first element in the path is not found.

Parameters:
tp - the old path
Returns:
the new path or tp if none was found, or if the path is unchanged.

expandAll

public void expandAll(boolean expand,
                      int levels)
Expand the tree

Parameters:
expand - true to expand, false to collapse
levels - the number of levels to expand, or -1 for all levels

expandAll

public void expandAll(boolean expand,
                      int levels,
                      javax.swing.tree.TreeNode startNode)
Expand the tree

Parameters:
expand - true to expand, false to collapse
levels - the number of levels to expand, or -1 for all levels

expandAll

public void expandAll(javax.swing.tree.TreePath parent,
                      boolean expand,
                      int levels)

createToolTip

public javax.swing.JToolTip createToolTip()
Overrides:
createToolTip in class javax.swing.JComponent

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent me)
Overrides:
getToolTipText in class javax.swing.JTree

setCustomToolTip

public void setCustomToolTip(java.lang.String clsName)
Set the class for rendering teh tooltip

Parameters:
clsName -

paint

public void paint(java.awt.Graphics g)
Paint the component, rendering the error badge if necessary

Overrides:
paint in class javax.swing.JComponent
Parameters:
g -

setErrorStatus

public void setErrorStatus(int status)
Set the error status

Specified by:
setErrorStatus in interface ErrorDisplay
Parameters:
status -

setErrorMessage

public void setErrorMessage(java.lang.String errorMsg)
Set the error message

Specified by:
setErrorMessage in interface ErrorDisplay
Parameters:
errorMsg - the message text