diva.canvas.interactor
Class SelectionDragger

java.lang.Object
  extended by diva.canvas.interactor.AbstractInteractor
      extended by diva.canvas.interactor.DragInteractor
          extended by diva.canvas.interactor.SelectionDragger
All Implemented Interfaces:
LayerListener, LayerMotionListener, Interactor, java.util.EventListener

public class SelectionDragger
extends DragInteractor

A class that implements rubber-banding on a canvas. It contains references to one or more instances of SelectionInteractor, which it notifies whenever dragging on the canvas covers or uncovers items. The SelectionDragger requires three layers: an Event Layer, which it listens to perform drag-selection, an OutlineLayer, on which it draws the drag-selection box, and a FigureLayer, which it selects figures on. It can also accept a GraphicsPane in its constructor, in which case it will use the background event layer, outline layer, and foreground event layer from that pane.

Version:
$Id: SelectionDragger.java 38798 2005-07-08 20:00:01Z cxh $
Author:
John Reekie

Field Summary
private  java.util.HashSet _currentFigures
          A hash-set containing those figures
private  EventLayer _eventLayer
           
private  FigureLayer _figureLayer
           
private  java.util.HashSet _holdovers
          A hash-set containing figures that overlap the rubber-band but are not "hit"
private  GeometricSet _intersectedFigures
           
private  boolean _isSelecting
          The selection mode flags
private  boolean _isToggling
           
private  double _originX
           
private  double _originY
           
private  OverlayLayer _overlayLayer
           
private  java.awt.geom.Rectangle2D _rubberBand
           
private  MouseFilter _selectionFilter
          The mouse filter for selecting items
private  java.util.List _selectionModels
          The list of selection models selected by this dragger.
private  MouseFilter _toggleFilter
          The mouse filter for toggling items
 
Constructor Summary
SelectionDragger()
          Create a new SelectionDragger
SelectionDragger(GraphicsPane gpane)
          Create a new SelectionDragger attached to the given graphics pane.
 
Method Summary
 void addSelectionInteractor(SelectionInteractor interactor)
          Add the selection model of the given selection interactor to the set of selection models selected by this dragger.
 void addSelectionModel(SelectionModel model)
          Add the given selection model to the set of selection models selected by this dragger.
 void clearSelection()
          Clear the selection in all the relevant selection interactors.
 void contractSelection(SelectionInteractor i, Figure figure)
          Contract the selection by removing an item from it and removing highlight rendering.
 void expandSelection(SelectionInteractor i, Figure figure)
          Expand the selection by adding an item to it and adding highlight rendering to it.
 EventLayer getEventLayer()
          Get the layer that drag events are listened on
 FigureLayer getFigureLayer()
          Get the layer that figures are selected on
 OverlayLayer getOverlayLayer()
          Get the layer that drag rectangles are drawn on
 MouseFilter getSelectionFilter()
          Get the mouse filter that controls when this selection filter is activated.
 MouseFilter getToggleFilter()
          Get the mouse filter that controls the toggling of selections
 void mouseDragged(LayerEvent event)
          Reshape the rubber-band, swapping coordinates if necessary.
 void mousePressed(LayerEvent event)
          Clear the selection, and create the rubber-band
 void mouseReleased(LayerEvent event)
          Delete the rubber-band
 void removeSelectionModel(SelectionModel model)
          Remove a selection model from the list of models selected by this dragger.
 java.util.Iterator selectionModels()
          Get the selection interactors
 void setEventLayer(EventLayer l)
          Set the layer that drag events are listened on
 void setFigureLayer(FigureLayer l)
          Set the layer that figures are selected on
 void setOverlayLayer(OverlayLayer l)
          Set the layer that drag rectangles are drawn on
 void setSelectionFilter(MouseFilter f)
          Set the mouse filter that controls when this selection filter is activated.
 void setToggleFilter(MouseFilter f)
          Set the mouse filter that controls the toggling of selections.
 void terminateDragSelection()
          Terminate drag-selection operation.
 
Methods inherited from class diva.canvas.interactor.DragInteractor
addLayerListener, appendConstraint, constrainPoint, fireLayerEvent, getSelectiveEnabled, getTargetArray, getX, getY, prependConstraint, removeLayerListener, setSelectiveEnabled, setTargetArray, setup, targets, translate
 
