diva.canvas.interactor
Class SelectionInteractor

java.lang.Object
  extended by diva.canvas.interactor.AbstractInteractor
      extended by diva.canvas.interactor.CompositeInteractor
          extended by diva.canvas.interactor.SelectionInteractor
All Implemented Interfaces:
LayerListener, LayerMotionListener, Interactor, java.util.EventListener
Direct Known Subclasses:
EdgeInteractor, NodeInteractor

public class SelectionInteractor
extends CompositeInteractor

A SelectionInteractor is attached to an object that can be put into and out of a selection. Associated with each such role is a selection model, which is the selection that figures are added to or removed from. When a mouse pressed event has occurred, all figures associated with the same SelectionModel will be unselected before the new one is selected. So, to make sure only one figure is selected at a time, do this: SelectionModel m = new SelectionModel(); SelectionInteractor s1 = new SelectionInteractor(m); SelectionInteractor s2 = new SelectionInteractor(m);

When an item is selected, events are then forwarded to other interactors. If, however, the clicked-on figure has just been removed from the figure, do not forward events.

Version:
$Id: SelectionInteractor.java 53042 2009-04-10 20:31:21Z cxh $
Author:
John Reekie

Field Summary
private  SelectionRenderer _renderer
          The selection renderer
private  SelectionModel _selection
          The selection model
private  MouseFilter _selectionFilter
          The mouse filter for selecting items
private  MouseFilter _toggleFilter
          The mouse filter for toggling items
 
Constructor Summary
SelectionInteractor()
          Create a new SelectionInteractor with a default selection model and a default selection renderer.
SelectionInteractor(SelectionModel model)
          Create a new SelectionInteractor with the given selection model and a null selection renderer.
 
Method Summary
 boolean accept(LayerEvent e)
          Accept an event if it will be accepted by the selection filters.
 MouseFilter getSelectionFilter()
          Get the mouse filter that controls when this selection filter is activated.
 SelectionModel getSelectionModel()
          Get the selection model
 SelectionRenderer getSelectionRenderer()
          Get the selection renderer
 MouseFilter getToggleFilter()
          Get the mouse filter that controls the toggling of selections
static boolean isSelected(LayerEvent e)
          Given a mouse event, check that the figure it contains as its event source is selected.
 void mousePressed(LayerEvent event)
          Handle a mouse press event.
 void setConsuming(boolean flag)
          Set the consuming flag of this interactor.
 void setPrototypeDecorator(FigureDecorator decorator)
          Set the prototype decorator for selected figures.
 void setSelectionFilter(MouseFilter f)
          Set the mouse filter that controls when this selection filter is activated.
 void setSelectionManipulator(Manipulator manipulator)
          Deprecated. Use setPrototypeDecorator instead
 void setSelectionModel(SelectionModel model)
          Set the selection model.
 void setSelectionRenderer(SelectionRenderer r)
          Set the selection renderer.
 void setToggleFilter(MouseFilter f)
          Set the mouse filter that controls the toggling of selections.
 
Methods inherited from class diva.canvas.interactor.CompositeInteractor
addInteractor, interactors, isMotionEnabled, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseReleased, removeInteractor
 
Methods inherited from class diva.canvas.interactor.AbstractInteractor
getMouseFilter, isConsuming, isEnabled, mouseClicked, setEnabled, setMotionEnabled, setMouseFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_selection

private SelectionModel _selection
The selection model


_renderer

private SelectionRenderer _renderer
The selection renderer


_selectionFilter

private MouseFilter _selectionFilter
The mouse filter for selecting items


_toggleFilter

private MouseFilter _toggleFilter
The mouse filter for toggling items

Constructor Detail

SelectionInteractor

public SelectionInteractor()
Create a new SelectionInteractor with a default selection model and a default selection renderer.


SelectionInteractor

public SelectionInteractor(SelectionModel model)
Create a new SelectionInteractor with the given selection model and a null selection renderer.

Method Detail

accept

public boolean accept(LayerEvent e)
Accept an event if it will be accepted by the selection filters.

Specified by:
accept in interface Interactor
Overrides:
accept in class CompositeInteractor

getSelectionFilter

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


getSelectionModel

public SelectionModel getSelectionModel()
Get the selection model


getSelectionRenderer

public SelectionRenderer getSelectionRenderer()
Get the selection renderer


getToggleFilter

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


isSelected

public static boolean isSelected(LayerEvent e)
Given a mouse event, check that the figure it contains as its event source is selected. By selected, we mean that figure has a SelectionInteractor as its interactor, and that the figure is in the SelectionModel of that interactor.


mousePressed

public void mousePressed(LayerEvent event)
Handle a mouse press event. Add or remove the clicked-on item to or from the selection. If it's still in the selection, pass the event to the superclass to handle.

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

setConsuming

public void setConsuming(boolean flag)
Set the consuming flag of this interactor. This flag is a little more complicated than in simple interactors: if not set, then the event is consumed only if the clicked-on figure is added to or removed from the selection. Otherwise it is not consumed. If the flag is set, then the event is always consumed, thus making it effectively "opaque" to events.

Note that the behaviour when the flag is false is the desired behaviour when building panes that have an interactor attached to the background. That way, the event passes through to the background if a figure is hit on but the selection interactor's filters are set up to ignore that particular event.

There is a third possibility, which is not supported: never consume events. There is no way to do this currently, as the other two behaviors seemed more likely to be useful. (Also, that behaviour is harder to implement because of interaction with the superclass.)

Overrides:
setConsuming in class AbstractInteractor

setSelectionModel

public void setSelectionModel(SelectionModel model)
Set the selection model. The existing selection model is cleared first.


setSelectionFilter

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


setPrototypeDecorator

public void setPrototypeDecorator(FigureDecorator decorator)
Set the prototype decorator for selected figures. Selected figures will have a copy of this decorator wrapped around them. This call is a convenience short-hand for
    this.setSelectionRenderer(new BasicSelectionRenderer(decorator);
 

This method nullifies any previous renderers set with setSelectionRenderer();


setSelectionManipulator

public void setSelectionManipulator(Manipulator manipulator)
Deprecated. Use setPrototypeDecorator instead

Set the prototype selection manipulator. Selected figures will have a copy of this manipulator wrapped around them. This method nullifies any previous renderers set with setSelectionRenderer();


setSelectionRenderer

public void setSelectionRenderer(SelectionRenderer r)
Set the selection renderer. The object is not used in this class, but can be set here so that other objects that need to render selected objects know how to do so.


setToggleFilter

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