uavsim.graphics
Class GraphicsSupport

java.lang.Object
  extended by uavsim.graphics.GraphicsSupport

public abstract class GraphicsSupport
extends java.lang.Object

Provides general-purpose graphics support functionality globally throughout the system. It is declared abstract to play a singleton role. These methods are mid-level helpers that interpret high-level semantics defined in terms of their system context to low-level Java graphics. In most cases, the unit of measurement is pixels.

Author:
Dan Tappan [19.06.11]

Field Summary
private static AngleMathematical ARC_STEP
          the arc length between points on any rendered arc.
 
Constructor Summary
private GraphicsSupport()
          Prevents subclassing and inadvertent instantiation.
 
Method Summary
static void activateClipMode(java.awt.Graphics2D graphics, Box box)
          Activates the Java2D clipping mode to prevent drawing outside a rectangular region.
static CoordinateCartesianAbsolute[] calculateLineCircleIntercepts(Line line, Circle circle)
          Calculates the two points where a line passing through a circle intercepts the perimeter.
static void deactivateClipMode(java.awt.Graphics2D graphics)
          Deactivates the Java2D clipping mode to prevent drawing outside a rectangular region.
static
<_UNIT_ extends I_Unitable<_UNIT_>>
java.awt.Polygon
drawArc(java.awt.Graphics2D graphics, Radius radius, CoordinateCartesianAbsolute origin, ArcDescriptor<_UNIT_> descriptor, I_AngleMapper<_UNIT_> instrument)
          Draws an arc.
static void drawBox(java.awt.Graphics2D graphics, Box box, boolean isFilled)
          Draws a box anchored at its center, not top left, as in Java graphics.
static void drawBoxOutlined(java.awt.Graphics2D graphics, BoxDescriptor descriptor, boolean... isClipModeEnabled)
          Draws a box anchored at its center, not top left, as in Java graphics.
static void drawCircle(java.awt.Graphics2D graphics, Circle circle, boolean isFilled)
          Draws a circle anchored at its center, not top left, as in Java graphics.
static void drawCircleOutlined(java.awt.Graphics2D graphics, CircleDescriptor descriptor)
          Draws a box anchored at its center, not top left, as in Java graphics.
static void drawLine(java.awt.Graphics2D graphics, CoordinateCartesianAbsolute start, CoordinateCartesianAbsolute end)
          Draws a line.
static void drawLine(java.awt.Graphics2D graphics, CoordinateCartesianAbsolute origin, CoordinatePolarMathematical vector)
          Draws a line.
static void drawLine(java.awt.Graphics2D graphics, Line line)
          Draws a line.
static
<_UNIT_ extends I_Unitable<_UNIT_>>
java.awt.Polygon
drawNeedle(java.awt.Graphics2D graphics, Radius radius, CoordinateCartesianAbsolute origin, NeedleDescriptor descriptor, I_AngleMapper<_UNIT_> instrument, _UNIT_ value)
          Draws a needle.
static
<_UNIT_ extends I_Unitable<_UNIT_>>
void
drawNumbers(java.awt.Graphics2D graphics, Radius radius, CoordinateCartesianAbsolute origin, NumberDescriptor<_UNIT_> descriptor, I_AngleMapper<_UNIT_> instrument, _UNIT_... offset)
          Draws numbers on a ringed instrument.
static java.awt.Polygon drawPolygon(java.awt.Graphics2D graphics, CoordinateCartesianAbsolute origin, double[][] polygon, Size scale, AngleMathematical rotation, boolean isFilled)
          Draws a polygon.
static void drawText(java.awt.Graphics2D graphics, java.lang.String text, Size canvasSize, CoordinateCartesianAbsolute canvasAnchor, CoordinateCartesianRelative anchorScale, TextProperties textProperties)
          Draws text.
static void drawText(java.awt.Graphics2D graphics, TextDescriptor text)
          Draws text.
static
<_UNIT_ extends I_Unitable<_UNIT_>>
void
drawTick(java.awt.Graphics2D graphics, CoordinateCartesianAbsolute anchor, _UNIT_ value, Ring radii, int width, I_AngleMapper<_UNIT_> instrument)
          Draws a single tick.
static void drawTick(java.awt.Graphics2D graphics, CoordinateCartesianAbsolute anchor, AngleMathematical angle, Ring radii, int width)
          Draws a single tick.
static
<_UNIT_ extends I_Unitable<_UNIT_>>
void
drawTicks(java.awt.Graphics2D graphics, Radius radius, CoordinateCartesianAbsolute anchor, TickDescriptor<_UNIT_> tickDescriptor, I_AngleMapper<_UNIT_> instrument, _UNIT_... offset)
          Draws ticks over an interval on a ringed instrument.
static void resetLineWidth(java.awt.Graphics2D graphics)
          Resets the line width in pixels modally to 1.
static void setColor(java.awt.Graphics2D graphics, java.awt.Color color)
          Sets the color of the graphics context modally.
static void setLineWidth(java.awt.Graphics2D graphics, float width)
          Sets the line width in pixels modally.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARC_STEP

private static final AngleMathematical ARC_STEP
the arc length between points on any rendered arc. Higher is smoother but slower

Constructor Detail

GraphicsSupport

private GraphicsSupport()
Prevents subclassing and inadvertent instantiation.

Method Detail

activateClipMode

public static void activateClipMode(java.awt.Graphics2D graphics,
                                    Box box)
Activates the Java2D clipping mode to prevent drawing outside a rectangular region.

Parameters:
graphics - - the graphics context
box - - the rectangle

calculateLineCircleIntercepts

public static CoordinateCartesianAbsolute[] calculateLineCircleIntercepts(Line line,
                                                                          Circle circle)
Calculates the two points where a line passing through a circle intercepts the perimeter. The line must intercept.

Parameters:
line - - the line
circle - - the circle
Returns:
the two intercept points

deactivateClipMode

public static void deactivateClipMode(java.awt.Graphics2D graphics)
Deactivates the Java2D clipping mode to prevent drawing outside a rectangular region.

Parameters:
graphics - - the graphics context

drawArc

public static <_UNIT_ extends I_Unitable<_UNIT_>> java.awt.Polygon drawArc(java.awt.Graphics2D graphics,
                                                                           Radius radius,
                                                                           CoordinateCartesianAbsolute origin,
                                                                           ArcDescriptor<_UNIT_> descriptor,
                                                                           I_AngleMapper<_UNIT_> instrument)
Draws an arc.

Type Parameters:
_UNIT_ - - the unit that the arc is based on
Parameters:
graphics - - the graphics context base
radius - - the radius of the arc, which is scaled by descriptor
origin - - the arc origin
descriptor - - the inner and outer scalers for the radius
instrument - - the instrument defining the arc
Returns:
a polygon representing the arc

drawBox

public static void drawBox(java.awt.Graphics2D graphics,
                           Box box,
                           boolean isFilled)
Draws a box anchored at its center, not top left, as in Java graphics.

Parameters:
graphics - - the graphics context
box - - the rectangle
isFilled - - whether to fill the box

drawBoxOutlined

public static void drawBoxOutlined(java.awt.Graphics2D graphics,
                                   BoxDescriptor descriptor,
                                   boolean... isClipModeEnabled)
Draws a box anchored at its center, not top left, as in Java graphics.

Parameters:
graphics - - the graphics context
descriptor - - the box descriptor
isClipModeEnabled - - whether to optionally activate clip mode

drawCircle

public static void drawCircle(java.awt.Graphics2D graphics,
                              Circle circle,
                              boolean isFilled)
Draws a circle anchored at its center, not top left, as in Java graphics.

Parameters:
graphics - - the graphics context
circle - - the circle
isFilled - - whether to fill the circle

drawCircleOutlined

public static void drawCircleOutlined(java.awt.Graphics2D graphics,
                                      CircleDescriptor descriptor)
Draws a box anchored at its center, not top left, as in Java graphics.

Parameters:
graphics - - the graphics context
descriptor - - the circle descriptor

drawLine

public static void drawLine(java.awt.Graphics2D graphics,
                            CoordinateCartesianAbsolute start,
                            CoordinateCartesianAbsolute end)
Draws a line.

Parameters:
graphics - - the graphics context
start - - the line start
end - - the line end

drawLine

public static void drawLine(java.awt.Graphics2D graphics,
                            CoordinateCartesianAbsolute origin,
                            CoordinatePolarMathematical vector)
Draws a line.

Parameters:
graphics - - the graphics context
origin - - the line start
vector - - the line end

drawLine

public static void drawLine(java.awt.Graphics2D graphics,
                            Line line)
Draws a line.

Parameters:
graphics - - the graphics context
line - - the line

drawNeedle

public static <_UNIT_ extends I_Unitable<_UNIT_>> java.awt.Polygon drawNeedle(java.awt.Graphics2D graphics,
                                                                              Radius radius,
                                                                              CoordinateCartesianAbsolute origin,
                                                                              NeedleDescriptor descriptor,
                                                                              I_AngleMapper<_UNIT_> instrument,
                                                                              _UNIT_ value)
Draws a needle.

Type Parameters:
_UNIT_ - - the unit that the needle is based on
Parameters:
graphics - - the graphics context
radius - - the radius of the needle
origin - - the needle origin
descriptor - - the needle descriptor
instrument - - the instrument defining the arc
value - - the unit value of the needle
Returns:
a polygon representing the needle

drawNumbers

public static <_UNIT_ extends I_Unitable<_UNIT_>> void drawNumbers(java.awt.Graphics2D graphics,
                                                                   Radius radius,
                                                                   CoordinateCartesianAbsolute origin,
                                                                   NumberDescriptor<_UNIT_> descriptor,
                                                                   I_AngleMapper<_UNIT_> instrument,
                                                                   _UNIT_... offset)
Draws numbers on a ringed instrument.

Type Parameters:
_UNIT_ - - the unit that the numbers are based on
Parameters:
graphics - - the graphics context
radius - - the radius of the numbers
origin - - the numbers origin
descriptor - - the number descriptor
instrument - - the instrument defining the arc
offset - - the optional offset for starting the number series

drawPolygon

public static java.awt.Polygon drawPolygon(java.awt.Graphics2D graphics,
                                           CoordinateCartesianAbsolute origin,
                                           double[][] polygon,
                                           Size scale,
                                           AngleMathematical rotation,
                                           boolean isFilled)
Draws a polygon.

Parameters:
graphics - - the graphics context
origin - - the polygon origin
polygon - - the polygon as (x,y) pixel coordinates
scale - - the scale to apply to the polygon vertices
rotation - - the rotation about the origin
isFilled - - whether to fill the polygon
Returns:
a scaled polygon representing the polygon

drawText

public static void drawText(java.awt.Graphics2D graphics,
                            java.lang.String text,
                            Size canvasSize,
                            CoordinateCartesianAbsolute canvasAnchor,
                            CoordinateCartesianRelative anchorScale,
                            TextProperties textProperties)
Draws text.

Parameters:
graphics - - the graphics context
text - - the text
canvasSize - - the square size of the instrument footprint in pixels
canvasAnchor - - the anchor position for the center of the canvas in pixels
anchorScale - - the absolute coordinate offset from canvasAnchor mapped onto canvasSize
textProperties - - the text properties
See Also:
CoordinateCartesianAbsolute.convertToCoordinateAbsolute(CoordinateCartesianRelative,Size)

drawText

public static void drawText(java.awt.Graphics2D graphics,
                            TextDescriptor text)
Draws text.

Parameters:
graphics - - the graphics context
text - - the text descriptor

drawTick

public static <_UNIT_ extends I_Unitable<_UNIT_>> void drawTick(java.awt.Graphics2D graphics,
                                                                CoordinateCartesianAbsolute anchor,
                                                                _UNIT_ value,
                                                                Ring radii,
                                                                int width,
                                                                I_AngleMapper<_UNIT_> instrument)
Draws a single tick.

Type Parameters:
_UNIT_ - - the unit that the tick is based on
Parameters:
graphics - - the graphics context
anchor - - the anchor of the radius in pixels
value - - the equivalent value of the tick that determines where on the interval arc to draw it based on the I_AngleMapper doing the angle mapping
radii - - the inner and outer radii in pixels
width - - the width in pixels
instrument - - the instrument defining the arc

drawTick

public static void drawTick(java.awt.Graphics2D graphics,
                            CoordinateCartesianAbsolute anchor,
                            AngleMathematical angle,
                            Ring radii,
                            int width)
Draws a single tick.

Parameters:
graphics - - the graphics context
anchor - - the anchor of the radius in pixels
angle - - the angle
radii - - the inner and outer radii in pixels
width - - the tick width in pixels

drawTicks

public static <_UNIT_ extends I_Unitable<_UNIT_>> void drawTicks(java.awt.Graphics2D graphics,
                                                                 Radius radius,
                                                                 CoordinateCartesianAbsolute anchor,
                                                                 TickDescriptor<_UNIT_> tickDescriptor,
                                                                 I_AngleMapper<_UNIT_> instrument,
                                                                 _UNIT_... offset)
Draws ticks over an interval on a ringed instrument.

Type Parameters:
_UNIT_ - - the unit that the ticks are based on
Parameters:
graphics - - the graphics context
radius - - the radius defining the size of the instrument, against which the inner and outer radii in TickDescriptor will be scaled
anchor - - the anchor of the radius in pixels
tickDescriptor - - the tick descriptor
instrument - - the instrument defining the arc
offset - - the optional offset for starting the ticks

resetLineWidth

public static void resetLineWidth(java.awt.Graphics2D graphics)
Resets the line width in pixels modally to 1.

Parameters:
graphics - - the graphics context

setColor

public static void setColor(java.awt.Graphics2D graphics,
                            java.awt.Color color)
Sets the color of the graphics context modally.

Parameters:
graphics - - the graphics context
color - - the color

setLineWidth

public static void setLineWidth(java.awt.Graphics2D graphics,
                                float width)
Sets the line width in pixels modally.

Parameters:
graphics - - the graphics context
width - - the width