|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.hws.jcm.draw.Drawable | +--edu.hws.jcm.draw.DrawGeometric
A DrawGeometric object is a geometic figure such as a line or rectangle that can be drawn in a CoordinateRect. The data for the object always consists of four numbers, which are interpreted differenetly depending on the object. These numbers can be specified as Value objects. A DrawGeometric is a Computable, and the Values will be re-computed when its compute() method is called. It should be added to a Controller that can respond to any changes in the data that define the Values. If one of the Value objects has an undefined value, nothing will be drawn.
The type of object is given as one of the constants defined in this class: LINE_ABSOLUTE, OVAL_RELATIVE, CROSS, and so on. In the descriptions of these constants, x1, x2, y1, and y2 refer to the values of Value objects that provide data for the DrawGeomentric while h and v refer to int's that can be specified in place of x2 and y2 for certain types of figures. For those figures, h or v is used if x2 or y2, respectively, is null.
Field Summary | |
protected double |
a
Value of x1. |
protected double |
b
Value of y1. |
protected double |
c
Value of x2. |
protected java.awt.Color |
color
Color of the shappe. |
static int |
CROSS
Specifies a cross centered on the point (x1,y1). |
protected double |
d
Value of y2. |
protected java.awt.Color |
fillColor
Rects and ovals are filled with this color, if it is non-null. |
protected int |
h
Integer that gives horizontal pixel offset from x1. |
static int |
INFINITE_LINE_ABSOLUTE
Specifies a line that extends through the points (x1,y1) and (x2,y2) and beyond. |
static int |
INFINITE_LINE_RELATIVE
Specifies an infinite line through (x1,y1) and (x1+x2,y1+y2), or through (x1,y1) and (x1+h,y1+v) if x2,y2 are null. |
static int |
LINE_ABSOLUTE
Specifies a line segment from (x1,y1) to (x2,y2). |
static int |
LINE_CENTERED
Specifies a line segment centered on (x1,y1). |
static int |
LINE_RELATIVE
Specifies a line segment from (x1,y1) to (x1+x2,y1+y2), or to (x1+h,y1+v) if x2,y2 are null. |
protected int |
lineWidth
The width, in pixels, of lines, including the outlines of rects and ovals. |
static int |
OVAL_ABSOLUTE
Specifies an oval that just fits in the rectangle with corners at (x1,y1) and (x2,y2). |
static int |
OVAL_CENTERED
Specifies an oval that just fits inside the rect specified by RECT_CENTERED. |
static int |
OVAL_RELATIVE
Specifies an oval that just fits inside the rect specified by RECT_RELATIVE. |
static int |
RECT_ABSOLUTE
Specifies a rectangle with corners at (x1,y1) and (x2,y2). |
static int |
RECT_CENTERED
Specifies a Rectangle centered on (x1,y1). |
static int |
RECT_RELATIVE
Specifies a rectangle with one corner at (x1,y1), and with width given by x2, or h if if x2 is null, and with height given by y2, or by v if y2 is null. |
protected int |
shape
One of the constants such as OVAL_CENTERED, specifying the shape to be drawn |
protected int |
v
Integer that gives vertical pixel offset fromy1. |
protected Value |
x1
One of the Value objects that determine the shape that is drawn. |
protected Value |
x2
One of the Value objects that determine the shape that is drawn. |
protected Value |
y1
One of the Value objects that determine the shape that is drawn. |
protected Value |
y2
One of the Value objects that determine the shape that is drawn. |
Fields inherited from class edu.hws.jcm.draw.Drawable |
canvas, coords |
Constructor Summary | |
DrawGeometric()
Create a DrawGeometric object. |
|
DrawGeometric(int shape,
Value x1,
Value y1,
int h,
int v)
Create a DrawGeometric with a specified shape and values. |
|
DrawGeometric(int shape,
Value x1,
Value y1,
Value x2,
Value y2)
Create a DrawGeometric with the specified shape and values for x1,x2,y1,y2 Any of the shapes makes sense in this context. |
Method Summary | |
void |
compute()
Recompute the values that define the size/postion of the DrawGeometric. |
void |
draw(java.awt.Graphics g,
boolean coordsChanged)
Do the drawing. |
java.awt.Color |
getColor()
Get the non-null color that is used for drawing the shape. |
java.awt.Color |
getFillColor()
Get the color that is used for filling ovals and rects. |
int |
getH()
Get the horizontal offset from (x1,y1). |
int |
getLineWidth()
Get the width, in pixels, of lines that are drawn. |
int |
getV()
Get the vertical offset from (x1,y1). |
Value |
getX1()
Get the value that gives the x-coordinate of the first point that determines the shape. |
Value |
getX2()
Get the value that gives the x-coordinate of the second point that determines the shape. |
Value |
getY1()
Get the value that gives the y-coordinate of the first point that determines the shape. |
Value |
getY2()
Get the value that gives the y-coordinate of the second point that determines the shape. |
void |
setColor(java.awt.Color c)
Set the color that is used for drawing the shape. |
void |
setFillColor(java.awt.Color c)
Set the color that is used for filling ovals and rects. |
void |
setH(int x)
Set the integer that gives the horizontal offset from (x1,y1). |
void |
setLineWidth(int width)
Set the width, in pixels, of lines that are drawn. |
void |
setPoints(Value x1,
Value y1,
int h,
int v)
Set the values that specify a point (x1,y1) and an offset (h,v) from that point. |
void |
setPoints(Value x1,
Value y1,
Value x2,
Value y2)
Set the Value objects that specify the two points that determine the shape. |
void |
setShape(int shape)
Set the shape, which should be given as one of the shape constants such as LINE_ABSOLUTE or CROSS. |
void |
setV(int y)
Set the integer that gives the vertical offset from (x1,y1). |
void |
setX1(Value x)
Set the value that gives the x-coordinate of the first point that determines the shape. |
void |
setX2(Value x)
Set the value that gives the x-coordinate of the second point that determines the shape. |
void |
setY1(Value y)
Set the value that gives the y-coordinate of the first point that determines the shape. |
void |
setY2(Value y)
Set the value that gives the y-coordinate of the second point that determines the shape. |
Methods inherited from class edu.hws.jcm.draw.Drawable |
getVisible, needsRedraw, setOwnerData, setVisible |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int LINE_ABSOLUTE
public static final int INFINITE_LINE_ABSOLUTE
public static final int RECT_ABSOLUTE
public static final int OVAL_ABSOLUTE
public static final int LINE_RELATIVE
public static final int INFINITE_LINE_RELATIVE
public static final int RECT_RELATIVE
public static final int OVAL_RELATIVE
public static final int LINE_CENTERED
public static final int RECT_CENTERED
public static final int OVAL_CENTERED
public static final int CROSS
protected int shape
protected Value x1
protected Value x2
protected Value y1
protected Value y2
protected int h
protected int v
protected double a
protected double b
protected double c
protected double d
protected java.awt.Color color
protected java.awt.Color fillColor
protected int lineWidth
Constructor Detail |
public DrawGeometric()
public DrawGeometric(int shape, Value x1, Value y1, Value x2, Value y2)
shape
- One of the shape constants such as LINE_ABSOLUTE or RECT_RELATIVE.public DrawGeometric(int shape, Value x1, Value y1, int h, int v)
shape
- One of the "RELATIVE" or "CENTERED" shape constants such as LINE_RELATIVE or OVAL_CENTERED or CROSS.Method Detail |
public void setShape(int shape)
public void setPoints(Value x1, Value y1, Value x2, Value y2)
public void setPoints(Value x1, Value y1, int h, int v)
public void setX1(Value x)
public Value getX1()
public void setX2(Value x)
public Value getX2()
public void setY1(Value y)
public Value getY1()
public void setY2(Value y)
public Value getY2()
public void setH(int x)
public int getH()
public void setV(int y)
public int getV()
public void setColor(java.awt.Color c)
public java.awt.Color getColor()
public void setFillColor(java.awt.Color c)
public java.awt.Color getFillColor()
public void setLineWidth(int width)
public int getLineWidth()
public void compute()
compute
in interface Computable
public void draw(java.awt.Graphics g, boolean coordsChanged)
draw
in class Drawable
edu.hws.jcm.draw.Drawable
g
- The graphics context in which the Drawble is to be drawn. (The drawing
can change the color in g, but should not permanently change font, painting mode, etc.
Thus, every drawable is responsible for setting the color it wants to use.)coordsChanged
- Indicates whether the CoordinateRect has changed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |