uk.ac.starlink.ttools.plot2.task
Class PlotDisplay<P,A>

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by uk.ac.starlink.ttools.plot2.task.PlotDisplay<P,A>
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class PlotDisplay<P,A>
extends JComponent

Graphical component which displays a plot. The plot is in general 'live', and may repaint itself differently over its lifetime according to user navigation actions, window size, and underlying data, depending on how it is configured.

This class can be used as-is, or as a template.

Since:
1 Mar 2013
Author:
Mark Taylor
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String ASPECT_PROPERTY
          Name of property that changes when plot Aspect is reset.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PlotDisplay(PlotLayer[] layers, SurfaceFactory<P,A> surfFact, P profile, A aspect, Icon legend, float[] legPos, String title, ShadeAxisFactory shadeFact, Range shadeFixRange, PaperTypeSelector ptSel, Compositor compositor, DataStore dataStore, boolean surfaceAuxRange, Navigator<A> navigator, boolean caching)
          Constructor.
 
Method Summary
 void addPointSelectionListener(PointSelectionListener psl)
          Adds a listener which will be notified when the user clicks on the plot region to select a point.
 void clearPlot()
          Clears the current cached plot image, if any, so that regeneration of the image from the data is forced when the next paint operation is performed; otherwise it may be copied from a cached image.
static Icon createIcon(PlotPlacement placer, PlotLayer[] layers, Map<AuxScale,Range> auxRanges, DataStore dataStore, PaperType paperType, boolean cached)
          Creates an icon which will paint the content of this plot.
static
<P,A> PlotDisplay
createPlotDisplay(PlotLayer[] layers, SurfaceFactory<P,A> surfFact, ConfigMap config, Icon legend, float[] legPos, String title, ShadeAxisFactory shadeFact, Range shadeFixRange, PaperTypeSelector ptSel, Compositor compositor, DataStore dataStore, boolean surfaceAuxRange, boolean navigable, boolean caching)
          Creates a new PlotDisplay, interrogating a supplied ConfigMap object.
 A getAspect()
          Returns the most recently set aspect.
static Map<AuxScale,Range> getAuxRanges(PlotLayer[] layers, Surface surface, Range shadeFixRange, ShadeAxisFactory shadeFact, DataStore dataStore)
          Gathers requested ranging information from data.
 Surface getSurface()
          Returns the most recently used plot surface.
 void invalidate()
           
protected  void paintComponent(Graphics g)
           
 void removePointSelectionListener(PointSelectionListener psl)
          Removes a previously added point selection listener.
 void setAspect(A aspect)
          Sets the surface aspect.
 void setDataInsets(Insets dataInsets)
          Sets the geometry of the region between the external bound of this component (excluding component borders) and the data region of the plot.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ASPECT_PROPERTY

public static final String ASPECT_PROPERTY
Name of property that changes when plot Aspect is reset. Can be monitored by use of a PropertyChangeListener. The property object type is an aspect, that is of this class's parameterised type A.

See Also:
Constant Field Values
Constructor Detail

PlotDisplay

public PlotDisplay(PlotLayer[] layers,
                   SurfaceFactory<P,A> surfFact,
                   P profile,
                   A aspect,
                   Icon legend,
                   float[] legPos,
                   String title,
                   ShadeAxisFactory shadeFact,
                   Range shadeFixRange,
                   PaperTypeSelector ptSel,
                   Compositor compositor,
                   DataStore dataStore,
                   boolean surfaceAuxRange,
                   Navigator<A> navigator,
                   boolean caching)
Constructor.

Parameters:
layers - layers constituting plot content
surfFact - surface factory
profile - surface profile
aspect - initial surface aspect (may get changed by zooming etc)
legend - legend icon, or null if none required
legPos - 2-element array giving x,y fractional legend placement position within plot (elements in range 0..1), or null for external legend
title - plot title, or null
shadeFact - makes shader axes, or null if not required
shadeFixRange - fixed shader range, or null for auto-range where required
ptSel - paper type selector
compositor - compositor for pixel composition
dataStore - data storage object
surfaceAuxRange - determines whether aux ranges are recalculated when the surface changes
navigator - user gesture navigation controller, or null for a non-interactive plot
caching - if true, plot image will be cached where applicable, if false it will be regenerated from the data on every repaint
Method Detail

clearPlot

public void clearPlot()
Clears the current cached plot image, if any, so that regeneration of the image from the data is forced when the next paint operation is performed; otherwise it may be copied from a cached image. This method is called automatically by invalidate(), but may also be called manually, for instance if the data in the data store may have changed.

This method has no effect if caching is not in force.


addPointSelectionListener

public void addPointSelectionListener(PointSelectionListener psl)
Adds a listener which will be notified when the user clicks on the plot region to select a point.

Parameters:
psl - listener to add

removePointSelectionListener

public void removePointSelectionListener(PointSelectionListener psl)
Removes a previously added point selection listener.

Parameters:
psl - listener to remove

invalidate

public void invalidate()
Overrides:
invalidate in class Container

paintComponent

protected void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

setAspect

public void setAspect(A aspect)
Sets the surface aspect. This triggers a repaint if appropriate.

Parameters:
aspect - new aspect

getAspect

public A getAspect()
Returns the most recently set aspect.

Returns:
current aspect

getSurface

public Surface getSurface()
Returns the most recently used plot surface. It will have been generated by this display's SurfaceFactory.

Returns:
current plotting surface

setDataInsets

public void setDataInsets(Insets dataInsets)
Sets the geometry of the region between the external bound of this component (excluding component borders) and the data region of the plot. This insets region is where axis labels, legend, and other plot decorations are drawn. If null (the default), the extent of the region is worked out automatically and dynamically on the basis of what labels need to be drawn etc.

Parameters:
dataInsets - geometry of the region outside the actual data plot

createPlotDisplay

@Slow
public static <P,A> PlotDisplay createPlotDisplay(PlotLayer[] layers,
                                                       SurfaceFactory<P,A> surfFact,
                                                       ConfigMap config,
                                                       Icon legend,
                                                       float[] legPos,
                                                       String title,
                                                       ShadeAxisFactory shadeFact,
                                                       Range shadeFixRange,
                                                       PaperTypeSelector ptSel,
                                                       Compositor compositor,
                                                       DataStore dataStore,
                                                       boolean surfaceAuxRange,
                                                       boolean navigable,
                                                       boolean caching)
Creates a new PlotDisplay, interrogating a supplied ConfigMap object. This will perform ranging from data if it is required; in that case, it may take time to execute.

Parameters:
layers - layers constituting plot content
surfFact - surface factory
config - map containing surface profile, initial aspect and navigator configuration
legend - legend icon, or null if none required
legPos - 2-element array giving x,y fractional legend placement position within plot (elements in range 0..1), or null for external legend
title - plot title, or null
shadeFact - makes shader axis, or null if not required
shadeFixRange - fixed shader range, or null for auto-range where required
ptSel - paper type selector
compositor - compositor for pixel composition
dataStore - data storage object
surfaceAuxRange - determines whether aux ranges are recalculated when the surface changes
navigable - true for an interactive plot
caching - if true, plot image will be cached where applicable, if false it will be regenerated from the data on every repaint
Returns:
new plot component

createIcon

@Slow
public static Icon createIcon(PlotPlacement placer,
                                   PlotLayer[] layers,
                                   Map<AuxScale,Range> auxRanges,
                                   DataStore dataStore,
                                   PaperType paperType,
                                   boolean cached)
Creates an icon which will paint the content of this plot.

Parameters:
placer - plot placement
layers - layers constituting plot content
auxRanges - requested range information calculated from data
dataStore - data storage object
paperType - rendering type
cached - whether to cache pixels for future use

getAuxRanges

@Slow
public static Map<AuxScale,Range> getAuxRanges(PlotLayer[] layers,
                                                    Surface surface,
                                                    Range shadeFixRange,
                                                    ShadeAxisFactory shadeFact,
                                                    DataStore dataStore)
Gathers requested ranging information from data.

Parameters:
layers - plot layers
surface - plot surface
shadeFixRange - fixed shade range limits, if any
shadeFact - makes shader axis, or null
dataStore - data storage object


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.