org.geotools.gui.swing
Class Plot2D

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byorg.geotools.gui.swing.ZoomPane
                  extended byorg.geotools.gui.swing.Plot2D
All Implemented Interfaces:
DeformableViewer, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Plot2D
extends ZoomPane

A lightweight widget displaying two axis and an arbitrary amount of data series with zoom capability. Axis may have arbitrary orientation (they don't need to be perpendicular). This widget is not a replacement for full featured toolkit like JGraph; it just provides a mean to quickly display a time serie.

Axis color and font can bet set with JComponent.setForeground(java.awt.Color) and JComponent.setFont(java.awt.Font). A scroll pane can be created with ZoomPane.createScrollPane().

 

 

Version:
$Id: Plot2D.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
JGraph, Serialized Form

Nested Class Summary
static interface Plot2D.Series
          A series to be displayed in a Plot2D widget.
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class org.geotools.gui.swing.ZoomPane
DEFAULT_ZOOM, RESET, ROTATE, SCALE_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y, UNIFORM_SCALE, zoom
 
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
Plot2D()
          Construct an initially empty Plot2D with zoom capabilities on horizontal and vertical axis.
Plot2D(boolean zoomX, boolean zoomY)
          Construct an initially empty Plot2D with zoom capabilities on the specified axis.
 
Method Summary
 Plot2D.Series addSeries(Plot2D.Series series)
          Add a new serie to the chart.
 Plot2D.Series addSeries(java.lang.String name, java.lang.Object x, java.lang.Object y)
          Add a new serie to the chart.
 Plot2D.Series addSeries(java.lang.String name, java.lang.Object x, java.lang.Object y, int lower, int upper)
          Add a new serie to the chart.
 void clear(boolean removeAxis)
          Remove all series.
 java.awt.geom.Rectangle2D getArea()
          Returns a bounding box that contains the logical coordinates of all data that may be displayed in this Plot2D.
 Axis2D[] getAxis(Plot2D.Series series)
          Returns the {x, y} axis for the specified series.
 java.util.Set getSeries()
          Returns the set of series to be draw.
protected  java.awt.Rectangle getZoomableBounds(java.awt.Rectangle bounds)
          Returns the zoomable area in pixel coordinates.
 void newAxis(int dimension, java.lang.String title)
          Advises that the next series to be added with addSeries(...)
protected  void paintComponent(java.awt.Graphics2D graphics)
          Paints the axis and all series.
 void reset()
          Reinitialize the zoom to its default value.
 void transform(java.awt.geom.AffineTransform transform)
          Apply a zoom.
 
Methods inherited from class org.geotools.gui.swing.ZoomPane
addMouseListener, addZoomChangeListener, buildNavigationMenu, correctApparentPixelPosition, createScrollPane, fireZoomChanged, getDefaultSize, getInsets, getInsets, getMagnifierBorder, getMagnifierGlass, getMagnifierMenu, getMouseSelectionShape, getPopupMenu, getPreferredArea, getPreferredPixelSize, getScaleFactor, getVisibleArea, hasPreferredArea, isMagnifierEnabled, isMagnifierVisible, isPaintingWhileAdjusting, mouseSelectionPerformed, paintComponent, paintMagnifier, printComponent, printComponent, removeZoomChangeListener, repaint, reset, scrollRectToVisible, setMagnifierBorder, setMagnifierEnabled, setMagnifierGlass, setMagnifierVisible, setPaintingWhileAdjusting, setPreferredArea, setResetPolicy, setVisibleArea, tieModels, transformPixels, untieModels, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 

Constructor Detail

Plot2D

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


Plot2D

public Plot2D(boolean zoomX,
              boolean zoomY)
Construct 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

newAxis

public void newAxis(int dimension,
                    java.lang.String title)
Advises that the next series to be added with addSeries(...) should uses a new axis for the specified dimension. Dimension 0 is for the x axis while dimension 1 is for the y axis. If this method is never invoked, then addSeries(...) will automatically create untitled axis.

Parameters:
dimension - 0 for adding a new x axis, or 1 for adding a new y axis.
title - The axis title.

addSeries

public Plot2D.Series addSeries(java.lang.String name,
                               java.lang.Object x,
                               java.lang.Object y)
                        throws java.lang.ClassCastException,
                               javax.vecmath.MismatchedSizeException
Add a new serie to the chart. The x and y vectors may be arrays of any of Java primitive types: double[], float[], long[], int[], short[], byte[], char[] (which may be used as a kind of unsigned short) or boolean[] (0 or 1 values). The x and y arrays doesn't need to be of the same type. Arrays are stored by reference only; they are not cloned.

Parameters:
name - The series name.
x - x values.
y - y values.
Returns:
The series added.
Throws:
java.lang.ClassCastException - if x and y are not arrays of a primitive type.
javax.vecmath.MismatchedSizeException - if arrays doesn't have the same length.

addSeries

public Plot2D.Series addSeries(java.lang.String name,
                               java.lang.Object x,
                               java.lang.Object y,
                               int lower,
                               int upper)
                        throws java.lang.ClassCastException
Add a new serie to the chart. The x and y vectors may be arrays of any of Java primitive types.

Parameters:
name - The series name.
x - x values.
y - y values.
lower - Index of first point, inclusive.
upper - Index of last point, exclusive.
Returns:
The series added.
Throws:
java.lang.ClassCastException - if x and y are not arrays of a primitive type.

addSeries

public Plot2D.Series addSeries(Plot2D.Series series)
Add a new serie to the chart.

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

getSeries

public java.util.Set getSeries()
Returns the set of series to be draw. Series are painted in the order they are returned.


getAxis

public Axis2D[] getAxis(Plot2D.Series series)
                 throws java.util.NoSuchElementException
Returns the {x, y} axis 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:
java.util.NoSuchElementException - if this widget doesn't contains the specified series.

getArea

public java.awt.geom.Rectangle2D getArea()
Returns a bounding box that contains the logical coordinates of all data that may be displayed in this Plot2D.

Specified by:
getArea in class ZoomPane
Returns:
A bounding box for the logical coordinates of every series that is going to be drawn on this Plot2D.

getZoomableBounds

protected java.awt.Rectangle getZoomableBounds(java.awt.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 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 widget.

reset

public void reset()
Reinitialize the zoom to its default value. This method is used by ZoomPane and usually doesn't need to be explicitely invoked.

Overrides:
reset in class ZoomPane

transform

public void transform(java.awt.geom.AffineTransform transform)
Apply a zoom. This method is used by ZoomPane and usually doesn't need to be explicitely invoked.

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

paintComponent

protected void paintComponent(java.awt.Graphics2D graphics)
Paints the axis and all series.

Specified by:
paintComponent in class ZoomPane

clear

public void clear(boolean removeAxis)
Remove all series. If the removeAxis is true, then all axis are removed as well. Otherwise, the last pair of axis is keep.

Parameters:
removeAxis - true for removing axis as well, or false for keeping the last used axis.


Copyright © GeoTools. All Rights Reserved.