01: package com.opensymphony.workflow.designer;
02:
03: import java.io.PrintWriter;
04: import java.awt.geom.Rectangle2D;
05:
06: import org.w3c.dom.Element;
07: import org.jgraph.graph.GraphConstants;
08:
09: import com.opensymphony.workflow.loader.XMLUtil;
10: import com.opensymphony.workflow.util.XMLizable;
11:
12: public class CellPosition implements XMLizable {
13: private int id = 0;
14: private String type;
15: private double height;
16: private double width;
17: private double x;
18: private double y;
19:
20: public CellPosition(WorkflowCell cell) {
21: id = cell.getId();
22: type = cell.getClass().getName();
23: type = type.substring(type.lastIndexOf('.') + 1, type.length());
24: Rectangle2D bounds = GraphConstants.getBounds(cell
25: .getAttributes());
26: height = bounds.getHeight();
27: width = bounds.getWidth();
28: x = bounds.getX();
29: y = bounds.getY();
30: }
31:
32: public CellPosition(Element activity) {
33: try {
34: id = Integer.parseInt(activity.getAttribute("id"));
35: type = activity.getAttribute("type");
36: height = Double
37: .parseDouble(activity.getAttribute("height"));
38: width = Double.parseDouble(activity.getAttribute("width"));
39: x = Double.parseDouble(activity.getAttribute("x"));
40: y = Double.parseDouble(activity.getAttribute("y"));
41: } catch (Exception e) {
42: System.out.println("Error parsing cell position:" + e);
43: }
44: }
45:
46: public int getId() {
47: return id;
48: }
49:
50: public String getType() {
51: return type;
52: }
53:
54: public void writeXML(PrintWriter out, int indent) {
55: XMLUtil.printIndent(out, indent++);
56: StringBuffer buf = new StringBuffer();
57: buf.append("<cell ");
58: buf.append("id=\"").append(id).append("\"");
59: buf.append(" type=\"").append(type).append("\"");
60: buf.append(" height=\"").append(height).append("\"");
61: buf.append(" width=\"").append(width).append("\"");
62: buf.append(" x=\"").append(x).append("\"");
63: buf.append(" y=\"").append(y).append("\"");
64:
65: buf.append("/>");
66: out.println(buf.toString());
67: }
68:
69: public double[] getBounds2D() {
70: return new double[] { x, y, width, height };
71: }
72: }
|