Back to index

moin  1.9.0~rc2
OffsetLocator.java
Go to the documentation of this file.
00001 /*
00002  * @(#)OffsetLocator.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 
00017 public  class OffsetLocator extends AbstractLocator {
00018 
00019     /*
00020      * Serialization support.
00021      */
00022     private static final long serialVersionUID = 2679950024611847621L;
00023     private int offsetLocatorSerializedDataVersion = 1;
00024 
00025     private Locator fBase;
00026     private int     fOffsetX;
00027     private int     fOffsetY;
00028 
00029     public OffsetLocator() {
00030         fBase = null;
00031         fOffsetX = 0;
00032         fOffsetY = 0;
00033     }
00034 
00035     public OffsetLocator(Locator base) {
00036         this();
00037         fBase = base;
00038     }
00039 
00040     public OffsetLocator(Locator base, int offsetX, int offsetY) {
00041         this(base);
00042         fOffsetX = offsetX;
00043         fOffsetY = offsetY;
00044     }
00045 
00046     public Point locate(Figure owner) {
00047         Point p = fBase.locate(owner);
00048         p.x += fOffsetX;
00049         p.y += fOffsetY;
00050         return p;
00051     }
00052 
00053     public void moveBy(int dx, int dy) {
00054         fOffsetX += dx;
00055         fOffsetY += dy;
00056     }
00057 
00058     public void write(StorableOutput dw) {
00059         super.write(dw);
00060         dw.writeInt(fOffsetX);
00061         dw.writeInt(fOffsetY);
00062         dw.writeStorable(fBase);
00063     }
00064 
00065     public void read(StorableInput dr) throws IOException {
00066         super.read(dr);
00067         fOffsetX = dr.readInt();
00068         fOffsetY = dr.readInt();
00069         fBase = (Locator)dr.readStorable();
00070     }
00071 }
00072