Horus Doc || Java GUI Reference || Doxygen's quick Index  

CanvasArrow Class Reference

Inheritance diagram for CanvasArrow::

ScribbleFigure ScribbleObject CanvasObject List of all members.

Public Methods

 CanvasArrow (double x, double y, double length, int angle)
 CanvasArrow (double x, double y, double length, int angle, Color color)
 CanvasArrow (double x, double y, double length, int angle, Color color, boolean fixed)
 CanvasArrow (double x, double y, double length, int angle, int mode, Color color, boolean stroke, float linew, float trans, boolean fixed, double ccs_scale)
void draw (Graphics g)
 Draw CanvasObject on 'g', using internal CCS values. More...

Object clone ()
 Return an identical copy of this CanvasObject. More...

boolean isInside (double x, double y)
boolean isNear (double x, double y)
void setPosition (double x, double y)
 Place top left position of CanvasObject's bounding box at position (x, y). More...

void setDimension (double w, double h)
 Resize CanvasObject to width 'w' and height 'h'. More...

void setZoomFactor (double zoomFactor)
 Scale CanvasObject according to 'zoomFactor'. More...

double getLength ()
void setLength (double length)
int getAngle ()
void setAngle (int angle)
boolean getFixed ()
void setFixed (boolean b)
boolean getHeaded ()
void setHeaded (boolean b)
Vector getVisualChangeMethods ()
 Builds up a list of functions that are to fill a menu for changing the visualization aspects of an object. More...

 CanvasArrow (int x, int y, int length, int angle, int mode, Color color, boolean fixed, double ccs_scale)
boolean isInsideCcs (int x, int y)
 To be removed. More...

boolean isNearCcs (int x, int y)
 To be removed. More...

void setPosition (int x, int y)
void setDimension (int w, int h)
void doMove (int w, int h)
int changePoint (int index, int x, int y)
Point getOrigin ()
Point getHead ()

Protected Methods

void initArrow (double x, double y, double length, int angle, boolean fixed)
void setICS ()
void transformICStoCCS ()
 Perform a full ICS to CCS coordinate transformation. More...

void calcHead ()
void calcAngle (double w, double h)

Protected Attributes

double ics_length
int ccs_length
int headX
int headY
int angle
int beta
int gamma
int bx
int by
int gx
int gy
double cosa
double sina
double cosb
double sinb
double cosg
double sing
boolean fixed = false
boolean headed = true
boolean scaled = false

Static Protected Attributes

final int HEAD_LENGTH = 6
final int HEAD_ANGLE = 20

Constructor & Destructor Documentation

CanvasArrow::CanvasArrow double    x,
double    y,
double    length,
int    angle
[inline]
 

00035     {
00036         this(x, y, length, angle, COPY_MODE,
00037              NO_COLOR, false, DEF_LINEW, DEF_TRANS, false, DEF_SCALE);
00038     }

CanvasArrow::CanvasArrow double    x,
double    y,
double    length,
int    angle,
Color    color
[inline]
 

00043     {
00044         this(x, y, length, angle, COPY_MODE,
00045              color, false, DEF_LINEW, DEF_TRANS, false, DEF_SCALE);
00046     }

CanvasArrow::CanvasArrow double    x,
double    y,
double    length,
int    angle,
Color    color,
boolean    fixed
[inline]
 

00051     {
00052         this(x, y, length, angle, COPY_MODE,
00053              color, false, DEF_LINEW, DEF_TRANS, fixed, DEF_SCALE);
00054     }

CanvasArrow::CanvasArrow double    x,
double    y,
double    length,
int    angle,
int    mode,
Color    color,
boolean    stroke,
float    linew,
float    trans,
boolean    fixed,
double    ccs_scale
[inline]
 

00061     {
00062         super(x, y, 0., 0.,
00063               mode, color, stroke, linew, trans, ccs_scale);
00064         initArrow(x, y, length, angle, fixed);
00065     }

CanvasArrow::CanvasArrow int    x,
int    y,
int    length,
int    angle,
int    mode,
Color    color,
boolean    fixed,
double    ccs_scale
[inline]
 

00247     {
00248         super(x, y, 0, 0, mode, color, ccs_scale);
00249 
00250         int[]    ccs_vals = { x, y, length };
00251         double[] ics_vals = Converter.CCStoICS(ccs_vals, ccs_scale);
00252 
00253         initArrow(ics_vals[0], ics_vals[1],
00254                   ics_vals[2] + 0.5, angle, fixed);
00255     }


Member Function Documentation

void CanvasArrow::draw Graphics    g [inline, virtual]
 

