Class 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 doing
        style1 = 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 the equals() method. A style may however have a null shapeId, 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.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MarkStyle​(java.awt.Color color, java.lang.Object otherAtts, MarkShape shapeId, int size, int maxr)
      Constructor.
    • 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 supplied ColorTweaker 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 supplied ColorTweaker 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 if o 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 to equals() this one's
      ErrorRenderer 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 java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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.
    • Constructor Detail

      • MarkStyle

        protected MarkStyle​(java.awt.Color color,
                            java.lang.Object otherAtts,
                            MarkShape shapeId,
                            int size,
                            int maxr)
        Constructor.
        Parameters:
        color - colour
        otherAtts - distinguisher for this instance (besides class and colour)
        shapeId - style factory
        size - nominal size
        maxr - 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 invokes drawShape(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 calls drawShape(java.awt.Graphics).
        Parameters:
        g - graphics context
        x - x position
        y - 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 supplied ColorTweaker 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 to drawMarker, but doing it like this makes sure that the graphics context has been assigned the right colour and position.
        Parameters:
        g - graphics context
        x - x position
        y - y position
        fixer - 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 context
        x - data point X coordinate
        y - data point Y coordinate
        xoffs - 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 supplied ColorTweaker object.
        Parameters:
        g - graphics context
        x - data point X coordinate
        y - data point Y coordinate
        xoffs - 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 context
        x - X coordinate of point
        y - Y coordinate of point
        label - 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 context
        x - X coordinate of point
        y - Y coordinate of point
        label - text to draw
        fixer - 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 width
        height - 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 the drawMarker() 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 draw
        x - X coordinate of point to label
        y - Y coordinate of point to label
        clip - clipping region, or null
      • equals

        public boolean equals​(java.lang.Object o)
        Description copied from class: DefaultStyle
        Returns true if o satisfies the following conditions
        1. It has the same class as this one
        2. It has the same colour as this one
        3. It has the same stroke as this one
        4. The otherAtts object specified at its creation matches (according to equals() this one's
        Overrides:
        equals in class DefaultStyle
      • 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 style
        plotData - 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.