Class GestureFollower
Object
CanvasFollower
GestureFollower
- All Implemented Interfaces:
PropertyChangeListener, EventListener, EventHandler<MouseEvent>, Disposable
A listener of mouse or keyboard events in a source canvas which can be reproduced in a target canvas.
This listener can reproduce the "real world" displacements documented in parent class.
In addition, this class can also follow mouse movements in source canvas and move a cursor in the target canvas
at the same "real world" position. These two features are disabled by default and can be enabled by setting the
transformEnabled and/or cursorEnabled flags to true.
Listeners
GestureFollower listeners need to be registered explicitly by a call to the CanvasFollower.initialize() method.
Conversely, the dispose() method unregisters all those listeners. The listeners are unidirectional:
changes in the source canvas are applied on the target canvas, but not the converse.
Multi-threading
This class is not thread-safe. All events should be processed in the JavaFX thread.- Since:
- 1.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal BooleanPropertyWhether mouse position in source canvas should be shown by a cursor in the target canvas.final BooleanPropertyWhether changes in the "objective to display" transforms should be propagated from source to target canvas.Fields inherited from class CanvasFollower
source, targetModifier and TypeFieldDescriptionfinal PlanarCanvasThe canvas which is the source of zoom, translation or rotation events.final PlanarCanvasThe canvas on which to apply the change of zoom, translation or rotation. -
Constructor Summary
ConstructorsConstructorDescriptionGestureFollower(MapCanvas source, MapCanvas target) Creates a new listener for synchronizing "objective to display" transform changes and cursor position between the specified canvas. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Removes all listeners registered by thisGestureFollowerinstance.protected booleanfilter(TransformChangeEvent event) Returnstrueif this listener should replicate the following changes on the target canvas.Returns the position for the mouse cursor in the source canvas if that position is known.voidhandle(MouseEvent event) Invoked when the mouse position changed.protected voidInvoked after the source "objective to display" transform has been updated.Methods inherited from class CanvasFollower
getDisplayTransform, getFollowRealWorld, getSourceObjectivePOI, initialize, isDisabled, propertyChange, setDisabled, setFollowRealWorld, transformDisplayCoordinates, transformedTarget, transformObjectiveCoordinatesModifier and TypeMethodDescriptionReturns the transform from source display coordinates to target display coordinates.booleanReturns whether this instance is following changes in "real world" coordinates.Returns the objective coordinates of the Point Of Interest (POI) in source canvas.voidRegisters all listeners needed by this object.booleanReturnstrueif this object stopped to replicate changes from source canvas to target canvas.voidInvoked when the objective CRS, zoom, translation or rotation changed on a map that we are tracking.voidsetDisabled(boolean stop) Sets whether to stop to replicate changes from source canvas to target canvas.voidsetFollowRealWorld(boolean real) Sets whether this instance should following changes in "real world" coordinates.protected voidInvoked byCanvasFollower.propertyChange(PropertyChangeEvent)for updating the transform of the target canvas in display units (typically pixels).protected voidInvoked after the target "objective to display" transform has been updated.protected voidInvoked byCanvasFollower.propertyChange(PropertyChangeEvent)for updating the transform of the target canvas in units of the objective CRS.
-
Field Details
-
transformEnabled
Whether changes in the "objective to display" transforms should be propagated from source to target canvas. The default value isfalse. This property needs to be enabled explicitly by caller if desired.- See Also:
-
cursorEnabled
Whether mouse position in source canvas should be shown by a cursor in the target canvas. The default value isfalse. This property needs to be enabled explicitly by caller if desired.
-
-
Constructor Details
-
GestureFollower
Creates a new listener for synchronizing "objective to display" transform changes and cursor position between the specified canvas. This is a unidirectional binding: changes in source are applied on target, but not the converse.Caller needs to register listeners by a call to the
CanvasFollower.initialize()method. This is not done automatically by this constructor for allowing users to control when to start listening tosourcechange events.- Parameters:
source- the canvas which is the source of zoom, pan or rotation events.target- the canvas on which to apply the changes of zoom, pan or rotation.- Throws:
IllegalArgumentException- ifsourceandtargetare the same map canvas.
-
-
Method Details
-
getSourceDisplayPOI
Returns the position for the mouse cursor in the source canvas if that position is known. This information is used when the source and target canvases do not use the same CRS.GestureFollowertries to transform the canvas views in such a way that the "real world" change is the same for both canvas at that location.The returned value is "live"; it may change with mouse and gesture events. Callers should not modify that value, and copy it if they need to keep it.
- Overrides:
getSourceDisplayPOIin classCanvasFollower- Returns:
- mouse position in source canvas where displacements, zooms and rotations applied on the source canvas should be mirrored exactly on the target canvas.
-
handle
Invoked when the mouse position changed. This method should be invoked only ifcursorEnabledistrue(this is not verified by this method).- Specified by:
handlein interfaceEventHandler<MouseEvent>- Parameters:
event- the enter, exit or move event.
-
filter
Returnstrueif this listener should replicate the following changes on the target canvas. This implementation returnstrueif the transform reason isTransformChangeEvent.Reason.INTERIM. It allows immediate feedback to users without waiting for the background thread to complete the rendering.- Overrides:
filterin classCanvasFollower- Parameters:
event- a transform change event that occurred on the source canvas.- Returns:
- whether to replicate that change on the target canvas.
-
transformedSource
Invoked after the source "objective to display" transform has been updated. This implementation adjusts the cursor position for compensating the relative change in mouse position.Details
If the map moved in the source canvas without a change of mouse cursor position (for example if the user navigates using the keyboard), then the mouse position changed relatively to the map, so the cursor position on the target canvas needs to be updated accordingly. This is a temporary change applied until the nextMouseEventgives us new mouse coordinates relative to the map.- Overrides:
transformedSourcein classCanvasFollower- Parameters:
event- the change which has been applied on the CanvasFollower.source canvas.
-
dispose
public void dispose()Removes all listeners registered by thisGestureFollowerinstance. This method should be invoked whenGestureFolloweris no longer needed, in order to avoid memory leak.- Specified by:
disposein interfaceDisposable- Overrides:
disposein classCanvasFollower- See Also:
-