Class TLspSwipeController

java.lang.Object
com.luciad.view.lightspeed.controller.ALspController
com.luciad.view.lightspeed.controller.visualinspection.TLspSwipeController
All Implemented Interfaces:
ILcdAWTEventListener, ILspController

public class TLspSwipeController extends ALspController
Mouse controller that allows to visually comparing two sets of layers by displaying them on either side of a swipe line. By moving the swipe line different parts of the layer sets are revealed and hidden. This allows easily spotting differences between the layer sets.

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 of swiping between two layers

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.

This class is not thread safe. It should be used only on the paint thread.
Since:
2014.1
See Also:
  • 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

      public void startInteraction(ILspView aView)
      Description copied from class: ALspController
      Called to start interacting with the controller. This automatically happens when setting the controller on the view using ILspView.setController(com.luciad.view.lightspeed.controller.ILspController).

      This implementation sends out a status event based on the short description. It also calls startInteraction on the next controller. Override startInteractionImpl if you want to add your own behavior to this controller.

      Specified by:
      startInteraction in interface ILspController
      Overrides:
      startInteraction in class ALspController
      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 have layer type BACKGROUND, using them in this controller will change their type to INTERACTIVE. 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 null
      aLayers2 - 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, or startInteraction(com.luciad.view.lightspeed.ILspView) has been called already.
    • terminateInteraction

      public void terminateInteraction(ILspView aView)
      Description copied from class: ALspController
      Terminates interaction with this controller. This automatically happens when setting a different controller on the view using ILspView.setController(com.luciad.view.lightspeed.controller.ILspController).

      This implementation also calls terminateInteraction on the next controller. Override terminateInteractionImpl if you want to add your own behavior to this controller.

      Specified by:
      terminateInteraction in interface ILspController
      Overrides:
      terminateInteraction in class ALspController
      Parameters:
      aView - the view the controller was operating on
    • handleAWTEventImpl

      public AWTEvent handleAWTEventImpl(AWTEvent aAWTEvent)
      Description copied from class: ALspController
      Called by handleAWTEvent. Returns null when the controller consumed the event or a partially consumed event when the controller partially consumed the event (which could happen with TLcdTouchEvents). When the controller did not use the given event, it is returned unaltered.
      Specified by:
      handleAWTEventImpl in class ALspController
      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

      public Event handleFXEventImpl(Event aEvent)
      Description copied from class: ALspController
      Called by handleFXEvent. Returns null when the controller consumed the event. When the controller did not use the given event, it is returned unaltered.
      Overrides:
      handleFXEventImpl in class ALspController
      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

      public List<Collection<ILspLayer>> getLayers()
      Returns the list of layer collections that we are swiping between.
      Returns:
      the list of layer collections that we are swiping between
    • getSwipeLineOrientation

      public TLspSwipeController.SwipeLineOrientation 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

      public void setSwipeLineOrientation(TLspSwipeController.SwipeLineOrientation aSwipeLineOrientation)
      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

      public Point 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

      public ILspStyler 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

      public void setSwipeLineStyler(ILspStyler aSwipeLineStyler)
      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

      public ILspStyler 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

      public 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).
      Parameters:
      aFocusSwipeLineStyler - the styler used to visualize the swipe line when it has focus
    • getActiveSwipeLineStyler

      public ILspStyler 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

      public 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).
      Parameters:
      aActiveSwipeLineStyler - the styler used to visualize the swipe line when there is interaction
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener aListener)
      Description copied from interface: ILspController
      Adds a PropertyChangeListener to this ILspController.
      Specified by:
      addPropertyChangeListener in interface ILspController
      Overrides:
      addPropertyChangeListener in class ALspController
      Parameters:
      aListener - the listener
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener aListener)
      Description copied from interface: ILspController
      Removes the given PropertyChangeListener from this ILspController.
      Specified by:
      removePropertyChangeListener in interface ILspController
      Overrides:
      removePropertyChangeListener in class ALspController
      Parameters:
      aListener - the listener.