Draw CanvasObject on 'g', using internal CCS values.

Reimplemented from CanvasObject.

00072     {
00073         setupDrawMode(g);
00074         if (!getTransformOK()) {
00075             transformICStoCCS();
00076         }
00077         g.drawLine(getStartXCcs(), getStartYCcs(), headX, headY);
00078         if (headed) {
00079             g.drawLine(headX, headY, bx, by);
00080             g.drawLine(headX, headY, gx, gy);
00081         }
00082     }

Object CanvasArrow::clone   [inline, virtual]
 

Return an identical copy of this CanvasObject.

Reimplemented from CanvasObject.

00086     {
00087         Color color = drawColor;
00088         if (hasNoColor) {
00089             color = NO_COLOR;
00090         }
00091         CanvasArrow ca = new CanvasArrow(getStartX(), getStartY(),
00092                                          ics_length, angle, getDrawMode(),
00093                                          color, strokeSet, lineWidth,
00094                                          transparency, fixed, getZoomFactor());
00095         ca.setHeaded(headed);
00096         return ca;
00097     }

boolean CanvasArrow::isInside double    x,
double    y
[inline]
 

00101     {
00102         return false;
00103     }

boolean CanvasArrow::isNear double    x,
double    y
[inline]
 

00107     {
00108         // taken from 'Graphics Gems II' - James Arvo,
00109         // chap. 1.3, 'Distance from a point to a line', pages 10-13.
00110 
00111 
00112         // check if inside enlarged bounding box (== box + SPHERE)
00113 
00114         if ((x >= getX1() - SPHERE) && (x < getX1() + getWidth() + SPHERE) &&
00115             (y >= getY1() - SPHERE) && (y < getY1() + getHeight() + SPHERE)) {
00116 
00117 
00118             // calculate the area of the triangle formed by the two
00119             // CanvasArrow points and the 'check' point
00120 
00121             double area = (y - getStartY())*(headX - getStartX()) -
00122                           (x - getStartX())*(headY - getStartY());
00123 
00124 
00125             // calculate approximation of distance perpendicular to
00126             // CanvasArrow
00127 
00128             double abs1 = Math.abs(headX - getStartX());
00129             double abs2 = Math.abs(headY - getStartY());
00130 
00131             int distance = (int)(Math.abs(area) /
00132                            (abs1 + abs2 - 0.5 * Math.min(abs1, abs2)));
00133 
00134 
00135             // this approximation can also be used as an approximation
00136             // for the 'true' distance
00137 
00138             if (distance <= SPHERE) {
00139                 return true;
00140             }
00141         }
00142         return false;
00143     }

void CanvasArrow::setPosition double    x,
double    y
[inline]
 

Place top left position of CanvasObject's bounding box at position (x, y).

Parameters are assumed Image Coordinate System values.

Reimplemented from ScribbleObject.

00147     {
00148         doMove(x-getStartX(), y-getStartY());
00149     }

void CanvasArrow::setDimension double    w,
double    h
[inline]
 

Resize CanvasObject to width 'w' and height 'h'.

Parameters are assumed Image Coordinate System values.

Reimplemented from ScribbleObject.

00153     {
00154         super.setDimension(w, h);
00155 
00156         ics_length = (double)(Math.sqrt(w*w + h*h));
00157         calcAngle(w, h);
00158         setICS();
00159     }

void CanvasArrow::setZoomFactor double    zoomFactor [inline]
 

Scale CanvasObject according to 'zoomFactor'.

The internal ICS values are taken as base values to calculate the associated CCS values.

Reimplemented from CanvasObject.

00163     {
00164         super.setZoomFactor(zoomFactor);
00165         scaled = true;
00166     }

double CanvasArrow::getLength   [inline]
 

00170     {
00171         return ics_length;
00172     }

void CanvasArrow::setLength double    length [inline]
 

00176     {
00177         ics_length = length;
00178         setICS();
00179     }

int CanvasArrow::getAngle   [inline]
 

00183     {
00184         return angle;
00185     }

void CanvasArrow::setAngle int    angle [inline]
 

00189     {
00190         this.angle = angle;
00191         setICS();
00192     }

boolean CanvasArrow::getFixed   [inline]
 

00196     {
00197         return fixed;
00198     }

void CanvasArrow::setFixed boolean    b [inline]
 

00202     {
00203         fixed = b;
00204     }

boolean CanvasArrow::getHeaded   [inline]
 

00208     {
00209         return headed;
00210     }

void CanvasArrow::setHeaded boolean    b [inline]
 

00214     {
00215         headed = b;
00216     }

Vector CanvasArrow::getVisualChangeMethods   [inline]
 

Builds up a list of functions that are to fill a menu for changing the visualization aspects of an object.

Classes derived from this one typically add their class-specific methods to their parents' methods by first calling the parent to fill the vector and then add their own. The result is a Vector of CallableMethods.

Reimplemented from ScribbleFigure.

00223     {
00224         Vector v = super.getVisualChangeMethods();
00225         v.add(new CallableMethod("setFixed", "boolean", "b", "boolean"));
00226         v.add(new CallableMethod("setHeaded", "boolean", "b", "boolean"));
00227         return v;
00228     }

boolean CanvasArrow::isInsideCcs int    x,
int    y
[inline]
 

To be removed.

Reimplemented from CanvasObject.

00259     {
00260         return false;
00261     }

boolean CanvasArrow::isNearCcs int    x,
int    y
[inline]
 

To be removed.

Reimplemented from CanvasObject.

00265     {
00266         if (!getTransformOK()) {
00267             transformICStoCCS();
00268         }
00269 
00270         // taken from 'Graphics Gems II' - James Arvo,
00271         // chap. 1.3, 'Distance from a point to a line', pages 10-13.
00272 
00273 
00274         // check if inside enlarged bounding box (== box + SPHERE)
00275 
00276         if ((x >= getX1Ccs() - SPHERE) && (x < getX1Ccs() + getWidthCcs() + SPHERE) &&
00277             (y >= getY1Ccs() - SPHERE) && (y < getY1Ccs() + getHeightCcs() + SPHERE)) {
00278 
00279 
00280             // calculate the area of the triangle formed by the two
00281             // CanvasArrow points and the 'check' point
00282 
00283             int area = (y - getStartYCcs())*(headX - getStartXCcs()) -
00284                        (x - getStartXCcs())*(headY - getStartYCcs());
00285 
00286 
00287             // calculate approximation of distance perpendicular to
00288             // CanvasArrow
00289 
00290             int abs1 = Math.abs(headX - getStartXCcs());
00291             int abs2 = Math.abs(headY - getStartYCcs());
00292 
00293             int distance = (int)(Math.abs(area) /
00294                            (abs1 + abs2 - 0.5 * Math.min(abs1, abs2)));
00295 
00296 
00297             // this approximation can also be used as an approximation
00298             // for the 'true' distance
00299 
00300             if (distance <= SPHERE) {
00301                 return true;
00302             }
00303         }
00304         return false;
00305     }

void CanvasArrow::setPosition int    x,
int    y
[inline]
 

Reimplemented from ScribbleObject.

00309     {
00310         doMove(x-getStartXCcs(), y-getStartYCcs());
00311     }

void CanvasArrow::setDimension int    w,
int    h
[inline]
 

Reimplemented from ScribbleObject.

00315     {
00316         super.setDimension(w, h);
00317         if (w < 0) {
00318             setWidth(-getWidth());
00319         }
00320         if (h < 0) {
00321             setHeight(-getHeight());
00322         }
00323         this.setDimension(getWidth(), getHeight());
00324     }

void CanvasArrow::doMove int    w,
int    h
[inline]
 

Reimplemented from ScribbleObject.

00328     {
00329         super.doMove(w, h);
00330         headX += w;
00331         headY += h;
00332         bx    += w;
00333         by    += h;
00334         gx    += w;
00335         gy    += h;
00336     }

int CanvasArrow::changePoint int    index,
int    x,
int    y
[inline]
 

Reimplemented from ScribbleFigure.

00340     {
00341         if (!getTransformOK()) {
00342             transformICStoCCS();
00343         }
00344 
00345         int w = x - getStartXCcs();
00346         int h = y - getStartYCcs();
00347         setDimension(w, h);
00348         return index;
00349     }

Point CanvasArrow::getOrigin   [inline]
 

00353     {
00354         if (!getTransformOK()) {
00355             transformICStoCCS();
00356         }
00357 
00358         return new Point(getStartXCcs(), getStartYCcs());
00359     }

Point CanvasArrow::getHead   [inline]
 

00363     {
00364         if (!getTransformOK()) {
00365             transformICStoCCS();
00366         }
00367 
00368         return new Point(headX, headY);
00369     }

void CanvasArrow::initArrow double    x,
double    y,
double    length,
int    angle,
boolean    fixed
[inline, protected]
 

00384     {
00385         this.fixed      = fixed;
00386         this.angle      = angle;
00387         this.ics_length = length;
00388 
00389         setICS();
00390         transformICStoCCS();
00391     }

