Back to index

moin  1.9.0~rc2
LocatorConnector.java
Go to the documentation of this file.
00001 /*
00002  * @(#)LocatorConnector.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import java.awt.*;
00009 import java.io.IOException;
00010 import CH.ifa.draw.framework.*;
00011 import CH.ifa.draw.util.*;
00012 
00020 public class LocatorConnector extends AbstractConnector {
00021 
00026     public static final int SIZE = 8;
00027 
00028     private Locator  fLocator;
00029 
00030     /*
00031      * Serialization support.
00032      */
00033     private static final long serialVersionUID = 5062833203337604181L;
00034     private int locatorConnectorSerializedDataVersion = 1;
00035 
00036     public LocatorConnector() { // only used for Storable
00037         fLocator = null;
00038     }
00039 
00040     public LocatorConnector(Figure owner, Locator l) {
00041         super(owner);
00042         fLocator = l;
00043     }
00044 
00045     protected Point locate(ConnectionFigure connection) {
00046         return fLocator.locate(owner());
00047     }
00048 
00052     public boolean containsPoint(int x, int y) {
00053         return displayBox().contains(x, y);
00054     }
00055 
00059     public Rectangle displayBox() {
00060         Point p = fLocator.locate(owner());
00061         return new Rectangle(
00062                 p.x - SIZE / 2,
00063                 p.y - SIZE / 2,
00064                 SIZE,
00065                 SIZE);
00066     }
00067 
00071     public void draw(Graphics g) {
00072         Rectangle r = displayBox();
00073 
00074         g.setColor(Color.blue);
00075         g.fillOval(r.x, r.y, r.width, r.height);
00076         g.setColor(Color.black);
00077         g.drawOval(r.x, r.y, r.width, r.height);
00078     }
00079 
00083     public void write(StorableOutput dw) {
00084         super.write(dw);
00085         dw.writeStorable(fLocator);
00086     }
00087 
00091     public void read(StorableInput dr) throws IOException {
00092         super.read(dr);
00093         fLocator = (Locator)dr.readStorable();
00094     }
00095 
00096 }
00097