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 SLinkElbowLeftTop { 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 SLinkElbowLeftTop(SLinkElbow link) { 49 this.link = link; 50 } 51 52 public void updateRightTop() { 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 updateLeftTop() { 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 Vector2D p1 = new Vector2D(link.end.x, link.start.y-GElementRect.DEFAULT_HEIGHT*0.5-10); 90 Vector2D p2 = new Vector2D(start_.x, p1.y); 91 92 path.add(link.start); 93 path.add(start_); 94 path.add(p2); 95 path.add(p1); 96 path.add(link.end); 97 98 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, -LABEL_OFFSET)); 99 } else { 100 Vector2D ab = start_.sub(link.end); 101 Vector2D p1 = new Vector2D(link.end.x, link.end.y+ab.y*0.5); 102 Vector2D p2 = new Vector2D(p1.x+ab.x, p1.y); 103 Vector2D p3 = new Vector2D(p2.x, start_.y); 104 105 path.add(link.start); 106 path.add(start_); 107 path.add(p3); 108 path.add(p2); 109 path.add(p1); 110 path.add(link.end); 111 112 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, LABEL_OFFSET)); 113 } 114 } 115 116 public void buildHorizontalPath() { 117 Vector2D start_ = link.getStartWithOffset(); 118 Vector2D end_ = link.getEndWithOffset(); 119 120 Vector2D ab = link.start.sub(end_); 121 Vector2D p1 = new Vector2D(end_.x+ab.x*0.5, end_.y); 122 Vector2D p2 = new Vector2D(p1.x, start_.y); 123 124 path.add(link.start); 125 path.add(start_); 126 path.add(p2); 127 path.add(p1); 128 path.add(end_); 129 path.add(link.end); 130 131 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(LABEL_OFFSET, 0)); 132 } 133 134 public void buildHorizontalLeftPath(boolean left) { 135 Vector2D start_ = link.getStartWithOffset(); 136 Vector2D end_ = link.getEndWithOffset(); 137 138 double farest_x; 139 double farest_y = Math.min(end_.y, start_.y-GElementRect.DEFAULT_HEIGHT*0.5-10); 140 141 if(left) 142 farest_x = Math.min(end_.x-GElementRect.DEFAULT_WIDTH*0.5-10, start_.x); 143 else 144 farest_x = Math.max(end_.x+GElementRect.DEFAULT_WIDTH*0.5+10, start_.x); 145 146 Vector2D p1 = new Vector2D(end_.x, farest_y); 147 Vector2D p2 = new Vector2D(farest_x, p1.y); 148 Vector2D p3 = new Vector2D(p2.x, start_.y); 149 150 path.add(link.start); 151 path.add(p3); 152 path.add(p2); 153 path.add(p1); 154 path.add(end_); 155 path.add(link.end); 156 157 link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, -LABEL_OFFSET)); 158 } 159 160 } 161 | Popular Tags |