Back to index

moin  1.9.0~rc2
EllipseFigure.java
Go to the documentation of this file.
00001 /*
00002  * @(#)EllipseFigure.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.figures;
00007 
00008 import java.awt.*;
00009 import java.io.*;
00010 import java.net.*;
00011 import java.util.Vector;
00012 import CH.ifa.draw.util.*;
00013 import CH.ifa.draw.framework.*;
00014 import CH.ifa.draw.standard.*;
00015 
00019 public class EllipseFigure extends AttributeFigure {
00020 
00021     private Rectangle   fDisplayBox;
00022 
00023     /*
00024      * Serialization support.
00025      */
00026     private static final long serialVersionUID = -6856203289355118951L;
00027     private int ellipseFigureSerializedDataVersion = 1;
00028 
00029     public EllipseFigure() {
00030         this(new Point(0,0), new Point(0,0));
00031     }
00032 
00033     public EllipseFigure(Point origin, Point corner) {
00034         basicDisplayBox(origin,corner);
00035     }
00036 
00037     public Vector handles() {
00038         Vector handles = new Vector();
00039         BoxHandleKit.addHandles(this, handles);
00040         return handles;
00041     }
00042 
00043     public void basicDisplayBox(Point origin, Point corner) {
00044         fDisplayBox = new Rectangle(origin);
00045         fDisplayBox.add(corner);
00046     }
00047 
00048     public Rectangle displayBox() {
00049         return new Rectangle(
00050             fDisplayBox.x,
00051             fDisplayBox.y,
00052             fDisplayBox.width,
00053             fDisplayBox.height);
00054     }
00055 
00056     protected void basicMoveBy(int x, int y) {
00057         fDisplayBox.translate(x,y);
00058     }
00059 
00060     public void drawBackground(Graphics g) {
00061         Rectangle r = displayBox();
00062         g.fillOval(r.x, r.y, r.width, r.height);
00063     }
00064 
00065     public void drawFrame(Graphics g) {
00066         Rectangle r = displayBox();
00067         g.drawOval(r.x, r.y, r.width-1, r.height-1);
00068     }
00069 
00070     public Insets connectionInsets() {
00071         Rectangle r = fDisplayBox;
00072         int cx = r.width/2;
00073         int cy = r.height/2;
00074         return new Insets(cy, cx, cy, cx);
00075     }
00076 
00077     public Connector connectorAt(int x, int y) {
00078         return new ChopEllipseConnector(this);
00079     }
00080 
00081     public void write(StorableOutput dw) {
00082         super.write(dw);
00083         dw.writeInt(fDisplayBox.x);
00084         dw.writeInt(fDisplayBox.y);
00085         dw.writeInt(fDisplayBox.width);
00086         dw.writeInt(fDisplayBox.height);
00087     }
00088 
00089     public String getMap() {
00090        String sense = (String)getAttribute("Sensitive");
00091        if (sense != null && sense.length() > 0) {
00092               try {
00093                      sense = URLDecoder.decode(sense);
00094               } catch (Exception e) {}
00095            Rectangle box = displayBox();
00096            double w = box.width / 2.0;
00097            double h = box.height / 2.0;
00098            double ang = (box.height > box.width) ? Math.PI / 2 : 0;
00099            Point c = center();
00100            String coords = "";
00101            for (int i = 0; i < 6; i++) {
00102               if (i > 0)
00103                   coords += ",";
00104               int x = (int)(c.x + Math.cos(ang) * w);
00105               int y = (int)(c.y + Math.sin(ang) * h);
00106               coords += x + "," + y;
00107               ang += Math.PI / 3;
00108            }
00109            return "<area shape=\"poly\" coords=\"" + coords +
00110               "\" href=\"" +
00111               sense + "\" />\n";
00112        }
00113        return "";
00114     }
00115 
00116     public void read(StorableInput dr) throws IOException {
00117         super.read(dr);
00118         fDisplayBox = new Rectangle(
00119             dr.readInt(),
00120             dr.readInt(),
00121             dr.readInt(),
00122             dr.readInt());
00123     }
00124 }