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

CanvasFigure Class Reference

Inheritance diagram for CanvasFigure::

CanvasObject CanvasCorbaBlob2d CanvasCorbaBSplineCurve CanvasCorbaHistogram CanvasCorbaPolyline2d CanvasCorbaSampledBSplineCurve CanvasHxBlob2d CanvasHxBSplineCurve CanvasHxHistogram CanvasHxPolyline2d CanvasHxSampledBSplineCurve List of all members.

Public Methods

Object clone ()
 Implements CanvasObject abstract function. More...

void draw (Graphics g)
 Implements CanvasObject "interface". More...

boolean isHitCcs (int x, int y, Graphics2D g)
 A more specialized version of isHitCcs that uses the Graphics2d.hit and the getShape() member function to determine if this figures is selected with the given position. More...

boolean hasNoColor ()
Color getColor ()
void setColor (Color newColor)
boolean getFilled ()
void setFilled (boolean filled)
boolean getDashed ()
void setDashed (boolean dashed)
boolean hasLineWidth ()
float getLineWidth ()
void setLineWidth (float linew)
float getTransparency ()
void setTransparency (float trans)
Vector getVisualChangeMethods ()
 Builds up a list of functions that are to fill a menu for changing the visualization aspects of an object. More...


Static Public Attributes

final int NO_PIX = 0x00000000
 Indicates that no pixel value is set. More...

final int INV_PIX = 0x00FFFFFF
 Invert pixel via : c.getRGB() ^ INV_COLOR. More...

final Color NO_COLOR = (Color) null
 No color specified. More...

final Color DEF_COLOR = Color.red
 The default color for drawing figures. More...

final float DEF_LINEW = 1.0f
 The default line width for figures. More...

final float DEF_TRANS = 0.0f
 The default transparency for figures. More...


Protected Methods

 CanvasFigure (double x1, double y1, double x2, double y2)
abstract Shape getShape ()
 Derived classes have to implement this method to supply the shape that represents the CanvasFigures. More...

abstract boolean hitOnStroke ()
 Derived classes have to implement this method to indicate whether they are selected (hit) based on their stroke (border) or on their interior. More...

void setupDrawMode (Graphics g)
 Setup drawmode for 'g'. More...


Constructor & Destructor Documentation

CanvasFigure::CanvasFigure double    x1,
double    y1,
double    x2,
double    y2
[inline, protected]
 

00044 {
00045     super(x1, y1, x2, y2);
00046 }


Member Function Documentation

Object CanvasFigure::clone   [inline, virtual]
 

Implements CanvasObject abstract function.

This side of the tree is not clonable, nor need it be?

Reimplemented from CanvasObject.

00053 {
00054     return null;
00055 }

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

Implements CanvasObject "interface".

Reimplemented from CanvasObject.

Reimplemented in CanvasHxBlob2d, and CanvasCorbaBlob2d.

00061 {
00062     setupDrawMode(g);
00063     if (g instanceof Graphics2D) {
00064         Graphics2D g2d = (Graphics2D) g;
00065         if (_filled)
00066             g2d.fill(getShape());
00067         else
00068             g2d.draw(getShape());
00069     } else {
00070         ErrorStreamArea.println("CanvasFigure: draw needs Graphics2d.");
00071     }
00072 }

boolean CanvasFigure::isHitCcs int    x,
int    y,
Graphics2D    g
[inline]
 

A more specialized version of isHitCcs that uses the Graphics2d.hit and the getShape() member function to determine if this figures is selected with the given position.

Uses hitOnStroke to choose between hit on stroke or hit on interior.

Reimplemented from CanvasObject.

00081 {
00082     int spere = CanvasObject.SPHERE;
00083     if (! hitOnStroke())
00084         spere = 1;
00085     Rectangle r = new Rectangle(x - spere, y - spere, 2 * spere, 2 * spere);
00086     return g.hit(r, getShape(), hitOnStroke());
00087 }

boolean CanvasFigure::hasNoColor   [inline]
 

00091 {
00092     return _hasNoColor;
00093 }

Color CanvasFigure::getColor   [inline]
 

00097 {
00098     return _drawColor;
00099 }

void CanvasFigure::setColor Color    color [inline]
 

Reimplemented in CanvasHxBlob2d, and CanvasCorbaBlob2d.

00103 {
00104     if (newColor == NO_COLOR) {
00105         _drawColor  = DEF_COLOR;
00106         _hasNoColor = true;
00107     } else {
00108         _drawColor  = newColor;
00109         _hasNoColor = false;
00110     }
00111 }

boolean CanvasFigure::getFilled   [inline]
 

00115 {
00116     return _filled;
00117 }

void CanvasFigure::setFilled boolean    filled [inline]
 

00121 {
00122     _filled = filled;
00123 }

boolean CanvasFigure::getDashed   [inline]
 

00127 {
00128     return _dashed;
00129 }

void CanvasFigure::setDashed boolean    dashed [inline]
 

00133 {
00134     if (_hasLineWidth) // no dash without a linewidth
00135         _dashed = dashed;
00136 }

boolean CanvasFigure::hasLineWidth   [inline]
 

00140 {
00141     return _hasLineWidth;
00142 }

float CanvasFigure::getLineWidth   [inline]
 

00146 {
00147     return _lineWidth;
00148 }

