Back to index

moin  1.9.0~rc2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes
CH.ifa.draw.figures.PolyLineFigure Class Reference

A poly line figure consists of a list of points. More...

Inheritance diagram for CH.ifa.draw.figures.PolyLineFigure:
Inheritance graph
[legend]
Collaboration diagram for CH.ifa.draw.figures.PolyLineFigure:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PolyLineFigure ()
 PolyLineFigure (int size)
 PolyLineFigure (int x, int y)
Rectangle displayBox ()
boolean isEmpty ()
Vector handles ()
void basicDisplayBox (Point origin, Point corner)
void addPoint (int x, int y)
 Adds a node to the list of points.
Enumeration points ()
int pointCount ()
void setPointAt (Point p, int i)
 Changes the position of a node.
void insertPointAt (Point p, int i)
 Insert a node at the given point.
void removePointAt (int i)
int splitSegment (int x, int y)
 Splits the segment at the given point if a segment was hit.
Point pointAt (int i)
boolean joinSegments (int x, int y)
 Joins to segments into one if the given point hits a node of the polyline.
Connector connectorAt (int x, int y)
void setStartDecoration (LineDecoration l)
 Sets the start decoration.
void setEndDecoration (LineDecoration l)
 Sets the end decoration.
void draw (Graphics g, boolean showGuides)
boolean containsPoint (int x, int y)
int findSegment (int x, int y)
 Gets the segment of the polyline that is hit by the given point.
Object getAttribute (String name)
 Gets the attribute with the given name.
void setAttribute (String name, Object value)
 Sets the attribute with the given name.
void write (StorableOutput dw)
String getMap ()
void read (StorableInput dr) throws IOException

Static Public Member Functions

static Locator locator (int pointIndex)
 Creates a locator for the point with the given index.

Static Public Attributes

static final int ARROW_TIP_NONE = 0
static final int ARROW_TIP_START = 1
static final int ARROW_TIP_END = 2
static final int ARROW_TIP_BOTH = 3

Protected Member Functions

void basicMoveBy (int dx, int dy)
Color getFrameColor ()
void setFrameColor (Color c)

Protected Attributes

Vector fPoints
LineDecoration fStartDecoration = null
LineDecoration fEndDecoration = null
Color fFrameColor = Color.black

Private Member Functions

void drawURL (Graphics g)
void decorate (Graphics g)

Private Attributes

int polyLineFigureSerializedDataVersion = 1

Static Private Attributes

static final long serialVersionUID = -7951352179906577773L

Detailed Description

A poly line figure consists of a list of points.

It has an optional line decoration at the start and end.

See also:
LineDecoration

Definition at line 22 of file PolyLineFigure.java.


Constructor & Destructor Documentation

Definition at line 40 of file PolyLineFigure.java.

                            {
        fPoints = new Vector(4);
    }

Definition at line 44 of file PolyLineFigure.java.

                                    {
        fPoints = new Vector(size);
    }
CH.ifa.draw.figures.PolyLineFigure.PolyLineFigure ( int  x,
int  y 
) [inline]

Definition at line 48 of file PolyLineFigure.java.

                                        {
       fPoints = new Vector();
       fPoints.addElement(new Point(x, y));
    }

Member Function Documentation

void CH.ifa.draw.figures.PolyLineFigure.addPoint ( int  x,
int  y 
) [inline]

Adds a node to the list of points.

Definition at line 80 of file PolyLineFigure.java.

                                       {
        fPoints.addElement(new Point(x, y));
        changed();
    }

Here is the caller graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.basicDisplayBox ( Point  origin,
Point  corner 
) [inline]

Reimplemented in CH.ifa.draw.figures.LineFigure.

Definition at line 74 of file PolyLineFigure.java.

                                                            {
    }
void CH.ifa.draw.figures.PolyLineFigure.basicMoveBy ( int  dx,
int  dy 
) [inline, protected]

Reimplemented in CH.ifa.draw.figures.LineConnection.

Definition at line 93 of file PolyLineFigure.java.

                                               {
        Enumeration k = fPoints.elements();
        while (k.hasMoreElements())
            ((Point) k.nextElement()).translate(dx, dy);
    }
Connector CH.ifa.draw.figures.PolyLineFigure.connectorAt ( int  x,
int  y 
) [inline]

