01: package org.cougaar.core.qos.frame.visualizer;
02:
03: import java.util.HashMap;
04: import java.util.Iterator;
05: import java.awt.geom.RectangularShape;
06: import java.awt.geom.RoundRectangle2D;
07: import java.awt.*;
08:
09: /**
10: * Created by IntelliJ IDEA.
11: * User: mwalczak
12: * Date: May 2, 2005
13: * Time: 2:08:48 PM
14: * To change this template use File | Settings | File Templates.
15: */
16: public class Shapes {
17: private HashMap shapes;
18:
19: public Shapes() {
20: shapes = new HashMap();
21: }
22:
23: public void add(String name, RectangularShape shape) {
24: shapes.put(name, shape);
25: }
26:
27: public RectangularShape get(String name) {
28: return getCopy(name);//(RectangularShape) shapes.get(name);
29: }
30:
31: private RectangularShape getCopy(String name) {
32: RectangularShape s = (RectangularShape) shapes.get(name);
33: if (s != null)
34: return (RectangularShape) s.clone();
35: return null;
36: }
37:
38: public String[] toXML() {
39: String shapeName;
40: RectangularShape sh;
41: String shapeStr[] = new String[shapes.size()];
42: int i = 0;
43: Rectangle r;
44: String append = "";
45:
46: for (Iterator ii = shapes.keySet().iterator(); ii.hasNext(); i++) {
47: shapeName = (String) ii.next();
48: sh = (RectangularShape) shapes.get(shapeName);
49: r = sh.getBounds();
50: if (sh instanceof RoundRectangle2D)
51: append = " arcw=\""
52: + ((RoundRectangle2D) sh).getArcWidth()
53: + "\" arch=\""
54: + ((RoundRectangle2D) sh).getArcHeight()
55: + "\" ";
56:
57: shapeStr[i] = "<shape name=" + shapeName + " class=\""
58: + sh.getClass().getName()
59: + "\" x=\"0\" y=\"0\" w=\"" + r.width + "\" h=\""
60: + r.height + "\" " + append + "/>";
61: }
62: return shapeStr;
63: }
64:
65: }
|