Back to index

moin  1.9.0~rc2
RadiusHandle.java
Go to the documentation of this file.
00001 /*
00002  * @(#)RadiusHandle.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.figures;
00007 
00008 import java.awt.*;
00009 import CH.ifa.draw.framework.*;
00010 import CH.ifa.draw.standard.*;
00011 import CH.ifa.draw.util.Geom;
00012 
00016 class RadiusHandle extends AbstractHandle {
00017 
00018     private Point fRadius;
00019     private RoundRectangleFigure fOwner;
00020     private static final int OFFSET = 4;
00021 
00022     public RadiusHandle(RoundRectangleFigure owner) {
00023         super(owner);
00024         fOwner = owner;
00025     }
00026 
00027     public void invokeStart(int  x, int  y, DrawingView view) {
00028         fRadius = fOwner.getArc();
00029         fRadius.x = fRadius.x/2;
00030         fRadius.y = fRadius.y/2;
00031     }
00032 
00033     public void invokeStep (int x, int y, int anchorX, int anchorY, DrawingView view) {
00034         int dx = x-anchorX;
00035         int dy = y-anchorY;
00036         Rectangle r = fOwner.displayBox();
00037         int rx = Geom.range(0, r.width, 2*(fRadius.x + dx));
00038         int ry = Geom.range(0, r.height, 2*(fRadius.y + dy));
00039         fOwner.setArc(rx, ry);
00040     }
00041 
00042     public Point locate() {
00043         Point radius = fOwner.getArc();
00044         Rectangle r = fOwner.displayBox();
00045         return new Point(r.x+radius.x/2+OFFSET, r.y+radius.y/2+OFFSET);
00046     }
00047 
00048     public void draw(Graphics g) {
00049         Rectangle r = displayBox();
00050 
00051         g.setColor(Color.yellow);
00052         g.fillOval(r.x, r.y, r.width, r.height);
00053 
00054         g.setColor(Color.black);
00055         g.drawOval(r.x, r.y, r.width, r.height);
00056     }
00057 }
00058