Back to index

moin  1.9.0~rc2
ElbowConnection.java
Go to the documentation of this file.
00001 /*
00002  * @(#)ElbowConnection.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.figures;
00007 
00008 import java.awt.*;
00009 import java.util.*;
00010 import java.io.IOException;
00011 import CH.ifa.draw.framework.*;
00012 import CH.ifa.draw.standard.*;
00013 import CH.ifa.draw.util.*;
00014 
00019 public  class ElbowConnection extends LineConnection {
00020 
00021     /*
00022      * Serialization support.
00023      */
00024     private static final long serialVersionUID = 2193968743082078559L;
00025     private int elbowConnectionSerializedDataVersion = 1;
00026 
00027     public ElbowConnection() {
00028         super();
00029     }
00030 
00031     public void updateConnection() {
00032         super.updateConnection();
00033         updatePoints();
00034     }
00035 
00036     public void layoutConnection() {
00037     }
00038 
00042     public Vector handles() {
00043         Vector handles = new Vector(fPoints.size()*2);
00044         handles.addElement(new ChangeConnectionStartHandle(this));
00045         for (int i = 1; i < fPoints.size()-1; i++)
00046             handles.addElement(new NullHandle(this, locator(i)));
00047         handles.addElement(new ChangeConnectionEndHandle(this));
00048         for (int i = 0; i < fPoints.size()-1; i++)
00049             handles.addElement(new ElbowHandle(this, i));
00050         return handles;
00051     }
00052 
00053     public Locator connectedTextLocator(Figure f) {
00054         return new ElbowTextLocator();
00055     }
00056 
00057     protected void updatePoints() {
00058         willChange();
00059         Point start = startPoint();
00060         Point end = endPoint();
00061         fPoints.removeAllElements();
00062         fPoints.addElement(start);
00063 
00064         if (start.x == end.x || start.y == end.y) {
00065             fPoints.addElement(end);
00066         }
00067         else {
00068             Rectangle r1 = start().owner().displayBox();
00069             Rectangle r2 = end().owner().displayBox();
00070 
00071             int x1, y1, x2, y2;
00072             int dir = Geom.direction(r1.x + r1.width/2, r1.y + r1.height/2,
00073                         r2.x + r2.width/2, r2.y + r2.height/2);
00074             if (dir == Geom.NORTH || dir == Geom.SOUTH) {
00075                 fPoints.addElement(new Point(start.x, (start.y + end.y)/2));
00076                 fPoints.addElement(new Point(end.x, (start.y + end.y)/2));
00077             }
00078             else {
00079                 fPoints.addElement(new Point((start.x + end.x)/2, start.y));
00080                 fPoints.addElement(new Point((start.x + end.x)/2, end.y));
00081             }
00082             fPoints.addElement(end);
00083         }
00084         changed();
00085     }
00086 }
00087 
00088