Back to index

moin  1.9.0~rc2
RoundRectangleFigure.java
Go to the documentation of this file.
00001 /*
00002  * @(#)RoundRectangleFigure.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.framework.*;
00013 import CH.ifa.draw.standard.*;
00014 import CH.ifa.draw.util.*;
00015 
00016 
00021 public  class RoundRectangleFigure extends AttributeFigure {
00022 
00023     private Rectangle   fDisplayBox;
00024     private int         fArcWidth;
00025     private int         fArcHeight;
00026     private static final int DEFAULT_ARC = 8;
00027 
00028     /*
00029      * Serialization support.
00030      */
00031     private static final long serialVersionUID = 7907900248924036885L;
00032     private int roundRectangleSerializedDataVersion = 1;
00033 
00034     public RoundRectangleFigure() {
00035         this(new Point(0,0), new Point(0,0));
00036         fArcWidth = fArcHeight = DEFAULT_ARC;
00037     }
00038 
00039     public RoundRectangleFigure(Point origin, Point corner) {
00040         basicDisplayBox(origin,corner);
00041         fArcWidth = fArcHeight = DEFAULT_ARC;
00042     }
00043 
00044     public void basicDisplayBox(Point origin, Point corner) {
00045         fDisplayBox = new Rectangle(origin);
00046         fDisplayBox.add(corner);
00047     }
00048 
00052     public void setArc(int width, int height) {
00053         willChange();
00054         fArcWidth = width;
00055         fArcHeight = height;
00056         changed();
00057     }
00058 
00062     public Point getArc() {
00063         return new Point(fArcWidth, fArcHeight);
00064     }
00065 
00066     public Vector handles() {
00067         Vector handles = new Vector();
00068         BoxHandleKit.addHandles(this, handles);
00069 
00070         handles.addElement(new RadiusHandle(this));
00071 
00072         return handles;
00073     }
00074 
00075     public Rectangle displayBox() {
00076         return new Rectangle(
00077             fDisplayBox.x,
00078             fDisplayBox.y,
00079             fDisplayBox.width,
00080             fDisplayBox.height);
00081     }
00082 
00083     protected void basicMoveBy(int x, int y) {
00084         fDisplayBox.translate(x,y);
00085     }
00086 
00087     public void drawBackground(Graphics g) {
00088         Rectangle r = displayBox();
00089         g.fillRoundRect(r.x, r.y, r.width, r.height, fArcWidth, fArcHeight);
00090     }
00091 
00092     public void drawFrame(Graphics g) {
00093         Rectangle r = displayBox();
00094         g.drawRoundRect(r.x, r.y, r.width-1, r.height-1, fArcWidth, fArcHeight);
00095     }
00096 
00097     public Insets connectionInsets() {
00098         return new Insets(fArcHeight/2, fArcWidth/2, fArcHeight/2, fArcWidth/2);
00099     }
00100 
00101     public Connector connectorAt(int x, int y) {
00102         return new ShortestDistanceConnector(this); // just for demo purposes
00103     }
00104 
00105     public void write(StorableOutput dw) {
00106         super.write(dw);
00107         dw.writeInt(fDisplayBox.x);
00108         dw.writeInt(fDisplayBox.y);
00109         dw.writeInt(fDisplayBox.width);
00110         dw.writeInt(fDisplayBox.height);
00111         dw.writeInt(fArcWidth);
00112         dw.writeInt(fArcHeight);
00113     }
00114 
00115     public String getMap() {
00116        String sense = (String)getAttribute("Sensitive");
00117        if (sense != null && sense.length() > 0) {
00118               try {
00119                      sense = URLDecoder.decode(sense);
00120               } catch (Exception e) {}
00121            Rectangle box = displayBox();
00122            return "<area shape=\"rect\" coords=\"" +
00123                      box.x + "," + box.y + "," +
00124                      (box.x + box.width) + "," +
00125                      (box.y + box.height) +
00126                      "\" href=\"" +
00127                      sense + "\" />\n";
00128        }
00129        return "";
00130     }
00131 
00132     public void read(StorableInput dr) throws IOException {
00133         super.read(dr);
00134         fDisplayBox = new Rectangle(
00135             dr.readInt(),
00136             dr.readInt(),
00137             dr.readInt(),
00138             dr.readInt());
00139         fArcWidth = dr.readInt();
00140         fArcHeight = dr.readInt();
00141     }
00142 
00143 }