public abstract class Plot
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
Plot(PlotParams params)
Creates a plot with the supplied parameters.
|
Modifier and Type | Method and Description |
---|---|
protected PlotPoint |
addPoint(TreatmentStep step,
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 |
addVisibilityChangedListener(java.util.function.Consumer<java.lang.Boolean> listener)
Adds a listener for visibility changes to this plot.
|
void |
applyTextAttributes(java.text.AttributedString as)
Applies this plot's standard text attributes to an attributed string.
|
boolean |
areTreatmentStepsLabelled()
Determines whether the points should be labelled.
|
protected void |
clearPoints()
Clear this plot's internal buffer of points.
|
protected java.awt.geom.Rectangle2D |
cropRectangle(java.awt.geom.Rectangle2D rectangle,
double left,
double right,
double top,
double bottom)
Returns a cropped version of a specified rectangle.
|
abstract void |
draw(java.awt.Graphics2D graphics)
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.
|
TreatmentStep |
getTreatmentStepForPosition(java.awt.geom.Point2D position)
Returns the datum associated with the point at the given position,
or null if no such datum exists.
|
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 |
putText(java.awt.Graphics2D graphics,
java.text.AttributedString text,
double x,
double y,
Direction dir,
double θ,
double padding)
Write some text on this plot.
|
void |
putText(java.awt.Graphics2D g,
java.lang.String textString,
double x,
double y,
Direction dir,
double θ,
double padding)
Write some text on this plot.
|
void |
removeSampleClickListener(SampleClickListener listener)
Removes a sample click listener which was previously added to this plot.
|
void |
removeVisibilityChangedListener(java.util.function.Consumer<java.lang.Boolean> listener)
Removes a listener for visibility changes to this plot.
|
void |
selectByRectangle(java.awt.geom.Rectangle2D rectangle,
boolean state)
Sets selection state for data points in a 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,
java.awt.Graphics2D graphics)
Returns an attributed string representing a number in scientific
notation.
|
protected java.text.AttributedString |
timesTenToThe(java.lang.String significand,
java.lang.String exponent,
java.awt.Graphics2D graphics)
Returns an attributed string representing a number in scientific
notation.
|
protected void |
writeString(java.awt.Graphics2D graphics,
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.
|
protected final PlotParams params
protected java.awt.geom.Rectangle2D dimensions
protected static final double PLOT_POINT_SIZE
protected static final java.lang.String DEFAULT_PLOT_POSITIONS
public Plot(PlotParams params)
params
- the parameters of the plotpublic java.awt.geom.Rectangle2D getDimensions()
public void setDimensions(java.awt.geom.Rectangle2D dimensions)
dimensions
- dimensions the new dimensions of this plotpublic boolean areTreatmentStepsLabelled()
Plot
's drawing routines. As defined in Plot
, this method
always returns false
. Plots which use labelled points should
override it.true
if this plot's points should be labelledpublic void setDimensionsToDefault()
DEFAULT_PLOT_POSITIONS
.public int getMargin()
public java.awt.Stroke getStroke()
public java.awt.Stroke getDashedStroke()
public final float getUnitSize()
public float getTickLength()
public final float getFontSize()
public java.util.Map<? extends java.text.AttributedCharacterIterator.Attribute,?> getTextAttributes()
public void applyTextAttributes(java.text.AttributedString as)
as
- the string to which to apply this plot's standard text
attributesprotected void writeString(java.awt.Graphics2D g, java.lang.String text, float x, float y)
g
- the graphics object to which to write thetext
- the text to writex
- the x co-ordinate of the texty
- the y co-ordinate of the textprotected void writeString(java.awt.Graphics2D graphics, java.text.AttributedString as, float x, float y)
graphics
- the graphics object to which to write theas
- the text to writex
- the x co-ordinate of the texty
- the y co-ordinate of the textprotected java.text.AttributedString timesTenToThe(java.lang.String significand, java.lang.String exponent, java.awt.Graphics2D graphics)
PuffinRenderingHints.KEY_E_NOTATION
, a notation
of the form "1.2E34." is produced instead.significand
- the significand of the numberexponent
- the exponent of the numbergraphics
- a graphics contextprotected java.text.AttributedString timesTenToThe(java.lang.String significand, int exponent, java.awt.Graphics2D graphics)
timesTenToThe(java.lang.String, java.lang.String, java.awt.Graphics2D)
for details of the notation produced.significand
- the significand of the numberexponent
- the exponent of the numbergraphics
- a graphics contexttimesTenToThe(java.lang.String, java.lang.String, java.awt.Graphics2D)
protected java.awt.geom.Rectangle2D cropRectangle(java.awt.geom.Rectangle2D rectangle, double left, double right, double top, double bottom)
rectangle
- a rectangleleft
- the amount to crop at the leftright
- the amount to crop at the righttop
- the amount to crop at the topbottom
- the amount to crop at the bottompublic java.lang.String getDimensionsAsString()
plotSizes
Preferences entry from which
the plot reads its initial dimensions.protected void drawPoints(java.awt.Graphics2D g)
g
- the graphics object to which to draw the pointsprotected PlotPoint addPoint(TreatmentStep step, java.awt.geom.Point2D p, boolean filled, boolean special, boolean line)
step
- the datum associated with the point (null
if none)p
- the position of the pointfilled
- true
if the point should be filledspecial
- true
if the point should be highlightedline
- true
if a line should be drawn from the previous
point to this one.protected void clearPoints()
public void putText(java.awt.Graphics2D graphics, java.text.AttributedString text, double x, double y, Direction dir, double θ, double padding)
dir
controls whether the text
should be offset up, down, left, or right of the point. In the axis
perpendicular to the offset direction, the text is centred, so for
example if the text is placed below the specified point, it will also be
centred horizontally relative to the point. An angle of rotation can also
be specified for the text; note that at present only rotations of 0
(horizontal, rightward) and pi/2 (vertical, upward) have been tested.graphics
- the graphics contexttext
- the text to writex
- the x position of the texty
- the y position of the textdir
- the location of the text relative to the given positionθ
- the rotation of the text, in radians (0 = horizontal)padding
- the distance between the text and the given positionpublic void putText(java.awt.Graphics2D g, java.lang.String textString, double x, double y, Direction dir, double θ, double padding)
g
- the graphics contexttextString
- the text to writex
- the x position of the texty
- the y position of the textdir
- the location of the text relative to the given positionθ
- the rotation of the text, in radians (0 = horizontal)padding
- the distance between the text and the given positionpublic void mouseClicked(java.awt.geom.Point2D position, java.awt.event.MouseEvent e)
position
- the position of the clicke
- the event associated with the clickpublic TreatmentStep getTreatmentStepForPosition(java.awt.geom.Point2D position)
position
- a positionpublic void selectByRectangle(java.awt.geom.Rectangle2D rectangle, boolean state)
isHidden()
is false
) are affected
by this method.rectangle
- a rectangle defining which points should be selectedstate
- true
to select points, false
to deselectpublic abstract java.lang.String getName()
public java.lang.String getNiceName()
public abstract void draw(java.awt.Graphics2D graphics)
graphics
- the graphics object onto which to draw this plotpublic boolean isVisible()
true
if this plot is visible; false
if it is
hiddenpublic void setVisible(boolean visible)
visible
- true
to draw this plot; false
not to draw
itpublic void addSampleClickListener(SampleClickListener listener)
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.listener
- the listener to addSampleClickListener
,
removeSampleClickListener(net.talvi.puffinplot.plots.SampleClickListener)
public void removeSampleClickListener(SampleClickListener listener)
listener
- the listener to removeaddSampleClickListener(net.talvi.puffinplot.plots.SampleClickListener)
,
SampleClickListener
public void addVisibilityChangedListener(java.util.function.Consumer<java.lang.Boolean> listener)
listener
- the listener to addremoveVisibilityChangedListener(Consumer)
public void removeVisibilityChangedListener(java.util.function.Consumer<java.lang.Boolean> listener)
listener
- the listener to removeaddVisibilityChangedListener(Consumer)