Class TLspPortholeController

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

public class TLspPortholeController extends ALspController
Mouse controller that allows to visually compare two sets of layers by exposing one set of layers through a porthole in the other set.

The first set of layers is visible by default. The second set is shown in a rectangular area around the mouse location. By moving the mouse different parts of the layer sets are revealed and hidden. This allows easily spotting differences between the layer sets. Holding down the shift key and moving the mouse wheel will resize the porthole.

Example usage of using the controller to compare two layers is shown below:

 

 ILspLayer layer1 = ...;
 ILspLayer layer2 = ...;
 ILspView view = ...;

 TLspPortholeController controller = new TLspPortholeController();
 controller.setLayers(Collections.singleton(layer1), Collections.singleton(layer2));

 view.setController(controller);

 
 

The behavior of the controller can be adapted by overriding or extending handleAWTEventImpl and using the setPortholeLocation(double, double) and setPortholeSize(int) methods, for example based on key strokes.

This class can also be used to implement a programmatic porthole action. In this case, please ensure to call startInteraction and terminateInteraction before and after interacting with it respectively.

This code sample shows how to set up a porthole between two layers in an ILcdAction around AWT location (200, 300):

 

 final ILspLayer layer1 = ...;
 final ILspLayer layer2 = ...;
 final ILspView view = ...;
 final TLspPortholeController controller = new TLspPortholeController();

 ALcdAction action = new ALcdAction() {

   public void actionPerformed(ActionEvent e) {
     if (getValue(ILcdAction.SELECTED_KEY) == Boolean.TRUE) {
       controller.setLayers(Collections.singleton(layer1), Collections.singleton(layer2));
       controller.startInteraction(view);
       controller.setPortholeLocation(200, 300);
       controller.setPortholeSize(100);

       // optionally, enable specific styling of the porthole shape
       for (int i = 0; i < controller.getLayered().layerCount(); i++) {
        getView().addLayer((ILspLayer) controller.getLayered().getLayer(i));
       }
     } else {
       for (int i = 0; i < controller.getLayered().layerCount(); i++) {
        getView().removeLayer(controller.getLayered().getLayer(i));
       }
       controller.terminateInteraction(view);
       controller.removeAllLayers();
     }
   }

 };
 
 

The controller adds a layer to the view to visualize the porthole outline. To customize the visualization, you can use setPortholeStyler(ILspStyler).

This class is not thread safe. It should be used only on the paint thread.

Since:
2016.0
See Also:
  • Constructor Details

    • TLspPortholeController

      public TLspPortholeController()
      Constructs a new controller that visually compares two sets of layers by exposing one set of layers through a porthole in the other set.
  • 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)
      Configures a porthole through the first set of layers, exposing the second set of layers.

      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 interact between layers A and C, but layer B appears in-between layer A and C, that the controller will turn the left part of A visible and the right part of C visible, but that B will obstruct C and the interaction will appear to happen between A and B as opposed to A and C. To overcome this, make sure that you always interact between consecutive layers. In the example this would mean that you interact between the collections {A,B} and {C}.

      Parameters:
      aLayers1 - The layers that will only be visible around the porthole, can be null
      aLayers2 - The layers that will only be visible inside the porthole, 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(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 interacting with.
      Returns:
      the list of layer collections that we are interacting with
    • getPortholeLocation

      public Point getPortholeLocation()
      Returns the porthole center in view coordinates.
      Returns:
      the coordinates that define the location of the porthole in the view
    • setPortholeLocation

      public void setPortholeLocation(double aX, double aY)
      Sets the porthole center in view coordinates.
      Parameters:
      aX - the x-coordinate
      aY - the y-coordinate
    • setPortholeSize

      public void setPortholeSize(int aPortholeSize)
      Defines the size of the area around the porthole location.
      Parameters:
      aPortholeSize - the new width and height of the porthole
    • getPortholeSize

      public int getPortholeSize()
      Returns the size of the area around the porthole location.
      Returns:
      the width and height of the porthole
    • getPortholeStyler

      public ILspStyler getPortholeStyler()
      Returns the styler that is used to visualize the porthole.
      Returns:
      the styler used to visualize the porthole
    • setPortholeStyler

      public void setPortholeStyler(ILspStyler aPortholeStyler)
      Sets the styler that is used to visualize the porthole. The porthole geometry will be a bounds object in view coordinates.
      Parameters:
      aPortholeStyler - the styler used to visualize the porthole
    • 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.