Class SymbolDraw
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 Summary
Modifier and TypeMethodDescriptionstatic voiddrawCross(Graphics2D g2, int x, int y, int s2, Color lc) Draw a centered cross (+) symbol.static voiddrawDavid(Graphics2D g2, int x, int y, int s2, Color lc, Color fc) Draw a bowtie (hourglass) symbol.static voiddrawDiamond(Graphics2D g2, int x, int y, int s2, Color lc, Color fc) Draw a centered diamond symbol.static voiddrawDownTriangle(Graphics2D g2, int x, int y, int s2, Color lc, Color fc) Draw a centered downward-pointing triangle symbol.static voiddrawGhostSymbol(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.static voiddrawOval(Graphics2D g2, int x, int y, int w2, int h2, Color lc, Color fc) Draw a centered oval symbol.static voiddrawRectangle(Graphics2D g2, int x, int y, int w2, int h2, Color lc, Color fc) Draw a centerd rectangle symbol.static voiddrawStar(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.static voiddrawSymbol(Graphics2D g2, int x, int y, IStyled style) Draw the symbol described bystyleat the given screen position.static voiddrawSymbol(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.static voiddrawUpTriangle(Graphics2D g2, int x, int y, int s2, Color lc, Color fc) Draw a centered upward-pointing triangle symbol.static voiddrawX(Graphics2D g2, int x, int y, int s2, Color lc) Draw a centered X (×) symbol.
-
Method Details
-
drawSymbol
Draw the symbol described bystyleat the given screen position.Symbol type, size, border color, and fill color are all read from
style.- Parameters:
g2- the graphics contextx- x pixel coordinate of the symbol centery- y pixel coordinate of the symbol centerstyle- the drawing style; must not benull
-
drawGhostSymbol
Draw a "ghost" symbol — three stacked copies of the symbol with slight vertical offsets — to produce a shadow/emboss effect.The three passes are:
- At
(x, y+1)with a white outline (shadow). - At
(x, y)with the style's normal line color. - At
(x, y-1)with the style's normal line color (highlight).
- Parameters:
g2- the graphics contextx- x pixel coordinate of the symbol centery- y pixel coordinate of the symbol centerstyle- the drawing style; must not benull
- At
-
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
symbolisSymbolType.NOSYMBOLthe method returns immediately without drawing.- Parameters:
g2- the graphics contextx- x pixel coordinate of the symbol centery- y pixel coordinate of the symbol centersymbol- the symbol type to drawsymbolSize- total symbol size in pixels (half-size is derived internally assymbolSize / 2)lineColor- outline color;nullsuppresses the outline (or causes the fill color to be used as the outline for symbols that require one)fillColor- fill color;nullsuppresses fill (not relevant for line-only symbols such asCROSS,X, andSTAR)
-
drawStar
Draw a star symbol composed of four crossing lines (horizontal, vertical, and two diagonals) meeting at the center.- Parameters:
g2- the graphics contextx- x pixel coordinate of the centery- y pixel coordinate of the centers2- half-size (arm length) in pixelslc- line color; no-op ifnull
-
drawRectangle
Draw a centerd rectangle symbol.If
lcisnullthe fill color is used for the outline so the symbol boundary remains visible.- Parameters:
g2- the graphics contextx- x pixel coordinate of the centery- y pixel coordinate of the centerw2- half-width in pixelsh2- half-height in pixelslc- outline color; defaults tofcifnullfc- fill color;nullsuppresses fill
-
drawOval
Draw a centered oval symbol.If
lcisnullthe fill color is used for the outline.- Parameters:
g2- the graphics contextx- x pixel coordinate of the centery- y pixel coordinate of the centerw2- half-width in pixelsh2- half-height in pixelslc- outline color; defaults tofcifnullfc- fill color;nullsuppresses fill
-
drawUpTriangle
Draw a centered upward-pointing triangle symbol.The triangle has its apex at the top and its base at the bottom. If
lcisnullthe fill color is used for the outline.- Parameters:
g2- the graphics contextx- x pixel coordinate of the centery- y pixel coordinate of the centers2- half-size in pixels (applies to both width and height)lc- outline color; defaults tofcifnullfc- fill color;nullsuppresses fill
-
drawDownTriangle
Draw a centered downward-pointing triangle symbol.The triangle has its apex at the bottom and its base at the top. If
lcisnullthe fill color is used for the outline.- Parameters:
g2- the graphics contextx- x pixel coordinate of the centery- y pixel coordinate of the centers2- half-size in pixels (applies to both width and height)lc- outline color; defaults tofcifnullfc- fill color;nullsuppresses fill
-
drawDavid
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 contextx- x pixel coordinate of the centery- y pixel coordinate of the centers2- half-size in pixelslc- outline color;nullsuppresses outlinefc- fill color;nullsuppresses fill
-
drawCross
Draw a centered cross (+) symbol.- Parameters:
g2- the graphics contextx- x pixel coordinate of the centery- y pixel coordinate of the centers2- half-size (arm length) in pixelslc- line color; no-op ifnull
-
drawX
Draw a centered X (×) symbol.- Parameters:
g2- the graphics contextx- x pixel coordinate of the centery- y pixel coordinate of the centers2- half-size (arm length) in pixelslc- line color; no-op ifnull
-
drawDiamond
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. Iflcisnullthe fill color is used for the outline.- Parameters:
g2- the graphics contextx- x pixel coordinate of the centery- y pixel coordinate of the centers2- half-size in pixels (applies to all four arms)lc- outline colou=r; defaults tofcifnullfc- fill color;nullsuppresses fill
-