edu.rice.cs.util.docnavigation
Class JTreeSortNavigator<ItemT extends INavigatorItem>

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 edu.rice.cs.util.docnavigation.JTreeSortNavigator<ItemT>
All Implemented Interfaces:
IAWTContainerNavigatorActor, IDocumentNavigator<ItemT>, DropTargetListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, TreeExpansionListener, TreeSelectionListener, Scrollable

public class JTreeSortNavigator<ItemT extends INavigatorItem>
extends JTree
implements IDocumentNavigator<ItemT>, TreeSelectionListener, TreeExpansionListener, DropTargetListener

See Also:
Serialized Form

Nested Class Summary
private  class JTreeSortNavigator.CustomTreeCellRenderer
          The cell renderer for this tree.
 
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
private  NodeData<ItemT> _current
          The currently selected item.
private  DisplayManager<? super ItemT> _displayManager
           
private  HashMap<ItemT,LeafNode<ItemT>> _doc2node
          Maps documents to tree nodes.
private  NodeDataVisitor<ItemT,ItemT> _leafVisitor
           
private  DefaultTreeModel _model
          The model of the tree.
private  OneToOneRelation<String,InnerNode<?,ItemT>> _path2node
          Maps path's to nodes and nodes to paths.
private  JTreeSortNavigator.CustomTreeCellRenderer _renderer
          The renderer for this JTree.
private  Icon _rootIcon
           
private  List<GroupNode<ItemT>> _roots
           
(package private)  DropTarget dropTarget
          Drag and drop target.
private  ArrayList<INavigationListener<? super ItemT>> navListeners
          The collection of INavigationListeners listening to this JListNavigator
 
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 edu.rice.cs.util.docnavigation.IDocumentNavigator
MODEL_INITIATED_PROPERTY_NAME
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JTreeSortNavigator(String projRoot)
          Standard constructor.
JTreeSortNavigator(String projRoot, DisplayManager<? super ItemT> dm)
          Alternate constructor specifying the display manager that provides icons for the navigator.
 
Method Summary
 boolean _contains(ItemT doc)
          Tests to see if a given document is contained in this navigator.
 void addDocument(ItemT doc)
          Adds an IDocument to this navigator.
 void addDocument(ItemT doc, String path)
          Adds an INavigatorItem to this navigator in the specified position.
 void addNavigationListener(INavigationListener<? super ItemT> listener)
          Adds an INavigationListener to this navigator.
 void addTopLevelGroup(String name, INavigatorItemFilter<? super ItemT> f)
          Adds a top level group to the navigator.
private  void addTopLevelGroupToRoot(InnerNode<?,ItemT> parent)
           
 Container asContainer()
           
private  void cleanFolderNode(DefaultMutableTreeNode node)
          If the given node is an InnerNode with no children, it removes it from the tree.
 void clear()
          Removes all IDocuments from this IDocumentNavigator.
(package private)  void collapsePaths(HashSet<String> paths)
          Set variation of collapsePaths(String ...).
 void collapsePaths(String[] paths)
          Collapses all the paths in the tree that match one of the path strings included in the given hash set.
 boolean contains(ItemT doc)
          Tests to see if a given document is contained in this navigator.
 void dragEnter(DropTargetDragEvent dropTargetDragEvent)
          User dragged something into the component.
 void dragExit(DropTargetEvent dropTargetEvent)
           
 void dragOver(DropTargetDragEvent dropTargetDragEvent)
           
 void drop(DropTargetDropEvent dropTargetDropEvent)
          User dropped something on the component.
 void dropActionChanged(DropTargetDragEvent dropTargetDragEvent)
           
