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
ConstructorsConstructorDescriptionCreates a newTLspSelectControllerModelwith default settings. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplySelection(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 inaSelectionCandidatesintThis method returns the sensitivity that will be used when selecting objects or labels.voidselect(ALspSelectInput aInput, Set<TLspPaintRepresentation> aRepresentations, TLspSelectChoice aChoice, TLspSelectMode aMode, ILspView aView) Selects (an) object(s) interacting with a rectangle in a view according to theTLspSelectChoiceandTLspSelectMode.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.voidsetSelectionCandidateHandlerFor(TLspSelectChoice aChoice, ILspSelectionCandidateHandler aHandler) RegistersaHandleras the selection candidate handler to use foraChoice.voidsetSensitivity(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 newTLspSelectControllerModelwith default settings.
-
-
Method Details
-
setSelectionCandidateHandlerFor
public void setSelectionCandidateHandlerFor(TLspSelectChoice aChoice, ILspSelectionCandidateHandler aHandler) RegistersaHandleras the selection candidate handler to use foraChoice. By defaultTLspSelectChoice.DEFAULTis mapped on a standardTLspDefaultSelectionCandidateHandlerandTLspSelectChoice.CHOOSEis mapped on a defaultTLspPopupMenuSelectionCandidateHandler.- Parameters:
aChoice- TheTLspSelectChoiceto 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
TLspSelectChoiceandTLspSelectMode.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.DEFAULTandTLspSelectChoice.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
ILspSelectionCandidateHandlerforaChoice. By default this controller supports 2 choices:TLspSelectChoice.DEFAULT: the controller uses aTLspDefaultSelectionCandidateHandlerto update the selection.TLspSelectChoice.CHOOSE: the controller uses aTLspPopupMenuSelectionCandidateHandlerto 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
-