1 29 30 package hero.client.grapheditor; 31 32 import java.awt.BasicStroke ; 33 import java.awt.Color ; 34 import java.awt.Dimension ; 35 import java.awt.Font ; 36 import java.awt.Graphics ; 37 import java.awt.Graphics2D ; 38 39 import com.jgraph.JGraph; 40 import com.jgraph.graph.CellMapper; 41 import com.jgraph.graph.CellViewRenderer; 42 import com.jgraph.graph.GraphConstants; 43 import com.jgraph.graph.VertexRenderer; 44 import com.jgraph.graph.VertexView; 45 import java.util.Map ; 46 import javax.swing.ImageIcon ; 47 import java.awt.Toolkit ; 48 49 public class BonitaActivityView extends VertexView { 50 51 public ActivityRenderer renderer; 52 53 public BonitaActivityView(Object arg0, JGraph arg1, CellMapper arg2) { 54 super(arg0, arg1, arg2); 55 renderer = new ActivityRenderer((BonitaActivityCell) arg0); 56 } 57 58 public CellViewRenderer getRenderer() { 59 return renderer; 60 } 61 62 public static class ActivityRenderer extends VertexRenderer { 63 64 private BonitaActivityCell activity; 65 66 public ActivityRenderer(BonitaActivityCell rb) { 67 activity = rb; 68 } 69 70 public void paint(Graphics g) { 71 72 Graphics2D g2 = (Graphics2D ) g; 73 Dimension d = getSize(); 74 boolean tmp = selected; 75 76 try { 78 setBorder(null); 79 setOpaque(false); 80 setText(""); 81 selected = false; 82 super.paint(g); 83 } finally { 84 selected = tmp; 85 } 86 87 if (selected) { 89 g2.setStroke(GraphConstants.SELECTION_STROKE); 90 } else { 91 g2.setStroke(new BasicStroke (1)); 92 } 93 94 int y = ((getHeight() - 19) / 2) + 1; 95 96 Color contour = Color.decode("#3E6AAB"); 97 Map props = activity.getAttributes(); 98 99 if (!selected) { 101 g2.setColor(getBackground()); 102 if (((String )props.get("subProcess")).equals("yes")) 103 g2.fillOval(4, 4, getWidth() - 9, getHeight() - 9); 104 else 105 g2.fillRoundRect(4, 4, getWidth() - 9, getHeight() - 9, 10, 10); 106 } 107 g2.setColor(contour); 108 109 if (((String )props.get("subProcess")).equals("yes")) 110 g2.drawOval(4, 4, getWidth() - 9, getHeight() - 9); 111 else 112 g2.drawRoundRect(4, 4, getWidth() - 9, getHeight() - 9, 10, 10); 113 114 Map propers = activity.getAttributes(); 116 String iteration = (String )propers.get("iterate"); 117 if (!iteration.equals("false")) { 118 String iconPath=null; 119 if (iteration.equals("from")) 120 iconPath = "images/from.gif"; 121 else 122 iconPath = "images/to.gif"; 123 try { 125 java.net.URL iconUrl = Thread.currentThread().getContextClassLoader().getResource(iconPath); 126 g2.drawImage(Toolkit.getDefaultToolkit().getImage(iconUrl),5,y,10,10,Frame.getFrame().getWorkflowGraph()); 128 } catch(Exception e){ 129 System.out.println("Unable to load image " + iconPath); 130 } 131 } 132 133 g2.setColor(Color.WHITE); 135 if (((String )props.get("subProcess")).equals("yes")) 136 g2.setFont(g2.getFont().deriveFont((float) (12))); 137 else 138 g2.setFont(g2.getFont().deriveFont((float) (11))); 139 g2.setFont(g2.getFont().deriveFont(Font.ITALIC)); 140 141 String name = (String )props.get("name"); 142 g2.drawString(name, 11, y + 12); 143 } 144 } 145 146 } 147 | Popular Tags |