<InType,ReturnType>
ReturnType
execute(IDocumentNavigatorAlgo<ItemT,InType,ReturnType> algo, InType input)
          Standard visitor pattern.
 String generatePathString(TreePath tp)
          Generates a path string for the given tree node.
 String[] getCollapsedPaths()
           
 ItemT getCurrent()
          Returns the currently selected leaf node, or null if the selected node is not a leaf.
 int getDocumentCount()
          Returns the number of IDocuments contained by this IDocumentNavigator Not synchronized on the assumption that size field of a HashMap always has a legitimate value (either the size of the current state or the size of its state before some concurrent operation started.
 ArrayList<ItemT> getDocuments()
          Returns all the IDocuments contained in this navigator.
 int getDocumentSelectedCount()
           
 ArrayList<ItemT> getDocumentsInBin(String binName)
          Returns all the IDocuments contained in the specified bin.
 ItemT getFirst()
          Returns the first document in the collection (using enumeration order).
 int getGroupSelectedCount()
           
 ItemT getLast()
          Returns the last document in the collection (using enumeration order).
 Object getModelLock()
          Returns the model lock.
 Set<String> getNamesOfSelectedTopLevelGroup()
          Returns the names of the top level groups that the selected items descend from.
 Collection<INavigationListener<? super ItemT>> getNavigatorListeners()
          Returns a collection of all navigator listeners.
 ItemT getNext(ItemT doc)
          Returns the next document in the collection (using enumeration order).
private  LeafNode<ItemT> getNodeForDoc(ItemT doc)
          Assumes lock on _model is already held or that it is being run in the event thread.
private  ItemT getNodeUserObject(DefaultMutableTreeNode n)
          Returns a typed equivalent to next.getUserObject().
 ItemT getPrevious(ItemT doc)
          Returns the previous document in the collection (using enumeration order).
 Component getRenderer()
          Returns a renderer for this object.
 List<ItemT> getSelectedDocuments()
           
 List<File> getSelectedFolders()
           
private  void insertFolderSortedInto(InnerNode<?,ItemT> child, InnerNode<?,ItemT> parent)
          Inserts a folder (String) into sorted position under the parent.
private  void insertNodeSortedInto(LeafNode<ItemT> child, InnerNode<?,ItemT> parent)
          Inserts the child node (INavigatorItem) into the sorted position as a parent node's child.
 boolean isDocumentSelected()
           
 boolean isEmpty()
          Returns whether this IDocumentNavigator contains any IDocuments.
 boolean isGroupSelected()
           
 boolean isNextChangeModelInitiated()
           
 boolean isRootSelected()
          Returns true if the root is selected.
 boolean isSelectedAt(int x, int y)
          Returns true if the item at the x,y coordinate of the navigator pane is currently selected.
 boolean isSelectedInGroup(ItemT i)
           
 boolean isTopLevelGroupSelected()
          Returns true if at least one top level group is selected.
 void refreshDocument(ItemT doc, String path)
          Resets a given INavigatorItem in the tree.
 ItemT removeDocument(ItemT doc)
          Removes a given INavigatorItem from this navigator.
 void removeNavigationListener(INavigationListener<? super ItemT> listener)
          Removes the given listener from observing this navigator.
private  ItemT removeNode(LeafNode<ItemT> node)
          Only takes in nodes that have an INavigatorItem as their object; assumes _model lock is already held.
 void requestSelectionUpdate(ItemT ini)
          If the currently selected item is not an INavigatorItem, select the one given.
 void selectDocument(ItemT doc)
          Sets the specified document to be active (current).
 boolean selectDocumentAt(int x, int y)
          Selects the document at the x,y coordinate of the navigator pane and installs it as the active document.
 void setBackground(Color c)
          Sets the background color of this tree
 void setDisplayManager(DisplayManager<? super ItemT> manager)
          Sets the display manager that is used to select icons for the leaves of the tree.
 void setForeground(Color c)
          Sets the foreground color of this JTree
 void setNextChangeModelInitiated(boolean b)
          Marks the next selection change as model-initiated (true) or user-initiated (false; default).
 void setRootIcon(Icon ico)
          Sets the icon to be displayed at the root of the tree
 void treeCollapsed(TreeExpansionEvent event)
          Called whenever an item in the tree has been collapsed.
 void treeExpanded(TreeExpansionEvent event)
          Called whenever an item in the tree has been expanded.
 void valueChanged(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, 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, 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, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, 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 edu.rice.cs.util.docnavigation.IDocumentNavigator
addFocusListener, getFocusListeners, getSelectionCount, removeFocusListener, repaint
 

Field Detail

_model

private final DefaultTreeModel _model
The model of the tree.


_current

private volatile NodeData<ItemT extends INavigatorItem> _current
The currently selected item. Updated by a listener. It is not volatile because all accessed are protected by explicit synchronization.


_doc2node

private final HashMap<ItemT extends INavigatorItem,LeafNode<ItemT extends INavigatorItem>> _doc2node
Maps documents to tree nodes.


_path2node

private final OneToOneRelation<String,InnerNode<?,ItemT extends INavigatorItem>> _path2node
Maps path's to nodes and nodes to paths.


navListeners

private final ArrayList<INavigationListener<? super ItemT extends INavigatorItem>> navListeners
The collection of INavigationListeners listening to this JListNavigator


_renderer

private final JTreeSortNavigator.CustomTreeCellRenderer _renderer
The renderer for this JTree.


_displayManager

private volatile DisplayManager<? super ItemT extends INavigatorItem> _displayManager

_rootIcon

private volatile Icon _rootIcon

_roots

private List<GroupNode<ItemT extends INavigatorItem>> _roots

_leafVisitor

private final NodeDataVisitor<ItemT extends INavigatorItem,ItemT extends INavigatorItem> _leafVisitor

dropTarget

DropTarget dropTarget
Drag and drop target.

Constructor Detail

JTreeSortNavigator

public JTreeSortNavigator(String projRoot)
Standard constructor.

Parameters:
projRoot - the path identifying the root node for the project

JTreeSortNavigator

public JTreeSortNavigator(String projRoot,
                          DisplayManager<? super ItemT> dm)
Alternate constructor specifying the display manager that provides icons for the navigator.

Parameters:
projRoot - the path identifying the root node for the project
dm - the display manager for the navigagtor
Method Detail

setForeground

public void setForeground(Color c)
Sets the foreground color of this JTree

Overrides:
setForeground in class JComponent
Parameters:
c - the color to set to

setBackground

public void setBackground(Color c)
Sets the background color of this tree

Overrides:
setBackground in class JComponent
Parameters:
c - the color for the background

setDisplayManager

public void setDisplayManager(DisplayManager<? super ItemT> manager)
Sets the display manager that is used to select icons for the leaves of the tree. This does not apply to the inner nodes or the root.


setRootIcon

public void setRootIcon(Icon ico)
Sets the icon to be displayed at the root of the tree


asContainer

public Container asContainer()
Specified by:
asContainer in interface IAWTContainerNavigatorActor
Specified by:
asContainer in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
an AWT component which interacts with this document navigator

addDocument

public void addDocument(ItemT doc)
Adds an IDocument to this navigator. Should only executed from event thread.

Specified by:
addDocument in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
doc - the document to be added into this navigator.

addDocument

public void addDocument(ItemT doc,
                        String path)
Adds an INavigatorItem to this navigator in the specified position. The behavior of this navigator and the position associated with a path are left to the implementing class. Only runs in event-handling thread.

Specified by:
addDocument in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
doc - the document to be added into this navigator.
path - in navigator to parent directory for doc
Throws:
IllegalArgumentException - if this navigator does not contain relativeto as tested by the contains method.

addTopLevelGroupToRoot

private void addTopLevelGroupToRoot(InnerNode<?,ItemT> parent)

insertNodeSortedInto

private void insertNodeSortedInto(LeafNode<ItemT> child,
                                  InnerNode<?,ItemT> parent)
Inserts the child node (INavigatorItem) into the sorted position as a parent node's child. Only executes in the event thread. Assumes that _model lock is already held.

Parameters:
child - the node to add
parent - the node to add under

insertFolderSortedInto

private void insertFolderSortedInto(InnerNode<?,ItemT> child,
                                    InnerNode<?,ItemT> parent)
Inserts a folder (String) into sorted position under the parent. Only executes in event thread. Assumes that _model lock is already held

Parameters:
child - the folder to add
parent - the folder to add under

removeDocument

public ItemT removeDocument(ItemT doc)
Removes a given INavigatorItem from this navigator. Removes all INavigatorItems from this navigator that are "equal" (using .equals(...)) to the passed argument. Any of the removed documents may be returned by this method. If the NavigatorItem is found in the navigator, null is returned. Only executes from event thread.

Specified by:
removeDocument in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
doc - the docment to be removed
Returns:
doc a document removed from this navigator as a result of invoking this method.
Throws:
IllegalArgumentException - if this navigator contains no document equal to doc

getNodeForDoc

private LeafNode<ItemT> getNodeForDoc(ItemT doc)
Assumes lock on _model is already held or that it is being run in the event thread.


removeNode

private ItemT removeNode(LeafNode<ItemT> node)
Only takes in nodes that have an INavigatorItem as their object; assumes _model lock is already held. Only executes in event thread.


cleanFolderNode

private void cleanFolderNode(DefaultMutableTreeNode node)
If the given node is an InnerNode with no children, it removes it from the tree. If the given node is a leaf or the root, it does nothing to it. Assumes that _model lock is already held. Only executes in the event thread.


refreshDocument

public void refreshDocument(ItemT doc,
                            String path)
Resets a given INavigatorItem in the tree. Updates the placement of the item and its display to reflect any changes made in the model. Only executes in the event thread. Note: full synchronization commented out because this operation is only performed in the event thread. The synchronized sections must be atomic but the rest of the code can run concurrently with read operations in other threads.

Specified by:
refreshDocument in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
doc - the document to be refreshed
path - the path to the parent folder for this document
Throws:
IllegalArgumentException - if this navigator contains no document equal to doc.

selectDocument

public void selectDocument(ItemT doc)
Sets the specified document to be active (current). Only executes in the event thread.

Specified by:
selectDocument in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
doc - the document to select

getNodeUserObject

private ItemT getNodeUserObject(DefaultMutableTreeNode n)
Returns a typed equivalent to next.getUserObject(). Assumes the DefaultMutableTreeNode is a leaf node in _model and thus, if parameterized, would have type ItemT. This is a workaround for the lack of a generic implementation of TreeModel and TreeNode. If those classes become generified, this code will no longer be necessary.


getNext

public ItemT getNext(ItemT doc)
Returns the next document in the collection (using enumeration order). Executes in any thread.

Specified by:
getNext in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
doc - the INavigatorItem of interest
Returns:
the INavigatorItem which comes after doc

getPrevious

public ItemT getPrevious(ItemT doc)
Returns the previous document in the collection (using enumeration order). Executes in any thread.

Specified by:
getPrevious in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
doc - the INavigatorItem of interest
Returns:
the INavigatorItem which comes before doc

getFirst

public ItemT getFirst()
Returns the first document in the collection (using enumeration order). Executes in any thread.

Specified by:
getFirst in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
the INavigatorItem which comes before doc

getLast

public ItemT getLast()
Returns the last document in the collection (using enumeration order). Executes in any thread.

Specified by:
getLast in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
the INavigatorItem which comes before doc

contains

public boolean contains(ItemT doc)
Tests to see if a given document is contained in this navigator. Executes in any thread.

Specified by:
contains in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
doc - the document to test for containment.
Returns:
true if this navigator contains a document that is "equal" (as tested by the equalsfalse.

_contains

public boolean _contains(ItemT doc)
Tests to see if a given document is contained in this navigator. Only executes in event thread.


getDocuments

public ArrayList<ItemT> getDocuments()
Returns all the IDocuments contained in this navigator. Does not assert any type of ordering on the returned structure. Executes in any thread.

Specified by:
getDocuments in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
an INavigatorItem enumeration of this navigator's contents.

getDocumentsInBin

public ArrayList<ItemT> getDocumentsInBin(String binName)
Returns all the IDocuments contained in the specified bin.

Specified by:
getDocumentsInBin in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
binName - name of bin
Returns:
an INavigatorItem enumeration of this navigator's contents.

getDocumentCount

public int getDocumentCount()
Returns the number of IDocuments contained by this IDocumentNavigator Not synchronized on the assumption that size field of a HashMap always has a legitimate value (either the size of the current state or the size of its state before some concurrent operation started. Executes in any thread. Assume size() always returns a valid (perhaps stale) value.

Specified by:
getDocumentCount in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
the number of documents within this navigator.

isEmpty

public boolean isEmpty()
Returns whether this IDocumentNavigator contains any IDocuments.

Specified by:
isEmpty in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
true if this navigator contains one or more documents, else false. Executes in any thread. Assume isEmpty() always returns a valid (perhaps stale) value.

clear

public void clear()
Removes all IDocuments from this IDocumentNavigator. Only executes in event thread.

Specified by:
clear in interface IDocumentNavigator<ItemT extends INavigatorItem>

addNavigationListener

public void addNavigationListener(INavigationListener<? super ItemT> listener)
Adds an INavigationListener to this navigator. After invoking this method, the passed listener will be eligible for observing this navigator. If the provided listener is already observing this navigator (as tested by the == operator), no action is taken. Only executes in event thread.

Specified by:
addNavigationListener in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
listener - the listener to be added to this navigator.

removeNavigationListener

public void removeNavigationListener(INavigationListener<? super ItemT> listener)
Removes the given listener from observing this navigator. After invoking this method, all observers watching this navigator "equal" (as tested by the == operator) will no longer receive observable dispatches. Only executes in event thread.

Specified by:
removeNavigationListener in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
listener - the listener to be removed from this navigator

getNavigatorListeners

public Collection<INavigationListener<? super ItemT>> getNavigatorListeners()
Returns a collection of all navigator listeners. Note: this is a dangerous method since it exposes a shared data structure that must be synchronized with _model.

Specified by:
getNavigatorListeners in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
the collection of nav listeners listening to this navigator.

execute

public <InType,ReturnType> ReturnType execute(IDocumentNavigatorAlgo<ItemT,InType,ReturnType> algo,
                                              InType input)
Standard visitor pattern. Only used within this class.

Specified by:
execute in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
algo - the visitor to run
input - the input for the visitor

valueChanged

public void valueChanged(TreeSelectionEvent e)
Called whenever the value of the selection changes. Only runs in event thread. Runs _gainVisitor in global model

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

getRenderer

public Component getRenderer()
Returns a renderer for this object.

Specified by:
getRenderer in interface IAWTContainerNavigatorActor

selectDocumentAt

public boolean selectDocumentAt(int x,
                                int y)
Selects the document at the x,y coordinate of the navigator pane and installs it as the active document. Only runs in event thread.

Specified by:
selectDocumentAt in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
x - the x coordinate of the navigator pane
y - the y coordinate of the navigator pane

isSelectedAt

public boolean isSelectedAt(int x,
                            int y)
Returns true if the item at the x,y coordinate of the navigator pane is currently selected. Only runs in event thread. O

Specified by:
isSelectedAt in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
x - the x coordinate of the navigator pane
y - the y coordinate of the navigator pane
Returns:
true if the item is currently selected

isGroupSelected

public boolean isGroupSelected()
Specified by:
isGroupSelected in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
true if at least one group of INavigatorItems is selected. Only runs in event thread.

getGroupSelectedCount

public int getGroupSelectedCount()
Specified by:
getGroupSelectedCount in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
the number of groups selected. Only runs in event thread.

getSelectedFolders

public List<File> getSelectedFolders()
Specified by:
getSelectedFolders in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
the folders currently selected. Only runs in event thread.

isDocumentSelected

public boolean isDocumentSelected()
Specified by:
isDocumentSelected in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
true if at least one document is selected. Only runs in event thread.

getDocumentSelectedCount

public int getDocumentSelectedCount()
Specified by:
getDocumentSelectedCount in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
the number of documents selected. Only runs in event thread.

getSelectedDocuments

public List<ItemT> getSelectedDocuments()
Specified by:
getSelectedDocuments in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
the documents currently selected. Only runs in event thread.

isTopLevelGroupSelected

public boolean isTopLevelGroupSelected()
Returns true if at least one top level group is selected. Only runs in event thread.

Specified by:
isTopLevelGroupSelected in interface IDocumentNavigator<ItemT extends INavigatorItem>

isRootSelected

public boolean isRootSelected()
Returns true if the root is selected. Only runs in event thread.

Specified by:
isRootSelected in interface IDocumentNavigator<ItemT extends INavigatorItem>

getNamesOfSelectedTopLevelGroup

public Set<String> getNamesOfSelectedTopLevelGroup()
                                            throws GroupNotSelectedException
Returns the names of the top level groups that the selected items descend from. Only runs in event thread.

Specified by:
getNamesOfSelectedTopLevelGroup in interface IDocumentNavigator<ItemT extends INavigatorItem>
Throws:
GroupNotSelectedException

getCurrent

public ItemT getCurrent()
Returns the currently selected leaf node, or null if the selected node is not a leaf. Only reads a single volatile field that always has a valid value. Thread safe.

Specified by:
getCurrent in interface IDocumentNavigator<ItemT extends INavigatorItem>

getModelLock

public Object getModelLock()
Returns the model lock.

Specified by:
getModelLock in interface IDocumentNavigator<ItemT extends INavigatorItem>

isSelectedInGroup

public boolean isSelectedInGroup(ItemT i)
Specified by:
isSelectedInGroup in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
true if the INavigatorItem is in a selected group, if at least one group is selected. Only runs in event thread.

addTopLevelGroup

public void addTopLevelGroup(String name,
                             INavigatorItemFilter<? super ItemT> f)
Adds a top level group to the navigator. Only runs in event thread.

Specified by:
addTopLevelGroup in interface IDocumentNavigator<ItemT extends INavigatorItem>

treeCollapsed

public void treeCollapsed(TreeExpansionEvent event)
Called whenever an item in the tree has been collapsed. Only runs in event thread (except when testing).

Specified by:
treeCollapsed in interface TreeExpansionListener

treeExpanded

public void treeExpanded(TreeExpansionEvent event)
Called whenever an item in the tree has been expanded. Only runs in event thread.

Specified by:
treeExpanded in interface TreeExpansionListener

collapsePaths

public void collapsePaths(String[] paths)
Collapses all the paths in the tree that match one of the path strings included in the given hash set. Path strings must follow a specific format in order for them to work. See the documentation of generatePathString for information on the format of the path strings. Only executes in event thread.

Parameters:
paths - A hash set of path strings.

collapsePaths

void collapsePaths(HashSet<String> paths)
Set variation of collapsePaths(String ...). Private except for testing code. Only runs in event thread except for testing code.


getCollapsedPaths

public String[] getCollapsedPaths()
Returns:
an array of path strings corresponding to the paths of the tree nodes that are currently collapsed. See the documentation of generatePathString for information on the format of the path strings. Only runs in event thread (except when testing).

generatePathString

public String generatePathString(TreePath tp)
Generates a path string for the given tree node.

The path string does not include the project root node, but rather a period in its place. Following the "./" is one of the 3 main groups, "[ Source Files ]", "[ Auxiliary ]", "[ External ]". The nodes in the path are represented by their names delimited by the forward slash ("/"). The path ends with a final delimeter. (e.g. "./[ Source Files ]/util/docnavigation/") Only runs in event thread.

Returns:
the path string for the given node in the JTree

requestSelectionUpdate

public void requestSelectionUpdate(ItemT ini)
If the currently selected item is not an INavigatorItem, select the one given. Only runs in event thread.

Specified by:
requestSelectionUpdate in interface IDocumentNavigator<ItemT extends INavigatorItem>
Parameters:
ini - The suggested current INavigatorItem.

setNextChangeModelInitiated

public void setNextChangeModelInitiated(boolean b)
Marks the next selection change as model-initiated (true) or user-initiated (false; default).

Specified by:
setNextChangeModelInitiated in interface IDocumentNavigator<ItemT extends INavigatorItem>

isNextChangeModelInitiated

public boolean isNextChangeModelInitiated()
Specified by:
isNextChangeModelInitiated in interface IDocumentNavigator<ItemT extends INavigatorItem>
Returns:
whether the next selection change is model-initiated (true) or user-initiated (false).

dragEnter

public void dragEnter(DropTargetDragEvent dropTargetDragEvent)
User dragged something into the component.

Specified by:
dragEnter in interface DropTargetListener

dragExit

public void dragExit(DropTargetEvent dropTargetEvent)
Specified by:
dragExit in interface DropTargetListener

dragOver

public void dragOver(DropTargetDragEvent dropTargetDragEvent)
Specified by:
dragOver in interface DropTargetListener

dropActionChanged

public void dropActionChanged(DropTargetDragEvent dropTargetDragEvent)
Specified by:
dropActionChanged in interface DropTargetListener

drop

public void drop(DropTargetDropEvent dropTargetDropEvent)
User dropped something on the component. Only runs in event thread.

Specified by:
drop in interface DropTargetListener