Class Legend

java.lang.Object
noaa.coastwatch.render.Legend
Direct Known Subclasses:
DataColorScale, EarthPlotInfo

public abstract class Legend extends Object
A legend is used to annotate data with descriptive elements. A legend may have a desired size, font, and color. The actual size of the legend may vary from the desired size.
Since:
3.1.1
Author:
Peter Hollemans
  • Field Details

    • SPACE_SIZE

      public static final int SPACE_SIZE
      The default space size between legend elements.
      See Also:
    • DEFAULT_STROKE

      public static final Stroke DEFAULT_STROKE
      The default stroke for line drawing.
    • preferredSize

      protected Dimension preferredSize
      The preferred dimensions for the legend.
    • font

      protected Font font
      The legend font.
    • fore

      protected Color fore
      The legend foreground and background colors.
    • back

      protected Color back
      The legend foreground and background colors.
  • Constructor Details

    • Legend

      protected Legend(Dimension dim, Font font, Color fore, Color back)
      Creates a new legend with the specified properties.
      Parameters:
      dim - the dimensions for the legend, or null to detect the size of the legend from the subclass getSize(java.awt.Graphics2D) method.
      font - the font the use for the legend text.
      fore - the forground color to use for text and lines.
      back - the background colour for filling behind the legend contents.
  • Method Details

    • setForeground

      public void setForeground(Color color)
      Sets the foreground color.
      Parameters:
      color - the foreground color to be used for drawing legend elements.
    • setBackground

      public void setBackground(Color color)
      Sets the background color.
      Parameters:
      color - the background colour to be used for drawing the legend background, or null if no background is to be drawn.
    • setPreferredSize

      public void setPreferredSize(Dimension size)
      Sets the preferred size of the legend. The actual size of the legend may or may not match the preferred size. Use getSize(java.awt.Graphics2D) to determine the actual rendered size. If the preferred size is null, then the class determines an optimal size.
      Parameters:
      size - the preferred legend size, or null for none.
    • render

      public abstract void render(Graphics2D g, int x, int y)
      Renders the legend at the specified coordinates in the graphics device.
      Parameters:
      g - the graphics device for rendering.
      x - the x coordinate of the top-left corner.
      y - the y coordinate of the top-left corner.
    • getSize

      public abstract Dimension getSize(Graphics2D g)
      Gets the actual required legend size.
      Parameters:
      g - the graphics device that the legend will be rendered on.
    • setFont

      public void setFont(Font font)
      Sets the legend font.
      Parameters:
      font - the legend font, or null to use the default font face, plain style, 12 point.