void CanvasArrow::setICS   [inline, protected]
 

00395     {
00396         cosa = Math.cos((angle * Math.PI) / 180);
00397         sina = Math.sin((angle * Math.PI) / 180);
00398 /*
00399         setWidth(ics_length * cosa);
00400         setHeight(-(ics_length * sina));
00401 
00402         if (getWidth() < 0.) {
00403             setWidth(-getWidth());
00404             setX1(getStartX() - getWidth());
00405         }
00406         if (getHeight() < 0.) {
00407             setHeight(-getHeight());
00408             setY1(getStartY() - getHeight());
00409         }
00410 */
00411         double w = ics_length * cosa;
00412         double h = -(ics_length * sina);
00413 
00414         if (w < 0.0) {
00415             setX1(getStartX() + w);
00416             setX2(getStartX());
00417         } else {
00418             setX2(getStartX() + w);
00419         }
00420         if (h < 0.0) {
00421             setY1(getStartY() + h);
00422             setY2(getStartY());
00423         } else {
00424             setY2(getStartY() + h);
00425         }
00426         setTransformOK(false);
00427     }

void CanvasArrow::transformICStoCCS   [inline, protected]
 

Perform a full ICS to CCS coordinate transformation.

Reimplemented from CanvasObject.

00431     {
00432         super.transformICStoCCS();
00433 
00434         if (!fixed || !scaled) {
00435             double[] ics_vals = { ics_length - 0.5 };
00436             int[]    ccs_vals = Converter.ICStoCCS(ics_vals, getZoomFactor());
00437             ccs_length = ccs_vals[0];
00438         }
00439         calcHead();
00440         setTransformOK(true);
00441         scaled = false;
00442     }

void CanvasArrow::calcHead   [inline, protected]
 

00446     {
00447         beta  = 90 - angle - HEAD_ANGLE;
00448         gamma = angle - HEAD_ANGLE;
00449 
00450         cosb  = Math.cos((beta  * Math.PI) / 180);
00451         sinb  = Math.sin((beta  * Math.PI) / 180);
00452         cosg  = Math.cos((gamma * Math.PI) / 180);
00453         sing  = Math.sin((gamma * Math.PI) / 180);
00454 
00455         headX = getStartXCcs() + (int)(ccs_length * cosa);
00456         headY = getStartYCcs() - (int)(ccs_length * sina);
00457 
00458         int headl = Math.min(ccs_length/2 + 1, HEAD_LENGTH);
00459 
00460         bx = headX - (int)(headl * sinb);
00461         by = headY + (int)(headl * cosb);
00462         gx = headX - (int)(headl * cosg);
00463         gy = headY + (int)(headl * sing);
00464     }

void CanvasArrow::calcAngle double    w,
double    h
[inline, protected]
 

00468     {
00469         if (Math.abs(w) > Math.abs(h)) {
00470             angle = (int)(Math.asin(-h/ics_length) * 180.0 / Math.PI);
00471             if (w < 0.) {
00472                 angle = 180 - angle;
00473             } else if (h > 0.) {
00474                 angle = 360 + angle;
00475             }
00476         } else {
00477             angle = (int)(Math.acos(w/ics_length) * 180.0 / Math.PI);
00478             if (h > 0.) {
00479                 angle = 360 - angle;
00480             }
00481         }
00482     }


Member Data Documentation

final int CanvasArrow::HEAD_LENGTH = 6 [static, protected]
 

final int CanvasArrow::HEAD_ANGLE = 20 [static, protected]
 

double CanvasArrow::ics_length [protected]
 

int CanvasArrow::ccs_length [protected]
 

int CanvasArrow::headX [protected]
 

int CanvasArrow::headY [protected]
 

int CanvasArrow::angle [protected]
 

int CanvasArrow::beta [protected]
 

int CanvasArrow::gamma [protected]
 

int CanvasArrow::bx [protected]
 

int CanvasArrow::by [protected]
 

int CanvasArrow::gx [protected]
 

int CanvasArrow::gy [protected]
 

double CanvasArrow::cosa [protected]
 

double CanvasArrow::sina [protected]
 

double CanvasArrow::cosb [protected]
 

double CanvasArrow::sinb [protected]
 

double CanvasArrow::cosg [protected]
 

double CanvasArrow::sing [protected]
 

boolean CanvasArrow::fixed = false [protected]
 

boolean CanvasArrow::headed = true [protected]
 

boolean CanvasArrow::scaled = false [protected]
 


The documentation for this class was generated from the following file:
Generated on Tue Feb 3 14:19:37 2004 for JavaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001