Class SymbolDraw

java.lang.Object
edu.cnu.mdi.graphics.SymbolDraw

public final class SymbolDraw extends Object
Static utility methods for drawing MDI point symbols at pixel coordinates.

Symbol catalogue

The supported symbol types are defined by SymbolType: SQUARE, CIRCLE, DIAMOND, CROSS, UPTRIANGLE, DOWNTRIANGLE, BOWTIE, X, and STAR. NOSYMBOL suppresses drawing entirely.

Color conventions

Most symbols accept separate line (outline) and fill colors. Passing null for either color suppresses that part of the drawing. Where a line color is null but a fill color is provided, the fill color is used for the outline as well so that the symbol is always visible.

Graphics context

All methods accept Graphics2D directly. No casts from Graphics are performed. Callers that receive a Graphics context (e.g. inside an overridden Component.paint(java.awt.Graphics) method) should cast once at the call site:

 @Override
 public void paint(Graphics g) {
     Graphics2D g2 = (Graphics2D) g;
     SymbolDraw.drawSymbol(g2, x, y, style);
 }
 

Stroke management

drawSymbol(Graphics2D, int, int, SymbolType, int, Color, Color) temporarily sets a 1-pixel solid stroke for drawing and restores the previous stroke afterwards. Individual shape-drawing helpers do not manage the stroke; they rely on whatever stroke is current.

  • Method Details

    • drawSymbol

      public static void drawSymbol(Graphics2D g2, int x, int y, IStyled style)
      Draw the symbol described by style at the given screen position.

      Symbol type, size, border color, and fill color are all read from style.

      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the symbol center
      y - y pixel coordinate of the symbol center
      style - the drawing style; must not be null
    • drawGhostSymbol

      public static void drawGhostSymbol(Graphics2D g2, int x, int y, IStyled style)
      Draw a "ghost" symbol — three stacked copies of the symbol with slight vertical offsets — to produce a shadow/emboss effect.

      The three passes are:

      1. At (x, y+1) with a white outline (shadow).
      2. At (x, y) with the style's normal line color.
      3. At (x, y-1) with the style's normal line color (highlight).
      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the symbol center
      y - y pixel coordinate of the symbol center
      style - the drawing style; must not be null
    • drawSymbol

      public static void drawSymbol(Graphics2D g2, int x, int y, SymbolType symbol, int symbolSize, Color lineColor, Color fillColor)
      Draw a symbol at the given screen position with explicit style parameters.

      A 1-pixel solid stroke is set for the duration of the call and the previous stroke is restored afterwards. If symbol is SymbolType.NOSYMBOL the method returns immediately without drawing.

      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the symbol center
      y - y pixel coordinate of the symbol center
      symbol - the symbol type to draw
      symbolSize - total symbol size in pixels (half-size is derived internally as symbolSize / 2)
      lineColor - outline color; null suppresses the outline (or causes the fill color to be used as the outline for symbols that require one)
      fillColor - fill color; null suppresses fill (not relevant for line-only symbols such as CROSS, X, and STAR)
    • drawStar

      public static void drawStar(Graphics2D g2, int x, int y, int s2, Color lc)
      Draw a star symbol composed of four crossing lines (horizontal, vertical, and two diagonals) meeting at the center.
      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the center
      y - y pixel coordinate of the center
      s2 - half-size (arm length) in pixels
      lc - line color; no-op if null
    • drawRectangle

      public static void drawRectangle(Graphics2D g2, int x, int y, int w2, int h2, Color lc, Color fc)
      Draw a centerd rectangle symbol.

      If lc is null the fill color is used for the outline so the symbol boundary remains visible.

      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the center
      y - y pixel coordinate of the center
      w2 - half-width in pixels
      h2 - half-height in pixels
      lc - outline color; defaults to fc if null
      fc - fill color; null suppresses fill
    • drawOval

      public static void drawOval(Graphics2D g2, int x, int y, int w2, int h2, Color lc, Color fc)
      Draw a centered oval symbol.

      If lc is null the fill color is used for the outline.

      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the center
      y - y pixel coordinate of the center
      w2 - half-width in pixels
      h2 - half-height in pixels
      lc - outline color; defaults to fc if null
      fc - fill color; null suppresses fill
    • drawUpTriangle

      public static void drawUpTriangle(Graphics2D g2, int x, int y, int s2, Color lc, Color fc)
      Draw a centered upward-pointing triangle symbol.

      The triangle has its apex at the top and its base at the bottom. If lc is null the fill color is used for the outline.

      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the center
      y - y pixel coordinate of the center
      s2 - half-size in pixels (applies to both width and height)
      lc - outline color; defaults to fc if null
      fc - fill color; null suppresses fill
    • drawDownTriangle

      public static void drawDownTriangle(Graphics2D g2, int x, int y, int s2, Color lc, Color fc)
      Draw a centered downward-pointing triangle symbol.

      The triangle has its apex at the bottom and its base at the top. If lc is null the fill color is used for the outline.

      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the center
      y - y pixel coordinate of the center
      s2 - half-size in pixels (applies to both width and height)
      lc - outline color; defaults to fc if null
      fc - fill color; null suppresses fill
    • drawDavid

      public static void drawDavid(Graphics2D g2, int x, int y, int s2, Color lc, Color fc)
      Draw a bowtie (hourglass) symbol.

      The bowtie is a six-vertex polygon: two corners on the left and right edges, and one pinched point on each of the left and right sides of the center.

      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the center
      y - y pixel coordinate of the center
      s2 - half-size in pixels
      lc - outline color; null suppresses outline
      fc - fill color; null suppresses fill
    • drawCross

      public static void drawCross(Graphics2D g2, int x, int y, int s2, Color lc)
      Draw a centered cross (+) symbol.
      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the center
      y - y pixel coordinate of the center
      s2 - half-size (arm length) in pixels
      lc - line color; no-op if null
    • drawX

      public static void drawX(Graphics2D g2, int x, int y, int s2, Color lc)
      Draw a centered X (×) symbol.
      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the center
      y - y pixel coordinate of the center
      s2 - half-size (arm length) in pixels
      lc - line color; no-op if null
    • drawDiamond

      public static void drawDiamond(Graphics2D g2, int x, int y, int s2, Color lc, Color fc)
      Draw a centered diamond symbol.

      The diamond has four vertices at the top, bottom, left, and right extremes of the bounding box defined by s2. If lc is null the fill color is used for the outline.

      Parameters:
      g2 - the graphics context
      x - x pixel coordinate of the center
      y - y pixel coordinate of the center
      s2 - half-size in pixels (applies to all four arms)
      lc - outline colou=r; defaults to fc if null
      fc - fill color; null suppresses fill