Package uk.ac.starlink.ttools.plot2
Class NavigationListener<A>
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.NavigationListener<A>
-
- All Implemented Interfaces:
java.awt.event.MouseListener,java.awt.event.MouseMotionListener,java.awt.event.MouseWheelListener,java.util.EventListener
public abstract class NavigationListener<A> extends java.lang.Object implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListenerListener that receives mouse events and uses them in conjunction with a supplied navigator to feed navigation actions to a set of one or more plot surfaces.- Since:
- 30 Oct 2013
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedNavigationListener()Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddListeners(java.awt.Component component)Convenience method to install this listener on a graphical component.abstract java.util.function.Supplier<CoordSequence>createDataPosSupplier(java.awt.Point pos)Returns an iterable over a sequence of data space positions, which may be required to make sense of a click action.abstract Navigator<A>getNavigator(int isurf)Returns a navigator which is used to convert mouse gestures into navigation actions.abstract SurfacegetSurface(int isurf)Returns the current plotting surface corresponding to a given numeric label.abstract intgetSurfaceIndex(java.awt.Point pos)Return an index labelling the plotting surface which provides the context for navigation actions referenced at a given point.protected voidhandleClick(Navigator<A> navigator, int isurf, java.awt.Point pos, int ibutt, java.util.function.Supplier<CoordSequence> dposSupplier)Performs the actual work when a mouse click event is detected.voidmouseClicked(java.awt.event.MouseEvent evt)voidmouseDragged(java.awt.event.MouseEvent evt)voidmouseEntered(java.awt.event.MouseEvent evt)voidmouseExited(java.awt.event.MouseEvent evt)voidmouseMoved(java.awt.event.MouseEvent evt)voidmousePressed(java.awt.event.MouseEvent evt)voidmouseReleased(java.awt.event.MouseEvent evt)voidmouseWheelMoved(java.awt.event.MouseWheelEvent evt)voidremoveListeners(java.awt.Component component)Reverses the effect ofaddListeners.protected abstract voidsetAspect(int isurf, A aspect)Receives a new aspect requested by user interface actions in conjunction with this object.protected abstract voidsetDecoration(Decoration decoration)Sets a decoration to display over the plot to indicate navigation actions in progress.voidupdateDecoration(Decoration dec, boolean autoCancel)Requests a change of the current navigation decoration.
-
-
-
Method Detail
-
getSurfaceIndex
public abstract int getSurfaceIndex(java.awt.Point pos)
Return an index labelling the plotting surface which provides the context for navigation actions referenced at a given point.- Parameters:
pos- reference point for navigation- Returns:
- numeric label for plotting surface relevant for actions at, or starting at, the given point
-
getSurface
public abstract Surface getSurface(int isurf)
Returns the current plotting surface corresponding to a given numeric label. The supplied index must be one returned fromgetSurfaceIndex(java.awt.Point)(if not, behaviour is undefined).- Parameters:
isurf- surface index returned fromgetSurfaceIndex- Returns:
- current plotting surface corresponding to the given index; may be null
-
getNavigator
public abstract Navigator<A> getNavigator(int isurf)
Returns a navigator which is used to convert mouse gestures into navigation actions.- Parameters:
isurf- surface index returned fromgetSurfaceIndex- Returns:
- current navigator for indicated surface, may be null
-
createDataPosSupplier
public abstract java.util.function.Supplier<CoordSequence> createDataPosSupplier(java.awt.Point pos)
Returns an iterable over a sequence of data space positions, which may be required to make sense of a click action.- Parameters:
pos- reference position for data- Returns:
- iterable over data positions, may be null
- See Also:
Navigator.click(uk.ac.starlink.ttools.plot2.Surface, java.awt.Point, int, java.util.function.Supplier<uk.ac.starlink.ttools.plot2.CoordSequence>)
-
setAspect
protected abstract void setAspect(int isurf, A aspect)Receives a new aspect requested by user interface actions in conjunction with this object. The supplied aspect corresponds to the surface with the given index, as supplied by thegetSurfaceIndex(java.awt.Point)method.- Parameters:
isurf- label for surface to which new aspect appliesaspect- definition of requested plot surface
-
setDecoration
protected abstract void setDecoration(Decoration decoration)
Sets a decoration to display over the plot to indicate navigation actions in progress. This decoration should be displayed until further notice, that is, until this method is called again with a null argument.This method is called by
updateDecoration. It should not be called directly.- Parameters:
decoration- navigation decoration, or null for none
-
updateDecoration
public void updateDecoration(Decoration dec, boolean autoCancel)
Requests a change of the current navigation decoration. This performs some housekeeping operations, and callssetDecoration(uk.ac.starlink.ttools.plot2.Decoration). TheautoCancelparameter controls whether the decoration will be cancelled automatically or by hand. If the caller can guarantee to make a matching call with a null decoration in the future,autoCancelmay be false, otherwise it should be true.- Parameters:
dec- new decorationautoCancel- if true, decoration will be automatically cancelled
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent evt)
- Specified by:
mousePressedin interfacejava.awt.event.MouseListener
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent evt)
- Specified by:
mouseDraggedin interfacejava.awt.event.MouseMotionListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent evt)
- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent evt)
- Specified by:
mouseClickedin interfacejava.awt.event.MouseListener
-
handleClick
protected void handleClick(Navigator<A> navigator, int isurf, java.awt.Point pos, int ibutt, java.util.function.Supplier<CoordSequence> dposSupplier)
Performs the actual work when a mouse click event is detected. This method is invoked bymouseClicked. The default behaviour is to get a corresponding navigation action from the navigator, and callsetAspect(int, A)andupdateDecoration(uk.ac.starlink.ttools.plot2.Decoration, boolean)accordingly. However, it may be overridden by subclasses.- Parameters:
navigator- navigatorisurf- surface numeric labelpos- mouse positionibutt- logical mouse button indexdposSupplier- iterable over points if available
-
mouseWheelMoved
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt)
- Specified by:
mouseWheelMovedin interfacejava.awt.event.MouseWheelListener
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent evt)
- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent evt)
- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent evt)
- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener
-
addListeners
public void addListeners(java.awt.Component component)
Convenience method to install this listener on a graphical component. This currently just callsaddMouseListener,addMouseMotionListenerandaddMouseWheelListener.- Parameters:
component- component to which this object should listen
-
removeListeners
public void removeListeners(java.awt.Component component)
Reverses the effect ofaddListeners.- Parameters:
component- component to which this listener was previously added
-
-