net.sourceforge.webcompmath.draw
Class DrawGeometric

java.lang.Object
  extended by java.awt.Component
      extended by net.sourceforge.webcompmath.draw.Drawable
          extended by net.sourceforge.webcompmath.draw.DrawGeometric
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, Computable
Direct Known Subclasses:
Crosshair, TangentLine, WCMDrawGeometricBean

public class DrawGeometric
extends Drawable
implements Computable

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.

Author:
David Eck
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  double a
          Value of x1.
static int ARROW_ABSOLUTE
          Specifies a line segment from (x1,y1) to (x2,y2) with an arrow head at (x2,y2).
static int ARROW_RELATIVE
          Specifies a line segment from (x1,y1) to (x1+x2,y1+y2), or to (x1+h,y1+v) if x2,y2 are null, with an arrow head at the latter point.
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.
static int DASHED_STYLE
          Specifies that the shape should be drawn with dashed line(s).
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 HALF_LINE_ABSOLUTE
          Specifies a ray from (x1,y1) towards (x2,y2).
static int HALF_LINE_RELATIVE
          Specifies a ray through (x1,y1) and towards (x1+x2,y1+y2), or through (x1,y1) and towards (x1+h,y1+v) if x2,y2 are null.
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 lineStyle
          The line style, SOLID_STYLE or DASHED_STYLE
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
static int SOLID_STYLE
          Specifies that the shape should be drawn with solid line(s).
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 net.sourceforge.webcompmath.draw.Drawable
canvas, coords
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
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 getLineStyle()
          Get the line style, SOLID_STYLE or DASHED_STYLE
 int getLineWidth()
          Get the width, in pixels, of lines that are drawn.
 int getShape()
          Get the shape
 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 setLineStyle(int lineStyle)
          Set the line style, SOLID_STYLE or DASHED_STYLE
 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 net.sourceforge.webcompmath.draw.Drawable
getVisible, needsRedraw, setOwnerData, setVisible
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LINE_ABSOLUTE

public static final int LINE_ABSOLUTE
Specifies a line segment from (x1,y1) to (x2,y2).

See Also:
Constant Field Values

INFINITE_LINE_ABSOLUTE

public static final int INFINITE_LINE_ABSOLUTE
Specifies a line that extends through the points (x1,y1) and (x2,y2) and beyond.

See Also:
Constant Field Values

RECT_ABSOLUTE

public static final int RECT_ABSOLUTE
Specifies a rectangle with corners at (x1,y1) and (x2,y2).

See Also:
Constant Field Values

OVAL_ABSOLUTE

public static final int OVAL_ABSOLUTE
Specifies an oval that just fits in the rectangle with corners at (x1,y1) and (x2,y2).

See Also:
Constant Field Values

LINE_RELATIVE

public static final 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. (Note that h,v are given in terms of pixels while x1,x2,y1,y2 are given in terms of the CoordinateRect. If you use h,v, you get a line of a fixed size and direction.)

See Also:
Constant Field Values

INFINITE_LINE_RELATIVE

public static final 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.

See Also:
Constant Field Values

RECT_RELATIVE

public static final 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.

See Also:
Constant Field Values

OVAL_RELATIVE

public static final int OVAL_RELATIVE
Specifies an oval that just fits inside the rect specified by RECT_RELATIVE.

See Also:
Constant Field Values

LINE_CENTERED

public static final int LINE_CENTERED
Specifies a line segment centered on (x1,y1). The amount it extends in each direction is given by x2,y2 or by h,v

See Also:
Constant Field Values

RECT_CENTERED

public static final int RECT_CENTERED
Specifies a Rectangle centered on (x1,y1). The amount it extends in each direction is given by x2,y2 or by h,v. (Thus, x2 or h is the HALF-width and y2 or v is the HALF-height.)

See Also:
Constant Field Values

OVAL_CENTERED

public static final int OVAL_CENTERED
Specifies an oval that just fits inside the rect specified by RECT_CENTERED.

See Also:
Constant Field Values

CROSS

public static final int CROSS
Specifies a cross centered on the point (x1,y1). Its arms extend horizontally by a distance of x2, or h, in each direction. Its vertical arms extend y2, or v, in each direction.

See Also:
Constant Field Values

HALF_LINE_ABSOLUTE

public static final int HALF_LINE_ABSOLUTE
Specifies a ray from (x1,y1) towards (x2,y2).

See Also:
Constant Field Values

