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.Path2D; 36 import org.antlr.xjlib.appkit.gview.base.Vector2D; 37 import org.antlr.xjlib.appkit.gview.object.GElementRect; 38 39 public class SLinkElbowLeftBottom { 40 41 public static final int TOP_BOTTOM = 0; 42 public static final int BOTTOM_TOP = 1; 43 public static final int LABEL_OFFSET = 10; 44 45 public SLinkElbow link = null; 46 public Path2D path = null; 47 48 public SLinkElbowLeftBottom(SLinkElbow link) { 49 this.link = link; 50 } 51 52 public void updateRightBottom() { 53 this.path = link.path; 54 if(link.getEndWithOffset().y<=link.start.y) 55 buildVerticalPath(); 56 else if(link.start.x+link.outOffsetLength<link.end.x-GElementRect.DEFAULT_WIDTH+10) 57 buildHorizontalPath(); 58 else 59 buildHorizontalLeftPath(false); 60 } 61 62 public void updateLeftBottom() { 63 this.path = link.path; 64 if(link.getEndWithOffset().y<=link.start.y) 65 buildVerticalPath(); 66 else if(link.start.x>link.end.x+GElementRect.DEFAULT_WIDTH+10) 67 buildHorizontalPath(); 68 else 69 buildHorizontalLeftPath(true); 70 } 71 72 public void buildVerticalPath() { 73 Vector2D start_ = link.getStartWithOffset(); 74 Vector2D end_ = link.getEndWithOffset(); 75 76 if(link.start.x > link.end.x+link.outOffsetLength && link.startDirection == Anchor2D.DIRECTION_LEFT) { 77 path.add(link.start); 78 path.add(link.end.x, link.start.y); 79 path.add(link.end); 80 81 link.label.setPosition(link.end.x+(link.start.x-link.end.x)*0.5, link.start.y-LABEL_OFFSET); 82 } else if(link.start.x < link.end.x-link.outOffsetLength && link.startDirection == Anchor2D.DIRECTION_RIGHT) { 83 path.add(link.start); 84 path.add(link.end.x, link.start.y); 85 path.add(link.end); 86 87 link.label.setPosition(link.end.x+(link.start.x-link.end.x)*0.5, link.start.y-LABEL_OFFSET); 88 } else if(link.start.y-GElementRect.DEFAULT_HEIGHT*0.5<end_.y+10) { 89 90 Vector2D p1 = new Vector2D(link.end.x, link.start.y+GElementRect.DEFAULT_HEIGHT*0.5+10); 91 Vector2D p2 = new Vector2D(start_.x, p1.y); 92 93 path.add(link.start); 94 path.add(start_); 95 path.add(p2); 96 path.add(p1); 97 path.add(link.end); 98 99 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, LABEL_OFFSET)); 100 } else { 101 Vector2D ab = start_.sub(link.end); 102 Vector2D p1 = new Vector2D(link.end.x, link.end.y+ab.y*0.5); 103 Vector2D p2 = new Vector2D(p1.x+ab.x, p1.y); 104 Vector2D p3 = new Vector2D(p2.x, start_.y); 105 106 path.add(link.start); 107 path.add(start_); 108 path.add(p3); 109 path.add(p2); 110 path.add(p1); 111 path.add(link.end); 112 113 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, -LABEL_OFFSET)); 114 } 115 } 116 117 public void buildHorizontalPath() { 118 Vector2D start_ = link.getStartWithOffset(); 119 Vector2D end_ = link.getEndWithOffset(); 120 121 Vector2D ab = link.start.sub(end_); 122 Vector2D p1 = new Vector2D(end_.x+ab.x*0.5, end_.y); 123 Vector2D p2 = new Vector2D(p1.x, start_.y); 124 125 path.add(link.start); 126 path.add(start_); 127 path.add(p2); 128 path.add(p1); 129 path.add(end_); 130 path.add(link.end); 131 132 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(LABEL_OFFSET, 0)); 133 } 134 135 public void buildHorizontalLeftPath(boolean left) { 136 Vector2D start_ = link.getStartWithOffset(); 137 Vector2D end_ = link.getEndWithOffset(); 138 139 double farest_x; 140 double farest_y = Math.max(end_.y, start_.y+GElementRect.DEFAULT_HEIGHT*0.5+10); 141 142 if(left) 143 farest_x = Math.min(end_.x-GElementRect.DEFAULT_WIDTH*0.5-10, start_.x); 144 else 145 farest_x = Math.max(end_.x+GElementRect.DEFAULT_WIDTH*0.5+10, start_.x); 146 147 Vector2D p1 = new Vector2D(end_.x, farest_y); 148 Vector2D p2 = new Vector2D(farest_x, p1.y); 149 Vector2D p3 = new Vector2D(p2.x, start_.y); 150 151 path.add(link.start); 152 path.add(p3); 153 path.add(p2); 154 path.add(p1); 155 path.add(end_); 156 path.add(link.end); 157 158 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, LABEL_OFFSET)); 159 } 160 161 } 162 | Popular Tags |