|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectComponent
Container
JComponent
ZoomPane
Plot2D
public class Plot2D
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);
|
|
| 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 Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final List<Color> DEFAULT_COLORS
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 |
|---|
public Plot2D()
Plot2D with
zoom capabilities on horizontal and vertical axis.
public Plot2D(boolean zoomX,
boolean zoomY)
Plot2D with
zoom capabilities on the specified axis.
zoomX - true for allowing zooming on the x axis.zoomY - true for allowing zooming on the y axis.| Method Detail |
|---|
public void addXAxis(String label)
label - The axis label, or null if the axis should not have any label.public void addYAxis(String label)
label - The axis label, or null if the axis should not have any label.
public Plot2D.Series addSeries(String name,
Paint color,
float[] x,
float[] y)
throws MismatchedSizeException
Vector
objects and delegates to addSeries(Map, Vector, Vector).
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.
MismatchedSizeException - if the arrays don't have the same length.
public Plot2D.Series addSeries(String name,
Paint color,
double[] x,
double[] y)
throws MismatchedSizeException
Vector
objects and delegates to addSeries(Map, Vector, Vector).
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.
MismatchedSizeException - if the arrays don't have the same length.
public Plot2D.Series addSeries(Map<String,?> properties,
Vector x,
Vector y)
throws MismatchedSizeException
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:
"Name" for a String value to be used as the series name."Paint" for a Paint value to be used as the series paint.
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.
properties - The properties to be given to the new series.x - The vector of x values.y - The vector of y values.
MismatchedSizeException - if the arrays don't have the same length.public Plot2D.Series addSeries(Plot2D.Series series)
addXAxis and addYAxis.
series - The serie to add.
public Set<Plot2D.Series> getSeries()
public Color getGridColor()
null if the grid should not
be drawn.
null if none.public void setGridColor(Color color)
null if the grid should not
be drawn.
color - The new grid color to use, or null if none.
public Axis2D[] getAxes(Plot2D.Series series)
throws NoSuchElementException
series - The series for which axis are wanted.
NoSuchElementException - if this widget doesn't contains the specified series.public Rectangle2D getArea()
Plot2D component.
getArea in class ZoomPaneprotected Rectangle getZoomableBounds(Rectangle bounds)
getZoomableBounds in class ZoomPanebounds - 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.
ZoomPane widget.public Insets getMargin()
public void setMargin(Insets margin)
margin - The new margin between widget bounds and the area where the graph is plotted.
protected void reset(Rectangle zoomableBounds,
boolean yAxisUpward)
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.
reset in class ZoomPanezoomableBounds - 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.public void transform(AffineTransform change)
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.
transform in class ZoomPanechange - 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.protected void paintComponent(Graphics2D graphics)
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.
paintComponent in class ZoomPanegraphics - The graphics where to paint this component.public void clear()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||