HALF_LINE_RELATIVE

public static final int HALF_LINE_RELATIVE
Specifies a ray through (x1,y1) and towards (x1+x2,y1+y2), or through (x1,y1) and towards (x1+h,y1+v) if x2,y2 are null.

See Also:
Constant Field Values

ARROW_ABSOLUTE

public static final int ARROW_ABSOLUTE
Specifies a line segment from (x1,y1) to (x2,y2) with an arrow head at (x2,y2).

See Also:
Constant Field Values

ARROW_RELATIVE

public static final int ARROW_RELATIVE
Specifies a line segment from (x1,y1) to (x1+x2,y1+y2), or to (x1+h,y1+v) if x2,y2 are null, with an arrow head at the latter point. (Note that h,v are given in terms of pixels while x1,x2,y1,y2 are given in terms of the CoordinateRect. If you use h,v, you get a line of a fixed size and direction.)

See Also:
Constant Field Values

shape

protected int shape
One of the constants such as OVAL_CENTERED, specifying the shape to be drawn


x1

protected Value x1
One of the Value objects that determine the shape that is drawn. The shape is specified by two points, (x1,y1) and (x2,y2). x1 must be non-null.


x2

protected Value x2
One of the Value objects that determine the shape that is drawn. The shape is specified by two points, (x1,y1) and (x2,y2). x2 must be non-null for the "ABSOLUTE" shapes. (If not, they revert to "RELATIVE" shapes and use h,v as the offset values.)


y1

protected Value y1
One of the Value objects that determine the shape that is drawn. The shape is specified by two points, (x1,y1) and (x2,y2). y1 must be non-null.


y2

protected Value y2
One of the Value objects that determine the shape that is drawn. The shape is specified by two points, (x1,y1) and (x2,y2). y2 must be non-null for the "ABSOLUTE" shapes. (If not, they revert to "RELATIVE" shapes and use h,v as the offset values.)


h

protected int h
Integer that gives horizontal pixel offset from x1. This is only used if x2 is null.


v

protected int v
Integer that gives vertical pixel offset fromy1. This is only used if y2 is null.


a

protected double a
Value of x1. This is re-computed when the compute() method is called.


b

protected double b
Value of y1. This is re-computed when the compute() method is called.


c

protected double c
Value of x2. This is re-computed when the compute() method is called.


d

protected double d
Value of y2. This is re-computed when the compute() method is called.


color

protected java.awt.Color color
Color of the shappe. Color will be black if this is null. For shapes that have "insides", such as rects, this is the color of the outline.


fillColor

protected java.awt.Color fillColor
Rects and ovals are filled with this color, if it is non-null. If this is null, only the outline of the shape is drawn.


lineWidth

protected int lineWidth
The width, in pixels, of lines, including the outlines of rects and ovals. It is restricted to being an integer in the range from 0 to 10. A value of 0 means that lines won't be drawn at all; this would only be useful for a filled shape that has a colored interior.


SOLID_STYLE

public static final int SOLID_STYLE
Specifies that the shape should be drawn with solid line(s). This is the default.

See Also:
Constant Field Values

DASHED_STYLE

public static final int DASHED_STYLE
Specifies that the shape should be drawn with dashed line(s).

See Also:
Constant Field Values

lineStyle

protected int lineStyle
The line style, SOLID_STYLE or DASHED_STYLE

Constructor Detail

DrawGeometric

public DrawGeometric()
Create a DrawGeometric object. By default, it is a LINE_ABSOLUTE. However, nothing will be drawn as long as x1,y1,x2,y2 are null.


DrawGeometric

public 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.

Parameters:
x1 - x1 parameter
y1 - y1 parameter
x2 - x2 parameter
y2 - y2 parameter
shape - One of the shape constants such as LINE_ABSOLUTE or RECT_RELATIVE.

DrawGeometric

public DrawGeometric(int shape,
                     Value x1,
                     Value y1,
                     int h,
                     int v)
Create a DrawGeometric with a specified shape and values. The last two parameters give pixel offsets from x1,y1. The "ABSOLUTE" shapes don't make sense in this context. (They will be treated as the corresponding "RELATIVE" shapes.)

Parameters:
x1 - x1 parameter
y1 - y1 parameter
h - horizontal pixel offset
v - vertical pixel offset
shape - One of the "RELATIVE" or "CENTERED" shape constants such as LINE_RELATIVE or OVAL_CENTERED or CROSS.
Method Detail

setShape

