dsto.dfc.swing.tree
Class DfcTree

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 dsto.dfc.swing.tree.DfcTree
All Implemented Interfaces:
CommandSource, CnpProvider, DragComponent, DragDropComponent, DropComponent, SelectionEventSource, Disposable, PropertyEventSource, ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class DfcTree
extends JTree
implements CommandSource, SelectionEventSource, CnpProvider, DragDropComponent, PropertyEventSource, Disposable

DFC'ified JTree, adding support for operations based on the extended DfcTreeModel. Includes support for:

Version:
$Revision$
Author:
Matthew
See Also:
DfcTreeModel, Serialized Form

Nested Class Summary
protected  class DfcTree.MyTreeCellEditor
          Extension of DefaultTreeCellEditor to support value-based icons used in MyTreeCellRenderer
protected  class DfcTree.MyTreeCellRenderer
          Extends default tree cell renderer to add support for Iconic values.
 
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
 
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
DfcTree()
           
DfcTree(TreeModel model)
           
 
Method Summary
 void addSelectedEntry(Object entry)
           
 void addSelectionListener(SelectionListener l)
           
 Transferable cnpCopy()
          Perform copy operation.
 Transferable cnpCut()
          Perform cut operation.
 boolean cnpPaste(Transferable transferable)
          Perform paste operation.
 int[] deleteRows(int[] rows)
          Delete a number of rows from the model, ensuring correct deletion order.
 void disableEditCommands()
           
 void dispose()
          Dispose of the object (unregister listeners, close open resources etc).
protected  void doExpandAll(TreePath path, int levelCount, Selector selector)
           
 void enableDragAndDrop()
           
 void enableEditCommands()
           
 void endDrag(DragSourceDropEvent e, boolean moveData)
           
 void executeDrop(DropTargetDropEvent e)
          Execute a drop action.
 void expandAll()
          Expand all nodes in the tree.
 void expandAll(int maxLevel)
          Expand all nodes in the tree up to a given level (eg level == 1 would expand only the root node).
 void expandAll(TreePath path)
          Expand all nodes in the tree starting from a given entry.
 void expandAll(TreePath path, int maxLevel)
          Expand all nodes in the tree from a given path up to a given level (eg level == 1 would expand only the entry itself, level == 2 would expand the entry and its children etc).
 void expandAll(TreePath path, int maxLevel, Selector selector)
          Expand all nodes in the tree from a given path up to a given level.
 void expandChildren(TreePath parentPath, Object[] children)
           
 boolean getCnpCommandsEnabled()
           
 CommandView getCommandView(String viewName)
          Get the command view instance for a given view name.
 DfcTreeModel getDfcTreeModel()
          If the current model is a DfcTreeModel return it, otherwise return null.
static Object[] getPathForEntry(TreeModel model, Object entry)
           
 List getSelectedEntries()
           
 Object getSelectedEntry()
           
 int getSupportedDragActions()
          Return a mask of possible drag actions supported by this component eg DnDConstants.ACTION_COPY_OR_MOVE.
 int getSupportedDropActions()
          Return a mask of actions supported by this component eg DnDConstants.ACTION_COPY_OR_MOVE.
 void hideDragUnderFeedback()
          Remove any drag under feedback displayed by showDragUnderFeedback ().
 boolean isCnpCopyEnabled()
          True if a copy operation is possible.
 boolean isCnpCutEnabled()
          True if a cut operation is possible.
 boolean isCnpPasteEnabled(Transferable transferable)
          True if a paste operation with a given transferable is possible.
 boolean isDragOK(DragGestureEvent e)
          Return true if starting a drag in the given context is possible.
 boolean isDropOK(DropTargetDragEvent e)
          Return true if a drop in the context in a DropTargetDragEvent is possible.
 void removeSelectionListener(SelectionListener l)
           
 void selectEntry(Object entry)
           
protected  void selectionChanged(TreeSelectionEvent e)
           
 void setCnpCommandsEnabled(boolean newValue)
           
 void setEditable(boolean flag)
           
 void setSelectedEntry(Object entry)
           
 void setSelectionModel(TreeSelectionModel newSelModel)
           
 void showDragUnderFeedback(boolean dropOK, DropTargetDragEvent e)
          Display any drag under (ie displayed under the mouse in the component) feedback.
 Transferable startDrag(DragGestureEvent e)
          Start a drag operation.
