Back to index

wims  3.65+svn20090927
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
fr.ove.openmath.jome.ctrlview.bidim.Line Class Reference

A line. More...

Inheritance diagram for fr.ove.openmath.jome.ctrlview.bidim.Line:
Inheritance graph
[legend]
Collaboration diagram for fr.ove.openmath.jome.ctrlview.bidim.Line:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Line ()
 The constructor.
 Line (Point p1, Point p2, int thickness, byte alignment)
 The constructor.
void setP1 (Point p1)
 Sets a new starting point.
Point getP1 ()
 Returns the starting point of the line.
void setP2 (Point p2)
 Sets a new ending point.
Point getP2 ()
 Returns the ending point of the line.
void setAlignment (byte alignment)
 Sets a new alingment.
int getAlignment ()
 Returns the alignement of the line.
void setThickness (int thickness)
 Sets the thickness of the line.
int getThickness ()
 Returns the thickness of the line.
void draw (Graphics g)
 Draws the line.
Polygon getLine ()
 Returns the Polygon which represents the line.

Static Public Attributes

static final byte LEFT = 0
 The different alignements of the line.
static final byte CENTER = 1
 The thickness of the line is distributed in equitably on both sides of the line.
static final byte RIGHT = 2
 The thickness of the line is distributed to the right of the line.

Private Member Functions

void computeLine ()

Private Attributes

Point p1
 The starting point of the line.
Point p2
 The ending point of the line.
int thickness
 The thickness of the line.
byte alignment
 The alignment of the drawing of the line.
Polygon line

Detailed Description

A line.

Author:
1999 DIRAT Laurent
Version:
2.0 22/07/1999

Definition at line 40 of file Line.java.


Constructor & Destructor Documentation

The constructor.


Constructs the line [(0,0),(0,0)], with a thickness of 1.

Definition at line 73 of file Line.java.

                  {
        this(new Point(), new Point(), 1, CENTER);
    }
fr.ove.openmath.jome.ctrlview.bidim.Line.Line ( Point  p1,
Point  p2,
int  thickness,
byte  alignment 
) [inline]

The constructor.


Parameters:
p1the starting point of the line
p2the ending point of the line
thicknessthe thickness of the line
alignmentthe alignment of the line

Definition at line 84 of file Line.java.

                                                                   {
        this.p1 = p1;
        this.p2 = p2;
        this.thickness = thickness;
        this.alignment = alignment;
        computeLine();
    }

Here is the call graph for this function:


Member Function Documentation

Definition at line 170 of file Line.java.

                               {
        line = new Polygon();
        Point vectDir = new Point(p2.x - p1.x, p2.y - p1.y);
        float ortho_x = -vectDir.y;
        float ortho_y = vectDir.x;
        // On normalise ortho
        float norme = (float) Math.sqrt(ortho_x*ortho_x + ortho_y*ortho_y);
        ortho_x = (ortho_x/norme)*((float) thickness);
        ortho_y = (ortho_y/norme)*((float) thickness);
        
        int x, y;
        
        switch(alignment) {
            case RIGHT :
                line.addPoint(p1.x, p1.y);
                line.addPoint(p2.x, p2.y);
                line.addPoint((int) Math.round(((int) p2.x) - ortho_x), (int) Math.round(((int) p2.y) - ortho_y));
                line.addPoint((int) Math.round(((int) p1.x) - ortho_x), (int) Math.round(((int) p1.y) - ortho_y));
                break;
            case CENTER :
                float half_x = ortho_x/2.0f;
                float half_y = ortho_y/2.0f;
                line.addPoint((int) Math.round(((int) p1.x) - half_x), (int) Math.round(((int) p1.y) - half_y));
                line.addPoint((int) Math.round(((int) p2.x) - half_x), (int) Math.round(((int) p2.y) - half_y));
                line.addPoint((int) Math.round(((int) p2.x) + half_x), (int) Math.round(((int) p2.y) + half_y));
                line.addPoint((int) Math.round(((int) p1.x) + half_x), (int) Math.round(((int) p1.y) + half_y));
                break;
            case LEFT :
                line.addPoint(p1.x, p1.y);
                line.addPoint(p2.x, p2.y);
                line.addPoint((int) Math.round(((int) p2.x) + ortho_x), (int) Math.round(((int) p2.y) + ortho_y));
                line.addPoint((int) Math.round(((int) p1.x) + ortho_x), (int) Math.round(((int) p1.y) + ortho_y));
                break;
        }
    }

Here is the caller graph for this function:

void fr.ove.openmath.jome.ctrlview.bidim.Line.draw ( Graphics  g) [inline]

Draws the line.

Parameters:
gthe graphics in which the line has to be drawn.

Definition at line 159 of file Line.java.

                                 {
        g.fillPolygon(line);
    }

Here is the caller graph for this function:

Returns the alignement of the line.

Definition at line 135 of file Line.java.

                              {
        return alignment;
    }

Returns the Polygon which represents the line.

Definition at line 166 of file Line.java.

                             {
        return line;
    }

Returns the starting point of the line.

Definition at line 104 of file Line.java.

                         {
        return p1;
    }

Returns the ending point of the line.

Definition at line 120 of file Line.java.

                         {
        return p2;
    }

Returns the thickness of the line.

Definition at line 151 of file Line.java.

                              {
        return thickness;
    }
void fr.ove.openmath.jome.ctrlview.bidim.Line.setAlignment ( byte  alignment) [inline]

Sets a new alingment.

Parameters:
alignmentthe alignment of the line

Definition at line 128 of file Line.java.

                                             {
        this.alignment = alignment;
    }

Sets a new starting point.

Parameters:
p1the starting point of the line

Definition at line 96 of file Line.java.

                                {
        this.p1 = p1;
        computeLine();
    }

Here is the call graph for this function:

Sets a new ending point.

Parameters:
p2the ending point of the line

Definition at line 112 of file Line.java.

                                {
        this.p2 = p2;
        computeLine();
    }

Here is the call graph for this function:

Sets the thickness of the line.

Parameters:
thicknessthe thickness of the line

Definition at line 143 of file Line.java.

Here is the call graph for this function:


Member Data Documentation

The alignment of the drawing of the line.

  • LEFT : the thickness of the line is distributed to the left of the line
  • RIGHT : the thickness of the line is distributed to the right of the line
  • CENTER : the thickness of the line is distributed in equitably on both sides of the line

Be carefull of the position of the points. The line goes from P1 to P2.

Definition at line 65 of file Line.java.

The thickness of the line is distributed in equitably on both sides of the line.

Definition at line 218 of file Line.java.

The different alignements of the line.

The thickness of the line is distributed to the left of the line

Definition at line 213 of file Line.java.

Definition at line 67 of file Line.java.

The starting point of the line.

Definition at line 44 of file Line.java.

The ending point of the line.

Definition at line 49 of file Line.java.

The thickness of the line is distributed to the right of the line.

Definition at line 223 of file Line.java.

The thickness of the line.

Definition at line 54 of file Line.java.


The documentation for this class was generated from the following file: