Changeset 50 for trunk/src/org/expeditee/items/Line.java
- Timestamp:
- 05/16/08 10:25:28 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Line.java
r21 r50 81 81 82 82 // initialise the line size 83 float thick; 84 85 if (_start instanceof Dot && _end instanceof Dot) 86 thick = (((Dot) _start).getThickness() + ((Dot) _end) 87 .getThickness()) / 2.0f; 88 else if (_start instanceof Dot) 89 thick = ((Dot) _start).getThickness(); 90 else if (_end instanceof Dot) 91 thick = ((Dot) _end).getThickness(); 92 else 83 float thick = (_start.getThickness() + _end.getThickness()) / 2.0f; 84 85 if (thick < 0) 93 86 thick = 1; 87 /* 88 * if (_start instanceof Dot && _end instanceof Dot) thick = (((Dot) 89 * _start).getThickness() + ((Dot) _end) .getThickness()) / 2.0f; else 90 * if (_start instanceof Dot) thick = ((Dot) _start).getThickness(); 91 * else if (_end instanceof Dot) thick = ((Dot) _end).getThickness(); 92 * else thick = 1; 93 */ 94 94 95 95 setThickness(thick); … … 134 134 135 135 /** 136 * Replaces either the start or end point of this Line with the given Dot. 137 * This is used when merging two Dots. 136 * Replaces either the start or end point of this Line with the given 137 * LineEnd. This is used when merging LineEnds. It will also add and remove 138 * the line from the LineEnds as well as adjust constraints. 138 139 * 139 140 * @param replace … … 144 145 */ 145 146 public void replaceEnd(Item replace, Item with) { 146 if (_start == replace) 147 Item otherEnd = null; 148 if (_start == replace) { 147 149 setStartItem(with); 148 else 150 otherEnd = _end; 151 } else if (_end == replace) { 149 152 setEndItem(with); 153 otherEnd = _start; 154 } 155 // if no end was replaced 156 if (otherEnd == null) 157 return; 158 // Copy the constraints list so the endPoints list can be modified 159 List<Constraint> constraints = new ArrayList<Constraint>(replace 160 .getConstraints()); 161 // Now change all the constraints for this line only 162 for (int i = 0; i < constraints.size(); i++) { 163 Constraint c = constraints.get(i); 164 if (c.contains(otherEnd)) { 165 c.replaceEnd(replace, with); 166 } 167 } 150 168 } 151 169 … … 154 172 _start.removeLine(this); 155 173 156 if (!(start instanceof Dot)) { 157 _startOffset.x = _start.getX() - start.getX(); 158 _startOffset.y = _start.getY() - start.getY(); 159 } else { 174 /* 175 * if (!(start instanceof Dot)) { _startOffset.x = _start.getX() - 176 * start.getX(); _startOffset.y = _start.getY() - start.getY(); } 177 * else 178 */{ 160 179 _startOffset.x = 0; 161 180 _startOffset.y = 0; … … 172 191 _end.removeLine(this); 173 192 174 if (!(end instanceof Dot)) {175 _endOffset.x = _end.getX() - end.getX();176 _endOffset.y = _end.getY() - end.getY();177 } else{193 /* 194 * if (!(end instanceof Dot)) { _endOffset.x = _end.getX() - 195 * end.getX(); _endOffset.y = _end.getY() - end.getY(); } else 196 */{ 178 197 _endOffset.x = 0; 179 198 _endOffset.y = 0; … … 211 230 } 212 231 232 @Override 213 233 public void setX(int x) { 214 234 } 215 235 236 @Override 216 237 public void setY(int y) { 217 238 } … … 287 308 g.setColor(getPaintColor()); 288 309 289 // if (this._mode == Item.SelectedMode.Disconnect)290 // 291 310 // if (this._mode == Item.SelectedMode.Disconnect) 311 // System.out.println("Disconnect mode!"); 312 292 313 if (_start instanceof Text && ((Text) _start).startsWith("@c")) { 293 314 g.setStroke(_lineStroke); … … 340 361 Point endOffset) { 341 362 // only draw an arrowhead if necessary 342 if (!(this._mode == Item.SelectedMode.Disconnect 343 && withArrow._mode == Item.SelectedMode.Disconnect) 344 && (!withArrow.hasVisibleArrow() 345 || withArrow.getLines().size() > 1)) 363 if (!(this._mode == Item.SelectedMode.Disconnect && withArrow._mode == Item.SelectedMode.Disconnect) 364 && (!withArrow.hasVisibleArrow() || withArrow.getLines().size() > 1)) 346 365 return; 347 366 … … 356 375 double arrowRatio = withArrow.getArrowheadRatio(); 357 376 358 // set the size of the disconnect indicator arrowhead359 if (this._mode == Item.SelectedMode.Disconnect) {360 // System.out.println("Disconnect mode!");377 // set the size of the disconnect indicator arrowhead 378 if (this._mode == Item.SelectedMode.Disconnect) { 379 // System.out.println("Disconnect mode!"); 361 380 arrowLength = 15; 362 381 arrowRatio = 0.3; 363 // Make sure the arrowhead positions get recalculated382 // Make sure the arrowhead positions get recalculated 364 383 withArrow.setArrowhead(null); 365 384 } 366 385 367 386 // if the arrowhead is 'auto', then one and only one end must be 368 387 // floating … … 489 508 return end; 490 509 } else if (distStart < DISCONNECT_THRESHHOLD) { 491 start._mode = Item.SelectedMode.Disconnect; 510 if (start.getLines().size() > 1 511 || start.getConstraints().size() > 0) 512 start._mode = Item.SelectedMode.Disconnect; 513 else 514 start._mode = Item.SelectedMode.Normal; 492 515 return start; 493 516 } else if (distEnd < DISCONNECT_THRESHHOLD) { 494 end._mode = Item.SelectedMode.Disconnect; 517 if (end.getLines().size() > 1 || end.getConstraints().size() > 0) 518 end._mode = Item.SelectedMode.Disconnect; 519 else 520 end._mode = Item.SelectedMode.Normal; 495 521 return end; 496 522 } … … 520 546 super.setColor(c); 521 547 522 if (_start.getColor() != c) 523 _start.setColor(c); 524 525 if (_end.getColor() != c) 526 _end.setColor(c); 527 } 528 529 @Override 530 public int getSize() { 531 return _start.getSize(); 532 } 533 534 @Override 535 public void setSize(int size) { 548 _start.lineColorChanged(c); 549 _end.lineColorChanged(c); 536 550 } 537 551 … … 543 557 thick = DEFAULT_THICKNESS; 544 558 545 if (_start instanceof Dot) { 546 Dot start = (Dot) _start; 547 if (start.getThickness() != thick) 548 start.setThickness(thick); 549 } 550 551 if (_end instanceof Dot) { 552 Dot end = (Dot) _end; 553 if (end.getThickness() != thick) 554 end.setThickness(thick); 555 } 559 if (_start.getThickness() != thick) 560 _start.setThickness(thick); 561 562 if (_end.getThickness() != thick) 563 _end.setThickness(thick); 556 564 557 565 int[] pattern = _start.getLinePattern(); … … 734 742 private Dot _virtualSpot = null; 735 743 736 public void showVirtualSpot( Dotorig, int mouseX, int mouseY) {744 public void showVirtualSpot(Item orig, int mouseX, int mouseY) { 737 745 if (orig.getLines().size() != 1) 738 746 return; … … 742 750 return; 743 751 744 Dot spot = orig.copy(); 752 Dot spot = new Dot(-1, orig.getX(), orig.getY()); 753 Item.DuplicateItem(orig, spot); 745 754 spot.setThickness(Math.max(this.getThickness(), 5)); 746 755 if (this.getColor() != Color.RED) … … 817 826 } 818 827 819 public Item forceMerge(Item merger, int mouseX, int mouseY) { 820 Dot spot = (Dot) merger; 821 822 if (spot.getConstraints() != null) 823 spot.getConstraints().clear(); 824 825 if (_end.getConstraints() != null) 826 _end.getConstraints().clear(); 827 828 if (_start.getConstraints() != null) 829 _start.getConstraints().clear(); 828 public Item forceMerge(Item spot, int mouseX, int mouseY) { 829 830 spot.removeAllConstraints(); 831 832 _end.removeAllConstraints(); 833 834 _start.removeAllConstraints(); 830 835 831 836 // calculate nearest point on line from spot … … 840 845 // if the line is horizontal 841 846 if (slope1 == 0) { 842 x = merger.getX();847 x = spot.getX(); 843 848 y = _start.getY(); 844 849 // if the line is vertical 845 850 } else if (slope2 == 0) { 846 851 x = _start.getX(); 847 y = merger.getY();852 y = spot.getY(); 848 853 // otherwise, the line is sloped 849 854 } else { … … 875 880 @Override 876 881 public Item merge(Item merger, int mouseX, int mouseY) { 877 if (!(merger instanceof Dot))882 if (!(merger.isLineEnd())) 878 883 return merger; 879 884 880 Dot spot = (Dot)merger;885 Item spot = merger; 881 886 882 887 // dots with multiple lines cannot be attached, nor can dots with no … … 1015 1020 _end.delete(); 1016 1021 } 1022 1023 @Override 1024 public void anchor() { 1025 super.anchor(); 1026 fixArrowheadLength(); 1027 } 1028 1029 /** 1030 * Removes constraints from the end points of this line. 1031 */ 1032 @Override 1033 public void removeAllConstraints() { 1034 // Find all constraints that include both the start and end. 1035 for (Constraint c : _start.getConstraints()) { 1036 if (c.contains(_end)) { 1037 _start.removeConstraint(c); 1038 _end.removeConstraint(c); 1039 } 1040 } 1041 } 1017 1042 }
Note:
See TracChangeset
for help on using the changeset viewer.