java.lang.Object
org.jfree.chart.plot.Plot
com.inductiveautomation.factorypmi.application.components.chart.CustomCompassPlot
All Implemented Interfaces:
Serializable, Cloneable, EventListener, org.jfree.chart.event.AxisChangeListener, org.jfree.chart.event.MarkerChangeListener, org.jfree.chart.LegendItemSource, org.jfree.data.general.DatasetChangeListener, org.jfree.util.PublicCloneable

public class CustomCompassPlot extends org.jfree.chart.plot.Plot implements Cloneable, Serializable
A specialised plot that draws a compass to indicate a direction based on the value from a ValueDataset.

Unfortunately, I had to cut-and-paste this class so that I could customize the drawing and fix the font bug (the orig doesn't have a customizable font)

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Font
    The default label font.
    protected String
     
    protected static ResourceBundle
    The resourceBundle for the localization.
    static final int
    A constant for the label type.
    protected String
    Names of the directions
    protected double
    The count to complete one revolution.
    protected String
     
    static final int
    A constant for the label type.
    protected String
     

    Fields inherited from class org.jfree.chart.plot.Plot

    DEFAULT_BACKGROUND_ALPHA, DEFAULT_BACKGROUND_PAINT, DEFAULT_FOREGROUND_ALPHA, DEFAULT_INSETS, DEFAULT_LEGEND_ITEM_BOX, DEFAULT_LEGEND_ITEM_CIRCLE, DEFAULT_OUTLINE_PAINT, DEFAULT_OUTLINE_STROKE, MINIMUM_HEIGHT_TO_DRAW, MINIMUM_WIDTH_TO_DRAW, ZERO
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    CustomCompassPlot(org.jfree.data.general.ValueDataset dataset)
    Constructs a new compass plot.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addDataset(org.jfree.data.general.ValueDataset dataset)
    Adds a dataset to the compass.
    void
    addDataset(org.jfree.data.general.ValueDataset dataset, org.jfree.chart.needle.MeterNeedle needle)
    Adds a dataset to the compass.
    Returns a clone of the annotation.
    void
    draw(Graphics2D g2, Rectangle2D area, Point2D anchor, org.jfree.chart.plot.PlotState parentState, org.jfree.chart.plot.PlotRenderingInfo info)
    Draws the plot on a Java 2D graphics device (such as the screen or a printer).
    boolean
    Tests an object for equality with this plot.
    protected Font
    getCompassFont(int radius)
    Returns the font for the compass, adjusted for the size of the plot.
    org.jfree.data.general.ValueDataset[]
    Returns the dataset.
    boolean
    Returns a flag that controls whether or not a border is drawn.
    Returns the label font.
    int
    Returns the label type.
    org.jfree.chart.LegendItemCollection
    Returns the legend items for the plot.
    Returns a short string describing the type of plot.
    double
    Gets the count to complete one revolution.
    Returns the paint used to fill the inner background area of the compass.
    Returns the paint used to draw the circles, symbols and labels on the compass.
    Returns the paint used to fill the outer circle of the compass.
    void
    setDrawBorder(boolean status)
    Sets a flag that controls whether or not a border is drawn.
    void
    Sets the label font and sends a PlotChangeEvent to all registered listeners.
    void
    setLabelType(int type)
    Sets the label type (either NO_LABELS or VALUE_LABELS.
    void
    setRevolutionDistance(double size)
    Sets the count to complete one revolution.
    void
    Sets the paint used to fill the inner background area of the compass, and sends a PlotChangeEvent to all registered listeners.
    void
    Sets the paint used to draw the circles, symbols and labels of the compass, and sends a PlotChangeEvent to all registered listeners.
    void
    Sets the paint used to fill the outer circle of the compass, and sends a PlotChangeEvent to all registered listeners.
    void
    setSeriesNeedle(int type)
    Sets the needle type.
    void
    setSeriesNeedle(int index, int type)
    Sets the needle for a series.
    void
    setSeriesNeedle(int index, org.jfree.chart.needle.MeterNeedle needle)
    Sets the needle for a series.
    void
    setSeriesOutlinePaint(int series, Paint p)
    Sets the series outline paint.
    void
    setSeriesOutlineStroke(int series, Stroke stroke)
    Sets the series outline stroke.
    void
    setSeriesPaint(int series, Paint paint)
    Sets the series paint.
    void
    updateCardinalStrings(String north, String south, String east, String west)
    Updates the strings for the compass directions.
    void
    zoom(double percent)
    No zooming is implemented for compass plot, so this method is empty.

    Methods inherited from class org.jfree.chart.plot.Plot

    addChangeListener, axisChanged, datasetChanged, drawBackground, drawBackgroundImage, drawNoDataMessage, drawOutline, fillBackground, fillBackground, fireChangeEvent, getBackgroundAlpha, getBackgroundImage, getBackgroundImageAlignment, getBackgroundImageAlpha, getBackgroundPaint, getDatasetGroup, getDrawingSupplier, getForegroundAlpha, getInsets, getNoDataMessage, getNoDataMessageFont, getNoDataMessagePaint, getOutlinePaint, getOutlineStroke, getParent, getRectX, getRectY, getRootPlot, handleClick, isOutlineVisible, isSubplot, markerChanged, notifyListeners, removeChangeListener, resolveDomainAxisLocation, resolveRangeAxisLocation, setBackgroundAlpha, setBackgroundImage, setBackgroundImageAlignment, setBackgroundImageAlpha, setBackgroundPaint, setDatasetGroup, setDrawingSupplier, setDrawingSupplier, setForegroundAlpha, setInsets, setInsets, setNoDataMessage, setNoDataMessageFont, setNoDataMessagePaint, setOutlinePaint, setOutlineStroke, setOutlineVisible, setParent

    Methods inherited from class java.lang.Object

    finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_LABEL_FONT

      public static final Font DEFAULT_LABEL_FONT
      The default label font.
    • NO_LABELS

      public static final int NO_LABELS
      A constant for the label type.
      See Also:
    • VALUE_LABELS

      public static final int VALUE_LABELS
      A constant for the label type.
      See Also:
    • localizationResources

      protected static ResourceBundle localizationResources
      The resourceBundle for the localization.
    • revolutionDistance

      protected double revolutionDistance
      The count to complete one revolution. Can be arbitrarily set. For degrees (the default) it is 360, for radians this is 2*Pi, etc
    • north

      protected String north
      Names of the directions
    • south

      protected String south
    • east

      protected String east
    • west

      protected String west
  • Constructor Details

    • CustomCompassPlot

      public CustomCompassPlot()
      Default constructor.
    • CustomCompassPlot

      public CustomCompassPlot(org.jfree.data.general.ValueDataset dataset)
      Constructs a new compass plot.
      Parameters:
      dataset - the dataset for the plot (null permitted).
  • Method Details

    • getLabelType

      public int getLabelType()
      Returns the label type. Defined by the constants: NO_LABELS and VALUE_LABELS.
      Returns:
      The label type.
    • setLabelType

      public void setLabelType(int type)
      Sets the label type (either NO_LABELS or VALUE_LABELS.
      Parameters:
      type - the type.
    • getLabelFont

      public Font getLabelFont()
      Returns the label font.
      Returns:
      The label font.
    • setLabelFont

      public void setLabelFont(Font font)
      Sets the label font and sends a PlotChangeEvent to all registered listeners.
      Parameters:
      font - the new label font.
    • getRosePaint

      public Paint getRosePaint()
      Returns the paint used to fill the outer circle of the compass.
      Returns:
      The paint (never null).
    • setRosePaint

      public void setRosePaint(Paint paint)
      Sets the paint used to fill the outer circle of the compass, and sends a PlotChangeEvent to all registered listeners.
      Parameters:
      paint - the paint (null not permitted).
    • getRoseCenterPaint

      public Paint getRoseCenterPaint()
      Returns the paint used to fill the inner background area of the compass.
      Returns:
      The paint (never null).
    • setRoseCenterPaint

      public void setRoseCenterPaint(Paint paint)
      Sets the paint used to fill the inner background area of the compass, and sends a PlotChangeEvent to all registered listeners.
      Parameters:
      paint - the paint (null not permitted).
    • getRoseHighlightPaint

      public Paint getRoseHighlightPaint()
      Returns the paint used to draw the circles, symbols and labels on the compass.
      Returns:
      The paint (never null).
    • setRoseHighlightPaint

      public void setRoseHighlightPaint(Paint paint)
      Sets the paint used to draw the circles, symbols and labels of the compass, and sends a PlotChangeEvent to all registered listeners.
      Parameters:
      paint - the paint (null not permitted).
    • getDrawBorder

      public boolean getDrawBorder()
      Returns a flag that controls whether or not a border is drawn.
      Returns:
      The flag.
    • setDrawBorder

      public void setDrawBorder(boolean status)
      Sets a flag that controls whether or not a border is drawn.
      Parameters:
      status - the flag status.
    • setSeriesPaint

      public void setSeriesPaint(int series, Paint paint)
      Sets the series paint.
      Parameters:
      series - the series index.
      paint - the paint.
    • setSeriesOutlinePaint

      public void setSeriesOutlinePaint(int series, Paint p)
      Sets the series outline paint.
      Parameters:
      series - the series index.
      p - the paint.
    • setSeriesOutlineStroke

      public void setSeriesOutlineStroke(int series, Stroke stroke)
      Sets the series outline stroke.
      Parameters:
      series - the series index.
      stroke - the stroke.
    • setSeriesNeedle

      public void setSeriesNeedle(int type)
      Sets the needle type.
      Parameters:
      type - the type.
    • setSeriesNeedle

      public void setSeriesNeedle(int index, int type)
      Sets the needle for a series. The needle type is one of the following:
      • 0 = ArrowNeedle;
      • 1 = LineNeedle;
      • 2 = LongNeedle;
      • 3 = PinNeedle;
      • 4 = PlumNeedle;
      • 5 = PointerNeedle;
      • 6 = ShipNeedle;
      • 7 = WindNeedle;
      • 8 = ArrowNeedle;
      • 9 = MiddlePinNeedle;
      Parameters:
      index - the series index.
      type - the needle type.
    • setSeriesNeedle

      public void setSeriesNeedle(int index, org.jfree.chart.needle.MeterNeedle needle)
      Sets the needle for a series.
      Parameters:
      index - the series index.
      needle - the needle.
    • getDatasets

      public org.jfree.data.general.ValueDataset[] getDatasets()
      Returns the dataset.

      Provided for convenience.

      Returns:
      The dataset for the plot, cast as a ValueDataset.
    • addDataset

      public void addDataset(org.jfree.data.general.ValueDataset dataset)
      Adds a dataset to the compass.
      Parameters:
      dataset - the new dataset.
    • addDataset

      public void addDataset(org.jfree.data.general.ValueDataset dataset, org.jfree.chart.needle.MeterNeedle needle)
      Adds a dataset to the compass.
      Parameters:
      dataset - the new dataset.
      needle - the needle.
    • draw

      public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, org.jfree.chart.plot.PlotState parentState, org.jfree.chart.plot.PlotRenderingInfo info)
      Draws the plot on a Java 2D graphics device (such as the screen or a printer).
      Specified by:
      draw in class org.jfree.chart.plot.Plot
      Parameters:
      g2 - the graphics device.
      area - the area within which the plot should be drawn.
      anchor - the anchor point (null permitted).
      parentState - the state from the parent plot, if there is one.
      info - collects info about the drawing.
    • getPlotType

      public String getPlotType()
      Returns a short string describing the type of plot.
      Specified by:
      getPlotType in class org.jfree.chart.plot.Plot
      Returns:
      A string describing the plot.
    • getLegendItems

      public org.jfree.chart.LegendItemCollection getLegendItems()
      Returns the legend items for the plot. For now, no legend is available - this method returns null.
      Specified by:
      getLegendItems in interface org.jfree.chart.LegendItemSource
      Overrides:
      getLegendItems in class org.jfree.chart.plot.Plot
      Returns:
      The legend items.
    • zoom

      public void zoom(double percent)
      No zooming is implemented for compass plot, so this method is empty.
      Overrides:
      zoom in class org.jfree.chart.plot.Plot
      Parameters:
      percent - the zoom amount.
    • getCompassFont

      protected Font getCompassFont(int radius)
      Returns the font for the compass, adjusted for the size of the plot.
      Parameters:
      radius - the radius.
      Returns:
      The font.
    • equals

      public boolean equals(Object obj)
      Tests an object for equality with this plot.
      Overrides:
      equals in class org.jfree.chart.plot.Plot
      Parameters:
      obj - the object (null permitted).
    • clone

      public Object clone() throws CloneNotSupportedException
      Returns a clone of the annotation.
      Specified by:
      clone in interface org.jfree.util.PublicCloneable
      Overrides:
      clone in class org.jfree.chart.plot.Plot
      Returns:
      A clone.
      Throws:
      CloneNotSupportedException - this class will not throw this exception, but subclasses (if any) might.
    • setRevolutionDistance

      public void setRevolutionDistance(double size)
      Sets the count to complete one revolution. Can be arbitaly set For degrees (the default) it is 360, for radians this is 2*Pi, etc
      Parameters:
      size - the count to complete one revolution.
    • getRevolutionDistance

      public double getRevolutionDistance()
      Gets the count to complete one revolution.
      Returns:
      The count to complete one revolution
    • updateCardinalStrings

      public void updateCardinalStrings(String north, String south, String east, String west)
      Updates the strings for the compass directions. It's up to the caller to make sure it's not something stupidly long