public class PtPlotSurface extends JPanel implements PlotSurface
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected Color |
_background |
protected int |
_bottomPadding |
protected static Color[] |
_colors |
URL |
_documentBase |
protected int |
_expThreshold |
protected Color |
_foreground |
protected boolean |
_grid |
protected int |
_height |
protected Font |
_labelFont |
protected FontMetrics |
_labelFontMetrics |
protected int |
_leftPadding |
protected static double |
_LOG10SCALE |
protected int |
_lrx
The x value of the lower right corner of
the plot rectangle in pixels.
|
protected int |
_lry
The y value of the lower right corner of
the plot rectangle in pixels.
|
protected double |
_padding
The factor we pad by so that we don't plot points on the axes.
|
protected int |
_preferredHeight |
protected int |
_preferredWidth |
protected boolean |
_rangesGivenByZooming |
protected int |
_rightPadding |
protected boolean |
_sizeHasBeenSet |
protected Font |
_superscriptFont |
protected FontMetrics |
_superscriptFontMetrics |
int |
_tickLength
Length of tickmarks.
|
protected Font |
_titleFont |
protected FontMetrics |
_titleFontMetrics |
protected int |
_topPadding |
protected int |
_ulx
The x value of the upper left corner of the plot rectangle in pixels.
|
protected int |
_uly
The y value of the upper left corner of the plot rectangle in pixels.
|
protected boolean |
_usecolor |
protected int |
_width |
protected boolean |
_wrap |
protected double |
_wrapHigh |
protected double |
_wrapLow |
protected double |
_xBottom |
protected boolean |
_xflip |
protected double |
_xhighgiven |
protected boolean |
_xlog |
protected double |
_xlowgiven |
protected double |
_xMax |
protected double |
_xMin |
protected boolean |
_xRangeGiven |
protected double |
_xscale
Scaling used for the horizontal axis in plotting points.
|
protected double |
_xTop |
protected double |
_yBottom |
protected boolean |
_yflip |
protected double |
_yhighgiven |
protected boolean |
_ylog |
protected double |
_ylowgiven |
protected double |
_yMax |
protected double |
_yMin |
protected boolean |
_yRangeGiven |
protected double |
_yscale
Scaling used for the vertical axis in plotting points.
|
protected double |
_yTop |
static String |
PTPLOT_RELEASE |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
MAX_COORD
NO_SUCH_PAGE, PAGE_EXISTS
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
PtPlotSurface()
Constructs a new surface.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_drawPlot(Graphics graphics,
boolean clearfirst)
Draw the axes using the current range, label, and title information.
|
protected void |
_drawPlot(Graphics graphics,
boolean clearfirst,
Rectangle drawRect)
Draw the axes using the current range, label, and title information,
at the size of the specified rectangle.
|
protected void |
_drawPoint(Graphics graphics,
int dataset,
long xpos,
long ypos,
boolean clip)
Put a mark corresponding to the specified dataset at the
specified x and y position.
|
protected void |
_help()
Display basic information in its own window.
|
protected void |
_setButtonsVisibility(boolean vis)
Deprecated.
|
protected void |
_setPadding(double padding)
Set the padding multiple.
|
void |
_setYRange(double min,
double max) |
protected void |
_zoom(int x,
int y) |
void |
addLegend(int dataset,
String legend)
Add a legend (displayed at the upper right) for the specified
data set with the specified string.
|
void |
addXTick(String label,
double position)
Specify a tick mark for the X axis.
|
void |
addYTick(String label,
double position)
Specify a tick mark for the Y axis.
|
void |
clear(boolean axes)
If the argument is true, clear the axes.
|
void |
clearLegends()
Clear all legends.
|
Point |
dataToGraphics(double dx,
double dy,
boolean insideOnly)
Converts a point in data space to graphics space.
|
void |
deferIfNecessary(Runnable action)
If this method is called in the event thread, then simply
execute the specified action.
|
void |
fillPlot()
Rescale so that the data that is currently plotted just fits.
|
Shape |
getClip()
Returns the clip region in which points may be plotted.
|
boolean |
getColor()
Return whether the plot uses color.
|
static Color |
getColorByName(String name)
Convert a color name into a Color.
|
JComponent |
getComponent()
Returns the graphical component on which the plotting surface is
displayed.
|
String |
getDataurl()
Deprecated.
|
URL |
getDocumentBase()
Deprecated.
|
boolean |
getGrid()
Return whether the grid is drawn.
|
String |
getLegend(int dataset)
Get the legend for a dataset, or null if there is none.
|
Dimension |
getMaximumSize()
If the size of the plot has been set by setSize(),
then return that size.
|
Dimension |
getMinimumSize()
Get the minimum size of this component.
|
String |
getTitle()
Get the title of the graph, or an empty string if there is none.
|
String |
getXLabel()
Get the label for the X (horizontal) axis, or null if none has
been set.
|
boolean |
getXLog()
Return whether the X axis is drawn with a logarithmic scale.
|
double[] |
getXRange()
Get the X range.
|
Vector[] |
getXTicks()
Get the X ticks that have been specified, or null if none.
|
String |
getYLabel()
Get the label for the Y (vertical) axis, or null if none has
been set.
|
boolean |
getYLog()
Return whether the Y axis is drawn with a logarithmic scale.
|
double[] |
getYRange()
Get the Y range.
|
Vector[] |
getYTicks()
Get the Y ticks that have been specified, or null if none.
|
double[] |
graphicsToData(int px,
int py,
boolean insideOnly)
Converts a point in graphics space to data space.
|
void |
init()
Deprecated.
|
void |
paintComponent(Graphics graphics)
Paint the component contents, which in this base class is
only the axes.
|
void |
paintSurface(Graphics g)
Paints the plotting surface.
|
int |
print(Graphics graphics,
PageFormat format,
int index)
Print the plot to a printer, represented by the specified graphics
object.
|
void |
removeLegend(int dataset)
Remove the legend (displayed at the upper right) for the specified
data set.
|
void |
resetAxes()
Reset the X and Y axes to the ranges that were first specified
using setXRange() and setYRange().
|
void |
samplePlot()
Do nothing in this base class.
|
void |
setBackground(Color background)
Set the background color.
|
void |
setBounds(int x,
int y,
int width,
int height)
Move and resize this component.
|
void |
setButtons(boolean visible)
If the argument is true, make a fill button visible at the upper
right.
|
void |
setColor(boolean useColor)
If the argument is false, draw the plot without using color
(in black and white).
|
void |
setDataRange(double xlo,
double ylo,
double xhi,
double yhi)
Requests a range of data space values to be visible on
this plotting surface.
|
void |
setDataurl(String filespec)
Deprecated.
|
void |
setDocumentBase(URL documentBase)
Deprecated.
|
void |
setFont(Font font) |
void |
setForeground(Color foreground)
Set the foreground color.
|
void |
setGrid(boolean grid)
Control whether the grid is drawn.
|
void |
setLabelFont(String name)
Set the label font, which is used for axis labels and legend labels.
|
void |
setSize(int width,
int height)
Set the size of the plot.
|
void |
setState(PlotState state)
Signals to the plot the characteristics of the plot which will
be performed.
|
void |
setTitle(String title)
Set the title of the graph.
|
void |
setTitleFont(String name)
Set the title font.
|
void |
setWrap(boolean wrap)
Specify whether the X axis is wrapped.
|
void |
setXFlip(boolean xflip)
Specify whether the X axis numeric labels should be inverted.
|
void |
setXLabel(String label)
Set the label for the X (horizontal) axis.
|
void |
setXLog(boolean xlog)
Specify whether the X axis is drawn with a logarithmic scale.
|
void |
setXRange(double min,
double max)
Set the X (horizontal) range of the plot.
|
void |
setYFlip(boolean yflip)
Specify whether the Y axis numeric labels should be inverted.
|
void |
setYLabel(String label)
Set the label for the Y (vertical) axis.
|
void |
setYLog(boolean ylog)
Specify whether the Y axis is drawn with a logarithmic scale.
|
void |
setYRange(double min,
double max)
Set the Y (vertical) range of the plot.
|
void |
zoom(double lowx,
double lowy,
double highx,
double highy)
Zoom in or out to the specified rectangle.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
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, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, 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, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final String PTPLOT_RELEASE
protected transient double _yMax
protected transient double _yMin
protected transient double _xMax
protected transient double _xMin
protected double _padding
protected transient boolean _xRangeGiven
protected transient boolean _yRangeGiven
protected transient boolean _rangesGivenByZooming
protected double _xlowgiven
protected double _xhighgiven
protected double _ylowgiven
protected double _yhighgiven
protected double _xBottom
protected double _xTop
protected double _yBottom
protected double _yTop
protected boolean _xlog
protected boolean _ylog
protected boolean _xflip
protected boolean _yflip
protected static final double _LOG10SCALE
protected boolean _grid
protected boolean _wrap
protected double _wrapHigh
protected double _wrapLow
protected Color _background
protected Color _foreground
protected int _topPadding
protected int _bottomPadding
protected int _rightPadding
protected int _leftPadding
protected int _ulx
protected int _uly
protected int _lrx
protected int _lry
protected double _yscale
protected double _xscale
protected boolean _usecolor
public int _tickLength
protected static Color[] _colors
protected int _width
protected int _height
protected int _preferredWidth
protected int _preferredHeight
protected boolean _sizeHasBeenSet
protected int _expThreshold
public URL _documentBase
protected Font _labelFont
protected Font _superscriptFont
protected Font _titleFont
protected FontMetrics _labelFontMetrics
protected FontMetrics _superscriptFontMetrics
protected FontMetrics _titleFontMetrics
public void setFont(Font font)
setFont
in class JComponent
public void setState(PlotState state)
PlotSurface
PlotSurface.getComponent()
next paints itself it should do so following the specifications
made here.setState
in interface PlotSurface
state
- plot characteristicspublic void setDataRange(double xlo, double ylo, double xhi, double yhi)
PlotSurface
setDataRange
in interface PlotSurface
xlo
- (approximate) lower bound of X coordinateylo
- (approximate) lower bound of Y coordinatexhi
- (approximate) upper bound of X coordinateyhi
- (approximate) upper bound of Y coordinatepublic Point dataToGraphics(double dx, double dy, boolean insideOnly)
PlotSurface
insideOnly
flag is true, then null
will be returned in place of any result which would
give a point lying outside the visible plotting area.
The coordinates of the returned point must have absolute values
no greater than PlotSurface.MAX_COORD
.
dataToGraphics
in interface PlotSurface
dx
- data space X coordinatedy
- data space Y coordinateinsideOnly
- true to restrict non-null results to those
within the plotting surfacenull
public double[] graphicsToData(int px, int py, boolean insideOnly)
PlotSurface
insideOnly
flag is true, then null
will be returned in place of any result which would give a point
lying outside the visible plotting area.graphicsToData
in interface PlotSurface
px
- graphics space X coordinatepy
- graphics space Y coordinateinsideOnly
- true to restrict non-null results to those
within the plotting surfacenull
public Shape getClip()
PlotSurface
Graphics.setClip(java.awt.Shape)
- i.e. probably
a Rectangle
.getClip
in interface PlotSurface
public JComponent getComponent()
PlotSurface
JComponent.paintComponent(java.awt.Graphics)
to give a plotting background in accordance with the most recently
set PlotState
.getComponent
in interface PlotSurface
public void paintSurface(Graphics g)
PlotSurface
getComponent.paintComponent
,
except that it's public.
Requiring this here isn't very tidy, but following quite a bit of
experimentation I can't work out any other way to do scatter plot
image caching while still drawing to a potentially
hardware-accelerated graphics context
(see ScatterPlot
implementation).
paintSurface
in interface PlotSurface
g
- graphics contextprotected void _zoom(int x, int y)
public void addLegend(int dataset, String legend)
dataset
- The dataset index.legend
- The label for the dataset.public void addXTick(String label, double position)
label
- The label for the tick mark.position
- The position on the X axis.public void addYTick(String label, double position)
label
- The label for the tick mark.position
- The position on the Y axis.public void clear(boolean axes)
axes
- If true, clear the axes parameters.public void clearLegends()
public void deferIfNecessary(Runnable action)
action
- The Runnable object to execute.public void fillPlot()
public boolean getColor()
public static Color getColorByName(String name)
name
- A color name, or null if not found.public String getDataurl()
public URL getDocumentBase()
public boolean getGrid()
public String getLegend(int dataset)
dataset
- The dataset index.public Dimension getMaximumSize()
getMaximumSize
in class JComponent
public Dimension getMinimumSize()
getMinimumSize
in class JComponent
public String getTitle()
public String getXLabel()
public boolean getXLog()
public double[] getXRange()
public Vector[] getXTicks()
public String getYLabel()
public boolean getYLog()
public double[] getYRange()
public Vector[] getYTicks()
public void init()
public void paintComponent(Graphics graphics)
paintComponent
in class JComponent
graphics
- The graphics context.public int print(Graphics graphics, PageFormat format, int index) throws PrinterException
print
in interface Printable
graphics
- The context into which the page is drawn.format
- The size and orientation of the page being drawn.index
- The zero based index of the page to be drawn.PrinterException
- If the print job is terminated.public void removeLegend(int dataset)
dataset
- The dataset index.public void resetAxes()
public void samplePlot()
public void setBackground(Color background)
setBackground
in class JComponent
background
- The background color.public void setBounds(int x, int y, int width, int height)
public void setButtons(boolean visible)
public void setColor(boolean useColor)
useColor
- False to draw in back and white.public void setDataurl(String filespec)
public void setDocumentBase(URL documentBase)
public void setForeground(Color foreground)
setForeground
in class JComponent
foreground
- The foreground color.public void setGrid(boolean grid)
grid
- If true, a grid is drawn.public void setLabelFont(String name)
name
- A font name.public void setSize(int width, int height)
public void setTitle(String title)
title
- The title.public void setTitleFont(String name)
name
- A font name.public void setWrap(boolean wrap)
wrap
- If true, wrapping of the X axis is enabled.public void setXLabel(String label)
label
- The label.public void setXLog(boolean xlog)
xlog
- If true, logarithmic axis is used.public void setXFlip(boolean xflip)
xflip
- If true, numbers on X axis will be the negative of their
true valuespublic void setXRange(double min, double max)
min
- The left extent of the range.max
- The right extent of the range.public void setYLabel(String label)
label
- The label.public void setYLog(boolean ylog)
ylog
- If true, logarithmic axis is used.public void setYFlip(boolean yflip)
yflip
- If true, numbers on Y axis will be the negative of their
true valuespublic void setYRange(double min, double max)
min
- The bottom extent of the range.max
- The top extent of the range.public void zoom(double lowx, double lowy, double highx, double highy)
lowx
- The low end of the new X range.lowy
- The low end of the new Y range.highx
- The high end of the new X range.highy
- The high end of the new Y range.protected void _drawPlot(Graphics graphics, boolean clearfirst)
Note that this is synchronized so that points are not added by other threads while the drawing is occurring. This method should be called only from the event dispatch thread, consistent with swing policy.
graphics
- The graphics context.clearfirst
- If true, clear the plot before proceeding.protected void _drawPlot(Graphics graphics, boolean clearfirst, Rectangle drawRect)
Note that this is synchronized so that points are not added by other threads while the drawing is occurring. This method should be called only from the event dispatch thread, consistent with swing policy.
graphics
- The graphics context.clearfirst
- If true, clear the plot before proceeding.drawRect
- A specification of the size.protected void _drawPoint(Graphics graphics, int dataset, long xpos, long ypos, boolean clip)
true
, states
that the point should not be drawn if
it is out of range.
Note that this method is not synchronized, so the caller should be.
Moreover this method should always be called from the event thread
when being used to write to the screen.graphics
- The graphics context.dataset
- The index of the data set.xpos
- The X position.ypos
- The Y position.clip
- If true, do not draw if out of range.protected void _help()
protected void _setButtonsVisibility(boolean vis)
protected void _setPadding(double padding)
padding
- The padding multiple.public void _setYRange(double min, double max)
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.