Package furbelow

Class TreeAnimator

All Implemented Interfaces:
EventListener, TreeExpansionListener

public class TreeAnimator extends AbstractComponentDecorator implements TreeExpansionListener
Animates moving tree cells out of the way for a potential drop. This decorator completely over-paints the target JTree, optionally painting a dragged item and animating creation of a space for the dragged item to be dropped.
  • Constructor Details

    • TreeAnimator

      public TreeAnimator(JTree tree)
  • Method Details

    • canMove

      protected boolean canMove(TreePath path)
      The default assumes any node except the root may be moved.
    • canMove

      protected boolean canMove(TreePath fromPath, TreePath toPath, int index)
      Returns whether the node at the given path may be moved to the given index on the given target path. The default disallows moves only if the target is a descendent of the moved path.
    • moveNode

      protected void moveNode(TreePath fromPath, TreePath toPath, int index)
      Request that the node on the given path be moved to the given index on the given target path. If toPath is the parent path to fromPath, then the index represents the insertion index after the object is removed from its current index.
    • startDrag

      public boolean startDrag(Point where)
      Start a local drag. Returns whether the drag is started.
    • treeExpanded

      public void treeExpanded(TreeExpansionEvent e)
      Specified by:
      treeExpanded in interface TreeExpansionListener
    • treeCollapsed

      public void treeCollapsed(TreeExpansionEvent e)
      Specified by:
      treeCollapsed in interface TreeExpansionListener
    • setVisible

      public void setVisible(boolean visible)
      Description copied from class: AbstractComponentDecorator
      Use this to change the visibility of the decoration.
      Overrides:
      setVisible in class AbstractComponentDecorator
    • endDrag

      public void endDrag(Point where)
      End an internal drag.
    • dispose

      public void dispose()
      Description copied from class: AbstractComponentDecorator
      Stop decorating.
      Overrides:
      dispose in class AbstractComponentDecorator
    • getDragDestination

      protected TreeAnimator.DragDestination getDragDestination(Point where)
      Return a proposed insertion location for the given coordinate given in actual JTree coordinate space. If there is no vertical row change from the current insertion position, then horizontal movement is used to make changes in depth. Returns null if no insertion is allowed at the given location.
    • setPlaceholderLocation

      public void setPlaceholderLocation(Point where)
      Invoke this method as the cursor location changes.
    • getPlaceholderRow

      protected int getPlaceholderRow()
    • paint

      public void paint(Graphics g)
      Description copied from class: AbstractComponentDecorator
      Define the decoration's appearance. The point (0,0) represents the upper left corner of the decorated component. The default clip mask will be the extents of the decoration bounds, as indicated by AbstractComponentDecorator.getDecorationBounds(), which defaults to the decorated component bounds.
      Specified by:
      paint in class AbstractComponentDecorator
    • main

      public static void main(String[] args)
      Throw up a frame to demonstrate the animator at work.