1 19 package org.openharmonise.workfloweditor.flowchart.shapes; 20 21 import java.awt.*; 22 import java.awt.geom.*; 23 24 import org.openharmonise.workfloweditor.flowchart.*; 25 26 27 34 public class ConnectionLine extends AbstractWorkflowShape implements MoveListener { 35 36 39 private Line2D.Float m_line = null; 40 41 44 private StageShape m_startShape = null; 45 46 49 private StageShape m_endShape = null; 50 51 54 private LineSelectionPoint m_selectionPoint = null; 55 56 59 private Paint m_drawColor = Color.BLACK; 60 61 67 public ConnectionLine(float x, float y) { 68 super(x, y); 69 this.m_line = new Line2D.Float(x,y,x,y); 70 this.m_selectionPoint = new LineSelectionPoint( new Point2D.Double(this.m_line.x2-((this.m_line.x2-this.m_line.x1)/2), this.m_line.y2-((this.m_line.y2-this.m_line.y1)/2)) ); 71 } 72 73 76 public void drawSelf(Graphics2D g) { 77 g.setStroke( new BasicStroke(2)); 78 g.setPaint( this.m_drawColor ); 79 g.draw(m_line); 80 81 double dHeight = m_line.getX1()-m_line.x2; 82 double dWidth = m_line.getY1()-m_line.getY2(); 83 double dLength = Math.sqrt( dHeight*dHeight + dWidth*dWidth ); 84 double percent = (15/dLength)*100; 85 86 Graphics2D g2 = (Graphics2D) g.create(); 87 g2.rotate(Math.toRadians(25), m_line.x2, m_line.y2); 88 Line2D.Float arrow1 = new Line2D.Float(m_line.x2, m_line.y2, new Double ( this.m_line.x2-(((this.m_line.x2-this.m_line.x1)/100)*percent) ).floatValue(), new Double (this.m_line.y2-(((this.m_line.y2-this.m_line.y1)/100)*percent)).floatValue() ); 89 g2.draw(arrow1); 90 91 Graphics2D g3 = (Graphics2D) g.create(); 92 g3.rotate(-Math.toRadians(25), m_line.x2, m_line.y2); 93 Line2D.Float arrow2 = new Line2D.Float(m_line.x2, m_line.y2, new Double ( this.m_line.x2-(((this.m_line.x2-this.m_line.x1)/100)*percent) ).floatValue(), new Double (this.m_line.y2-(((this.m_line.y2-this.m_line.y1)/100)*percent)).floatValue() ); 94 g3.draw(arrow2); 95 96 this.m_selectionPoint.draw(g); 97 } 98 99 104 public void setEndPoint(Point2D.Float endPoint) { 105 this.m_line.x2 = endPoint.x; 106 this.m_line.y2 = endPoint.y; 107 this.setSelectionPointPos(); 108 } 109 110 115 public void setSelected(boolean bSelected) { 116 if(bSelected) { 117 this.m_drawColor = new Color(254,204,101); 118 } else { 119 this.m_drawColor = Color.BLACK; 120 } 121 } 122 123 128 public void setStartShape(StageShape startShape) { 129 if(this.m_startShape!=null) { 130 this.m_startShape.removeMoveListener(this); 131 } 132 this.m_startShape = startShape; 133 this.m_startShape.addMoveListener(this); 134 this.setStartByShape(startShape); 135 } 136 137 142 public StageShape getStartShape() { 143 return this.m_startShape; 144 } 145 146 151 public void setEndShape(StageShape endShape) { 152 if(this.m_endShape!=null) { 153 this.m_endShape.removeMoveListener(this); 154 } 155 this.m_endShape = endShape; 156 this.m_endShape.addMoveListener(this); 157 this.setEndByShape(endShape); 158 } 159 160 165 public StageShape getEndShape() { 166 return this.m_endShape; 167 } 168 169 177 public boolean selectionPointContains(double x, double y) { 178 return this.m_selectionPoint.contains(x, y); 179 } 180 181 184 public void moved(AbstractWorkflowShape shape) { 185 if(shape instanceof StageShape) { 186 if(shape==this.m_startShape) { 187 this.setStartByShape((StageShape) shape); 188 } else if(shape==this.m_endShape) { 189 this.setEndByShape((StageShape) shape); 190 } 191 } 192 } 193 194 199 private void setStartByShape(StageShape shape) { 200 this.m_line.x1 = shape.getOutConnectionPoint().getX(); 201 this.m_line.y1 = shape.getOutConnectionPoint().getY(); 202 this.setSelectionPointPos(); 203 } 204 205 210 private void setEndByShape(StageShape shape) { 211 this.m_line.x2 = shape.getInConnectionPoint().getX(); 212 this.m_line.y2 = shape.getInConnectionPoint().getY(); 213 this.setSelectionPointPos(); 214 } 215 216 220 private void setSelectionPointPos() { 221 this.m_selectionPoint.setX(this.m_line.x2-((this.m_line.x2-this.m_line.x1)/2)); 222 this.m_selectionPoint.setY(this.m_line.y2-((this.m_line.y2-this.m_line.y1)/2)); 223 } 224 } 225 | Popular Tags |