1 19 package org.openharmonise.workfloweditor.flowchart; 20 21 import java.awt.event.*; 22 import java.awt.geom.*; 23 import java.util.*; 24 25 import javax.swing.event.*; 26 27 import org.openharmonise.workfloweditor.flowchart.shapes.*; 28 import org.openharmonise.workfloweditor.model.*; 29 30 31 39 public class ConnectMouseHandler extends MouseInputAdapter { 40 41 44 private FlowChart m_chart = null; 45 46 49 private AbstractWorkflowShape m_startShape = null; 50 51 54 private AbstractWorkflowShape m_endShape = null; 55 56 59 private ConnectionLine m_connectionLine = null; 60 61 66 public ConnectMouseHandler(FlowChart chart) { 67 super(); 68 this.m_chart = chart; 69 } 70 71 74 public void mouseDragged(MouseEvent me) { 75 if(this.m_connectionLine!=null) { 76 this.m_connectionLine.setEndPoint( new Point2D.Float(me.getX(), me.getY()) ); 77 this.m_chart.repaint(); 78 } 79 } 80 81 84 public void mousePressed(MouseEvent me) { 85 Iterator itor = this.m_chart.getShapes().iterator(); 86 while (itor.hasNext()) { 87 AbstractWorkflowShape shape = (AbstractWorkflowShape) itor.next(); 88 if(shape instanceof StageShape) { 89 StageShape stageShape = (StageShape) shape; 90 if(stageShape.outConnectionPointContains(me.getX(), me.getY())) { 91 this.m_startShape = stageShape; 92 this.m_connectionLine = new ConnectionLine(me.getX(), me.getY()); 93 this.m_chart.addTempShape(this.m_connectionLine); 94 break; 95 } 96 } 97 } 98 } 99 100 103 public void mouseReleased(MouseEvent me) { 104 boolean bFoundEnd = false; 105 Iterator itor = this.m_chart.getShapes().iterator(); 106 while (itor.hasNext()) { 107 AbstractWorkflowShape shape = (AbstractWorkflowShape) itor.next(); 108 if(shape instanceof StageShape) { 109 StageShape stageShape = (StageShape) shape; 110 if(stageShape.inConnectionPointContains(me.getX(), me.getY())) { 111 this.m_endShape = stageShape; 112 bFoundEnd = true; 113 break; 114 } 115 } 116 } 117 if(!bFoundEnd) { 118 this.m_chart.removeTempShape(this.m_connectionLine); 119 } else { 120 boolean bLooped = false; 121 122 WorkflowStage startStage = ((StageShape) this.m_startShape).getStage(); 123 WorkflowStage endStage = ((StageShape) this.m_endShape).getStage(); 124 if(startStage==endStage) { 125 bLooped=true; 126 } else { 127 itor = startStage.getDependancies().iterator(); 128 while (itor.hasNext()) { 129 WorkflowStage tempStage = (WorkflowStage) itor.next(); 130 if(tempStage==endStage) { 131 bLooped=true; 132 } else { 133 134 } 135 if(!bLooped && tempStage.getDependancies().size()>0 && this.isStageInDependancyPath(tempStage, endStage)) { 136 bLooped=true; 137 } 138 } 139 } 140 if(!bLooped) { 141 this.m_connectionLine.setStartShape((StageShape) this.m_startShape); 142 this.m_connectionLine.setEndShape((StageShape) this.m_endShape); 143 ((StageShape) this.m_endShape).addDependancy((StageShape) this.m_startShape); 144 this.m_chart.removeTempShape(this.m_connectionLine); 145 this.m_chart.addShape(this.m_connectionLine); 146 } else { 147 this.m_chart.removeTempShape(this.m_connectionLine); 148 } 149 } 150 this.m_connectionLine = null; 151 this.m_startShape = null; 152 this.m_endShape = null; 153 this.m_chart.repaint(); 154 } 155 156 163 private boolean isStageInDependancyPath(WorkflowStage stages, WorkflowStage checkStage) { 164 boolean bLooped = false; 165 Iterator itor = stages.getDependancies().iterator(); 166 while (itor.hasNext()) { 167 WorkflowStage tempStage = (WorkflowStage) itor.next(); 168 if(tempStage==checkStage) { 169 bLooped=true; 170 } else { 171 172 } 173 if(!bLooped && tempStage.getDependancies().size()>0 && this.isStageInDependancyPath(tempStage, checkStage)) { 174 bLooped=true; 175 } 176 } 177 return bLooped; 178 } 179 180 } 181 | Popular Tags |