Methods inherited from class diva.canvas.interactor.AbstractInteractor
accept, getMouseFilter, isConsuming, isEnabled, isMotionEnabled, mouseClicked, mouseEntered, mouseExited, mouseMoved, setConsuming, setEnabled, setMotionEnabled, setMouseFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_overlayLayer

private OverlayLayer _overlayLayer

_eventLayer

private EventLayer _eventLayer

_figureLayer

private FigureLayer _figureLayer

_rubberBand

private java.awt.geom.Rectangle2D _rubberBand

_intersectedFigures

private GeometricSet _intersectedFigures

_currentFigures

private java.util.HashSet _currentFigures
A hash-set containing those figures


_holdovers

private java.util.HashSet _holdovers
A hash-set containing figures that overlap the rubber-band but are not "hit"


_originX

private double _originX

_originY

private double _originY

_selectionModels

private java.util.List _selectionModels
The list of selection models selected by this dragger.


_selectionFilter

private MouseFilter _selectionFilter
The mouse filter for selecting items


_toggleFilter

private MouseFilter _toggleFilter
The mouse filter for toggling items


_isSelecting

private boolean _isSelecting
The selection mode flags


_isToggling

private boolean _isToggling
Constructor Detail

SelectionDragger

public SelectionDragger()
Create a new SelectionDragger


SelectionDragger

public SelectionDragger(GraphicsPane gpane)
Create a new SelectionDragger attached to the given graphics pane.

Method Detail

addSelectionModel

public void addSelectionModel(SelectionModel model)
Add the given selection model to the set of selection models selected by this dragger. When drag-selecting, only figures that have a selection interactor with a selection model in this list are added to the selection model.


addSelectionInteractor

public void addSelectionInteractor(SelectionInteractor interactor)
Add the selection model of the given selection interactor to the set of selection models selected by this dragger. When drag-selecting, only figures that have a selection interactor with a selection model in this list are added to the selection model.


clearSelection

public void clearSelection()
Clear the selection in all the relevant selection interactors.


contractSelection

public void contractSelection(SelectionInteractor i,
                              Figure figure)
Contract the selection by removing an item from it and removing highlight rendering. If the figure is not in the selection, do nothing.


expandSelection

public void expandSelection(SelectionInteractor i,
                            Figure figure)
Expand the selection by adding an item to it and adding highlight rendering to it. If the figure is already in the selection, do nothing.


getOverlayLayer

public OverlayLayer getOverlayLayer()
Get the layer that drag rectangles are drawn on


getEventLayer

public EventLayer getEventLayer()
Get the layer that drag events are listened on


getFigureLayer

public FigureLayer getFigureLayer()
Get the layer that figures are selected on


getSelectionFilter

public MouseFilter getSelectionFilter()
Get the mouse filter that controls when this selection filter is activated.


getToggleFilter

public MouseFilter getToggleFilter()
Get the mouse filter that controls the toggling of selections


mouseDragged

public void mouseDragged(LayerEvent event)
Reshape the rubber-band, swapping coordinates if necessary. Any figures that are newly included or excluded from the drag region are added to or removed from the appropriate selection.

Specified by:
mouseDragged in interface LayerListener
Overrides:
mouseDragged in class DragInteractor

mousePressed

public void mousePressed(LayerEvent event)
Clear the selection, and create the rubber-band

Specified by:
mousePressed in interface LayerListener
Overrides:
mousePressed in class DragInteractor

mouseReleased

public void mouseReleased(LayerEvent event)
Delete the rubber-band

Specified by:
mouseReleased in interface LayerListener
Overrides:
mouseReleased in class DragInteractor

removeSelectionModel

public void removeSelectionModel(SelectionModel model)
Remove a selection model from the list of models selected by this dragger.


selectionModels

public java.util.Iterator selectionModels()
Get the selection interactors


setOverlayLayer

public void setOverlayLayer(OverlayLayer l)
Set the layer that drag rectangles are drawn on


setEventLayer

public void setEventLayer(EventLayer l)
Set the layer that drag events are listened on


setFigureLayer

public void setFigureLayer(FigureLayer l)
Set the layer that figures are selected on


setSelectionFilter

public void setSelectionFilter(MouseFilter f)
Set the mouse filter that controls when this selection filter is activated.


setToggleFilter

public void setToggleFilter(MouseFilter f)
Set the mouse filter that controls the toggling of selections.


terminateDragSelection

public void terminateDragSelection()
Terminate drag-selection operation. This must only be called from events that are triggered during a drag operation.