protected  void updateCnpEnabled()
           
 
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, 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, setCellRenderer, setDragEnabled, setDropMode, setExpandedState, setExpandsSelectedPaths, setInvokesStopCellEditing, setLargeModel, setLeadSelectionPath, setModel, setRootVisible, setRowHeight, setScrollsOnExpand, setSelectionInterval, 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, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, 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
 
Methods inherited from interface dsto.dfc.util.PropertyEventSource
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

DfcTree

public DfcTree()

DfcTree

public DfcTree(TreeModel model)
Method Detail

dispose

public void dispose()
Description copied from interface: Disposable
Dispose of the object (unregister listeners, close open resources etc). It should be safe to call this method more than once. Note for beans that support client event listeners: if there are listeners registered when this is called, this method should do nothing.

Specified by:
dispose in interface Disposable

enableDragAndDrop

public void enableDragAndDrop()

enableEditCommands

public void enableEditCommands()

disableEditCommands

public void disableEditCommands()

setCnpCommandsEnabled

public void setCnpCommandsEnabled(boolean newValue)

getCnpCommandsEnabled

public boolean getCnpCommandsEnabled()

setEditable

public void setEditable(boolean flag)
Overrides:
setEditable in class JTree

selectEntry

public void selectEntry(Object entry)

getDfcTreeModel

public DfcTreeModel getDfcTreeModel()
If the current model is a DfcTreeModel return it, otherwise return null.


setSelectionModel

public void setSelectionModel(TreeSelectionModel newSelModel)
Overrides:
setSelectionModel in class JTree

expandChildren

public void expandChildren(TreePath parentPath,
                           Object[] children)

expandAll

public void expandAll()
Expand all nodes in the tree.


expandAll

public void expandAll(int maxLevel)
Expand all nodes in the tree up to a given level (eg level == 1 would expand only the root node).


expandAll

public void expandAll(TreePath path)
Expand all nodes in the tree starting from a given entry.


expandAll

public void expandAll(TreePath path,
                      int maxLevel)
Expand all nodes in the tree from a given path up to a given level (eg level == 1 would expand only the entry itself, level == 2 would expand the entry and its children etc).


expandAll

public void expandAll(TreePath path,
                      int maxLevel,
                      Selector selector)
Expand all nodes in the tree from a given path up to a given level. Expansion can be further controlled by a selector.

Parameters:
path - The path to start expanding from.
maxLevel - The number of levels to expand (eg level == 1 would expand only the entry itself, level == 2 would expand the entry and its children etc).
selector - Only paths that are matched by this selector will be expanded. The matches () method of the selector is passed a TreePath instance.

doExpandAll

protected void doExpandAll(TreePath path,
                           int levelCount,
                           Selector selector)

deleteRows

public int[] deleteRows(int[] rows)
                 throws UnsupportedOperationException
Delete a number of rows from the model, ensuring correct deletion order.

Parameters:
rows - The rows to delete.
Returns:
The rows in the reverse order to which they were deleted.
Throws:
UnsupportedOperationException - if the current model is not a DfcTreeModel or if the model vetoed a delete operation.

getSelectedEntry

public Object getSelectedEntry()

setSelectedEntry

public void setSelectedEntry(Object entry)

addSelectedEntry

public void addSelectedEntry(Object entry)

getSelectedEntries

public List getSelectedEntries()

getPathForEntry

public static Object[] getPathForEntry(TreeModel model,
                                       Object entry)

addSelectionListener

public void addSelectionListener(SelectionListener l)
Specified by:
addSelectionListener in interface SelectionEventSource

removeSelectionListener

public void removeSelectionListener(SelectionListener l)
Specified by:
removeSelectionListener in interface SelectionEventSource

getCommandView

public CommandView getCommandView(String viewName)
Description copied from interface: CommandSource
Get the command view instance for a given view name.

Specified by:
getCommandView in interface CommandSource
Parameters:
viewName - The name of the view to be retrieved. Usually one of CommandView.MAIN_MENU_VIEW, CommandView.CONTEXT_MENU_VIEW or CommandView.TOOLBAR_VIEW, but custom views may be supported also.
Returns:
The command view instance or null if view is not defined.

isCnpCopyEnabled

public boolean isCnpCopyEnabled()
Description copied from interface: CnpProvider
True if a copy operation is possible. Implementors of this method who also implement PropertyEventSource are assumed to provide property change notification.

Specified by:
isCnpCopyEnabled in interface CnpProvider

isCnpCutEnabled

public boolean isCnpCutEnabled()
Description copied from interface: CnpProvider
True if a cut operation is possible. Implementors of this method who also implement PropertyEventSource are assumed to provide property change notification.

Specified by:
isCnpCutEnabled in interface CnpProvider

isCnpPasteEnabled

public boolean isCnpPasteEnabled(Transferable transferable)
Description copied from interface: CnpProvider
True if a paste operation with a given transferable is possible.

Specified by:
isCnpPasteEnabled in interface CnpProvider

cnpCopy

public Transferable cnpCopy()
                     throws UnsupportedOperationException,
                            CloneNotSupportedException
Description copied from interface: CnpProvider
Perform copy operation.

Specified by:
cnpCopy in interface CnpProvider
Returns:
Copied transferable or null if nothing is available to be copied (eg because there is nothing selected)
Throws:
UnsupportedOperationException - if copy operation not supported.
CloneNotSupportedException - if the data could not be cloned.

cnpCut

public Transferable cnpCut()
                    throws UnsupportedOperationException,
                           CloneNotSupportedException
Description copied from interface: CnpProvider
Perform cut operation.

Specified by:
cnpCut in interface CnpProvider
Returns:
Cut transferable or null if nothing is available to be cut (eg because there is nothing selected)
Throws:
UnsupportedOperationException - if cut operation not supported.
CloneNotSupportedException - if the data could not be cloned.

cnpPaste

public boolean cnpPaste(Transferable transferable)
                 throws UnsupportedOperationException,
                        UnsupportedFlavorException,
                        CloneNotSupportedException,
                        IOException
Description copied from interface: CnpProvider
Perform paste operation.

Specified by:
cnpPaste in interface CnpProvider
Parameters:
transferable - The data to be pasted.
Returns:
True is transferable was pasted, false if not (eg because there is no selection to define where pasted item goes).
Throws:
UnsupportedOperationException - if paste operation not supported.
UnsupportedFlavorException - if transferable does not contain a supported data flavor for pasting.
CloneNotSupportedException - if the data could not be cloned.
IOException - if IO exception occurs during data transfer.

updateCnpEnabled

protected final void updateCnpEnabled()

getSupportedDragActions

public int getSupportedDragActions()
Description copied from interface: DragComponent
Return a mask of possible drag actions supported by this component eg DnDConstants.ACTION_COPY_OR_MOVE. Note that the component may veto any particular drag attempt from DragComponent.isDragOK(java.awt.dnd.DragGestureEvent).

Specified by:
getSupportedDragActions in interface DragComponent

getSupportedDropActions

public int getSupportedDropActions()
Description copied from interface: DropComponent
Return a mask of actions supported by this component eg DnDConstants.ACTION_COPY_OR_MOVE. Note that the component may veto any particular drop attempt from DropComponent.isDropOK(java.awt.dnd.DropTargetDragEvent).

Specified by:
getSupportedDropActions in interface DropComponent

isDragOK

public boolean isDragOK(DragGestureEvent e)
Description copied from interface: DragComponent
Return true if starting a drag in the given context is possible.

Specified by:
isDragOK in interface DragComponent
Parameters:
e - The drag context.

startDrag

public Transferable startDrag(DragGestureEvent e)
Description copied from interface: DragComponent
Start a drag operation.

Specified by:
startDrag in interface DragComponent
Parameters:
e - The gesture that started the drag.
Returns:
The transferable data, or null if no data available.

endDrag

public void endDrag(DragSourceDropEvent e,
                    boolean moveData)
Specified by:
endDrag in interface DragComponent

isDropOK

public boolean isDropOK(DropTargetDragEvent e)
Description copied from interface: DropComponent
Return true if a drop in the context in a DropTargetDragEvent is possible.

Specified by:
isDropOK in interface DropComponent
Parameters:
e - The drop context.

executeDrop

public void executeDrop(DropTargetDropEvent e)
Description copied from interface: DropComponent
Execute a drop action.

Specified by:
executeDrop in interface DropComponent

showDragUnderFeedback

public void showDragUnderFeedback(boolean dropOK,
                                  DropTargetDragEvent e)
Description copied from interface: DropComponent
Display any drag under (ie displayed under the mouse in the component) feedback.

Specified by:
showDragUnderFeedback in interface DropComponent
Parameters:
dropOK - The value of isDropOK () when the mouse first entered the component.
e - The drop context.

hideDragUnderFeedback

public void hideDragUnderFeedback()
Description copied from interface: DropComponent
Remove any drag under feedback displayed by showDragUnderFeedback ().

Specified by:
hideDragUnderFeedback in interface DropComponent

selectionChanged

protected void selectionChanged(TreeSelectionEvent e)


Copyright © 2008 Commonwealth of Australia