Class SelectionInteractor
- java.lang.Object
-
- diva.canvas.interactor.AbstractInteractor
-
- diva.canvas.interactor.CompositeInteractor
-
- 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$
- Author:
- John Reekie
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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 modelSelectionRenderer
getSelectionRenderer()
Get the selection rendererMouseFilter
getToggleFilter()
Get the mouse filter that controls the toggling of selectionsstatic 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 insteadvoid
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
-
-
-
-
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 interfaceInteractor
- Overrides:
accept
in classCompositeInteractor
- Parameters:
e
- The event
-
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 interfaceLayerListener
- Overrides:
mousePressed
in classCompositeInteractor
- Parameters:
event
- The event
-
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 classAbstractInteractor
- Parameters:
flag
- The consuming flag
-
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 forthis.setSelectionRenderer(new BasicSelectionRenderer(decorator);
This method nullifies any previous renderers set with setSelectionRenderer();
-
setSelectionManipulator
@Deprecated public void setSelectionManipulator(Manipulator manipulator)
Deprecated.Use setPrototypeDecorator insteadSet 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.
-
-