Class TLspSwipeController
- All Implemented Interfaces:
ILcdAWTEventListener
,ILspController
Swiping is done by dragging the swipe line using the mouse from left-to-right or top-to-bottom. This is illustrated in the following screenshot:
Example usage of using the controller to compare two layers is shown below:
ILspLayer layer1 = ...; ILspLayer layer2 = ...; ILspView view = ...; TLspSwipeController swipeController = new TLspSwipeController(); swipeController.setLayers(Collections.singleton(layer1), Collections.singleton(layer2)); view.setController(swipeController);
The behavior of the swipe controller can
be adapted by overriding or extending handleAWTEventImpl
and using the setSwipeLineOrientation
and setSwipeLineLocation
methods
to perform the required swiping, for example on key strokes.
This class can also be used to implement a programmatic swiping action. In this case,
please ensure to call startInteraction
and
terminateInteraction
before and after swiping respectively.
This code sample shows how to set up a swipe line between two layers in an ILcdAction
:
final ILspLayer layer1 = ...;
final ILspLayer layer2 = ...;
final ILspView view = ...;
final TLspSwipeController swipeController = new TLspSwipeController();
ALcdAction swipeAction = new ALcdAction() {
public void actionPerformed(ActionEvent e) {
if (getValue(ILcdAction.SELECTED_KEY) == Boolean.TRUE) {
swipeController.setLayers(Collections.singleton(layer1), Collections.singleton(layer2));
swipeController.startInteraction(view);
swipeController.setSwipeLineOrientation(TLspSwipeController.SwipeLineOrientation.VERTICAL);
swipeController.setSwipeLineLocation(view.getWidth() / 2.0, view.getHeight() / 2.0);
// optionally, enable specific styling of the swipe line
for (int i = 0; i < swipeController.getLayered().layerCount(); i++) {
getView().addLayer((ILspLayer) swipeController.getLayered().getLayer(i));
}
} else {
for (int i = 0; i < swipeController.getLayered().layerCount(); i++) {
getView().removeLayer(swipeController.getLayered().getLayer(i));
}
swipeController.terminateInteraction(view);
swipeController.removeAllLayers();
}
}
};
The swipe controller adds a layer to the view to visualize the swipe line. To customize
the swipe line visualization, you can use setSwipeLineStyler
,
setFocusSwipeLineStyler
, and
setActiveSwipeLineStyler
.
- Since:
- 2014.1
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Indicates the direction of the swipe line. -
Constructor Summary
ConstructorDescriptionConstructs a controller that allows to visually compare two sets of layers by moving a swipe line left/right or up/down. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPropertyChangeListener
(PropertyChangeListener aListener) Adds aPropertyChangeListener
to thisILspController
.Gets the styler that is used to visualize the swipe line when there is interaction (i.e., when the mouse is dragging the swipe line).Gets the styler that is used to visualize the swipe line when the mouse is over the swipe line (i.e., has focus).Returns the list of layer collections that we are swiping between.Gets the swipe line location in view coordinates.Gets the orientation of the swipe line.Gets the styler that is used to visualize the swipe line when there is no interaction.handleAWTEventImpl
(AWTEvent aAWTEvent) Called byhandleAWTEvent
.handleFXEventImpl
(Event aEvent) Called byhandleFXEvent
.boolean
Determines whether the controller is allowed to automatically change the swipe line orientation when dragging the mouse in the opposite direction.boolean
Returns true if the swipe line has focus.void
Removes all layers.void
Removes the givenPropertyChangeListener
from thisILspController
.void
setActiveSwipeLineStyler
(ILspStyler aActiveSwipeLineStyler) Sets the styler that is used to visualize the swipe line when there is interaction (i.e., when the mouse is dragging the swipe line).void
setAutomaticOrientationChange
(boolean aValue) Sets whether the controller is allowed to automatically change the swipe line orientation when dragging the mouse in the opposite direction.void
setFocusSwipeLineStyler
(ILspStyler aFocusSwipeLineStyler) Sets the styler that is used to visualize the swipe line when the mouse is over the swipe line (i.e., has focus).void
setLayers
(Collection<? extends ILspLayer> aLayers1, Collection<? extends ILspLayer> aLayers2) Sets the two sets of layers to swipe.void
setSwipeLineLocation
(double aX, double aY) Sets the swipe line location in view coordinates.void
setSwipeLineOrientation
(TLspSwipeController.SwipeLineOrientation aSwipeLineOrientation) Sets the orientation of the swipe line.void
setSwipeLineStyler
(ILspStyler aSwipeLineStyler) Sets the styler that is used to visualize the swipe line when there is no interaction.void
startInteraction
(ILspView aView) Called to start interacting with the controller.void
terminateInteraction
(ILspView aView) Terminates interaction with this controller.Methods inherited from class com.luciad.view.lightspeed.controller.ALspController
addStatusListener, appendController, firePropertyChange, fireStatusEvent, getAWTFilter, getCursor, getFXCursor, getFXFilter, getIcon, getLayered, getName, getNextController, getShortDescription, getView, handleAWTEvent, handleFXEvent, paint, paintImpl, registerViewPropertyNameForReset, removeStatusListener, setAWTFilter, setCursor, setFXCursor, setFXFilter, setIcon, setName, setShortDescription, startInteractionImpl, terminateInteractionImpl
-
Constructor Details
-
TLspSwipeController
public TLspSwipeController()Constructs a controller that allows to visually compare two sets of layers by moving a swipe line left/right or up/down.
-
-
Method Details
-
startInteraction
Description copied from class:ALspController
Called to start interacting with the controller. This automatically happens when setting the controller on the view usingILspView.setController(com.luciad.view.lightspeed.controller.ILspController)
. This implementation sends out a status event based on theshort description
. It also callsstartInteraction
on the next controller. OverridestartInteractionImpl
if you want to add your own behavior to this controller.- Specified by:
startInteraction
in interfaceILspController
- Overrides:
startInteraction
in classALspController
- Parameters:
aView
- the view the controller operates on
-
setLayers
public void setLayers(Collection<? extends ILspLayer> aLayers1, Collection<? extends ILspLayer> aLayers2) Sets the two sets of layers to swipe. If the provided layers are raster layers and havelayer type
BACKGROUND
, using them in this controller will change their type toINTERACTIVE
. Upon termination the original layer type will be restored. Note that layers in the view that are not specified here are not affected. This for example means that if you swipe between layers A and C, but layer B appears in-between layer A and C, that the swipe controller will turn the left part of A visible and the right part of C visible, but that B will obstruct C and the swiping will appear to happen between A and B as opposed to A and C. To overcome this, make sure that you always swipe between consecutive layers. In the example this would mean that you swipe between the collections {A,B} and {C}.- Parameters:
aLayers1
- The left and top layer, can be nullaLayers2
- The right and bottom layer, can be null
-
removeAllLayers
public void removeAllLayers()Removes all layers. Should only be called when not interacting with the controller (i.e., it should not be set on the view).- Throws:
IllegalStateException
- when the controller is active on the view, orstartInteraction(com.luciad.view.lightspeed.ILspView)
has been called already.
-
terminateInteraction
Description copied from class:ALspController
Terminates interaction with this controller. This automatically happens when setting a different controller on the view usingILspView.setController(com.luciad.view.lightspeed.controller.ILspController)
. This implementation also callsterminateInteraction
on the next controller. OverrideterminateInteractionImpl
if you want to add your own behavior to this controller.- Specified by:
terminateInteraction
in interfaceILspController
- Overrides:
terminateInteraction
in classALspController
- Parameters:
aView
- the view the controller was operating on
-
handleAWTEventImpl
Description copied from class:ALspController
Called byhandleAWTEvent
. Returnsnull
when the controller consumed the event or a partially consumed event when the controller partially consumed the event (which could happen withTLcdTouchEvent
s). When the controller did not use the given event, it is returned unaltered.- Specified by:
handleAWTEventImpl
in classALspController
- Parameters:
aAWTEvent
- the event to be handled.- Returns:
null
when the input event was consumed, the (possibly modified) input event when it was (partially) consumed.
-
handleFXEventImpl
Description copied from class:ALspController
Called byhandleFXEvent
. Returnsnull
when the controller consumed the event. When the controller did not use the given event, it is returned unaltered.- Overrides:
handleFXEventImpl
in classALspController
- Parameters:
aEvent
- the event to be handled.- Returns:
null
when the input event was consumed, the (possibly modified) input event when it was (partially) consumed.
-
getLayers
Returns the list of layer collections that we are swiping between.- Returns:
- the list of layer collections that we are swiping between
-
getSwipeLineOrientation
Gets the orientation of the swipe line. A horizontal swipe line means that the line moves from the left to the right side of the view and that layers appear in the top- or bottom-half of the view. A vertical swipe line means that the line moves from top to bottom of the view and the layers are clipped to appear on the left or right side of the view.- Returns:
- the swipe line orientation
- See Also:
-
setSwipeLineOrientation
Sets the orientation of the swipe line. A horizontal swipe line means that the line moves from the left to the right side of the view and that layers appear in the top- or bottom-half of the view. A vertical swipe line means that the line moves from top to bottom of the view and the layers are clipped to appear on the left or right side of the view.- Parameters:
aSwipeLineOrientation
- the swipe line orientation- See Also:
-
setAutomaticOrientationChange
public void setAutomaticOrientationChange(boolean aValue) Sets whether the controller is allowed to automatically change the swipe line orientation when dragging the mouse in the opposite direction.By default such automatic orientation changes are allowed.
- Parameters:
aValue
- whether or not the controller automatically changes swipe line orientation- See Also:
-
isAutomaticOrientationChange
public boolean isAutomaticOrientationChange()Determines whether the controller is allowed to automatically change the swipe line orientation when dragging the mouse in the opposite direction.By default such automatic orientation changes are allowed.
- See Also:
-
getSwipeLineLocation
Gets the swipe line location in view coordinates. If the swipe line has a horizontal orientation, only the y coordinate is relevant. If the swipe line has a vertical orientation, the x coordinate is considered.- Returns:
- the coordinates that define the location of the swipe line in the view
-
setSwipeLineLocation
public void setSwipeLineLocation(double aX, double aY) Sets the swipe line location in view coordinates. If the swipe line has a horizontal orientation, only the y coordinate is relevant. If the swipe line has a vertical orientation, the x coordinate is considered.- Parameters:
aX
- the x-coordinate, relevant when the swipe line has vertical orientation.aY
- the y-coordinate, relevant when the swipe line has horizontal orientation.
-
getSwipeLineStyler
Gets the styler that is used to visualize the swipe line when there is no interaction.- Returns:
- the styler used to visualize the swipe line when there is no interaction
-
setSwipeLineStyler
Sets the styler that is used to visualize the swipe line when there is no interaction.By default getFocusSwipeLineStyler==getSwipeLineStyler.
- Parameters:
aSwipeLineStyler
- the styler used to visualize the swipe line when there is no interaction
-
isFocused
public boolean isFocused()Returns true if the swipe line has focus. This happens if the user is hovering over it or interacting with it.- Returns:
- true if the swipe line has focus.
-
getFocusSwipeLineStyler
Gets the styler that is used to visualize the swipe line when the mouse is over the swipe line (i.e., has focus).By default getFocusSwipeLineStyler==getSwipeLineStyler.
- Returns:
- the styler used to visualize the swipe line when it has focus
-
setFocusSwipeLineStyler
Sets the styler that is used to visualize the swipe line when the mouse is over the swipe line (i.e., has focus).- Parameters:
aFocusSwipeLineStyler
- the styler used to visualize the swipe line when it has focus
-
getActiveSwipeLineStyler
Gets the styler that is used to visualize the swipe line when there is interaction (i.e., when the mouse is dragging the swipe line).By default getActiveSwipeLineStyler==getSwipeLineStyler.
- Returns:
- the styler used to visualize the swipe line when there is interaction
-
setActiveSwipeLineStyler
Sets the styler that is used to visualize the swipe line when there is interaction (i.e., when the mouse is dragging the swipe line).- Parameters:
aActiveSwipeLineStyler
- the styler used to visualize the swipe line when there is interaction
-
addPropertyChangeListener
Description copied from interface:ILspController
Adds aPropertyChangeListener
to thisILspController
.- Specified by:
addPropertyChangeListener
in interfaceILspController
- Overrides:
addPropertyChangeListener
in classALspController
- Parameters:
aListener
- the listener
-
removePropertyChangeListener
Description copied from interface:ILspController
Removes the givenPropertyChangeListener
from thisILspController
.- Specified by:
removePropertyChangeListener
in interfaceILspController
- Overrides:
removePropertyChangeListener
in classALspController
- Parameters:
aListener
- the listener.
-