Definition at line 153 of file PolyLineFigure.java.

                                               {
        return new PolyLineConnector(this);
    }
boolean CH.ifa.draw.figures.PolyLineFigure.containsPoint ( int  x,
int  y 
) [inline]

Definition at line 208 of file PolyLineFigure.java.

                                               {
        Rectangle bounds = displayBox();
        bounds.grow(4,4);
        if (!bounds.contains(x, y))
            return false;

        Point p1, p2;
        for (int i = 0; i < fPoints.size()-1; i++) {
            p1 = (Point) fPoints.elementAt(i);
            p2 = (Point) fPoints.elementAt(i+1);
            if (Geom.lineContainsPoint(p1.x, p1.y, p2.x, p2.y, x, y))
                return true;
        }
        return false;
    }

Here is the call graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.decorate ( Graphics  g) [inline, private]

Definition at line 240 of file PolyLineFigure.java.

                                      {
        if (fStartDecoration != null) {
            Point p1 = (Point)fPoints.elementAt(0);
            Point p2 = (Point)fPoints.elementAt(1);
            fStartDecoration.draw(g, p1.x, p1.y, p2.x, p2.y);
        }
        if (fEndDecoration != null) {
            Point p3 = (Point)fPoints.elementAt(fPoints.size()-2);
            Point p4 = (Point)fPoints.elementAt(fPoints.size()-1);
            fEndDecoration.draw(g, p4.x, p4.y, p3.x, p3.y);
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 53 of file PolyLineFigure.java.

                                  {
        Enumeration k = points();
        Rectangle r = new Rectangle((Point) k.nextElement());
       
        while (k.hasMoreElements())
            r.add((Point) k.nextElement());
       
        return r;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.draw ( Graphics  g,
boolean  showGuides 
) [inline]

Definition at line 171 of file PolyLineFigure.java.

                                                     {
        g.setColor(getFrameColor());
        Point p1, p2;
        for (int i = 0; i < fPoints.size()-1; i++) {
            p1 = (Point) fPoints.elementAt(i);
            p2 = (Point) fPoints.elementAt(i+1);
            g.drawLine(p1.x, p1.y, p2.x, p2.y);
        }
        decorate(g);
       if (showGuides) {
           drawURL(g);
       }
    }

Here is the call graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.drawURL ( Graphics  g) [inline, private]

Definition at line 185 of file PolyLineFigure.java.

                                     {
       String sensitive = (String)getAttribute("Sensitive");
       if (sensitive == null || sensitive.length() == 0)
           return;
       int i;
       if (fPoints.size() < 3)
           i = 0;
       else
           i =  fPoints.size() / 2 - 1;
       Point p1, p2;

       if ((fPoints.size() & 1) == 1) {
           p2 = p1 = (Point) fPoints.elementAt(i+1);
       } else {
           p1 = (Point) fPoints.elementAt(i);
           p2 = (Point) fPoints.elementAt(i+1);
       }
       g.setColor(Color.red);
       g.setFont(dialogFont);
       g.drawString("url=" + sensitive, (p1.x + p2.x) / 2,
                   (p1.y + p2.y) / 2);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

int CH.ifa.draw.figures.PolyLineFigure.findSegment ( int  x,
int  y 
) [inline]

Gets the segment of the polyline that is hit by the given point.

Returns:
the index of the segment or -1 if no segment was hit.

Definition at line 229 of file PolyLineFigure.java.

                                         {
        Point p1, p2;
        for (int i = 0; i < fPoints.size()-1; i++) {
            p1 = (Point) fPoints.elementAt(i);
            p2 = (Point) fPoints.elementAt(i+1);
            if (Geom.lineContainsPoint(p1.x, p1.y, p2.x, p2.y, x, y))
                return i;
        }
        return -1;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Object CH.ifa.draw.figures.PolyLineFigure.getAttribute ( String  name) [inline]

Gets the attribute with the given name.

PolyLineFigure maps "ArrowMode"to a line decoration.

Definition at line 258 of file PolyLineFigure.java.

                                            {
        if (name.equals("FrameColor")) {
            return getFrameColor();
        } else if (name.equals("ArrowMode")) {
            int value = 0;
            if (fStartDecoration != null)
                value |= ARROW_TIP_START;
            if (fEndDecoration != null)
                value |= ARROW_TIP_END;
            return new Integer(value);
       }
        return super.getAttribute(name);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Color CH.ifa.draw.figures.PolyLineFigure.getFrameColor ( ) [inline, protected]

Definition at line 378 of file PolyLineFigure.java.

                                    {
        return fFrameColor;
    }

Here is the caller graph for this function:

Definition at line 315 of file PolyLineFigure.java.

                           {
       String sensitive = (String)getAttribute("Sensitive");
       if (sensitive == null || sensitive.length() == 0)
           return "";
       try {
              sensitive = URLDecoder.decode(sensitive);
       } catch (Exception e) {}
       Enumeration k = fPoints.elements();
       boolean first  = true;
       String forwards = "", backwards = "";
        for (int i = 1; i < fPoints.size(); i++) {
            Point p1 = (Point)fPoints.elementAt(i-1);
            Point p2 = (Point)fPoints.elementAt(i);
           double l = Math.sqrt((p2.x-p1.x) * (p2.x-p1.x) +
                             (p2.y-p1.y) * (p2.y-p1.y));
           int x = (int)(4 * (p2.y-p1.y) / l);
           int y = (int)(4 * (p2.x-p1.x) / l);
           if (!first) {
              forwards += ",";
              backwards = "," + backwards;
           }
           first = false;
           forwards += (p1.x + x) + "," + (p1.y + y) + "," +
              (p2.x + x) + "," + (p2.y + y);
           backwards = (p2.x - x) + "," + (p2.y - y) + "," +
              (p1.x - x) + "," + (p1.y - y) + backwards;
        }
       return "<area shape=\"poly\" coords=\"" +
           forwards + "," + backwards + "\" href=\"" +
           sensitive + "\" />\n";
    }

Here is the call graph for this function:

Reimplemented in CH.ifa.draw.figures.LineConnection, and CH.ifa.draw.figures.ElbowConnection.

Definition at line 67 of file PolyLineFigure.java.

                            {
        Vector handles = new Vector(fPoints.size());
        for (int i = 0; i < fPoints.size(); i++)
            handles.addElement(new PolyLineHandle(this, locator(i), i));
        return handles;
    }

Here is the call graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.insertPointAt ( Point  p,
int  i 
) [inline]

Insert a node at the given point.

Reimplemented in CH.ifa.draw.figures.LineConnection.

Definition at line 111 of file PolyLineFigure.java.

                                              {
        fPoints.insertElementAt(p, i);
        changed();
    }

Here is the caller graph for this function:

Definition at line 63 of file PolyLineFigure.java.

                             {
        return (size().width < 3) && (size().height < 3);
    }

Here is the call graph for this function:

boolean CH.ifa.draw.figures.PolyLineFigure.joinSegments ( int  x,
int  y 
) [inline]

Joins to segments into one if the given point hits a node of the polyline.

Returns:
true if the two segments were joined.

Definition at line 142 of file PolyLineFigure.java.

                                              {
        for (int i= 1; i < fPoints.size()-1; i++) {
            Point p = pointAt(i);
            if (Geom.length(x, y, p.x, p.y) < 3) {
                removePointAt(i);
                return true;
            }
        }
        return false;
    }

Here is the call graph for this function:

static Locator CH.ifa.draw.figures.PolyLineFigure.locator ( int  pointIndex) [inline, static]

Creates a locator for the point with the given index.

Definition at line 374 of file PolyLineFigure.java.

                                                  {
        return new PolyLineLocator(pointIndex);
    }

Here is the caller graph for this function:

Point CH.ifa.draw.figures.PolyLineFigure.pointAt ( int  i) [inline]

Definition at line 133 of file PolyLineFigure.java.

                                {
        return (Point)fPoints.elementAt(i);
    }

Here is the caller graph for this function:

Definition at line 89 of file PolyLineFigure.java.

                            {
        return fPoints.size();
    }

Here is the caller graph for this function:

Definition at line 85 of file PolyLineFigure.java.

                                {
        return fPoints.elements();
    }

Here is the caller graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.read ( StorableInput  dr) throws IOException [inline]

Reimplemented in CH.ifa.draw.figures.LineConnection.

Definition at line 347 of file PolyLineFigure.java.

                                                          {
       // test for the next token being a number to allow us to
       // skip attribute reading which. Old-format files don't
       // have attributes on connections.
       super.read(dr);
        int size = dr.readInt();
       if (size == -1) {
           // Temp for files created during devt. Remove when we're sure
           // they are all gone
           String s = dr.readString();
           setAttribute("Sensitive", s);
           size = dr.readInt();
       }
        fPoints = new Vector(size);
        for (int i=0; i<size; i++) {
            int x = dr.readInt();
            int y = dr.readInt();
            fPoints.addElement(new Point(x,y));
        }
        fStartDecoration = (LineDecoration)dr.readStorable();
        fEndDecoration = (LineDecoration)dr.readStorable();
        fFrameColor = dr.readColor();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in CH.ifa.draw.figures.LineConnection.

Definition at line 116 of file PolyLineFigure.java.

                                     {
        willChange();
        fPoints.removeElementAt(i);
        changed();
    }

Here is the caller graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.setAttribute ( String  name,
Object  value 
) [inline]

Sets the attribute with the given name.

PolyLineFigure interprets "ArrowMode"to set the line decoration.

Definition at line 277 of file PolyLineFigure.java.

                                                        {
        if (name.equals("FrameColor")) {
            setFrameColor((Color)value);
            changed();
        } else if (name.equals("ArrowMode")) {
            Integer intObj = (Integer) value;
            if (intObj != null) {
                int decoration = intObj.intValue();
                if ((decoration & ARROW_TIP_START) != 0)
                    fStartDecoration = new ArrowTip();
                else
                    fStartDecoration = null;
                if ((decoration & ARROW_TIP_END) != 0)
                    fEndDecoration = new ArrowTip();
                else
                    fEndDecoration = null;
            }
            changed();
       } else {
            super.setAttribute(name, value);
           changed();
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Sets the end decoration.

Definition at line 167 of file PolyLineFigure.java.

                                                   {
        fEndDecoration = l;
    }

Here is the caller graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.setFrameColor ( Color  c) [inline, protected]

Definition at line 382 of file PolyLineFigure.java.

                                          {
        fFrameColor = c;
    }

Here is the caller graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.setPointAt ( Point  p,
int  i 
) [inline]

Changes the position of a node.

Reimplemented in CH.ifa.draw.figures.LineConnection.

Definition at line 102 of file PolyLineFigure.java.

                                           {
        willChange();
        fPoints.setElementAt(p, i);
        changed();
    }

Here is the caller graph for this function:

Sets the start decoration.

Definition at line 160 of file PolyLineFigure.java.

                                                     {
        fStartDecoration = l;
    }

Here is the caller graph for this function:

int CH.ifa.draw.figures.PolyLineFigure.splitSegment ( int  x,
int  y 
) [inline]

Splits the segment at the given point if a segment was hit.

Returns:
the index of the segment or -1 if no segment was hit.

Definition at line 126 of file PolyLineFigure.java.

                                          {
        int i = findSegment(x, y);
        if (i != -1)
            insertPointAt(new Point(x, y), i+1);
        return i+1;
    }

Here is the call graph for this function:

void CH.ifa.draw.figures.PolyLineFigure.write ( StorableOutput  dw) [inline]

Reimplemented in CH.ifa.draw.figures.LineConnection.

Definition at line 301 of file PolyLineFigure.java.

                                         {
        super.write(dw);
        dw.writeInt(fPoints.size());
        Enumeration k = fPoints.elements();
        while (k.hasMoreElements()) {
            Point p = (Point) k.nextElement();
            dw.writeInt(p.x);
            dw.writeInt(p.y);
        }
        dw.writeStorable(fStartDecoration);
        dw.writeStorable(fEndDecoration);
        dw.writeColor(fFrameColor);
    }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 27 of file PolyLineFigure.java.

Definition at line 26 of file PolyLineFigure.java.

Definition at line 24 of file PolyLineFigure.java.

Definition at line 25 of file PolyLineFigure.java.

Definition at line 31 of file PolyLineFigure.java.

Color CH.ifa.draw.figures.PolyLineFigure.fFrameColor = Color.black [protected]

Definition at line 32 of file PolyLineFigure.java.

Definition at line 29 of file PolyLineFigure.java.

Definition at line 30 of file PolyLineFigure.java.

Definition at line 38 of file PolyLineFigure.java.

final long CH.ifa.draw.figures.PolyLineFigure.serialVersionUID = -7951352179906577773L [static, private]

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