This class provides similar functionality, Specifically, it is a graphical user interface (GUI) component that provides simple vector graphic services.
It uses the following concepts:
Drafter
class makes use of a Point
class that is not part of the Java API. The Point
class
must be an encapsulation of a vector/point on the plane. It:
Point
to be constructed).getCoordinate(i:int):double
method that
returns the value of coordinate i
.Drafter
class is abstract. To use it you should create
a class that extends Drafter
and implements the
method draw(upperRight:Point)
.
The draw(upperRight:Point)
method should contain
all of the "drawing instructions" the child class needs to perform.
These "instructions" amount to a sequence of calls to the following
methods:
setPaperColor(name:String)
setPenWidth(pixels:int)
setInkColor(name:String)
setLineStyle(name:String)
moveTo(p:Point)
drawTo(p:Point)
drawString(text:String, position:String, angle:double)
The Point
parameter that is passed to the
draw(upperRight:Point)
method contains the coordinates
of the upper right corner of the paper. (The lower left corner of the
paper has coordinate 0,0).
The draw(upperRight:Point)
method of descendants of
Drafter
will be called whenever they need to draw themselves.
Descendents of the Drafter
class must not call the
draw(upperRight:Point)
method themselves.
Drafter
class contains the following methods that
can be used by descendants in the draw(upperRight:Point)
method:
/** * Draw a String at the pen's current Point * (i.e., the result of the last moveTo() or drawTo()). * The String will be drawn at the given angle and will be positioned * relative to the current pen position. The possible positions * (relative to the current pen position) are: * "N" (centered above), "NE" (above and to the right), "E" (to the right), * "SE" (below and to the right), "S" (centered below), "SW" (below and * to the left), "W" (to the left), and "NW" (above and to the left). * * @param text The String * @param position The position relative to the current point (N, S, ...) * @param angle The rotation angle (relative to the first coordinate) */ protected void drawString(String text, String position, double angle)
/** * Draw a straight line segment from the pen's current Point * (i.e., the result of the last moveTo() or drawTo()) * to the given Point using the current ink color, pen width, * line style, etc... * * @param p The end of the line segment */ protected void drawTo(Point p)
/** * Lift the pen off of the paper and move it to * the given Point * * @param p The Point to move to */ protected void moveTo(Point p)
/** * Set the current ink color (using the names specified in * the CSS 3.0 and SVG 1.0 standards; see * http://www.w3.org/TR/2003/CR-css3-color-20030514/ ) * * @param name The name of the color */ protected void setInkColor(String name)
/** * Set the line type * * @param name The type ("solid", "dashed", "dotted", "dashdot") */ protected void setLineType(String name)
/** * Set the paper color (using the names specified in * the CSS 3.0 and SVG 1.0 standards; see * http://www.w3.org/TR/2003/CR-css3-color-20030514/ ) * * @param name The name of the color */ protected void setPaperColor(String name)
/** * Set the line width (in pixels) * * @param pixels The width of the line */ protected void setPenWidth(int pixels)
Copyright 2007