Back to index

moin  1.9.0~rc2
BoxHandleKit.java
Go to the documentation of this file.
00001 /*
00002  * @(#)BoxHandleKit.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import CH.ifa.draw.framework.*;
00009 import java.awt.*;
00010 import java.util.Vector;
00011 
00018  // TBD: use anonymous inner classes (had some problems with JDK 1.1)
00019 
00020 public class BoxHandleKit {
00021 
00026     static public void addCornerHandles(Figure f, Vector handles) {
00027         handles.addElement(southEast(f));
00028         handles.addElement(southWest(f));
00029         handles.addElement(northEast(f));
00030         handles.addElement(northWest(f));
00031     }
00032 
00037     static public void addHandles(Figure f, Vector handles) {
00038         addCornerHandles(f, handles);
00039         handles.addElement(south(f));
00040         handles.addElement(north(f));
00041         handles.addElement(east(f));
00042         handles.addElement(west(f));
00043     }
00044 
00045     static public Handle south(Figure owner) {
00046         return new SouthHandle(owner);
00047     }
00048 
00049     static public Handle southEast(Figure owner) {
00050         return new SouthEastHandle(owner);
00051     }
00052 
00053     static public Handle southWest(Figure owner) {
00054         return new SouthWestHandle(owner);
00055     }
00056 
00057     static public Handle north(Figure owner) {
00058         return new NorthHandle(owner);
00059     }
00060 
00061     static public Handle northEast(Figure owner) {
00062         return new NorthEastHandle(owner);
00063     }
00064 
00065     static public Handle northWest(Figure owner) {
00066         return new NorthWestHandle(owner);
00067     }
00068 
00069     static public Handle east(Figure owner) {
00070         return new EastHandle(owner);
00071     }
00072     static public Handle west(Figure owner) {
00073         return new WestHandle(owner);
00074     }
00075 }
00076 
00077 class NorthEastHandle extends LocatorHandle {
00078     NorthEastHandle(Figure owner) {
00079         super(owner, RelativeLocator.northEast());
00080     }
00081 
00082     public void invokeStep (int x, int y, int anchorX, int anchorY, DrawingView view) {
00083         Rectangle r = owner().displayBox();
00084         owner().displayBox(
00085             new Point(r.x, Math.min(r.y + r.height, y)),
00086             new Point(Math.max(r.x, x), r.y + r.height)
00087         );
00088     }
00089 }
00090 
00091 class EastHandle extends LocatorHandle {
00092     EastHandle(Figure owner) {
00093         super(owner, RelativeLocator.east());
00094     }
00095 
00096     public void invokeStep (int x, int y, int anchorX, int anchorY, DrawingView view) {
00097         Rectangle r = owner().displayBox();
00098         owner().displayBox(
00099             new Point(r.x, r.y), new Point(Math.max(r.x, x), r.y + r.height)
00100         );
00101     }
00102 }
00103 
00104 class NorthHandle extends LocatorHandle {
00105     NorthHandle(Figure owner) {
00106         super(owner, RelativeLocator.north());
00107     }
00108 
00109     public void invokeStep (int x, int y, int anchorX, int anchorY, DrawingView view) {
00110         Rectangle r = owner().displayBox();
00111         owner().displayBox(
00112             new Point(r.x, Math.min(r.y + r.height, y)),
00113             new Point(r.x + r.width, r.y + r.height)
00114         );
00115     }
00116 }
00117 
00118 class NorthWestHandle extends LocatorHandle {
00119     NorthWestHandle(Figure owner) {
00120         super(owner, RelativeLocator.northWest());
00121     }
00122 
00123     public void invokeStep (int x, int y, int anchorX, int anchorY, DrawingView view) {
00124         Rectangle r = owner().displayBox();
00125         owner().displayBox(
00126             new Point(Math.min(r.x + r.width, x), Math.min(r.y + r.height, y)),
00127             new Point(r.x + r.width, r.y + r.height)
00128         );
00129     }
00130 }
00131 
00132 class SouthEastHandle extends LocatorHandle {
00133     SouthEastHandle(Figure owner) {
00134         super(owner, RelativeLocator.southEast());
00135     }
00136 
00137     public void invokeStep (int x, int y, int anchorX, int anchorY, DrawingView view) {
00138         Rectangle r = owner().displayBox();
00139         owner().displayBox(
00140             new Point(r.x, r.y),
00141             new Point(Math.max(r.x, x), Math.max(r.y, y))
00142         );
00143     }
00144 }
00145 
00146 class SouthHandle extends LocatorHandle {
00147     SouthHandle(Figure owner) {
00148         super(owner, RelativeLocator.south());
00149     }
00150 
00151     public void invokeStep (int x, int y, int anchorX, int anchorY, DrawingView view) {
00152         Rectangle r = owner().displayBox();
00153         owner().displayBox(
00154             new Point(r.x, r.y),
00155             new Point(r.x + r.width, Math.max(r.y, y))
00156         );
00157     }
00158 }
00159 
00160 class SouthWestHandle extends LocatorHandle {
00161     SouthWestHandle(Figure owner) {
00162         super(owner, RelativeLocator.southWest());
00163     }
00164 
00165     public void invokeStep (int x, int y, int anchorX, int anchorY, DrawingView view) {
00166         Rectangle r = owner().displayBox();
00167         owner().displayBox(
00168             new Point(Math.min(r.x + r.width, x), r.y),
00169             new Point(r.x + r.width, Math.max(r.y, y))
00170         );
00171     }
00172 }
00173 
00174 class WestHandle extends LocatorHandle {
00175     WestHandle(Figure owner) {
00176         super(owner, RelativeLocator.west());
00177     }
00178 
00179     public void invokeStep (int x, int y, int anchorX, int anchorY, DrawingView view) {
00180         Rectangle r = owner().displayBox();
00181         owner().displayBox(
00182             new Point(Math.min(r.x + r.width, x), r.y),
00183             new Point(r.x + r.width, r.y + r.height)
00184         );
00185     }
00186 }