public class TLcdGXYSelectController2 extends TLcdGXYDragRectangleController implements MouseListener, ILcdGXYChainableController
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.
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.
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.
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.
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.
TLcdGXYSelectControllerModel2
.
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.
ActionListener
which 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.
ActionListener
which 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.
fXPressed, fXReleased, fYPressed, fYReleased
Constructor and Description |
---|
TLcdGXYSelectController2()
Constructs a new select controller.
|
TLcdGXYSelectController2(TLcdGXYSelectControllerModel2 aSelectControllerModel)
Constructs a new
TLcdGXYSelectController2 , with the given
TLcdGXYSelectControllerModel2 . |
Modifier and Type | Method and Description |
---|---|
void |
appendGXYController(ILcdGXYChainableController aEnd)
This method will append the passed controller to the end of the chain.
|
ILcdFilter<AWTEvent> |
getAWTFilter()
Returns the filter specifying to what mouse events the controller should respond to.
|
ActionListener |
getDoubleClickAction()
Returns the double click action.
|
int |
getMultiSelectModifierKey()
Returns the modifier key mask to trigger multi-select drag behavior.
|
ILcdGXYChainableController |
getNextGXYController()
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.
|
ActionListener |
getRightClickAction()
Returns the right click action.
|
TLcdGXYSelectControllerModel2 |
getSelectControllerModel()
Returns the
TLcdGXYSelectControllerModel2 . |
void |
handleAWTEvent(AWTEvent aEvent)
This is method is called when the target of the listener has a new AWTEvent available.
|
void |
mouseDragged(MouseEvent me) |
void |
mousePressed(MouseEvent me) |
void |
mouseReleased(MouseEvent me) |
void |
paint(Graphics aGraphics)
Draws a rectangle on the given graphics if
ALcdGXYSmartController.isDragging() returns true and
if the rectangle is larger as TLcdGXYDragRectangleController.getMouseDraggedSensitivity() . |
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, ...
|
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).
|
void |
setAWTFilter(ILcdFilter<AWTEvent> aAWTFilter)
Sets the filter specifying to what mouse events the controller should primarily respond to.
|
void |
setDoubleClickAction(ActionListener aDoubleClickAction)
Sets the double click action.
|
void |
setMultiSelectModifierKey(int aKeyDownMask)
Sets the modifier key mask to trigger multi-select drag behavior.
|
void |
setNextGXYController(ILcdGXYChainableController aNext)
This method sets the next controller in the chain for this controller.
|
void |
setRightClickAction(ActionListener aRightClickAction)
Sets the right click action.
|
void |
setSelectControllerModel(TLcdGXYSelectControllerModel2 aSelectControllerModel)
Sets the
TLcdGXYSelectControllerModel2 . |
void |
startInteraction(ILcdGXYView aGXYView)
Sets up the controller to receive input through the view passed.
|
void |
terminateInteraction(ILcdGXYView aGXYView)
Releases a few items.
|
void |
trigger(MouseEvent aEvent,
Rectangle aRectangleDragged)
This method is called on mouseReleased.
|
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, undo
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, updateViewLocationAfterZoomSFCT
addStatusListener, asGXYController, fireStatusEvent, getCursor, getGXYView, getIcon, getName, getShortDescription, registerInstance, removeStatusListener, retrieveGXYViewXYWorldTransformation, setClassTraceOn, setCursor, setGXYView, setIcon, setName, setShortDescription, viewRepaint
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
mouseClicked, mouseEntered, mouseExited
getCursor, getIcon, getLayered, getName, getShortDescription, viewRepaint
public TLcdGXYSelectController2()
ILcdGXYView.setGXYController(com.luciad.view.gxy.ILcdGXYController)
.public TLcdGXYSelectController2(TLcdGXYSelectControllerModel2 aSelectControllerModel)
TLcdGXYSelectController2
, with the given
TLcdGXYSelectControllerModel2
.aSelectControllerModel
- The controller model, defining the selection behavior.public TLcdGXYSelectControllerModel2 getSelectControllerModel()
TLcdGXYSelectControllerModel2
.TLcdGXYSelectControllerModel2
.setSelectControllerModel(TLcdGXYSelectControllerModel2)
public void setSelectControllerModel(TLcdGXYSelectControllerModel2 aSelectControllerModel)
TLcdGXYSelectControllerModel2
. This allows to customize
the behavior of for example modifier keys, disable selection by clicking on
labels, etc. Please refer to TLcdGXYSelectControllerModel2
for more
information.aSelectControllerModel
- The select controller model to set.TLcdGXYSelectControllerModel2
public ActionListener getDoubleClickAction()
setDoubleClickAction(java.awt.event.ActionListener)
public void setDoubleClickAction(ActionListener aDoubleClickAction)
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
aDoubleClickAction
- The double click action, or null.public ActionListener getRightClickAction()
setRightClickAction(java.awt.event.ActionListener)
public void setRightClickAction(ActionListener aRightClickAction)
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
.
aRightClickAction
- The right click action, or null.public void setAWTFilter(ILcdFilter<AWTEvent> aAWTFilter)
TLcdAWTEventFilterBuilder
public ILcdFilter<AWTEvent> getAWTFilter()
public final int getMultiSelectModifierKey()
InputEvent.SHIFT_DOWN_MASK
, InputEvent.CTRL_DOWN_MASK
, InputEvent.ALT_DOWN_MASK
,
InputEvent.META_DOWN_MASK
, or zero to always enable multi-select drag modepublic final void setMultiSelectModifierKey(int aKeyDownMask)
aKeyDownMask
- 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.public void mousePressed(MouseEvent me)
mousePressed
in interface MouseListener
mousePressed
in class TLcdGXYDragRectangleController
public void trigger(MouseEvent aEvent, Rectangle aRectangleDragged)
TLcdGXYDragRectangleController
aRectangleDragged.width >= getMouseDraggedSensitivity() ||
aRectangleDragged.height >= getMouseDraggedSensitivity()
trigger
in class TLcdGXYDragRectangleController
aEvent
- the MouseEvent
received on mouseReleased.aRectangleDragged
- the dragged java.awt.Rectangle. Do not reuse
this instance directly, make a copy instead.public void mouseReleased(MouseEvent me)
mouseReleased
in interface MouseListener
mouseReleased
in class TLcdGXYDragRectangleController
public void mouseDragged(MouseEvent me)
mouseDragged
in interface MouseMotionListener
mouseDragged
in class TLcdGXYDragRectangleController
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.
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_CHOOSE
is part of some select-how value should be done like this:
(aSelectHowMode & SELECT_HOW_CHOOSE) != 0
aGXYView
- The ILcdGXYView
, 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
- Either TLcdGXYSelectControllerModel2.INPUT_MODE_POINT
or TLcdGXYSelectControllerModel2.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.TLcdGXYSelectControllerModel2
that start with SELECT_BY
.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 TLcdGXYSelectControllerModel2
class starting with SELECT_HOW
.
The default selection of selection candidates is:
TLcdGXYSelectControllerModel2.SELECT_HOW_CHOOSE
).TLcdGXYSelectControllerModel2.SELECT_HOW_FIRST_TOUCHED
).The default update of the existing selection is:
TLcdGXYSelectControllerModel2.SELECT_HOW_INVERT
.TLcdGXYSelectControllerModel2.SELECT_HOW_NO_CHANGE
will be selected.
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_CHOOSE
is part of some select-how value should be done like this:
(aSelectHowMode & SELECT_HOW_CHOOSE) != 0
aGXYView
- The ILcdGXYView
, 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
- Either TLcdGXYSelectControllerModel2.INPUT_MODE_POINT
or TLcdGXYSelectControllerModel2.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 method selectByWhatMode
. It is a bit-wise
or of the constants in TLcdGXYSelectControllerModel2
that start with SELECT_BY
.TLcdGXYSelectControllerModel2
that start with SELECT_HOW
.public void paint(Graphics aGraphics)
TLcdGXYDragRectangleController
ALcdGXYSmartController.isDragging()
returns true and
if the rectangle is larger as TLcdGXYDragRectangleController.getMouseDraggedSensitivity()
.paint
in interface ILcdGXYController
paint
in class TLcdGXYDragRectangleController
aGraphics
- The graphics to draw on.public void startInteraction(ILcdGXYView aGXYView)
ALcdGXYController
All ILcdGXYView
implementations that support interaction call this method when the controller
has been made active with setGXYController
on 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
.
startInteraction
in interface ILcdGXYController
startInteraction
in class ALcdGXYSmartController
aGXYView
- the ILcdGXYView
this ILcdGXYController
will interact with.ILcdGXYView.setGXYController(com.luciad.view.gxy.ILcdGXYController)
,
ILcdGXYController.terminateInteraction(com.luciad.view.gxy.ILcdGXYView)
public void terminateInteraction(ILcdGXYView aGXYView)
ALcdGXYController
terminateInteraction
in interface ILcdGXYController
terminateInteraction
in class ALcdGXYSmartController
aGXYView
- the ILcdGXYView
this ILcdGXYController
interacted with.ILcdGXYView.setGXYController(com.luciad.view.gxy.ILcdGXYController)
,
ILcdGXYController.startInteraction(com.luciad.view.gxy.ILcdGXYView)
public ILcdGXYChainableController getNextGXYController()
ILcdGXYChainableController
getNextGXYController
in interface ILcdGXYChainableController
ILcdGXYChainableController.setNextGXYController(ILcdGXYChainableController)
public void setNextGXYController(ILcdGXYChainableController aNext)
ILcdGXYChainableController
setNextGXYController
in interface ILcdGXYChainableController
aNext
- the reference to the controller that will be the next element in the chainILcdGXYChainableController.getNextGXYController()
public void appendGXYController(ILcdGXYChainableController aEnd)
ILcdGXYChainableController
appendGXYController
in interface ILcdGXYChainableController
aEnd
- the controller to be appended to the end of the chain.public void handleAWTEvent(AWTEvent aEvent)
ILcdAWTEventListener
handleAWTEvent
in interface ILcdAWTEventListener
aEvent
- The event to be handled.