1 31 32 package org.antlr.xjlib.appkit.gview.shape; 33 34 import org.antlr.xjlib.appkit.gview.base.Anchor2D; 35 import org.antlr.xjlib.appkit.gview.base.Rect; 36 import org.antlr.xjlib.appkit.gview.base.Vector2D; 37 import org.antlr.xjlib.foundation.XJXMLSerializable; 38 39 import java.awt.*; 40 41 public abstract class SLink implements XJXMLSerializable { 42 43 protected Vector2D start; 44 protected Vector2D end; 45 46 protected Vector2D startDirection; 47 protected Vector2D endDirection; 48 49 protected Vector2D startOffset; 50 protected Vector2D endOffset; 51 52 protected double startTangentOffset; 53 protected double endTangentOffset; 54 55 protected Vector2D direction; 56 protected double flateness; 57 58 protected SArrow arrow = new SArrow(); 59 protected SLabel label = new SLabel(); 60 61 protected boolean selfLoop = false; 62 protected boolean arrowVisible = true; 63 64 protected Color color = Color.black; 65 66 68 protected transient Vector2D startWithOffset = null; 69 protected transient Vector2D endWithOffset = null; 70 71 public SLink() { 72 } 73 74 public void setStartAnchor(Anchor2D anchor) { 75 setStart(anchor.position); 76 setStartDirection(anchor.direction); 77 } 78 79 public void setEndAnchor(Anchor2D anchor) { 80 setEnd(anchor.position); 81 setEndDirection(anchor.direction); 82 } 83 84 public void setStart(Vector2D start) { 85 this.start = start.copy(); 86 computeOffsets(); 87 } 88 89 public void setStart(double x, double y) { 90 setStart(new Vector2D(x, y)); 91 } 92 93 public Vector2D getStart() { 94 return start; 95 } 96 97 public void setEnd(Vector2D end) { 98 this.end = end.copy(); 99 computeOffsets(); 100 } 101 102 public void setEnd(double x, double y) { 103 setEnd(new Vector2D(x, y)); 104 } 105 106 public void setEnd(Point p) { 107 end = Vector2D.vector(p); 108 } 109 110 public Vector2D getEnd() { 111 return end; 112 } 113 114 public void setDirection(Vector2D direction) { 115 this.direction = direction; 116 } 117 118 public Vector2D getDirection() { 119 return direction; 120 } 121 122 public void setFlateness(double flatness) { 123 this.flateness = flatness; 124 } 125 126 public double getFlateness() { 127 return flateness; 128 } 129 130 public void setStartDirection(Vector2D direction) { 131 this.startDirection = direction; 132 } 133 134 public Vector2D getStartDirection() { 135 return startDirection; 136 } 137 138 public void setEndDirection(Vector2D direction) { 139 this.endDirection = direction; 140 } 141 142 public Vector2D getEndDirection() { 143 return endDirection; 144 } 145 146 public void setStartTangentOffset(double offset) { 147 this.startTangentOffset = offset; 148 } 149 150 public double getStartTangentOffset() { 151 return startTangentOffset; 152 } 153 154 public void setEndTangentOffset(double offset) { 155 this.endTangentOffset = offset; 156 } 157 158 public double getEndTangentOffset() { 159 return endTangentOffset; 160 } 161 162 public void setStartOffset(Vector2D offset) { 163 this.startOffset = offset; 164 computeOffsets(); 165 } 166 167 public Vector2D getStartOffset() { 168 return startOffset; 169 } 170 171 public void setEndOffset(Vector2D offset) { 172 this.endOffset = offset; 173 computeOffsets(); 174 } 175 176 public Vector2D getEndOffset() { 177 return endOffset; 178 } 179 180 public void computeOffsets() { 181 startWithOffset = start; 182 endWithOffset = end; 183 184 if(start != null && startOffset != null) 185 startWithOffset = start.add(startOffset); 186 if(end != null && endOffset != null) 187 endWithOffset = end.add(endOffset); 188 } 189 190 public Vector2D getStartWithOffset() { 191 return startWithOffset; 192 } 193 194 public Vector2D getEndWithOffset() { 195 return endWithOffset; 196 } 197 198 public void setArrow(SArrow arrow) { 199 this.arrow = arrow; 200 } 201 202 public SArrow getArrow() { 203 return arrow; 204 } 205 206 public void setArrowVisible(boolean flag) { 207 this.arrowVisible = flag; 208 } 209 210 public void setLabel(String label) { 211 this.label.setTitle(label); 212 } 213 214 public void setLabel(SLabel label) { 215 this.label = label; 216 } 217 218 public SLabel getLabel() { 219 return label; 220 } 221 222 public void setSelfLoop(boolean selfLoop) { 223 this.selfLoop = selfLoop; 224 } 225 226 public boolean isSelfLoop() { 227 return selfLoop; 228 } 229 230 public void setColor(Color color) { 231 this.color = color; 232 } 233 234 public Color getColor() { 235 return color; 236 } 237 238 public void setLabelColor(Color color) { 239 label.setColor(color); 240 } 241 242 public void setLabelVisible(boolean flag) { 243 label.setVisible(flag); 244 } 245 246 public boolean isLabelVisible() { 247 return label.isVisible(); 248 } 249 250 public Rect getFrame() { 251 return new Rect(start, end); 252 } 253 254 public void setMousePosition(Vector2D position) { 255 256 } 257 258 public abstract boolean contains(double x, double y); 259 260 public abstract void update(); 261 public abstract void draw(Graphics2D g); 262 public abstract void drawShape(Graphics2D g); 263 264 } 265 | Popular Tags |