Back to index

moin  1.9.0~rc2
GroupFigure.java
Go to the documentation of this file.
00001 /*
00002  * @(#)GroupFigure.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.figures;
00007 
00008 import java.awt.*;
00009 //import java.awt.geom.*;
00010 import java.util.*;
00011 import CH.ifa.draw.framework.*;
00012 import CH.ifa.draw.standard.*;
00013 
00017 public  class GroupFigure extends CompositeFigure {
00018 
00019     /*
00020      * Serialization support.
00021      */
00022     private static final long serialVersionUID = 8311226373023297933L;
00023     private int groupFigureSerializedDataVersion = 1;
00024 
00028     public boolean canConnect() {
00029         return false;
00030     }
00031 
00036     public Rectangle displayBox() {
00037         FigureEnumeration k = figures();
00038         Rectangle r = k.nextFigure().displayBox();
00039 
00040         while (k.hasMoreElements())
00041             r.add(k.nextFigure().displayBox());
00042         return r;
00043     }
00044 
00051     public void basicDisplayBox(Point origin, Point corner) {
00052        Rectangle srcr = displayBox();
00053        Rectangle dstr = new Rectangle(
00054            origin.x, origin.y,
00055            corner.x - origin.x, corner.y - origin.y);
00056 
00057        if (srcr.equals(dstr) ||
00058            corner.x <= origin.x || corner.y <= origin.y)
00059            return;
00060 
00061        // Scaling transform
00062        double xtx = (double)(corner.x - origin.x) / srcr.width;
00063        double ytx = (double)(corner.y - origin.y) / srcr.height;
00064 
00065         FigureEnumeration k = figures();
00066 
00067         while (k.hasMoreElements()) {
00068            Figure child = k.nextFigure();
00069            Rectangle sr = child.displayBox();
00070            Point childOrigin = new Point(
00071               (int)Math.round(dstr.x + (sr.x - srcr.x) * xtx),
00072               (int)Math.round(dstr.y + (sr.y - srcr.y) * ytx));
00073            Point childCorner = new Point(
00074               (int)Math.round(childOrigin.x + sr.width * xtx),
00075               (int)Math.round(childOrigin.y + sr.height * ytx));
00076            child.displayBox(childOrigin, childCorner);
00077        }
00078     }
00079 
00080     public FigureEnumeration decompose() {
00081         return new FigureEnumerator(fFigures);
00082     }
00083 
00087     public Vector handles() {
00088         Vector handles = new Vector();
00089        // Handles changed to standard handles to support group scaling
00090        // Crawford Currie, Motorola
00091        BoxHandleKit.addCornerHandles(this, handles);
00092        /* Was:
00093        handles.addElement(new GroupHandle(this, RelativeLocator.northWest()));
00094         handles.addElement(new GroupHandle(this, RelativeLocator.northEast()));
00095         handles.addElement(new GroupHandle(this, RelativeLocator.southWest()));
00096         handles.addElement(new GroupHandle(this, RelativeLocator.southEast()));
00097        */
00098         return handles;
00099     }
00100 
00104     public void setAttribute(String name, Object value) {
00105         super.setAttribute(name, value);
00106         FigureEnumeration k = figures();
00107         while (k.hasMoreElements())
00108             k.nextFigure().setAttribute(name, value);
00109     }
00110 }