Class TLcdGXYSelectController2
- All Implemented Interfaces:
ILcdUndoableSource,ILcdAWTEventListener,ILcdStatusSource,ILcdGXYChainableController,ILcdGXYController,KeyListener,MouseListener,MouseMotionListener,Serializable,EventListener
- Direct Known Subclasses:
TLcdGXYEditController2
Controller that allows the user to select domain objects in the view using the mouse. The controller supports selection changes by clicking on the view or by dragging a rectangle.
If case you want to programmatically (de)select objects, query the selection or get informed about selection changes, you should use:
ILcdSelection.getSelectedObjects()to retrieve the selected objects from a single layer.ILcdLayer.selectObject(Object, boolean, int)to update the selected state of an object in a layer.ILcdSelection.addSelectionListener(ILcdSelectionListener)to register a listener which is informed about selection changes in a single layer.ILcdGXYView.addLayerSelectionListener(ILcdSelectionListener)to register a listener which is informed about selection changes in any of the layers contained in the view.
How selection works
The selection controller works in multiple steps:- The controller interprets the user input: first, this controller gathers information about the selection intent of the user. For example whether the user wants to add or remove the object to/from the selection, whether the user wants to drag a rectangle to select multiple objects in one go, ... .
-
The controller model performs the actual update of the selection:
once all this information is gathered, it is passed to the controller model:
- The selectionCandidates method is used to query the view and the layers for objects that match the mouse click (or the selection rectangle).
- The selection of those selection candidates is updated by calling the applySelection method.
Customizing the controller
(De)Activate rectangle selection mode
This controller uses the multi-select modifier key to determine whether or not a MouseEvent
should be interpreted as a "select by dragging a rectangle".
Call the setter if you want to replace the default key.
Selecting objects by their labels or only by their bodies
This controller calls the selectByWhatMode(ILcdGXYView, Rectangle, int, MouseEvent) method to determine whether the bodies
only or also the labels should be considered when determining which objects are selection candidates.
This information is passed to the TLcdGXYSelectControllerModel2, and it is the responsibility of the controller model
to respect this choice.
Overlapping objects: selecting the topmost element only or not
This controller calls the selectHowMode(ILcdGXYView, Rectangle, int, MouseEvent, int) method to determine how selection candidates
are selected when there are multiple candidates.
The resulting integer is passed to the controller model, and it is the controller model who decides how to handle this choice.
Selecting or deselecting the selection candidates
This controller calls the selectHowMode(ILcdGXYView, Rectangle, int, MouseEvent, int) to determine what to do
with the selection candidates.
For example should the objects be added to the current selection, replace the current selection, ... .
The resulting integer is passed to the controller model, and it is the controller model who decides how to handle this choice.
Replacing the controller model
The actual adjusting of the selection is done by theTLcdGXYSelectControllerModel2.
You can customize the selection behavior by installing a custom
controller model instance on this model, or by specifying a custom controller model in the constructor.
Double click and right click pop-up menu
This controller has methods to:-
Specify an
ActionListenerwhich should be triggered when a double click is performed (setDoubleClickAction(ActionListener)). A typical use-case of this is setting an action listener which shows the properties of an object when double-clicking on it. - Specify an
ActionListenerwhich should be triggered when the user performs a right click (setRightClickAction(ActionListener))}). A typical use-case of this is setting an action which shows a pop-up menu for the selected object when right-clicking.
- Since:
- 7.0
- See Also:
-
Field Summary
Fields inherited from class com.luciad.view.gxy.controller.TLcdGXYDragRectangleController
fXPressed, fXReleased, fYPressed, fYReleased -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new select controller.TLcdGXYSelectController2(TLcdGXYSelectControllerModel2 aSelectControllerModel) Constructs a newTLcdGXYSelectController2, with the givenTLcdGXYSelectControllerModel2. -
Method Summary
Modifier and TypeMethodDescriptionvoidThis method will append the passed controller to the end of the chain.Returns the filter specifying to what mouse events the controller should respond to.Returns the double click action.final intReturns the modifier key mask to trigger multi-select drag behavior.Returns a reference to the controller that is located after this one in a chain, or null if this controller is the last element of the chain.Returns the right click action.Returns theTLcdGXYSelectControllerModel2.voidhandleAWTEvent(AWTEvent aEvent) This is method is called when the target of the listener has a new AWTEvent available.voidvoidvoidvoidDraws a rectangle on the given graphics ifALcdGXYSmartController.isDragging()returns true and if the rectangle is larger asTLcdGXYDragRectangleController.getMouseDraggedSensitivity().protected intselectByWhatMode(ILcdGXYView aGXYView, Rectangle aSelectionBounds, int aMouseMode, MouseEvent aMouseEvent) Returns the mode that defines by what objects can be selected: by their bodies, their labels, ...protected intselectHowMode(ILcdGXYView aGXYView, Rectangle aSelectionBounds, int aMouseMode, MouseEvent aMouseEvent, int aSelectByWhatMode) Returns the mode that indicates how to select the actual candidates from a set of possible selection candidates (selecting the topmost element only or letting the user choose) and how those candidates should interact with the existing selection (add them, remove them, invert their selection state).voidsetAWTFilter(ILcdFilter<AWTEvent> aAWTFilter) Sets the filter specifying to what mouse events the controller should primarily respond to.voidsetDoubleClickAction(ActionListener aDoubleClickAction) Sets the double click action.final voidsetMultiSelectModifierKey(int aKeyDownMask) Sets the modifier key mask to trigger multi-select drag behavior.voidThis method sets the next controller in the chain for this controller.voidsetRightClickAction(ActionListener aRightClickAction) Sets the right click action.voidsetSelectControllerModel(TLcdGXYSelectControllerModel2 aSelectControllerModel) Sets theTLcdGXYSelectControllerModel2.voidstartInteraction(ILcdGXYView aGXYView) Sets up the controller to receive input through the view passed.voidterminateInteraction(ILcdGXYView aGXYView) Releases a few items.voidtrigger(MouseEvent aEvent, Rectangle aRectangleDragged) This method is called on mouseReleased.Methods inherited from class com.luciad.view.gxy.controller.TLcdGXYDragRectangleController
adaptRectangle, doPanGXYView, doZoomGXYView, drawGhost, getCurrentRectangle, getGhostColor, getGhostLineWidth, getHaloColor, getHaloThickness, getMouseDraggedSensitivity, getXORModelColor, isDragCentered, isForceToSquare, isHaloEnabled, isRepaintOnReleased, isTraceOn, isXORMode, lastXPressed, lastXReleased, lastYPressed, lastYReleased, mouseMoved, setDragCentered, setForceToSquare, setGhostColor, setGhostLineWidth, setHaloColor, setHaloEnabled, setHaloThickness, setMouseDraggedSensitivity, setRepaintOnReleased, setTraceOn, setXORMode, setXORModeColor, undoMethods inherited from class com.luciad.view.gxy.controller.ALcdGXYSmartController
addUndoableListener, fireUndoableEvent, getDownPanChars, getDownPanCodes, getLeftPanChars, getLeftPanCodes, getPanAbsDelta, getPanAbsDelta, getRightPanChars, getRightPanCodes, getUndoableListenerCount, getUpPanChars, getUpPanCodes, getZoomInChars, getZoomInCodes, getZoomOutChars, getZoomOutCodes, isDragging, isPanOnMouseDragExit, isPanOnMouseMoveExit, isPanUndoable, isRequestFocusOnMouseEntered, isRequestFocusOnMousePressed, isZoomUndoable, keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, removeUndoableListener, setDownPanChars, setDownPanCodes, setIsDragging, setLeftPanChars, setLeftPanCodes, setPanAbsDelta, setPanOnMouseDragExit, setPanOnMouseMoveExit, setPanUndoable, setRequestFocusOnMouseEntered, setRequestFocusOnMousePressed, setRightPanChars, setRightPanCodes, setUpPanChars, setUpPanCodes, setZoomInChars, setZoomInCodes, setZoomOutChars, setZoomOutCodes, setZoomUndoable, updateViewLocationAfterZoomSFCTMethods inherited from class com.luciad.view.gxy.controller.ALcdGXYController
addStatusListener, asGXYController, fireStatusEvent, getCursor, getGXYView, getIcon, getName, getShortDescription, registerInstance, removeStatusListener, retrieveGXYViewXYWorldTransformation, setClassTraceOn, setCursor, setGXYView, setIcon, setName, setShortDescription, viewRepaintMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.luciad.view.gxy.ILcdGXYController
getCursor, getIcon, getLayered, getName, getShortDescription, viewRepaintMethods inherited from interface java.awt.event.MouseListener
mouseClicked, mouseEntered, mouseExited
-
Constructor Details
-
TLcdGXYSelectController2
public TLcdGXYSelectController2()Constructs a new select controller. The controller can be activated usingILcdGXYView.setGXYController(com.luciad.view.gxy.ILcdGXYController). -
TLcdGXYSelectController2
Constructs a newTLcdGXYSelectController2, with the givenTLcdGXYSelectControllerModel2.- Parameters:
aSelectControllerModel- The controller model, defining the selection behavior.
-
-
Method Details
-
getSelectControllerModel
Returns theTLcdGXYSelectControllerModel2.- Returns:
- the
TLcdGXYSelectControllerModel2. - See Also:
-
setSelectControllerModel
Sets theTLcdGXYSelectControllerModel2. This allows to customize the behavior of for example modifier keys, disable selection by clicking on labels, etc. Please refer toTLcdGXYSelectControllerModel2for more information.- Parameters:
aSelectControllerModel- The select controller model to set.- See Also:
-
getDoubleClickAction
Returns the double click action.- Returns:
- the double click action.
- See Also:
-
setDoubleClickAction
Sets the double click action. This action is performed when the user double clicks. Use
null(the default) to disable this feature.The double click action will be triggered by a
TLcdActionAtLocationEvent- Parameters:
aDoubleClickAction- The double click action, or null.
-
getRightClickAction
Returns the right click action.- Returns:
- the right click action.
- See Also:
-
setRightClickAction
Sets the right click action. This action is performed when the user clicks with the right mouse button. This could for example popup a context sensitive menu. Use
null(the default) to disable this feature.The right click action will be triggered by a
TLcdActionAtLocationEvent.- Parameters:
aRightClickAction- The right click action, or null.
-
setAWTFilter
Sets the filter specifying to what mouse events the controller should primarily respond to. The right click action is not affected by this.- See Also:
-
getAWTFilter
Returns the filter specifying to what mouse events the controller should respond to.- Returns:
- a filter for the allowed mouse events (e.g. only for MouseEvent.BUTTON1), or null
-
getMultiSelectModifierKey
public final int getMultiSelectModifierKey()Returns the modifier key mask to trigger multi-select drag behavior. By default, the drag is triggered when holding down the shift key.- Returns:
- one of
InputEvent.SHIFT_DOWN_MASK,InputEvent.CTRL_DOWN_MASK,InputEvent.ALT_DOWN_MASK,InputEvent.META_DOWN_MASK, or zero to always enable multi-select drag mode - Since:
- 2019.0
-
setMultiSelectModifierKey
public final void setMultiSelectModifierKey(int aKeyDownMask) Sets the modifier key mask to trigger multi-select drag behavior.- Parameters:
aKeyDownMask- one ofInputEvent.SHIFT_DOWN_MASK,InputEvent.CTRL_DOWN_MASK,InputEvent.ALT_DOWN_MASK,InputEvent.META_DOWN_MASK, or zero to always enable multi-select drag mode.- Since:
- 2019.0
-
mousePressed
- Specified by:
mousePressedin interfaceMouseListener- Overrides:
mousePressedin classTLcdGXYDragRectangleController
-
trigger
Description copied from class:TLcdGXYDragRectangleControllerThis method is called on mouseReleased. It can be redefined to implement specific behavior with the "created" java.awt.Rectangle given as argument. Extensions might want to verify if the given rectangle is larger as the drag sensitivity, e.g.:aRectangleDragged.width >= getMouseDraggedSensitivity() || aRectangleDragged.height >= getMouseDraggedSensitivity()- Overrides:
triggerin classTLcdGXYDragRectangleController- Parameters:
aEvent- theMouseEventreceived on mouseReleased.aRectangleDragged- the dragged java.awt.Rectangle. Do not reuse this instance directly, make a copy instead.
-
mouseReleased
- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classTLcdGXYDragRectangleController
-
mouseDragged
- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classTLcdGXYDragRectangleController
-
selectByWhatMode
protected int selectByWhatMode(ILcdGXYView aGXYView, Rectangle aSelectionBounds, int aMouseMode, MouseEvent aMouseEvent) Returns the mode that defines by what objects can be selected: by their bodies, their labels, ...
The default behavior of this method is to indicate that objects can be selected by their bodies and labels, both when clicking or dragging the mouse.
Introducing custom modes
If none of the predefined modes is sufficient for your needs, you can introduce custom ones by overriding this method and returning a custom value. Make sure when defining a new mode that the integer constant for your mode is greater than or equal to
1 << 25.The select controller model installed on this controller must have custom implementations for:
TLcdGXYSelectControllerModel2.selectionCandidates(ILcdGXYView, Rectangle, int, MouseEvent, int, int)TLcdGXYSelectControllerModel2.applySelection(ILcdGXYView, Rectangle, int, int, int, int, int, ILcdGXYLayerSubsetList)
that can deal with this new mode.
Note that the select-by-what and select-how modes can be a bit-wise or of several constants, so when providing custom implementations for the above methods which are testing if for example
SELECT_HOW_CHOOSEis part of some select-how value should be done like this:(aSelectHowMode & SELECT_HOW_CHOOSE) != 0- Parameters:
aGXYView- TheILcdGXYView, provided as contextual information.aSelectionBounds- The selection rectangle, in view coordinates (pixels). This could for example be the rectangle the user dragged on the map, or a one pixel wide rectangle for a mouse click.aMouseMode- EitherTLcdGXYSelectControllerModel2.INPUT_MODE_POINTorTLcdGXYSelectControllerModel2.INPUT_MODE_RECTANGLE, indicating if this selection change originated from a mouse click or from a mouse drag.aMouseEvent- The last mouse event that was involved in the selection change.- Returns:
- The select-by-what mode, a bit-wise or of the constants defined in
TLcdGXYSelectControllerModel2that start withSELECT_BY.
-
selectHowMode
protected int selectHowMode(ILcdGXYView aGXYView, Rectangle aSelectionBounds, int aMouseMode, MouseEvent aMouseEvent, int aSelectByWhatMode) Returns the mode that indicates how to select the actual candidates from a set of possible selection candidates (selecting the topmost element only or letting the user choose) and how those candidates should interact with the existing selection (add them, remove them, invert their selection state).
This method should return a bitwise OR of the constants in the
TLcdGXYSelectControllerModel2class starting withSELECT_HOW.The default selection of selection candidates is:
- When the alt-key is pressed, the user is presented with UI to select which object(s) they wanted to select (
TLcdGXYSelectControllerModel2.SELECT_HOW_CHOOSE). - Otherwise, the controller assumes the user wanted to select the topmost element (
TLcdGXYSelectControllerModel2.SELECT_HOW_FIRST_TOUCHED).
The default update of the existing selection is:
- Pressing the shift key will use the
TLcdGXYSelectControllerModel2.SELECT_HOW_INVERT. - When right-clicking on top of an existing selection,
TLcdGXYSelectControllerModel2.SELECT_HOW_NO_CHANGEwill be selected.
Introducing custom modes
If none of the predefined modes is sufficient for your needs, you can introduce custom ones by overriding this method and returning a custom value. Make sure when defining a new mode that the integer constant for your mode is greater than or equal to
1 << 25.The select controller model installed on this controller must have custom implementations for:
TLcdGXYSelectControllerModel2.selectionCandidates(ILcdGXYView, Rectangle, int, MouseEvent, int, int)TLcdGXYSelectControllerModel2.applySelection(ILcdGXYView, Rectangle, int, int, int, int, int, ILcdGXYLayerSubsetList)
that can deal with this new mode.
Note that the select-by-what and select-how modes can be a bit-wise or of several constants, so when providing custom implementations for the above methods which are testing if for example
SELECT_HOW_CHOOSEis part of some select-how value should be done like this:(aSelectHowMode & SELECT_HOW_CHOOSE) != 0- Parameters:
aGXYView- TheILcdGXYView, provided as contextual information.aSelectionBounds- The selection rectangle, in view coordinates (pixels). This could for example be the rectangle the user dragged on the map, or a one pixel wide rectangle for a mouse click.aMouseMode- EitherTLcdGXYSelectControllerModel2.INPUT_MODE_POINTorTLcdGXYSelectControllerModel2.INPUT_MODE_RECTANGLE, indicating if this selection change originated from a mouse click or from a mouse drag.aMouseEvent- The last mouse event that was involved in the selection change.aSelectByWhatMode- The select-by-what mode, for example the result of the methodselectByWhatMode. It is a bit-wise or of the constants inTLcdGXYSelectControllerModel2that start withSELECT_BY.- Returns:
- The select-how mode, a bit-wise or of the constants in
TLcdGXYSelectControllerModel2that start withSELECT_HOW.
- When the alt-key is pressed, the user is presented with UI to select which object(s) they wanted to select (
-
paint
Description copied from class:TLcdGXYDragRectangleControllerDraws a rectangle on the given graphics ifALcdGXYSmartController.isDragging()returns true and if the rectangle is larger asTLcdGXYDragRectangleController.getMouseDraggedSensitivity().- Specified by:
paintin interfaceILcdGXYController- Overrides:
paintin classTLcdGXYDragRectangleController- Parameters:
aGraphics- The graphics to draw on.
-
startInteraction
Description copied from class:ALcdGXYControllerSets up the controller to receive input through the view passed.All
ILcdGXYViewimplementations that support interaction call this method when the controller has been made active withsetGXYControlleron the view, so this method shouldn't normally be called directly. Note that most view implementations add the controller as listener if appropriate before calling this method.Sets the cursor on the view and sets the view for which this controller is now active. Sends out a status event based on the
short description.- Specified by:
startInteractionin interfaceILcdGXYController- Overrides:
startInteractionin classALcdGXYSmartController- Parameters:
aGXYView- theILcdGXYViewthisILcdGXYControllerwill interact with.- See Also:
-
terminateInteraction
Description copied from class:ALcdGXYControllerReleases a few items. Can be redefined but this 'super' method should be called too.- Specified by:
terminateInteractionin interfaceILcdGXYController- Overrides:
terminateInteractionin classALcdGXYSmartController- Parameters:
aGXYView- theILcdGXYViewthisILcdGXYControllerinteracted with.- See Also:
-
getNextGXYController
Description copied from interface:ILcdGXYChainableControllerReturns a reference to the controller that is located after this one in a chain, or null if this controller is the last element of the chain.- Specified by:
getNextGXYControllerin interfaceILcdGXYChainableController- Returns:
- a reference to the next controller.
- See Also:
-
setNextGXYController
Description copied from interface:ILcdGXYChainableControllerThis method sets the next controller in the chain for this controller. You can set null if you want the chain to end. This method does not start or terminate any interaction. If you need to replace a controller while it's being used you are responsible for properly terminating and starting it yourself.- Specified by:
setNextGXYControllerin interfaceILcdGXYChainableController- Parameters:
aNext- the reference to the controller that will be the next element in the chain- See Also:
-
appendGXYController
Description copied from interface:ILcdGXYChainableControllerThis method will append the passed controller to the end of the chain. The controller will be the stored as the next controller in the last element of the current chain.- Specified by:
appendGXYControllerin interfaceILcdGXYChainableController- Parameters:
aEnd- the controller to be appended to the end of the chain.
-
handleAWTEvent
Description copied from interface:ILcdAWTEventListenerThis is method is called when the target of the listener has a new AWTEvent available.- Specified by:
handleAWTEventin interfaceILcdAWTEventListener- Parameters:
aEvent- The event to be handled.
-