Back to index

moin  1.9.0~rc2
ChopBoxConnector.java
Go to the documentation of this file.
00001 /*
00002  * @(#)ChopBoxConnector.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import java.awt.*;
00009 import CH.ifa.draw.framework.*;
00010 import CH.ifa.draw.util.Geom;
00011 
00018 public class ChopBoxConnector extends AbstractConnector {
00019 
00020     /*
00021      * Serialization support.
00022      */
00023     private static final long serialVersionUID = -1461450322712345462L;
00024 
00025     public ChopBoxConnector() { // only used for Storable implementation
00026     }
00027 
00028     public ChopBoxConnector(Figure owner) {
00029         super(owner);
00030     }
00031 
00032     public Point findStart(ConnectionFigure connection) {
00033         Figure startFigure = connection.start().owner();
00034         Rectangle r2 = connection.end().displayBox();
00035         Point r2c = null;
00036 
00037         if (connection.pointCount() == 2)
00038             r2c = new Point(r2.x + r2.width/2, r2.y + r2.height/2);
00039          else
00040             r2c = connection.pointAt(1);
00041 
00042         return chop(startFigure, r2c);
00043     }
00044 
00045     public Point findEnd(ConnectionFigure connection) {
00046         Figure endFigure = connection.end().owner();
00047         Rectangle r1 = connection.start().displayBox();
00048         Point r1c = null;
00049 
00050         if (connection.pointCount() == 2)
00051             r1c = new Point(r1.x + r1.width/2, r1.y + r1.height/2);
00052          else
00053             r1c = connection.pointAt(connection.pointCount()-2);
00054 
00055         return chop(endFigure, r1c);
00056     }
00057 
00058     protected Point chop(Figure target, Point from) {
00059         Rectangle r = target.displayBox();
00060         return Geom.angleToPoint(r, (Geom.pointToAngle(r, from)));
00061     }
00062 }
00063