Class TLspSelectControllerModel
Controller model for selection of objects in a view, used by the TLspSelectController
.
How selection works
The class javadoc of the TLspSelectController
explains how the select controller and this controller model work together to update the selection.
Customizing the selection behavior
Which domain objects are used as selection candidates
The object of which the selection is potentially updated are collected by the selectionCandidates(ALspSelectInput, Set, boolean, ILspView)
method.
When using the TLspSelectController
, the controller calls the select(ALspSelectInput, Set, TLspSelectChoice, TLspSelectMode, ILspView)
method
which in turn calls the selectionCandidates(ALspSelectInput, Set, boolean, ILspView)
method.
By overriding this method, you can use custom logic. An example is to only consider objects of which the bounds are completely contained in the selection rectangle instead of all objects with overlapping bounds.
Supporting custom selection update behavior
The update of the selection happens in the applySelection(ALspSelectInput, TLspSelectChoice, TLspSelectMode, List, ILspView)
method.
This method delegates the actual updating of the selection to a ILspSelectionCandidateHandler
.
You can replace the existing ones (or register your own instance when you have a custom TLspSelectChoice
)
by calling the setSelectionCandidateHandlerFor(TLspSelectChoice, ILspSelectionCandidateHandler)
method.
If that is not sufficient, you can always override the method to implement your own behavior.
An example customization is to show a dialog to the user when multiple selection candidates are available, and let the user decide which ones to select.
- Since:
- 2012.0
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates a newTLspSelectControllerModel
with default settings. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applySelection
(ALspSelectInput aInput, TLspSelectChoice aChoice, TLspSelectMode aMode, List<TLspDomainObjectContext> aSelectionCandidates, ILspView aView) Uses the passed arguments to change the selection of some or all of the objects inaSelectionCandidates
int
This method returns the sensitivity that will be used when selecting objects or labels.void
select
(ALspSelectInput aInput, Set<TLspPaintRepresentation> aRepresentations, TLspSelectChoice aChoice, TLspSelectMode aMode, ILspView aView) Selects (an) object(s) interacting with a rectangle in a view according to theTLspSelectChoice
andTLspSelectMode
.selectionCandidates
(ALspSelectInput aInput, Set<TLspPaintRepresentation> aRepresentations, boolean aMultiple, ILspView aView) Returns the set of selection candidates that should be considered for selection based on the passed arguments.void
setSelectionCandidateHandlerFor
(TLspSelectChoice aChoice, ILspSelectionCandidateHandler aHandler) RegistersaHandler
as the selection candidate handler to use foraChoice
.void
setSensitivity
(int aSensitivity) This method sets the sensitivity that should be used by painters to determine which object is selected by the input device (usually the mouse).
-
Constructor Details
-
TLspSelectControllerModel
public TLspSelectControllerModel()Creates a newTLspSelectControllerModel
with default settings.
-
-
Method Details
-
setSelectionCandidateHandlerFor
public void setSelectionCandidateHandlerFor(TLspSelectChoice aChoice, ILspSelectionCandidateHandler aHandler) RegistersaHandler
as the selection candidate handler to use foraChoice
. By defaultTLspSelectChoice.DEFAULT
is mapped on a standardTLspDefaultSelectionCandidateHandler
andTLspSelectChoice.CHOOSE
is mapped on a defaultTLspPopupMenuSelectionCandidateHandler
.- Parameters:
aChoice
- TheTLspSelectChoice
to map the passed handler to.aHandler
- The handler to be used for the passed choice.
-
getSensitivity
public int getSensitivity()This method returns the sensitivity that will be used when selecting objects or labels.
The sensitivity is the maximum distance at which the representation of an object can be removed from a selection point, such as the position of the mouse cursor, and still be considered a valid selection candidate. The distance is expressed in pixels.
- Returns:
- the sensitivity to be used for selecting objects, expressed in pixels.
- See Also:
-
setSensitivity
public void setSensitivity(int aSensitivity) This method sets the sensitivity that should be used by painters to determine which object is selected by the input device (usually the mouse).
The sensitivity is the maximum distance at which the representation of an object can be removed from a selection point, such as the position of the mouse cursor, and still be considered a valid selection candidate. The distance is expressed in pixels. Tweaking the selection sensitivity is especially useful when you are using less exact input methods like a touch screen.
- Parameters:
aSensitivity
- the sensitivity that will be used for selecting objects, expressed in pixels.- See Also:
-
select
public void select(ALspSelectInput aInput, Set<TLspPaintRepresentation> aRepresentations, TLspSelectChoice aChoice, TLspSelectMode aMode, ILspView aView) Selects (an) object(s) interacting with a rectangle in a view according to the
TLspSelectChoice
andTLspSelectMode
.The default implementation of this method:
- Retrieves the candidate selection objects by calling
selectionCandidates(ALspSelectInput, Set, boolean, ILspView)
. - Updates the layer selection by calling
applySelection(ALspSelectInput, TLspSelectChoice, TLspSelectMode, List, ILspView)
- Parameters:
aInput
- the selection input.aRepresentations
- the paint representations to be taken into account when selecting objects.aChoice
- the choice, this controls which of the possible selection candidates are taken into account. The default implementation only supportsTLspSelectChoice.DEFAULT
andTLspSelectChoice.CHOOSE
.aMode
- the mode, this controls how the selection is adapted for the remaining selection candidates.aView
- the view to select in.
- Retrieves the candidate selection objects by calling
-
selectionCandidates
public List<TLspDomainObjectContext> selectionCandidates(ALspSelectInput aInput, Set<TLspPaintRepresentation> aRepresentations, boolean aMultiple, ILspView aView) Returns the set of selection candidates that should be considered for selection based on the passed arguments.
The default implementation:- Only considers objects painted in visible and selectable layers.
- Orders the elements in the returned list from topmost object to lowest object.
- Parameters:
aInput
- the selection input.aRepresentations
- the paint representations to be taken into account when selecting objects.aMultiple
- flag that indicates whether or not multiple selection candidates are needed, this allows optimizations if only one is necessary.aView
- the view to select in.- Returns:
- a list of selection candidates (=objects that should be considered for selection according to the input parameters)
-
applySelection
protected void applySelection(ALspSelectInput aInput, TLspSelectChoice aChoice, TLspSelectMode aMode, List<TLspDomainObjectContext> aSelectionCandidates, ILspView aView) Uses the passed arguments to change the selection of some or all of the objects in
The default implementation:aSelectionCandidates
- Does nothing when the mode is
TLspSelectMode.NO_CHANGE
- First clears the existing selection if the mode is
TLspSelectMode.REPLACE
- Delegates the actual update of the selection to the registered
ILspSelectionCandidateHandler
foraChoice
. By default this controller supports 2 choices:TLspSelectChoice.DEFAULT
: the controller uses aTLspDefaultSelectionCandidateHandler
to update the selection.TLspSelectChoice.CHOOSE
: the controller uses aTLspPopupMenuSelectionCandidateHandler
to update the selection.
- Parameters:
aInput
- the selection input.aChoice
- the choice, this controls which of the possible selection candidates are taken into accountaMode
- the mode, this controls how the selection is adapted for the remaining selection candidates.aSelectionCandidates
- a list of objects for which a new selection state should be determined.aView
- the view to select in.
- Does nothing when the mode is
-