1 31 32 package org.antlr.xjlib.appkit.gview.shape; 33 34 import org.antlr.xjlib.appkit.gview.base.Path2D; 35 import org.antlr.xjlib.appkit.gview.base.Vector2D; 36 import org.antlr.xjlib.appkit.gview.object.GElementRect; 37 38 public class SLinkElbowBottomBottom { 39 40 public static final int BOTTOM_BOTTOM = 0; 41 public static final int TOP_TOP = 1; 42 public static final int LABEL_OFFSET = 10; 43 44 public SLinkElbow link = null; 45 public Path2D path = null; 46 47 public SLinkElbowBottomBottom(SLinkElbow link) { 48 this.link = link; 49 } 50 51 public void updateBottomBottom() { 52 this.path = link.path; 53 if(Math.abs(link.end.x-link.start.x)>=GElementRect.DEFAULT_WIDTH*0.5+10) { 54 buildHorizontalPath(BOTTOM_BOTTOM); 55 } else { 56 if(link.start.y>=link.end.y) 58 buildHorizontalRightBelowPath(); 59 else 60 buildHorizontalRightAbovePath(); 61 } 62 } 63 64 public void updateTopTop() { 65 this.path = link.path; 66 if(Math.abs(link.end.x-link.start.x)>=GElementRect.DEFAULT_WIDTH*0.5+10) { 67 buildHorizontalPath(TOP_TOP); 68 } else { 69 if(link.start.y>=link.end.y) 71 buildHorizontalRightAbovePath(); 72 else 73 buildHorizontalRightBelowPath(); 74 } 75 } 76 77 public void buildHorizontalPath(int direction) { 78 Vector2D start_ = link.getStartWithOffset(); 79 Vector2D end_ = link.getEndWithOffset(); 80 81 if(link.offsetToMouse != null) { 82 double y = link.offsetToMouse.y+link.start.y; 83 start_.y = end_.y = y; 84 } 85 86 double farest_y = 0; 87 if(direction == BOTTOM_BOTTOM) 88 farest_y = Math.max(start_.y, end_.y); 89 else 90 farest_y = Math.min(start_.y, end_.y); 91 92 Vector2D p1 = start_.add(new Vector2D(0, farest_y-start_.y)); 93 Vector2D p2 = end_.add(new Vector2D(0, farest_y-end_.y)); 94 95 path.add(link.start); 96 path.add(start_); 97 path.add(p1); 98 path.add(p2); 99 path.add(end_); 100 path.add(link.end); 101 102 if(direction == BOTTOM_BOTTOM) 103 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, LABEL_OFFSET)); 104 else 105 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, -LABEL_OFFSET)); 106 } 107 108 public void buildHorizontalRightBelowPath() { 109 Vector2D start_ = link.getStartWithOffset(); 110 Vector2D end_ = link.getEndWithOffset(); 111 112 Vector2D start = link.start; 113 Vector2D end = link.end; 114 115 double farest_x = start_.x+GElementRect.DEFAULT_WIDTH*0.5+10; 116 117 119 Vector2D p1 = start_.add(new Vector2D(farest_x-start_.x, 0)); 120 Vector2D p2 = end_.add(new Vector2D(farest_x-end_.x, 0)); 121 122 path.add(start); 123 path.add(start_); 124 path.add(p1); 125 path.add(p2); 126 path.add(end_); 127 path.add(end); 128 129 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(LABEL_OFFSET, 0)); 130 } 131 132 public void buildHorizontalRightAbovePath() { 133 Vector2D start_ = link.getStartWithOffset(); 134 Vector2D end_ = link.getEndWithOffset(); 135 136 Vector2D start = link.start; 137 Vector2D end = link.end; 138 139 double farest_x = end_.x+GElementRect.DEFAULT_WIDTH*0.5+10; 140 141 143 Vector2D p1 = start_.add(new Vector2D(farest_x-start_.x, 0)); 144 Vector2D p2 = end_.add(new Vector2D(farest_x-end_.x, 0)); 145 146 path.add(start); 147 path.add(start_); 148 path.add(p1); 149 path.add(p2); 150 path.add(end_); 151 path.add(end); 152 153 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(LABEL_OFFSET, 0)); 154 } 155 156 } 157 | Popular Tags |