Package uk.ac.starlink.ttools.plot
Class MarkStyle
- java.lang.Object
-
- uk.ac.starlink.ttools.plot.DefaultStyle
-
- uk.ac.starlink.ttools.plot.MarkStyle
-
- All Implemented Interfaces:
Style
public abstract class MarkStyle extends DefaultStyle
Defines a style of marker for plotting in a scatter plot. The marker part of a MarkStyle is characterised visually by its shapeId, colour and size. If it represents a line to be drawn as well it also has a stroke and a join type. A matching instance of a MarkStyle style can in general be produced by doingstyle1 = style0.getShapeId() .getStyle( style0.getColor(), style0.getSize() ); style1.setLine( style0.getLine() ); style1.setLineWidth( style0.getLineWidth() ); style1.setDash( style0.getDash() ); style1.setHidePoints( style0.getHidePoints() ); style1.setOpaqueLimit( style0.getOpaqueLimit() ); style1.setErrorRenderer( style0.getErrorRenderer() );
style0 and style1 should then match according to theequals()
method. A style may however have a nullshapeId
, in which case you can't generate a matching instance.- Since:
- 16 Jun 2004
- Author:
- Mark Taylor (Starlink)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MarkStyle.Line
Enumeration class describing the types of line which can be drawn in association with markers.
-
Field Summary
Fields Modifier and Type Field Description static MarkStyle.Line
DOT_TO_DOT
Symbolic constant meaning join points by straight line segments.static int
LEGEND_ICON_HEIGHT
static int
LEGEND_ICON_WIDTH
static MarkStyle.Line
LINEAR
Symbolic constant meaning draw a linear regression line.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
drawErrors(java.awt.Graphics g, int x, int y, int[] xoffs, int[] yoffs)
Draws error bars using this style's current error renderer.void
drawErrors(java.awt.Graphics g, int x, int y, int[] xoffs, int[] yoffs, ColorTweaker fixer)
Draws error bars using this style's current error renderer in a way which may be modified by a suppliedColorTweaker
object.void
drawLabel(java.awt.Graphics g, int x, int y, java.lang.String label)
Draws a label for a marker at a given point.void
drawLabel(java.awt.Graphics g, int x, int y, java.lang.String label, ColorTweaker fixer)
Draws a label for a marker at a given point with optional colour modification.void
drawLegendShape(java.awt.Graphics g)
Draws this marker's shape centred at the origin suitable for display as a legend.void
drawMarker(java.awt.Graphics g, int x, int y)
Draws this marker centered at a given position.void
drawMarker(java.awt.Graphics g, int x, int y, ColorTweaker fixer)
Draws this marker in a way which may be modified by a suppliedColorTweaker
object.abstract void
drawShape(java.awt.Graphics g)
Draws this marker's shape centered at the origin in a graphics context.boolean
equals(java.lang.Object o)
Returns true ifo
satisfies the following conditions It has the same class as this one It has the same colour as this one It has the same stroke as this one TheotherAtts
object specified at its creation matches (according toequals()
this one'sErrorRenderer
getErrorRenderer()
Returns the style used for drawing error bars around this marker.int[]
getFlattenedPixelOffsets(int xStride)
Returns an array of 1-dimensional pixel offsets which can be used to draw this marker onto a raster.boolean
getHidePoints()
Indicates whether points are hidden or visible.javax.swing.Icon
getIcon(int width, int height)
Returns an icon that draws this MarkStyle.java.awt.Color
getLabelColor()
Returns the colour to use for drawing labels.Pixellator
getLabelPixels(java.lang.String label, int x, int y, java.awt.Rectangle clip)
Returns an array over pixel positions which can be used to draw a label for this style.javax.swing.Icon
getLegendIcon()
Draws a legend icon for this style without error rendering.javax.swing.Icon
getLegendIcon(ErrorMode[] errorModes)
Draws a legend icon for this style given certain error modes.MarkStyle.Line
getLine()
Returns the line type for this style.int
getMaximumRadius()
Returns the maximum radius of a marker drawn by this class.int
getOpaqueLimit()
Returns the opacity limit for this style.Pixellator
getPixelOffsets()
Returns an iterator over pixel offsets which can be used to draw this marker onto a raster.MarkShape
getShapeId()
Returns this style's shape id.int
getSize()
Returns the nominal size of this style.static boolean
hasErrors(MarkStyle style, PlotData plotData)
Utility method indicating whether errors will be drawn for a given style when a given set of points is plotted.int
hashCode()
void
setErrorModeModels(ErrorModeSelection[] errSelections)
Sets the error mode suppliers with which this mark style will be used.void
setErrorRenderer(ErrorRenderer errorRenderer)
Sets the style used for drawing error bars around this marker.void
setHidePoints(boolean visible)
Sets whether points should be hidden or visible.void
setLine(MarkStyle.Line line)
Sets the line type for this style.void
setOpaqueLimit(int lim)
Sets the opacity limit for this style.static MarkStyle
targetStyle()
Returns a style which looks like a target.-
Methods inherited from class uk.ac.starlink.ttools.plot.DefaultStyle
getColor, getDash, getLineWidth, getOtherAtts, getStroke, getStroke, setColor, setDash, setLineWidth, toString
-
-
-
-
Field Detail
-
DOT_TO_DOT
public static final MarkStyle.Line DOT_TO_DOT
Symbolic constant meaning join points by straight line segments.
-
LINEAR
public static final MarkStyle.Line LINEAR
Symbolic constant meaning draw a linear regression line.
-
LEGEND_ICON_WIDTH
public static final int LEGEND_ICON_WIDTH
- See Also:
- Constant Field Values
-
LEGEND_ICON_HEIGHT
public static final int LEGEND_ICON_HEIGHT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MarkStyle
protected MarkStyle(java.awt.Color color, java.lang.Object otherAtts, MarkShape shapeId, int size, int maxr)
Constructor.- Parameters:
color
- colourotherAtts
- distinguisher for this instance (besides class and colour)shapeId
- style factorysize
- nominal sizemaxr
- maximum radius (furthest distance from centre that this style may plot a pixel)
-
-
Method Detail
-
drawShape
public abstract void drawShape(java.awt.Graphics g)
Draws this marker's shape centered at the origin in a graphics context. Implementing classes don't need to worry about the colour.- Parameters:
g
- graphics context
-
drawLegendShape
public void drawLegendShape(java.awt.Graphics g)
Draws this marker's shape centred at the origin suitable for display as a legend. The default implementation just invokesdrawShape(java.awt.Graphics)
, but it may be overridden if there are special requirements, for instance if drawShape draws a miniscule graphic.- Parameters:
g
- graphics context
-
getMaximumRadius
public int getMaximumRadius()
Returns the maximum radius of a marker drawn by this class. It is permissible to return a (gross) overestimate if no sensible maximum can be guaranteed.- Returns:
- maximum distance from the specified x,y point that drawMarker might draw
-
getShapeId
public MarkShape getShapeId()
Returns this style's shape id. This is a factory capable of producing match styles which resemble this one in point of shape (but may differ in size or colour).- Returns:
- style factory
-
getSize
public int getSize()
Returns the nominal size of this style. In general a size of 1 is the smallest, 2 is the next smallest etc.- Returns:
- style size
-
setLine
public void setLine(MarkStyle.Line line)
Sets the line type for this style.- Parameters:
line
- line type
-
getLine
public MarkStyle.Line getLine()
Returns the line type for this style.- Returns:
- line type
-
setHidePoints
public void setHidePoints(boolean visible)
Sets whether points should be hidden or visible. This will usually only be honoured if the line style is non-null.- Parameters:
visible
- true if you want points to be invisible
-
getHidePoints
public boolean getHidePoints()
Indicates whether points are hidden or visible. This should usually only be honoured if the line style is non-null.- Returns:
- true if points are to be invisible
-
setOpaqueLimit
public void setOpaqueLimit(int lim)
Sets the opacity limit for this style. The limit is the number of pixels plotted on top of each other which will result in complete opacity. The default is one, which corresponds to fully opaque pixels.- Parameters:
lim
- new opacity limit
-
getOpaqueLimit
public int getOpaqueLimit()
Returns the opacity limit for this style.- Returns:
- opacity limit
-
setErrorRenderer
public void setErrorRenderer(ErrorRenderer errorRenderer)
Sets the style used for drawing error bars around this marker.- Parameters:
errorRenderer
- error bar style
-
getErrorRenderer
public ErrorRenderer getErrorRenderer()
Returns the style used for drawing error bars around this marker.- Returns:
- error bar style
-
setErrorModeModels
public void setErrorModeModels(ErrorModeSelection[] errSelections)
Sets the error mode suppliers with which this mark style will be used. These objects are only used to affect the way that legends are drawn; in particular they are NOT used when determining object equality.- Parameters:
errSelections
- error mode choices
-
getLabelColor
public java.awt.Color getLabelColor()
Returns the colour to use for drawing labels.- Returns:
- label colour
-
drawMarker
public void drawMarker(java.awt.Graphics g, int x, int y)
Draws this marker centered at a given position. This method sets the colour of the graphics context and then callsdrawShape(java.awt.Graphics)
.- Parameters:
g
- graphics contextx
- x positiony
- y position
-
drawMarker
public void drawMarker(java.awt.Graphics g, int x, int y, ColorTweaker fixer)
Draws this marker in a way which may be modified by a suppliedColorTweaker
object. This permits changes to be made to the colour just before the marker is drawn. In some cases this could be handled by modifying the graphics context before the call todrawMarker
, but doing it like this makes sure that the graphics context has been assigned the right colour and position.- Parameters:
g
- graphics contextx
- x positiony
- y positionfixer
- hook for modifying the colour (may be null)
-
drawErrors
public void drawErrors(java.awt.Graphics g, int x, int y, int[] xoffs, int[] yoffs)
Draws error bars using this style's current error renderer.- Parameters:
g
- graphics contextx
- data point X coordinatey
- data point Y coordinatexoffs
- X coordinates of error bar limit offsets from (x,y)yoffs
- Y coordinates of error bar limit offsets from (x,y)- See Also:
ErrorRenderer.drawErrors(java.awt.Graphics, int, int, int[], int[])
-
drawErrors
public void drawErrors(java.awt.Graphics g, int x, int y, int[] xoffs, int[] yoffs, ColorTweaker fixer)
Draws error bars using this style's current error renderer in a way which may be modified by a suppliedColorTweaker
object.- Parameters:
g
- graphics contextx
- data point X coordinatey
- data point Y coordinatexoffs
- X coordinates of error bar limit offsets from (x,y)yoffs
- Y coordinates of error bar limit offsets from (x,y)fixer
- hook for modifying the colour (may be null)- See Also:
ErrorRenderer.drawErrors(java.awt.Graphics, int, int, int[], int[])
-
drawLabel
public void drawLabel(java.awt.Graphics g, int x, int y, java.lang.String label)
Draws a label for a marker at a given point.- Parameters:
g
- graphics contextx
- X coordinate of pointy
- Y coordinate of pointlabel
- text to draw
-
drawLabel
public void drawLabel(java.awt.Graphics g, int x, int y, java.lang.String label, ColorTweaker fixer)
Draws a label for a marker at a given point with optional colour modification.- Parameters:
g
- graphics contextx
- X coordinate of pointy
- Y coordinate of pointlabel
- text to drawfixer
- hook for modifying the colour (may be null)
-
getLegendIcon
public javax.swing.Icon getLegendIcon()
Draws a legend icon for this style without error rendering.- Returns:
- legend icon
-
getLegendIcon
public javax.swing.Icon getLegendIcon(ErrorMode[] errorModes)
Draws a legend icon for this style given certain error modes.- Parameters:
errorModes
- array of error modes, one for each dimension- Returns:
- legend icon
-
getIcon
public javax.swing.Icon getIcon(int width, int height)
Returns an icon that draws this MarkStyle.- Parameters:
width
- icon widthheight
- icon height- Returns:
- icon
-
getPixelOffsets
public Pixellator getPixelOffsets()
Returns an iterator over pixel offsets which can be used to draw this marker onto a raster. This can be used as an alternative to rendering the marker using thedrawMarker()
methods in situations where it might be more efficient. The assumption is that all the pixels are the same colour.- Returns:
- pixel offset iterator representing this style as a bitmap
-
getFlattenedPixelOffsets
public int[] getFlattenedPixelOffsets(int xStride)
Returns an array of 1-dimensional pixel offsets which can be used to draw this marker onto a raster.- Parameters:
xStride
- X dimension of the buffer- Returns:
- array of offsets into a buffer at which pixels representing this style should be inserted
-
getLabelPixels
public Pixellator getLabelPixels(java.lang.String label, int x, int y, java.awt.Rectangle clip)
Returns an array over pixel positions which can be used to draw a label for this style. The bounds of the returned pixellator are a reasonable estimate of the bounds of the text to be drawn.- Parameters:
label
- text of label to drawx
- X coordinate of point to labely
- Y coordinate of point to labelclip
- clipping region, or null
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:DefaultStyle
Returns true ifo
satisfies the following conditions- It has the same class as this one
- It has the same colour as this one
- It has the same stroke as this one
- The
otherAtts
object specified at its creation matches (according toequals()
this one's
- Overrides:
equals
in classDefaultStyle
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classDefaultStyle
-
hasErrors
public static boolean hasErrors(MarkStyle style, PlotData plotData)
Utility method indicating whether errors will be drawn for a given style when a given set of points is plotted.- Parameters:
style
- plotting styleplotData
- plotting data- Returns:
- false if rendering the error bars will have no effect
-
targetStyle
public static MarkStyle targetStyle()
Returns a style which looks like a target. Suitable for use as a cursor.
-
-