org.geotoolkit.gui.swing
Class Plot2D

Object
  extended by Component
      extended by Container
          extended by JComponent
              extended by ZoomPane
                  extended by Plot2D
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, DeformableViewer
Direct Known Subclasses:
MosaicPerformanceGraph

public class Plot2D
extends ZoomPane

Displays two axes and an arbitrary amount of series with zoom capability. Axes may have arbitrary orientation (they don't need to be perpendicular). It is possible for example to create a plot with a vertical x axis increasing downward, like the ones used in oceanography for plotting the data of Conductivity, Temperature, Depth (CTD) Sensors. Axes can also be oblique for simulating 3D effects.

Axes color and font can bet set with call to JComponent.setForeground(java.awt.Color) and JComponent.setFont(java.awt.Font) methods respectively. A scroll pane can be created with ZoomPane.createScrollPane(). The example below creates a plot with zoom capability restricted to the x axis:

float[] x = ...:
float[] y = ...:
Plot2D plot = new Plot2D(true, false);
plot.addXAxis("Some x values");
plot.addYAxis("Some y values");
plot.addSeries("Random values", Color.BLUE, x, y);


Demo
The image on the left side gives an example of this widget appearance. To try this component in your browser, see the demonstration applet.

Since:
1.1
Version:
3.00
Author:
Martin Desruisseaux (MPO, Geomatys)
See Also:
Serialized Form
Module:
display/geotk-widgets-swing (download)    View source code for this class

Nested Class Summary
static interface Plot2D.Series
          A series to be displayed in a Plot2D widget.
 
Nested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected static List<Color> DEFAULT_COLORS
          The default cycle of colors.
 
Fields inherited from class ZoomPane
DEFAULT_ZOOM, RESET, ROTATE, SCALE_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y, UNIFORM_SCALE, zoom
 
Fields inherited from class 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 Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Plot2D()
          Crestes an initially empty Plot2D with zoom capabilities on horizontal and vertical axis.
Plot2D(boolean zoomX, boolean zoomY)
          Creates an initially empty Plot2D with zoom capabilities on the specified axis.
 
Method Summary
 Plot2D.Series addSeries(Map<String,?> properties, Vector x, Vector y)
          Adds a new serie to the plot.
 Plot2D.Series addSeries(Plot2D.Series series)
          Adds a new serie to the plot.
 Plot2D.Series addSeries(String name, Paint color, double[] x, double[] y)
          Adds a new serie to the plot.
 Plot2D.Series addSeries(String name, Paint color, float[] x, float[] y)
          Adds a new serie to the plot.
 void addXAxis(String label)
          Adds a new x axis to be used for the next series to be added to this plot.
 void addYAxis(String label)
          Adds a new y axis to be used for the next series to be added to this plot.
 void clear()
          Removes all axes and series from this plot.
 Rectangle2D getArea()
          Returns the minimal and maximal ordinate values of all (x,y) points to be plotted.
 Axis2D[] getAxes(Plot2D.Series series)
          Returns the {x, y} axes for the specified series.
 Color getGridColor()
          Returns the color to use for drawing grid lines, or null if the grid should not be drawn.
 Insets getMargin()
          Returns the margin between the widget bounds and the zoomable bounds.
 Set<Plot2D.Series> getSeries()
          Returns the set of series to be plotted.
protected  Rectangle getZoomableBounds(Rectangle bounds)
          Returns the zoomable area in pixel coordinates.
protected  void paintComponent(Graphics2D graphics)
          Paints the axes and all series.
protected  void reset(Rectangle zoomableBounds, boolean yAxisUpward)
          Reinitializes the affine transform zoom in order to cancel any zoom, rotation or translation.
 void setGridColor(Color color)
          Sets the color to use for drawing grid lines, or null if the grid should not be drawn.
 void setMargin(Insets margin)
          Sets the margin between the widget bounds and the zoomable bounds to the given insets.
 void transform(AffineTransform change)
          Changes the zoom by applying an affine transform.
 
Methods inherited from class ZoomPane
addMouseListener, addZoomChangeListener, buildNavigationMenu, correctApparentPixelPosition, createScrollPane, fireZoomChanged, getDefaultSize, getInsets, getMagnifierBorder, getMagnifierGlass, getMagnifierMenu, getMouseSelectionShape, getPopupMenu, getPreferredArea, getPreferredPixelSize, getScaleFactor, getTransform, getVisibleArea, hasPreferredArea, isMagnifierEnabled, isMagnifierVisible, isPaintingWhileAdjusting, mouseSelectionPerformed, paintComponent, paintMagnifier, printComponent, printComponent, removeZoomChangeListener, repaint, reset, scrollRectToVisible, setMagnifierBorder, setMagnifierEnabled, setMagnifierGlass, setMagnifierVisible, setPaintingWhileAdjusting, setPreferredArea, setResetPolicy, setTransform, setVisibleArea, tieModels, transformPixels, untieModels, updateUI
 
Methods inherited from class JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, 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, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, 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
 
Methods inherited from class 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, invalidate, 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 Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, 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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_COLORS

protected static final List<Color> DEFAULT_COLORS
The default cycle of colors. They are used only if the user added a series without specifying explicitly the color to use for that series.

Those default colors may change in future Geotk versions. For safety, users are encouraged to specify the desired color explicitly when adding a series to a plot.

Constructor Detail

Plot2D

public Plot2D()
Crestes an initially empty Plot2D with zoom capabilities on horizontal and vertical axis.


Plot2D

public Plot2D(boolean zoomX,
              boolean zoomY)
Creates an initially empty Plot2D with zoom capabilities on the specified axis.

Parameters:
zoomX - true for allowing zooming on the x axis.
zoomY - true for allowing zooming on the y axis.
Method Detail

addXAxis

public void addXAxis(String label)
Adds a new x axis to be used for the next series to be added to this plot. Special cases:

Parameters:
label - The axis label, or null if the axis should not have any label.

addYAxis

public void addYAxis(String label)
Adds a new y axis to be used for the next series to be added to this plot. Special cases:

Parameters:
label - The axis label, or null if the axis should not have any label.

addSeries

public Plot2D.Series addSeries(String name,
                               Paint color,
                               float[] x,
                               float[] y)
                        throws MismatchedSizeException
Adds a new serie to the plot. This convenience method wraps the given arrays into Vector objects and delegates to addSeries(Map, Vector, Vector).

Parameters:
name - The series name, or null if none.
color - The color to use for plotting the series, or null for a default color.
x - The vector of x values.
y - The vector of y values.
Returns:
The series added.
Throws:
MismatchedSizeException - if the arrays don't have the same length.

addSeries

public Plot2D.Series addSeries(String name,
                               Paint color,
                               double[] x,
                               double[] y)
                        throws MismatchedSizeException
Adds a new serie to the plot. This convenience method wraps the given arrays into Vector objects and delegates to addSeries(Map, Vector, Vector).

Parameters:
name - The series name, or null if none.
color - The color to use for plotting the series, or null for a default color.
x - The vector of x values.
y - The vector of y values.
Returns:
The series added.
Throws:
MismatchedSizeException - if the arrays don't have the same length.

addSeries

public Plot2D.Series addSeries(Map<String,?> properties,
                               Vector x,
                               Vector y)
                        throws MismatchedSizeException
Adds a new serie to the plot. This method creates a default Plot2D.Series implementation for the given vectors and delegates to addSeries(Series). The series is configured using the values given in the properties map. The following keys are recognized:

Any keys not recognized by this method are ignored and can be used by subclasses for their own additional information. Missing entries will be replaced by default values. Future versions of the Plot2D class may add more keys - this method is using a Map argument for allowing such extensibility.

Parameters:
properties - The properties to be given to the new series.
x - The vector of x values.
y - The vector of y values.
Returns:
The series added.
Throws:
MismatchedSizeException - if the arrays don't have the same length.

addSeries

public Plot2D.Series addSeries(Plot2D.Series series)
Adds a new serie to the plot. The new series will use the axes given by the last calls to addXAxis and addYAxis.

Parameters:
series - The serie to add.
Returns:
The added series, returned for convenience.

getSeries

public Set<Plot2D.Series> getSeries()
Returns the set of series to be plotted. Series are painted in the order they are returned.

Returns:
The series to be plotted.

getGridColor

public Color getGridColor()
Returns the color to use for drawing grid lines, or null if the grid should not be drawn.

Returns:
The current grid color, or null if none.

setGridColor

public void setGridColor(Color color)
Sets the color to use for drawing grid lines, or null if the grid should not be drawn.

Parameters:
color - The new grid color to use, or null if none.

getAxes

public Axis2D[] getAxes(Plot2D.Series series)
                 throws NoSuchElementException
Returns the {x, y} axes for the specified series.

Parameters:
series - The series for which axis are wanted.
Returns:
An array of length 2 containing x and y axis.
Throws:
NoSuchElementException - if this widget doesn't contains the specified series.

getArea

public Rectangle2D getArea()
Returns the minimal and maximal ordinate values of all (x,y) points to be plotted. This is the union of the bounding boxes of all series in this Plot2D component.

Specified by:
getArea in class ZoomPane
Returns:
The minimal and maximal ordinate values of (x,y) points.

getZoomableBounds

protected Rectangle getZoomableBounds(Rectangle bounds)
Returns the zoomable area in pixel coordinates. This area will not cover the full widget area, since some room will be left for painting axis and titles.

Overrides:
getZoomableBounds in class ZoomPane
Parameters:
bounds - An optional pre-allocated rectangle, or null to create a new one. This argument is useful if the caller wants to avoid allocating a new object on the heap.
Returns:
The bounding box of the zoomable area, in pixel coordinates relative to this ZoomPane widget.

getMargin

public Insets getMargin()
Returns the margin between the widget bounds and the zoomable bounds. The zoomable bounds is the area where the graph will be plotted.

Returns:
The margin between widget bounds and the area where the graph is plotted.
Since:
3.00

setMargin

public void setMargin(Insets margin)
Sets the margin between the widget bounds and the zoomable bounds to the given insets.

Parameters:
margin - The new margin between widget bounds and the area where the graph is plotted.
Since:
3.00

reset

protected void reset(Rectangle zoomableBounds,
                     boolean yAxisUpward)
Reinitializes the affine transform zoom in order to cancel any zoom, rotation or translation. The argument yAxisUpward indicates whether the y axis should point upwards, which is usually true for a plot.

Overrides:
reset in class ZoomPane
Parameters:
zoomableBounds - Coordinates, in pixels, of the screen space in which to draw. This argument will usually be getZoomableBounds(null).
yAxisUpward - true if the y axis should point upwards rather than downwards.

transform

public void transform(AffineTransform change)
Changes the zoom by applying an affine transform. The change transform must express a change in the units of the series added to this widget. The location of axes will not change as a result of the given transform. Instead, the axis graduations will be updated with new minimal and maximal values matching the new zoom.

Overrides:
transform in class ZoomPane
Parameters:
change - The zoom change, as an affine transform in logical coordinates. If change is the identity transform, then this method does nothing and listeners are not notified.

paintComponent

protected void paintComponent(Graphics2D graphics)
Paints the axes and all series. At the opposite of typical ZoomPane subclasses, this method does not use directly the zoom transform. The zoom is honored only indirectly since the axis graduations have been determined from the zoom by the transform(AffineTransform) method.

Specified by:
paintComponent in class ZoomPane
Parameters:
graphics - The graphics where to paint this component.

clear

public void clear()
Removes all axes and series from this plot.



Copyright © 2009-2013 Geotoolkit.org. All Rights Reserved.