net.talvi.puffinplot.plots
Class Plot

java.lang.Object
  extended by net.talvi.puffinplot.plots.Plot
Direct Known Subclasses:
DemagPlot, DemagTable, EqAreaPlot, NrmHistogram, PlotTitle, SampleParamsLegend, SampleParamsTable, SiteParamsLegend, SiteParamsTable, TernaryPlot, ZPlot, ZPlot.ZplotLegend

public abstract class Plot
extends java.lang.Object

An abstract superclass for all plots and other data displays. Any class that needs to write or draw to one of PuffinPlot's graph display areas should extend this class. Plot's subclasses include both graphical plots and textual displays such as the plot title and data table.


Field Summary
protected static java.lang.String DEFAULT_PLOT_POSITIONS
          the default sizes and positions of the plots
protected  java.awt.geom.Rectangle2D dimensions
          the plot's dimensions
protected  PlotParams params
          the plot parameters
protected static double PLOT_POINT_SIZE
          the default size of a plotted data point
 
Constructor Summary
Plot(GraphDisplay parent, PlotParams params, java.util.prefs.Preferences prefs)
          Creates a plot with the supplied parameters.
 
Method Summary
protected  void addPoint(Datum d, java.awt.geom.Point2D p, boolean filled, boolean special, boolean line)
          Adds a point to this plot's internal buffer.
 void addSampleClickListener(SampleClickListener listener)
          Adds a listener for sample clicks to this plot.
 void applyTextAttributes(java.text.AttributedString as)
          Applies this plot's standard text attributes to an attributed string.
protected  void clearPoints()
          Clear this plot's internal buffer of points.
protected  java.awt.geom.Rectangle2D cropRectangle(java.awt.geom.Rectangle2D r, double left, double right, double top, double bottom)
          Returns a cropped version of a specified rectangle.
abstract  void draw(java.awt.Graphics2D g)
          Draws this plot.
protected  void drawPoints(java.awt.Graphics2D g)
          Draws the points in this plot's internal buffer.
 java.awt.Stroke getDashedStroke()
          Returns the default dashed stroke style.
 java.awt.geom.Rectangle2D getDimensions()
          Returns the dimensions of this plot.
 java.lang.String getDimensionsAsString()
          Returns a string representation of this plot's dimensions.
 float getFontSize()
          Returns the standard font size in plot units.
 int getMargin()
          Returns the size of the margin displayed when resizing the plot.
abstract  java.lang.String getName()
          Returns an internal name for this plot.
 java.lang.String getNiceName()
          Returns a user-friendly name for this plot.
 java.awt.Stroke getStroke()
          Returns the default solid stroke style.
 java.util.Map<? extends java.text.AttributedCharacterIterator.Attribute,?> getTextAttributes()
          Returns this plot's standard text attributes.
 float getTickLength()
          Returns the standard length of an axis tick in plot units.
 float getUnitSize()
          Returns the size of a plot unit in Java 2D units.
 boolean isVisible()
          Reports whether this plot is visible.
 void mouseClicked(java.awt.geom.Point2D position, java.awt.event.MouseEvent e)
          Handles a mouse click event on the plot.
 void removeSampleClickListener(SampleClickListener listener)
          Removes a sample click listener which was previously added to this plot.
 void selectByRectangle(java.awt.geom.Rectangle2D rectangle)
          Selects all the plotted data points within a specified rectangle.
 void setDimensions(java.awt.geom.Rectangle2D dimensions)
          Sets the dimensions of this plot.
 void setDimensionsToDefault()
          Resets the plot's dimensions to the default, as defined in DEFAULT_PLOT_POSITIONS.
 void setVisible(boolean visible)
          Sets whether this plot should be drawn.
protected  java.text.AttributedString timesTenToThe(java.lang.String significand, int exponent)
          Returns an attributed string representing a number in scientific notation.
protected  java.text.AttributedString timesTenToThe(java.lang.String significand, java.lang.String exponent)
          Returns an attributed string representing a number in scientific notation.
protected  void writeString(java.awt.Graphics2D g, java.text.AttributedString as, float x, float y)
          Writes an attributed text string onto this plot.
protected  void writeString(java.awt.Graphics2D g, java.lang.String text, float x, float y)
          Writes a text string onto this plot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

params

protected final PlotParams params
the plot parameters


dimensions

protected java.awt.geom.Rectangle2D dimensions
the plot's dimensions


PLOT_POINT_SIZE

protected static final double PLOT_POINT_SIZE
the default size of a plotted data point

See Also:
Constant Field Values

DEFAULT_PLOT_POSITIONS

protected static final java.lang.String DEFAULT_PLOT_POSITIONS
the default sizes and positions of the plots

See Also:
Constant Field Values
Constructor Detail

Plot

public Plot(GraphDisplay parent,
            PlotParams params,
            java.util.prefs.Preferences prefs)
Creates a plot with the supplied parameters.

Parameters:
parent - the graph display containing the plot
params - the parameters of the plot
prefs - the preferences containing the plot configuration
Method Detail

getDimensions

public java.awt.geom.Rectangle2D getDimensions()
Returns the dimensions of this plot.

Returns:
the dimensions of this plot

setDimensions

public void setDimensions(java.awt.geom.Rectangle2D dimensions)
Sets the dimensions of this plot.

Parameters:
dimensions - dimensions the new dimensions of this plot

setDimensionsToDefault

public void setDimensionsToDefault()
Resets the plot's dimensions to the default, as defined in DEFAULT_PLOT_POSITIONS.


getMargin

public int getMargin()
Returns the size of the margin displayed when resizing the plot.

Returns:
the size of the margin displayed when resizing the plot

getStroke

public java.awt.Stroke getStroke()
Returns the default solid stroke style.

Returns:
the default solid stroke style.

getDashedStroke

public java.awt.Stroke getDashedStroke()
Returns the default dashed stroke style.

Returns:
the default dashed stroke style.

getUnitSize

public final float getUnitSize()
Returns the size of a plot unit in Java 2D units.

Returns:
the size of a plot unit in Java 2D units

getTickLength

public float getTickLength()
Returns the standard length of an axis tick in plot units.

Returns:
the standard length of an axis tick in plot units

getFontSize

public final float getFontSize()
Returns the standard font size in plot units.

Returns:
the standard font size in plot units.

getTextAttributes

public java.util.Map<? extends java.text.AttributedCharacterIterator.Attribute,?> getTextAttributes()
Returns this plot's standard text attributes.

Returns:
this plot's standard text attributes

applyTextAttributes

public void applyTextAttributes(java.text.AttributedString as)
Applies this plot's standard text attributes to an attributed string.

Parameters:
as - the string to which to apply this plot's standard text attributes

writeString

protected void writeString(java.awt.Graphics2D g,
                           java.lang.String text,
                           float x,
                           float y)
Writes a text string onto this plot.

Parameters:
g - the graphics object to which to write the
text - the text to write
x - the x co-ordinate of the text
y - the y co-ordinate of the text

writeString

protected void writeString(java.awt.Graphics2D g,
                           java.text.AttributedString as,
                           float x,
                           float y)
Writes an attributed text string onto this plot.

Parameters:
g - the graphics object to which to write the
as - the text to write
x - the x co-ordinate of the text
y - the y co-ordinate of the text

timesTenToThe

protected java.text.AttributedString timesTenToThe(java.lang.String significand,
                                                   java.lang.String exponent)
Returns an attributed string representing a number in scientific notation. For example, a significand of 12 and an exponent of 34 would produce the string 12 × 1034.

Parameters:
significand - the significand of the number
exponent - the exponent of the number
Returns:
an attributed string representing the number in scientific notation

timesTenToThe

protected java.text.AttributedString timesTenToThe(java.lang.String significand,
                                                   int exponent)
Returns an attributed string representing a number in scientific notation. For example, a significand of 12 and an exponent of 34 would produce the string 12 × 1034.

Parameters:
significand - the significand of the number
exponent - the exponent of the number
Returns:
an attributed string representing the number in scientific notation

cropRectangle

protected java.awt.geom.Rectangle2D cropRectangle(java.awt.geom.Rectangle2D r,
                                                  double left,
                                                  double right,
                                                  double top,
                                                  double bottom)
Returns a cropped version of a specified rectangle.

Parameters:
r - a rectangle
left - the amount to crop at the left
right - the amount to crop at the right
top - the amount to crop at the top
bottom - the amount to crop at the bottom
Returns:
the cropped rectangle

getDimensionsAsString

public java.lang.String getDimensionsAsString()
Returns a string representation of this plot's dimensions. The string is in the same format as the plotSizes Preferences entry from which the plot reads its initial dimensions.

Returns:
a string representation of this plot's dimensions

drawPoints

protected void drawPoints(java.awt.Graphics2D g)
Draws the points in this plot's internal buffer.

Parameters:
g - the graphics object to which to draw the points

addPoint

protected void addPoint(Datum d,
                        java.awt.geom.Point2D p,
                        boolean filled,
                        boolean special,
                        boolean line)
Adds a point to this plot's internal buffer.

Parameters:
d - the datum associated with the point (null if none)
p - the position of the point
filled - true if the point should be filled
special - true if the point should be highlighted
line - true if a line should be drawn from the previous point to this one.

clearPoints

protected void clearPoints()
Clear this plot's internal buffer of points.


mouseClicked

public void mouseClicked(java.awt.geom.Point2D position,
                         java.awt.event.MouseEvent e)
Handles a mouse click event on the plot. If the click was on a plotted point, the associated datum (if any) will have its selection state toggled.

Parameters:
position - the position of the click
e - the event associated with the click

selectByRectangle

public void selectByRectangle(java.awt.geom.Rectangle2D rectangle)
Selects all the plotted data points within a specified rectangle.

Parameters:
rectangle - a rectangle defining which points should be selected

getName

public abstract java.lang.String getName()
Returns an internal name for this plot.

Returns:
an internal name for this plot

getNiceName

public java.lang.String getNiceName()
Returns a user-friendly name for this plot.

Returns:
a user-friendly name for this plot

draw

public abstract void draw(java.awt.Graphics2D g)
Draws this plot.

Parameters:
g - the graphics object onto which to draw this plot

isVisible

public boolean isVisible()
Reports whether this plot is visible.

Returns:
true if this plot is visible; false if it is hidden

setVisible

public void setVisible(boolean visible)
Sets whether this plot should be drawn.

Parameters:
visible - true to draw this plot; false not to draw it

addSampleClickListener

public void addSampleClickListener(SampleClickListener listener)
Adds a listener for sample clicks to this plot. When the user clicks on a plot element representing a sample, the SampleClickListener.sampleClicked(net.talvi.puffinplot.data.Sample) method of the supplied listener will be invoked. The listener can be removed using the removeSampleClickListener(net.talvi.puffinplot.plots.SampleClickListener) method.

Parameters:
listener - the listener to add
See Also:
SampleClickListener, removeSampleClickListener(net.talvi.puffinplot.plots.SampleClickListener)

removeSampleClickListener

public void removeSampleClickListener(SampleClickListener listener)
Removes a sample click listener which was previously added to this plot. If the listener was never added to the plot, no action is taken and no exception is raised.

Parameters:
listener - the listener to remove
See Also:
addSampleClickListener(net.talvi.puffinplot.plots.SampleClickListener), SampleClickListener