1 package com.opensymphony.workflow.designer; 2 3 import java.io.PrintWriter ; 4 import java.awt.*; 5 6 import org.w3c.dom.Element ; 7 8 import com.opensymphony.workflow.loader.XMLUtil; 9 import com.opensymphony.workflow.util.XMLizable; 10 11 public class CellPosition implements XMLizable 12 { 13 private int id = 0; 14 private String type; 15 private Rectangle bounds; 16 17 public CellPosition(WorkflowCell cell) 18 { 19 id = cell.getId(); 20 type = cell.getClass().getName(); 21 type = type.substring(type.lastIndexOf('.')+1, type.length()); 22 bounds = (Rectangle)cell.getAttributes().get("bounds"); 23 } 24 25 public CellPosition(Element activity) 26 { 27 try 28 { 29 id = Integer.parseInt(activity.getAttribute("id")); 30 type = activity.getAttribute("type"); 31 bounds = new Rectangle(); 32 bounds.height = Integer.parseInt(activity.getAttribute("height")); 33 bounds.width = Integer.parseInt(activity.getAttribute("width")); 34 bounds.x = Integer.parseInt(activity.getAttribute("x")); 35 bounds.y = Integer.parseInt(activity.getAttribute("y")); 36 } 37 catch(Exception e) 38 { 39 System.out.println("Error parsing cell position:" + e); 40 } 41 } 42 43 public int getId() 44 { 45 return id; 46 } 47 48 public String getType() 49 { 50 return type; 51 } 52 53 public void writeXML(PrintWriter out, int indent) 54 { 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(bounds.height).append("\""); 61 buf.append(" width=\"").append(bounds.width).append("\""); 62 buf.append(" x=\"").append(bounds.x).append("\""); 63 buf.append(" y=\"").append(bounds.y).append("\""); 64 65 buf.append("/>"); 66 out.println(buf.toString()); 67 } 68 69 public Rectangle getBounds() 70 { 71 return bounds; 72 } 73 } 74 | Popular Tags |