Class Plot

    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        For serialization.
        See Also:
        Constant Field Values
      • ZERO

        public static final java.lang.Number ZERO
        Useful constant representing zero.
      • DEFAULT_INSETS

        public static final RectangleInsets DEFAULT_INSETS
        The default insets.
      • DEFAULT_OUTLINE_STROKE

        public static final java.awt.Stroke DEFAULT_OUTLINE_STROKE
        The default outline stroke.
      • DEFAULT_OUTLINE_PAINT

        public static final java.awt.Paint DEFAULT_OUTLINE_PAINT
        The default outline color.
      • DEFAULT_FOREGROUND_ALPHA

        public static final float DEFAULT_FOREGROUND_ALPHA
        The default foreground alpha transparency.
        See Also:
        Constant Field Values
      • DEFAULT_BACKGROUND_ALPHA

        public static final float DEFAULT_BACKGROUND_ALPHA
        The default background alpha transparency.
        See Also:
        Constant Field Values
      • DEFAULT_BACKGROUND_PAINT

        public static final java.awt.Paint DEFAULT_BACKGROUND_PAINT
        The default background color.
      • MINIMUM_WIDTH_TO_DRAW

        public static final int MINIMUM_WIDTH_TO_DRAW
        The minimum width at which the plot should be drawn.
        See Also:
        Constant Field Values
      • MINIMUM_HEIGHT_TO_DRAW

        public static final int MINIMUM_HEIGHT_TO_DRAW
        The minimum height at which the plot should be drawn.
        See Also:
        Constant Field Values
      • DEFAULT_LEGEND_ITEM_BOX

        public static final java.awt.Shape DEFAULT_LEGEND_ITEM_BOX
        A default box shape for legend items.
      • DEFAULT_LEGEND_ITEM_CIRCLE

        public static final java.awt.Shape DEFAULT_LEGEND_ITEM_CIRCLE
        A default circle shape for legend items.
      • chart

        private JFreeChart chart
        The chart that the plot is assigned to. It can be null if the plot is not assigned to a chart yet, or if the plot is a subplot of a another plot.
      • parent

        private Plot parent
        The parent plot (null if this is the root plot).
      • datasetGroup

        private DatasetGroup datasetGroup
        The dataset group (to be used for thread synchronisation).
      • noDataMessage

        private java.lang.String noDataMessage
        The message to display if no data is available.
      • noDataMessageFont

        private java.awt.Font noDataMessageFont
        The font used to display the 'no data' message.
      • noDataMessagePaint

        private transient java.awt.Paint noDataMessagePaint
        The paint used to draw the 'no data' message.
      • insets

        private RectangleInsets insets
        Amount of blank space around the plot area.
      • outlineVisible

        private boolean outlineVisible
        A flag that controls whether or not the plot outline is drawn.
      • outlineStroke

        private transient java.awt.Stroke outlineStroke
        The Stroke used to draw an outline around the plot.
      • outlinePaint

        private transient java.awt.Paint outlinePaint
        The Paint used to draw an outline around the plot.
      • backgroundPaint

        private transient java.awt.Paint backgroundPaint
        An optional color used to fill the plot background.
      • backgroundImage

        private transient java.awt.Image backgroundImage
        An optional image for the plot background.
      • backgroundImageAlignment

        private int backgroundImageAlignment
        The alignment for the background image.
      • backgroundImageAlpha

        private float backgroundImageAlpha
        The alpha value used to draw the background image.
      • foregroundAlpha

        private float foregroundAlpha
        The alpha-transparency for the plot.
      • backgroundAlpha

        private float backgroundAlpha
        The alpha transparency for the background paint.
      • drawingSupplier

        private DrawingSupplier drawingSupplier
        The drawing supplier.
      • listenerList

        private transient javax.swing.event.EventListenerList listenerList
        Storage for registered change listeners.
      • notify

        private boolean notify
        A flag that controls whether or not the plot will notify listeners of changes (defaults to true, but sometimes it is useful to disable this).
    • Constructor Detail

      • Plot

        protected Plot()
        Creates a new plot.
    • Method Detail

      • getChart

        public JFreeChart getChart()
        Returns the chart that this plot is assigned to. This method can return null if the plot is not yet assigned to a plot, or if the plot is a subplot of another plot.
        Returns:
        The chart (possibly null).
      • setChart

        public void setChart​(JFreeChart chart)
        Sets the chart that the plot is assigned to. This method is not intended for external use.
        Parameters:
        chart - the chart (null permitted).
      • fetchElementHintingFlag

        public boolean fetchElementHintingFlag()
        Fetches the element hinting flag from the chart that this plot is assigned to. If the plot is not assigned (directly or indirectly) to a chart instance, this method will return false.
        Returns:
        A boolean.
      • setDatasetGroup

        protected void setDatasetGroup​(DatasetGroup group)
        Sets the dataset group (not currently used).
        Parameters:
        group - the dataset group (null permitted).
        See Also:
        getDatasetGroup()
      • setNoDataMessage

        public void setNoDataMessage​(java.lang.String message)
        Sets the message that is displayed when the dataset is empty or null, and sends a PlotChangeEvent to all registered listeners.
        Parameters:
        message - the message (null permitted).
        See Also:
        getNoDataMessage()
      • setNoDataMessageFont

        public void setNoDataMessageFont​(java.awt.Font font)
        Sets the font used to display the 'no data' message and sends a PlotChangeEvent to all registered listeners.
        Parameters:
        font - the font (null not permitted).
        See Also:
        getNoDataMessageFont()
      • setNoDataMessagePaint

        public void setNoDataMessagePaint​(java.awt.Paint paint)
        Sets the paint used to display the 'no data' message and sends a PlotChangeEvent to all registered listeners.
        Parameters:
        paint - the paint (null not permitted).
        See Also:
        getNoDataMessagePaint()
      • getPlotType

        public abstract java.lang.String getPlotType()
        Returns a short string describing the plot type.

        Note: this gets used in the chart property editing user interface, but there needs to be a better mechanism for identifying the plot type.

        Returns:
        A short string describing the plot type (never null).
      • getParent

        public Plot getParent()
        Returns the parent plot (or null if this plot is not part of a combined plot).
        Returns:
        The parent plot.
        See Also:
        setParent(Plot), getRootPlot()
      • setParent

        public void setParent​(Plot parent)
        Sets the parent plot. This method is intended for internal use, you shouldn't need to call it directly.
        Parameters:
        parent - the parent plot (null permitted).
        See Also:
        getParent()
      • getRootPlot

        public Plot getRootPlot()
        Returns the root plot.
        Returns:
        The root plot.
        See Also:
        getParent()
      • isSubplot

        public boolean isSubplot()
        Returns true if this plot is part of a combined plot structure (that is, getParent() returns a non-null value), and false otherwise.
        Returns:
        true if this plot is part of a combined plot structure.
        See Also:
        getParent()
      • setInsets

        public void setInsets​(RectangleInsets insets,
                              boolean notify)
        Sets the insets for the plot and, if requested, and sends a PlotChangeEvent to all registered listeners.
        Parameters:
        insets - the new insets (null not permitted).
        notify - a flag that controls whether the registered listeners are notified.
        See Also:
        getInsets(), setInsets(RectangleInsets)
      • getBackgroundPaint

        public java.awt.Paint getBackgroundPaint()
        Returns the background color of the plot area.
        Returns:
        The paint (possibly null).
        See Also:
        setBackgroundPaint(Paint)
      • setBackgroundPaint

        public void setBackgroundPaint​(java.awt.Paint paint)
        Sets the background color of the plot area and sends a PlotChangeEvent to all registered listeners.
        Parameters:
        paint - the paint (null permitted).
        See Also:
        getBackgroundPaint()
      • getBackgroundAlpha

        public float getBackgroundAlpha()
        Returns the alpha transparency of the plot area background.
        Returns:
        The alpha transparency.
        See Also:
        setBackgroundAlpha(float)
      • setBackgroundAlpha

        public void setBackgroundAlpha​(float alpha)
        Sets the alpha transparency of the plot area background, and notifies registered listeners that the plot has been modified.
        Parameters:
        alpha - the new alpha value (in the range 0.0f to 1.0f).
        See Also:
        getBackgroundAlpha()
      • setDrawingSupplier

        public void setDrawingSupplier​(DrawingSupplier supplier)
        Sets the drawing supplier for the plot and sends a PlotChangeEvent to all registered listeners. The drawing supplier is responsible for supplying a limitless (possibly repeating) sequence of Paint, Stroke and Shape objects that the plot's renderer(s) can use to populate its (their) tables.
        Parameters:
        supplier - the new supplier.
        See Also:
        getDrawingSupplier()
      • setDrawingSupplier

        public void setDrawingSupplier​(DrawingSupplier supplier,
                                       boolean notify)
        Sets the drawing supplier for the plot and, if requested, sends a PlotChangeEvent to all registered listeners. The drawing supplier is responsible for supplying a limitless (possibly repeating) sequence of Paint, Stroke and Shape objects that the plot's renderer(s) can use to populate its (their) tables.
        Parameters:
        supplier - the new supplier.
        notify - notify listeners?
        See Also:
        getDrawingSupplier()
      • getBackgroundImage

        public java.awt.Image getBackgroundImage()
        Returns the background image that is used to fill the plot's background area.
        Returns:
        The image (possibly null).
        See Also:
        setBackgroundImage(Image)
      • setBackgroundImage

        public void setBackgroundImage​(java.awt.Image image)
        Sets the background image for the plot and sends a PlotChangeEvent to all registered listeners.
        Parameters:
        image - the image (null permitted).
        See Also:
        getBackgroundImage()
      • getBackgroundImageAlignment

        public int getBackgroundImageAlignment()
        Returns the background image alignment. Alignment constants are defined in the Align class.
        Returns:
        The alignment.
        See Also:
        setBackgroundImageAlignment(int)
      • setBackgroundImageAlignment

        public void setBackgroundImageAlignment​(int alignment)
        Sets the alignment for the background image and sends a PlotChangeEvent to all registered listeners. Alignment options are defined by the Align class.
        Parameters:
        alignment - the alignment.
        See Also:
        getBackgroundImageAlignment()
      • getBackgroundImageAlpha

        public float getBackgroundImageAlpha()
        Returns the alpha transparency used to draw the background image. This is a value in the range 0.0f to 1.0f, where 0.0f is fully transparent and 1.0f is fully opaque.
        Returns:
        The alpha transparency.
        See Also:
        setBackgroundImageAlpha(float)
      • setBackgroundImageAlpha

        public void setBackgroundImageAlpha​(float alpha)
        Sets the alpha transparency used when drawing the background image.
        Parameters:
        alpha - the alpha transparency (in the range 0.0f to 1.0f, where 0.0f is fully transparent, and 1.0f is fully opaque).
        Throws:
        java.lang.IllegalArgumentException - if alpha is not within the specified range.
        See Also:
        getBackgroundImageAlpha()
      • isOutlineVisible

        public boolean isOutlineVisible()
        Returns the flag that controls whether or not the plot outline is drawn. The default value is true. Note that for historical reasons, the plot's outline paint and stroke can take on null values, in which case the outline will not be drawn even if this flag is set to true.
        Returns:
        The outline visibility flag.
        See Also:
        setOutlineVisible(boolean)
      • setOutlineVisible

        public void setOutlineVisible​(boolean visible)
        Sets the flag that controls whether or not the plot's outline is drawn, and sends a PlotChangeEvent to all registered listeners.
        Parameters:
        visible - the new flag value.
        See Also:
        isOutlineVisible()
      • getOutlineStroke

        public java.awt.Stroke getOutlineStroke()
        Returns the stroke used to outline the plot area.
        Returns:
        The stroke (possibly null).
        See Also:
        setOutlineStroke(Stroke)
      • setOutlineStroke

        public void setOutlineStroke​(java.awt.Stroke stroke)
        Sets the stroke used to outline the plot area and sends a PlotChangeEvent to all registered listeners. If you set this attribute to null, no outline will be drawn.
        Parameters:
        stroke - the stroke (null permitted).
        See Also:
        getOutlineStroke()
      • getOutlinePaint

        public java.awt.Paint getOutlinePaint()
        Returns the color used to draw the outline of the plot area.
        Returns:
        The color (possibly null).
        See Also:
        setOutlinePaint(Paint)
      • setOutlinePaint

        public void setOutlinePaint​(java.awt.Paint paint)
        Sets the paint used to draw the outline of the plot area and sends a PlotChangeEvent to all registered listeners. If you set this attribute to null, no outline will be drawn.
        Parameters:
        paint - the paint (null permitted).
        See Also:
        getOutlinePaint()
      • getForegroundAlpha

        public float getForegroundAlpha()
        Returns the alpha-transparency for the plot foreground.
        Returns:
        The alpha-transparency.
        See Also:
        setForegroundAlpha(float)
      • setForegroundAlpha

        public void setForegroundAlpha​(float alpha)
        Sets the alpha-transparency for the plot and sends a PlotChangeEvent to all registered listeners.
        Parameters:
        alpha - the new alpha transparency.
        See Also:
        getForegroundAlpha()
      • isNotify

        public boolean isNotify()
        Returns a flag that controls whether or not change events are sent to registered listeners.
        Returns:
        A boolean.
        See Also:
        setNotify(boolean)
      • setNotify

        public void setNotify​(boolean notify)
        Sets a flag that controls whether or not listeners receive PlotChangeEvent notifications.
        Parameters:
        notify - a boolean.
        See Also:
        isNotify()
      • notifyListeners

        public void notifyListeners​(PlotChangeEvent event)
        Notifies all registered listeners that the plot has been modified.
        Parameters:
        event - information about the change event.
      • fireChangeEvent

        protected void fireChangeEvent()
        Sends a PlotChangeEvent to all registered listeners.
      • draw

        public abstract void draw​(java.awt.Graphics2D g2,
                                  java.awt.geom.Rectangle2D area,
                                  java.awt.geom.Point2D anchor,
                                  PlotState parentState,
                                  PlotRenderingInfo info)
        Draws the plot within the specified area. The anchor is a point on the chart that is specified externally (for instance, it may be the last point of the last mouse click performed by the user) - plots can use or ignore this value as they see fit.

        Subclasses need to provide an implementation of this method, obviously.
        Parameters:
        g2 - the graphics device.
        area - the plot area.
        anchor - the anchor point (null permitted).
        parentState - the parent state (if any, null permitted).
        info - carries back plot rendering info.
      • drawBackground

        public void drawBackground​(java.awt.Graphics2D g2,
                                   java.awt.geom.Rectangle2D area)
        Draws the plot background (the background color and/or image).

        This method will be called during the chart drawing process and is declared public so that it can be accessed by the renderers used by certain subclasses. You shouldn't need to call this method directly.

        Parameters:
        g2 - the graphics device.
        area - the area within which the plot should be drawn.
      • fillBackground

        protected void fillBackground​(java.awt.Graphics2D g2,
                                      java.awt.geom.Rectangle2D area,
                                      PlotOrientation orientation)
        Fills the specified area with the background paint. If the background paint is an instance of GradientPaint, the gradient will run in the direction suggested by the plot's orientation.
        Parameters:
        g2 - the graphics target.
        area - the plot area.
        orientation - the plot orientation (null not permitted).
      • drawOutline

        public void drawOutline​(java.awt.Graphics2D g2,
                                java.awt.geom.Rectangle2D area)
        Draws the plot outline. This method will be called during the chart drawing process and is declared public so that it can be accessed by the renderers used by certain subclasses. You shouldn't need to call this method directly.
        Parameters:
        g2 - the graphics device.
        area - the area within which the plot should be drawn.
      • drawNoDataMessage

        protected void drawNoDataMessage​(java.awt.Graphics2D g2,
                                         java.awt.geom.Rectangle2D area)
        Draws a message to state that there is no data to plot.
        Parameters:
        g2 - the graphics device.
        area - the area within which the plot should be drawn.
      • createAndAddEntity

        protected void createAndAddEntity​(java.awt.geom.Rectangle2D dataArea,
                                          PlotRenderingInfo plotState,
                                          java.lang.String toolTip,
                                          java.lang.String urlText)
        Creates a plot entity that contains a reference to the plot and the data area as shape.
        Parameters:
        dataArea - the data area used as hot spot for the entity.
        plotState - the plot rendering info containing a reference to the EntityCollection.
        toolTip - the tool tip (defined in the respective Plot subclass) (null permitted).
        urlText - the url (defined in the respective Plot subclass) (null permitted).
      • handleClick

        public void handleClick​(int x,
                                int y,
                                PlotRenderingInfo info)
        Handles a 'click' on the plot. Since the plot does not maintain any information about where it has been drawn, the plot rendering info is supplied as an argument so that the plot dimensions can be determined.
        Parameters:
        x - the x coordinate (in Java2D space).
        y - the y coordinate (in Java2D space).
        info - an object containing information about the dimensions of the plot.
      • zoom

        public void zoom​(double percent)
        Performs a zoom on the plot. Subclasses should override if zooming is appropriate for the type of plot.
        Parameters:
        percent - the zoom percentage.
      • axisChanged

        public void axisChanged​(AxisChangeEvent event)
        Receives notification of a change to one of the plot's axes.
        Specified by:
        axisChanged in interface AxisChangeListener
        Parameters:
        event - information about the event (not used here).
      • datasetChanged

        public void datasetChanged​(DatasetChangeEvent event)
        Receives notification of a change to the plot's dataset.

        The plot reacts by passing on a plot change event to all registered listeners.

        Specified by:
        datasetChanged in interface DatasetChangeListener
        Parameters:
        event - information about the event (not used here).
      • getRectX

        protected double getRectX​(double x,
                                  double w1,
                                  double w2,
                                  RectangleEdge edge)
        Adjusts the supplied x-value.
        Parameters:
        x - the x-value.
        w1 - width 1.
        w2 - width 2.
        edge - the edge (left or right).
        Returns:
        The adjusted x-value.
      • getRectY

        protected double getRectY​(double y,
                                  double h1,
                                  double h2,
                                  RectangleEdge edge)
        Adjusts the supplied y-value.
        Parameters:
        y - the x-value.
        h1 - height 1.
        h2 - height 2.
        edge - the edge (top or bottom).
        Returns:
        The adjusted y-value.
      • equals

        public boolean equals​(java.lang.Object obj)
        Tests this plot for equality with another object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object (null permitted).
        Returns:
        true or false.
      • canEqual

        public boolean canEqual​(java.lang.Object other)
        Ensures symmetry between super/subclass implementations of equals. For more detail, see http://jqno.nl/equalsverifier/manual/inheritance.
        Parameters:
        other - Object
        Returns:
        true ONLY if the parameter is THIS class type
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Creates a clone of the plot.
        Specified by:
        clone in interface PublicCloneable
        Overrides:
        clone in class java.lang.Object
        Returns:
        A clone.
        Throws:
        java.lang.CloneNotSupportedException - if some component of the plot does not support cloning.
      • 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.
      • 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.
      • resolveDomainAxisLocation

        public static RectangleEdge resolveDomainAxisLocation​(AxisLocation location,
                                                              PlotOrientation orientation)
        Resolves a domain axis location for a given plot orientation.
        Parameters:
        location - the location (null not permitted).
        orientation - the orientation (null not permitted).
        Returns:
        The edge (never null).
      • resolveRangeAxisLocation

        public static RectangleEdge resolveRangeAxisLocation​(AxisLocation location,
                                                             PlotOrientation orientation)
        Resolves a range axis location for a given plot orientation.
        Parameters:
        location - the location (null not permitted).
        orientation - the orientation (null not permitted).
        Returns:
        The edge (never null).