Class XYShapeRenderer

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.EventListener, AnnotationChangeListener, LegendItemSource, XYItemRenderer, PublicCloneable

    public class XYShapeRenderer
    extends AbstractXYItemRenderer
    implements XYItemRenderer, java.lang.Cloneable, PublicCloneable, java.io.Serializable
    A renderer that draws shapes at (x, y) coordinates and, if the dataset is an instance of XYZDataset, fills the shapes with a paint that is based on the z-value (the paint is obtained from a lookup table). The renderer also allows for optional guidelines, horizontal and vertical lines connecting the shape to the edges of the plot.

    The example shown here is generated by the XYShapeRendererDemo1.java program included in the JFreeChart demo collection:

    XYShapeRendererSample.png

    This renderer has similarities to, but also differences from, the XYLineAndShapeRenderer.
    See Also:
    Serialized Form
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Auto generated serial version id.
        See Also:
        Constant Field Values
      • paintScale

        private PaintScale paintScale
        The paint scale (never null).
      • drawOutlines

        private boolean drawOutlines
        A flag that controls whether or not the shape outlines are drawn.
      • useOutlinePaint

        private boolean useOutlinePaint
        A flag that controls whether or not the outline paint is used (if not, the regular paint is used).
      • useFillPaint

        private boolean useFillPaint
        A flag that controls whether or not the fill paint is used (if not, the fill paint is used).
      • guideLinesVisible

        private boolean guideLinesVisible
        Flag indicating if guide lines should be drawn for every item.
      • guideLinePaint

        private transient java.awt.Paint guideLinePaint
        The paint used for drawing the guide lines (never null).
      • guideLineStroke

        private transient java.awt.Stroke guideLineStroke
        The stroke used for drawing the guide lines (never null).
    • Constructor Detail

      • XYShapeRenderer

        public XYShapeRenderer()
        Creates a new XYShapeRenderer instance with default attributes.
    • Method Detail

      • setPaintScale

        public void setPaintScale​(PaintScale scale)
        Sets the paint scale used by the renderer and sends a RendererChangeEvent to all registered listeners.
        Parameters:
        scale - the scale (null not permitted).
        See Also:
        getPaintScale()
      • getDrawOutlines

        public boolean getDrawOutlines()
        Returns true if outlines should be drawn for shapes, and false otherwise.
        Returns:
        A boolean.
        See Also:
        setDrawOutlines(boolean)
      • setDrawOutlines

        public void setDrawOutlines​(boolean flag)
        Sets the flag that controls whether outlines are drawn for shapes, and sends a RendererChangeEvent to all registered listeners.

        In some cases, shapes look better if they do NOT have an outline, but this flag allows you to set your own preference.

        Parameters:
        flag - the flag.
        See Also:
        getDrawOutlines()
      • getUseFillPaint

        public boolean getUseFillPaint()
        Returns true if the renderer should use the fill paint setting to fill shapes, and false if it should just use the regular paint.

        Refer to XYLineAndShapeRendererDemo2.java to see the effect of this flag.

        Returns:
        A boolean.
        See Also:
        setUseFillPaint(boolean), getUseOutlinePaint()
      • setUseFillPaint

        public void setUseFillPaint​(boolean flag)
        Sets the flag that controls whether the fill paint is used to fill shapes, and sends a RendererChangeEvent to all registered listeners.
        Parameters:
        flag - the flag.
        See Also:
        getUseFillPaint()
      • getUseOutlinePaint

        public boolean getUseOutlinePaint()
        Returns the flag that controls whether the outline paint is used for shape outlines. If not, the regular series paint is used.
        Returns:
        A boolean.
        See Also:
        setUseOutlinePaint(boolean)
      • setUseOutlinePaint

        public void setUseOutlinePaint​(boolean use)
        Sets the flag that controls whether the outline paint is used for shape outlines, and sends a RendererChangeEvent to all registered listeners.
        Parameters:
        use - the flag.
        See Also:
        getUseOutlinePaint()
      • isGuideLinesVisible

        public boolean isGuideLinesVisible()
        Returns a flag that controls whether or not guide lines are drawn for each data item (the lines are horizontal and vertical "crosshairs" linking the data point to the axes).
        Returns:
        A boolean.
        See Also:
        setGuideLinesVisible(boolean)
      • setGuideLinesVisible

        public void setGuideLinesVisible​(boolean visible)
        Sets the flag that controls whether or not guide lines are drawn for each data item and sends a RendererChangeEvent to all registered listeners.
        Parameters:
        visible - the new flag value.
        See Also:
        isGuideLinesVisible()
      • getGuideLinePaint

        public java.awt.Paint getGuideLinePaint()
        Returns the paint used to draw the guide lines.
        Returns:
        The paint (never null).
        See Also:
        setGuideLinePaint(Paint)
      • setGuideLinePaint

        public void setGuideLinePaint​(java.awt.Paint paint)
        Sets the paint used to draw the guide lines and sends a RendererChangeEvent to all registered listeners.
        Parameters:
        paint - the paint (null not permitted).
        See Also:
        getGuideLinePaint()
      • getGuideLineStroke

        public java.awt.Stroke getGuideLineStroke()
        Returns the stroke used to draw the guide lines.
        Returns:
        The stroke.
        See Also:
        setGuideLineStroke(Stroke)
      • setGuideLineStroke

        public void setGuideLineStroke​(java.awt.Stroke stroke)
        Sets the stroke used to draw the guide lines and sends a RendererChangeEvent to all registered listeners.
        Parameters:
        stroke - the stroke (null not permitted).
        See Also:
        getGuideLineStroke()
      • findZBounds

        public Range findZBounds​(XYZDataset dataset)
        Return the range of z-values in the specified dataset.
        Parameters:
        dataset - the dataset (null permitted).
        Returns:
        The range (null if the dataset is null or empty).
      • drawItem

        public void drawItem​(java.awt.Graphics2D g2,
                             XYItemRendererState state,
                             java.awt.geom.Rectangle2D dataArea,
                             PlotRenderingInfo info,
                             XYPlot plot,
                             ValueAxis domainAxis,
                             ValueAxis rangeAxis,
                             XYDataset dataset,
                             int series,
                             int item,
                             CrosshairState crosshairState,
                             int pass)
        Draws the block representing the specified item.
        Specified by:
        drawItem in interface XYItemRenderer
        Parameters:
        g2 - the graphics device.
        state - the state.
        dataArea - the data area.
        info - the plot rendering info.
        plot - the plot.
        domainAxis - the x-axis.
        rangeAxis - the y-axis.
        dataset - the dataset.
        series - the series index.
        item - the item index.
        crosshairState - the crosshair state.
        pass - the pass index.
      • getPaint

        protected java.awt.Paint getPaint​(XYDataset dataset,
                                          int series,
                                          int item)
        Get the paint for a given series and item from a dataset.
        Parameters:
        dataset - the dataset.
        series - the series index.
        item - the item index.
        Returns:
        The paint.
      • equals

        public boolean equals​(java.lang.Object obj)
        Tests this instance for equality with an arbitrary object. This method returns true if and only if:
        • obj is an instance of XYShapeRenderer (not null);
        • obj has the same field values as this XYShapeRenderer;
        Overrides:
        equals in class AbstractXYItemRenderer
        Parameters:
        obj - the object (null permitted).
        Returns:
        A boolean.
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a clone of this renderer.
        Specified by:
        clone in interface PublicCloneable
        Overrides:
        clone in class AbstractXYItemRenderer
        Returns:
        A clone of this renderer.
        Throws:
        java.lang.CloneNotSupportedException - if there is a problem creating the clone.
      • readObject

        private void readObject​(java.io.ObjectInputStream stream)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Provides serialization support.
        Parameters:
        stream - the input stream.
        Throws:
        java.io.IOException - if there is an I/O error.
        java.lang.ClassNotFoundException - if there is a classpath problem.
      • writeObject

        private void writeObject​(java.io.ObjectOutputStream stream)
                          throws java.io.IOException
        Provides serialization support.
        Parameters:
        stream - the output stream.
        Throws:
        java.io.IOException - if there is an I/O error.