public void setShape(int shape)
Set the shape, which should be given as one of the shape constants such as LINE_ABSOLUTE or CROSS.

Parameters:
shape - a shape constant

getShape

public int getShape()
Get the shape

Returns:
the shape type

setPoints

public void setPoints(Value x1,
                      Value y1,
                      Value x2,
                      Value y2)
Set the Value objects that specify the two points that determine the shape. The first two parameters, x1 and y1, must be non-null.

Parameters:
x1 - x1 parameter
y1 - y1 parameter
x2 - x2 parameter
y2 - y2 parameter

setPoints

public 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. This only makes sense for RELATIVE shapes. The Value objects x1 and y1 must be non-null

Parameters:
x1 - x1 parameter
y1 - y1 parameter
h - horizontal pixel offset
v - vertical pixel offset

setX1

public void setX1(Value x)
Set the value that gives the x-coordinate of the first point that determines the shape. This must be non-null, or nothing will be drawn.

Parameters:
x - x1 parameter

getX1

public Value getX1()
Get the value that gives the x-coordinate of the first point that determines the shape.

Returns:
x1 parameter

setX2

public void setX2(Value x)
Set the value that gives the x-coordinate of the second point that determines the shape. If this is null, then the value of h is used instead.

Parameters:
x - x2 parameter

getX2

public Value getX2()
Get the value that gives the x-coordinate of the second point that determines the shape.

Returns:
x2 parameter

setY1

public void setY1(Value y)
Set the value that gives the y-coordinate of the first point that determines the shape. This must be non-null, or nothing will be drawn.

Parameters:
y - y1 parameter

getY1

public Value getY1()
Get the value that gives the y-coordinate of the first point that determines the shape.

Returns:
y1 parameter

setY2

public void setY2(Value y)
Set the value that gives the y-coordinate of the second point that determines the shape. If this is null, then the value of v is used instead.

Parameters:
y - y2 parameter

getY2

public Value getY2()
Get the value that gives the y-coordinate of the second point that determines the shape.

Returns:
y2 parameter

setH

public void setH(int x)
Set the integer that gives the horizontal offset from (x1,y1). This only makes sense for RELATIVE shapes. This method also sets x2 to null, since the h value is only used when x2 is null.

Parameters:
x - horizontal offset

getH

public int getH()
Get the horizontal offset from (x1,y1).

Returns:
horizontal offset

setV

public void setV(int y)
Set the integer that gives the vertical offset from (x1,y1). This only makes sense for RELATIVE shapes. This method also sets y2 to null, since the v value is only used when y2 is null.

Parameters:
y - vertical offset

getV

public int getV()
Get the vertical offset from (x1,y1).

Returns:
vertical offset

setColor

public void setColor(java.awt.Color c)
Set the color that is used for drawing the shape. If the color is null, black is used. For shapes that have interiors, such as rects, this is only the color of the outline of the shaape.

Parameters:
c - shape color

getColor

public java.awt.Color getColor()
Get the non-null color that is used for drawing the shape.

Returns:
shape color

setFillColor

public void setFillColor(java.awt.Color c)
Set the color that is used for filling ovals and rects. If the color is null, only the outline of the shape is drawn.

Parameters:
c - fill color

getFillColor

public java.awt.Color getFillColor()
Get the color that is used for filling ovals and rects. If null, no fill is done.

Returns:
fill color

setLineWidth

public void setLineWidth(int width)
Set the width, in pixels, of lines that are drawn. This is also used for outlines of rects and ovals. If set to 0, the thinnest possible line is drawn.

Parameters:
width - line width

getLineWidth

public int getLineWidth()
Get the width, in pixels, of lines that are drawn. This is also used for outlines of rects and ovals.

Returns:
line width

getLineStyle

public int getLineStyle()
Get the line style, SOLID_STYLE or DASHED_STYLE

Returns:
Returns the lineStyle.

setLineStyle

public void setLineStyle(int lineStyle)
Set the line style, SOLID_STYLE or DASHED_STYLE

Parameters:
lineStyle - The lineStyle to set.

compute

public void compute()
Recompute the values that define the size/postion of the DrawGeometric. This is ordinarily only called by a Controller.

Specified by:
compute in interface Computable

draw

public void draw(java.awt.Graphics g,
                 boolean coordsChanged)
Do the drawing. This is not meant to be called directly.

Specified by:
draw in class Drawable
Parameters:
g - graphics context
coordsChanged - true or false