Back to index

moin  1.9.0~rc2
RectangleFigure.java
Go to the documentation of this file.
00001 /*
00002  * @(#)RectangleFigure.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 
00020 public class RectangleFigure extends AttributeFigure {
00021 
00022     private Rectangle   fDisplayBox;
00023 
00024     /*
00025      * Serialization support.
00026      */
00027     private static final long serialVersionUID = 184722075881789163L;
00028     private int rectangleFigureSerializedDataVersion = 1;
00029 
00030     public RectangleFigure() {
00031         this(new Point(0,0), new Point(0,0));
00032     }
00033 
00034     public RectangleFigure(Point origin, Point corner) {
00035         basicDisplayBox(origin,corner);
00036     }
00037 
00038     public void basicDisplayBox(Point origin, Point corner) {
00039         fDisplayBox = new Rectangle(origin);
00040         fDisplayBox.add(corner);
00041     }
00042 
00043     public Vector handles() {
00044         Vector handles = new Vector();
00045         BoxHandleKit.addHandles(this, handles);
00046         return handles;
00047     }
00048 
00049     public Rectangle displayBox() {
00050         return new Rectangle(
00051             fDisplayBox.x,
00052             fDisplayBox.y,
00053             fDisplayBox.width,
00054             fDisplayBox.height);
00055     }
00056 
00057     protected void basicMoveBy(int x, int y) {
00058         fDisplayBox.translate(x,y);
00059     }
00060 
00061     public void drawBackground(Graphics g) {
00062         Rectangle r = displayBox();
00063        g.fillRect(r.x, r.y, r.width, r.height);
00064     }
00065 
00066     public void drawFrame(Graphics g) {
00067         Rectangle r = displayBox();
00068        g.drawRect(r.x, r.y, r.width-1, r.height-1);
00069     }
00070 
00071     //-- store / load ----------------------------------------------
00072 
00073     public void write(StorableOutput dw) {
00074         super.write(dw);
00075         dw.writeInt(fDisplayBox.x);
00076         dw.writeInt(fDisplayBox.y);
00077         dw.writeInt(fDisplayBox.width);
00078         dw.writeInt(fDisplayBox.height);
00079     }
00080 
00081     public String getMap() {
00082        String sense = (String)getAttribute("Sensitive");
00083        if (sense != null && sense.length() > 0) {
00084               try {
00085                      sense = URLDecoder.decode(sense);
00086               } catch (Exception e) {}
00087            Rectangle box = displayBox();
00088            return "<area shape=\"rect\" coords=\"" +
00089               box.x + "," + box.y + "," +
00090               (box.x + box.width) + "," +
00091               (box.y + box.height) +
00092               "\" href=\"" + sense + "\" />\n";
00093        }
00094        return "";
00095     }
00096 
00097     public void read(StorableInput dr) throws IOException {
00098         super.read(dr);
00099         fDisplayBox = new Rectangle(
00100             dr.readInt(),
00101             dr.readInt(),
00102             dr.readInt(),
00103             dr.readInt());
00104     }
00105 
00106 }