1 19 package org.openharmonise.workfloweditor.flowchart.shapes; 20 21 import java.awt.*; 22 import java.awt.geom.*; 23 import java.util.*; 24 import java.util.List ; 25 26 import javax.swing.*; 27 28 import org.openharmonise.workfloweditor.model.*; 29 30 31 38 public class StageShape extends AbstractMoveableShape { 39 40 43 private ConnectionPoint m_inConnectionPoint = null; 44 45 48 private ConnectionPoint m_outConnectionPoint = null; 49 50 53 private JLabel m_label = null; 54 55 58 private JCheckBox m_isMandatory = null; 59 60 63 private JCheckBox m_isInheritable = null; 64 65 68 private int m_nWidth = 100; 69 70 73 private int m_nHeight = 80; 74 75 78 private ArrayList m_dependancies = new ArrayList(); 79 80 83 private WorkflowStage m_stage = null; 84 85 88 private ArrayList m_roles = new ArrayList(); 89 90 93 private boolean m_bHasOwnRoles = false; 94 95 102 public StageShape(float x, float y, WorkflowStage stage) { 103 super(x, y); 104 this.m_stage = stage; 105 m_label = new JLabel(this.m_stage.getTitle()); 106 m_isMandatory = new JCheckBox("Mandatory"); 107 if(this.m_stage.isMandatory()) { 108 m_isMandatory.setSelected(true); 109 } 110 m_isInheritable = new JCheckBox("Clear on edit"); 111 if(!this.m_stage.isInheritable()) { 112 m_isInheritable.setSelected(true); 113 } 114 if(this.m_isInheritable.getPreferredSize().width>this.m_label.getPreferredSize().width) { 115 this.m_nWidth = this.m_isInheritable.getPreferredSize().width+40; 116 } else { 117 this.m_nWidth = this.m_label.getPreferredSize().width+40; 118 } 119 super.setMoveControl( new Point2D.Double(x, y), this.m_nWidth, 20); 120 Iterator itor = stage.getModel().getAvailableRoles().iterator(); 121 while (itor.hasNext()) { 122 Role role = (Role) itor.next(); 123 RoleShape roleShape = new RoleShape(role, stage); 124 this.m_roles.add(roleShape); 125 if(roleShape.isSelected()) { 126 this.m_bHasOwnRoles=true; 127 } 128 m_nHeight = m_nHeight+20; 129 } 130 if(!this.m_bHasOwnRoles) { 131 Iterator itor2 = this.m_roles.iterator(); 132 while (itor2.hasNext()) { 133 RoleShape roleTemp = (RoleShape) itor2.next(); 134 if(this.m_stage.getDefinition().getRoles().contains(roleTemp.getRole())) { 135 roleTemp.setSelected(true, false); 136 } 137 } 138 } 139 this.setConnectionsPos(); 140 } 141 142 145 public void drawSelf(Graphics2D g) { 146 Graphics2D g1 = (Graphics2D) g.create(); 147 g1.setStroke(new BasicStroke(3)); 148 Rectangle2D.Float rect = new Rectangle2D.Float(this.getX(), this.getY(), this.m_nWidth, this.m_nHeight); 149 g1.setPaint(Color.WHITE); 150 g1.fill(rect); 151 g1.setPaint(Color.BLACK); 152 g1.draw(rect); 153 rect = new Rectangle2D.Float(this.getX(), this.getY(), this.m_nWidth, 20); 154 g1.setPaint(Color.LIGHT_GRAY); 155 g1.fill(rect); 156 g1.setPaint(Color.BLACK); 157 g1.draw(rect); 158 rect = new Rectangle2D.Float(this.getX()+this.m_nWidth-20, this.getY(), 20, 20); 159 g1.setPaint(Color.BLACK); 160 g1.draw(rect); 161 Line2D.Float line = new Line2D.Float(this.getX()+this.m_nWidth-15, this.getY()+5,this.getX()+this.m_nWidth-5, this.getY()+15); 162 g1.draw(line); 163 line = new Line2D.Float(this.getX()+this.m_nWidth-5, this.getY()+5,this.getX()+this.m_nWidth-15, this.getY()+15); 164 g1.draw(line); 165 166 this.m_inConnectionPoint.draw(g1); 167 this.m_outConnectionPoint.draw(g1); 168 this.m_inConnectionPoint.draw(g1); 169 this.m_outConnectionPoint.draw(g1); 170 int x = new Float (this.getX()).intValue(); 171 int y = new Float (this.getY()).intValue(); 172 173 this.m_label.setSize(this.m_label.getPreferredSize()); 174 Graphics2D g2 = (Graphics2D) g.create(); 175 g2.translate(x+10, y+2); 176 this.m_label.paint(g2); 177 178 this.m_isMandatory.setSize(this.m_isMandatory.getPreferredSize()); 179 this.m_isMandatory.setBackground(Color.WHITE); 180 Graphics2D g3 = (Graphics2D) g.create(); 181 g3.translate(x+3, y+22); 182 this.m_isMandatory.paint(g3); 183 184 this.m_isInheritable.setSize(this.m_isInheritable.getPreferredSize()); 185 this.m_isInheritable.setBackground(Color.WHITE); 186 Graphics2D g4 = (Graphics2D) g.create(); 187 g4.translate(x+3, y+42); 188 this.m_isInheritable.paint(g4); 189 190 g.setPaint(Color.BLACK); 191 g.setStroke( new BasicStroke(1)); 192 g.draw( new Line2D.Float(x+10, y+66, x+this.m_nWidth-10, y+66) ); 193 194 int nYpos = y+72; 195 196 Iterator itor = this.m_roles.iterator(); 197 while (itor.hasNext()) { 198 RoleShape roleShape = (RoleShape) itor.next(); 199 roleShape.setSize(roleShape.getPreferredSize()); 200 roleShape.setBackground(Color.WHITE); 201 Rectangle2D.Float rectTemp = new Rectangle2D.Float(x+2, nYpos, roleShape.getPreferredSize().width, roleShape.getPreferredSize().height); 202 roleShape.setRect(rectTemp); 203 Graphics2D gTemp = (Graphics2D) g.create(); 204 gTemp.setPaint(Color.BLACK); 205 gTemp.translate(x+3, nYpos); 206 roleShape.paint(gTemp); 207 nYpos = nYpos+20; 208 } 209 } 210 211 215 private void setConnectionsPos() { 216 if(this.m_inConnectionPoint==null) { 217 this.m_inConnectionPoint = new ConnectionPoint(this.getX()+this.m_nWidth/2, this.getY()-5); 218 } else { 219 this.m_inConnectionPoint.setX(this.getX()+this.m_nWidth/2); 220 this.m_inConnectionPoint.setY(this.getY()-5); 221 } 222 if(this.m_outConnectionPoint==null) { 223 this.m_outConnectionPoint = new ConnectionPoint(this.getX()+this.m_nWidth/2, this.getY()+this.m_nHeight+5); 224 225 } else { 226 this.m_outConnectionPoint.setX(this.getX()+this.m_nWidth/2); 227 this.m_outConnectionPoint.setY(this.getY()+this.m_nHeight+5); 228 229 } 230 } 231 232 237 public ConnectionPoint getInConnectionPoint() { 238 return this.m_inConnectionPoint; 239 } 240 241 246 public ConnectionPoint getOutConnectionPoint() { 247 return this.m_outConnectionPoint; 248 } 249 250 258 public boolean inConnectionPointContains(double x, double y) { 259 return this.m_inConnectionPoint.contains(x, y); 260 } 261 262 270 public boolean outConnectionPointContains(double x, double y) { 271 return this.m_outConnectionPoint.contains(x, y); 272 } 273 274 281 public boolean mandatoryContains(double x, double y) { 282 Rectangle2D.Float rect = new Rectangle2D.Float(this.getX()+3, this.getY()+30, this.m_isMandatory.getWidth(), 15); 283 return rect.contains(new Double (x).intValue(), new Double (y).intValue()); 284 } 285 286 293 public boolean inheritableContains(double x, double y) { 294 Rectangle2D.Float rect = new Rectangle2D.Float(this.getX()+3, this.getY()+50, this.m_isInheritable.getWidth(), 15); 295 return rect.contains(new Double (x).intValue(), new Double (y).intValue()); 296 } 297 298 305 public boolean closeContains(double x, double y) { 306 Rectangle2D.Float rect = new Rectangle2D.Float(this.getX()+this.m_nWidth-20, this.getY(), 20, 20); 307 return rect.contains(new Double (x).intValue(), new Double (y).intValue()); 308 } 309 310 314 public void mandatoryClicked() { 315 this.m_stage.setMandatory(!this.m_isMandatory.isSelected()); 316 this.m_isMandatory.setSelected(this.m_stage.isMandatory()); 317 } 318 319 323 public void inheritableClicked() { 324 this.m_stage.setInheritable(this.m_isInheritable.isSelected()); 325 this.m_isInheritable.setSelected(!this.m_stage.isInheritable()); 326 } 327 328 331 public void setX(float x) { 332 super.setX(x); 333 this.setConnectionsPos(); 334 } 335 336 339 public void setY(float y) { 340 super.setY(y); 341 this.setConnectionsPos(); 342 } 343 344 349 public void addDependancy(StageShape shape) { 350 this.m_dependancies.add(shape); 351 this.m_stage.addDependancy(shape.getStage()); 352 } 353 354 359 public void removeDependancy(StageShape shape) { 360 this.m_dependancies.remove(shape); 361 this.m_stage.removeDependancy(shape.getStage()); 362 } 363 364 369 public List getDependancies() { 370 return (List ) this.m_dependancies.clone(); 371 } 372 373 378 public WorkflowStage getStage() { 379 return this.m_stage; 380 } 381 382 388 public void mouseClicked(double x, double y) { 389 if(this.inheritableContains(x, y)) { 390 this.inheritableClicked(); 391 } else if(this.mandatoryContains(x, y)) { 392 this.mandatoryClicked(); 393 } else { 394 Iterator itor = this.m_roles.iterator(); 395 while (itor.hasNext()) { 396 RoleShape roleShape = (RoleShape) itor.next(); 397 if(roleShape.contains(x, y)) { 398 if(!this.m_bHasOwnRoles) { 399 Iterator itor2 = this.m_roles.iterator(); 400 while (itor2.hasNext()) { 401 RoleShape roleTemp = (RoleShape) itor2.next(); 402 if(roleTemp.isSelected()) { 403 roleTemp.setSelected(true, true); 404 } 405 } 406 this.m_bHasOwnRoles = true; 407 } 408 if(roleShape.isSelected()) { 409 410 int nSelectedCount = 0; 411 Iterator itor2 = this.m_roles.iterator(); 412 while (itor2.hasNext()) { 413 RoleShape checkRole = (RoleShape) itor2.next(); 414 if(checkRole.isSelected()) { 415 nSelectedCount++; 416 } 417 } 418 if(nSelectedCount>1) { 419 roleShape.setSelected(false, true); 420 } 421 } else { 422 roleShape.setSelected(true, true); 423 } 424 } 425 } 426 } 427 } 428 429 436 public boolean contains(double x, double y) { 437 Rectangle2D.Float rect = new Rectangle2D.Float(this.getX(), this.getY(), this.m_nWidth, this.m_nHeight); 438 return rect.contains(x, y); 439 } 440 441 } 442 | Popular Tags |