void CanvasFigure::setLineWidth float    linew [inline]
 

00152 {
00153     if (_hasLineWidth) {
00154         if (linew < DEF_LINEW) {
00155             linew = DEF_LINEW;
00156         }
00157         _lineWidth = linew;
00158     }
00159 }

float CanvasFigure::getTransparency   [inline]
 

00163 {
00164     return _transparency;
00165 }

void CanvasFigure::setTransparency float    trans [inline]
 

Reimplemented in CanvasHxBlob2d, and CanvasCorbaBlob2d.

00169 {
00170     if (trans < 0.0f) {
00171         trans = 0.0f;
00172     } else if (trans > 1.0f) {
00173         trans = 1.0f;
00174     }
00175     _transparency = trans;
00176 }

Vector CanvasFigure::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 CanvasObject.

Reimplemented in CanvasHxBlob2d, CanvasHxBSplineCurve, CanvasHxSampledBSplineCurve, CanvasCorbaBlob2d, CanvasCorbaBSplineCurve, and CanvasCorbaSampledBSplineCurve.

00183 {
00184     Vector v = super.getVisualChangeMethods();
00185     v.add(new CallableMethod("setColor", "Color", "c", "Color"));
00186     v.add(new CallableMethod("setFilled", "boolean", "b", "boolean"));
00187     v.add(new CallableMethod("setDashed", "boolean", "b", "boolean"));
00188     v.add(new CallableMethod("setLineWidth", "float", "w", "float"));
00189     v.add(new CallableMethod("setTransparency", "float", "t", "float"));
00190     return v;
00191 }

abstract Shape CanvasFigure::getShape   [protected, pure virtual]
 

Derived classes have to implement this method to supply the shape that represents the CanvasFigures.

It is used to draw to figure as well as determine which figure is selected (hit) by the cursor within a canvas.

Reimplemented in CanvasHxBlob2d, CanvasHxBSplineCurve, CanvasHxHistogram, CanvasHxPolyline2d, CanvasHxSampledBSplineCurve, CanvasCorbaBlob2d, CanvasCorbaBSplineCurve, CanvasCorbaHistogram, CanvasCorbaPolyline2d, and CanvasCorbaSampledBSplineCurve.

abstract boolean CanvasFigure::hitOnStroke   [protected, pure virtual]
 

Derived classes have to implement this method to indicate whether they are selected (hit) based on their stroke (border) or on their interior.

Reimplemented in CanvasHxBlob2d, CanvasHxBSplineCurve, CanvasHxHistogram, CanvasHxPolyline2d, CanvasHxSampledBSplineCurve, CanvasCorbaBlob2d, CanvasCorbaBSplineCurve, CanvasCorbaHistogram, CanvasCorbaPolyline2d, and CanvasCorbaSampledBSplineCurve.

void CanvasFigure::setupDrawMode Graphics    g [inline, protected]
 

Setup drawmode for 'g'.

Reimplemented from CanvasObject.

00217 {
00218     if (g instanceof Graphics2D) {
00219 
00220         Graphics2D g2d = (Graphics2D) g;
00221         switch (getDrawMode()) {
00222             case COPY_MODE :
00223                     g2d.setPaintMode();
00224                     g2d.setComposite(AlphaComposite.getInstance(
00225                            AlphaComposite.SRC_OVER, 1.0f - _transparency));
00226                     if (_drawColor != null) {
00227                         g2d.setColor(_drawColor);
00228                     }
00229                     break;
00230 
00231             case XOR_MODE  :
00232                     g2d.setXORMode(XOR_COLOR);
00233                     g2d.setColor(DEF_COLOR);
00234                     g2d.setComposite(AlphaComposite.getInstance(
00235                                      AlphaComposite.SRC_OVER, 1.0f));
00236                     g2d.setStroke(new BasicStroke());
00237                     return;
00238         }
00239 
00240         float lwidth;
00241 
00242         if (_hasLineWidth) {
00243             lwidth = _lineWidth;
00244         } else {
00245             lwidth = DEF_LINEW;
00246         }
00247 
00248         float[] dash = { 6.f };
00249         if (!(_dashed && _hasLineWidth)) {
00250             dash = null;
00251         }
00252         g2d.setStroke(new BasicStroke(lwidth,
00253                                       BasicStroke.CAP_BUTT,
00254                                       BasicStroke.JOIN_MITER,
00255                                       10.f, dash, 0.f));
00256     } else { // We have a "normal" graphics
00257         super.setupDrawMode(g);
00258         if (getDrawMode() == XOR_MODE) {
00259             g.setColor(DEF_COLOR);
00260         } else {
00261             g.setColor(_drawColor);
00262         }
00263     }
00264 }


Member Data Documentation

final int CanvasFigure::NO_PIX = 0x00000000 [static]
 

Indicates that no pixel value is set.

final int CanvasFigure::INV_PIX = 0x00FFFFFF [static]
 

Invert pixel via : c.getRGB() ^ INV_COLOR.

final Color CanvasFigure::NO_COLOR = (Color) null [static]
 

No color specified.

final Color CanvasFigure::DEF_COLOR = Color.red [static]
 

The default color for drawing figures.

final float CanvasFigure::DEF_LINEW = 1.0f [static]
 

The default line width for figures.

final float CanvasFigure::DEF_TRANS = 0.0f [static]
 

The default transparency for figures.


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