| 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.foundation.XJXMLSerializable; 38 39 import java.awt.*; 40 41 public class SLinkElbow extends SLink implements XJXMLSerializable { 42 43 protected SLinkElbowTopBottom topbottom = new SLinkElbowTopBottom(this); 44 protected SLinkElbowLeftRight leftright = new SLinkElbowLeftRight(this); 45 protected SLinkElbowBottomBottom bottombottom = new SLinkElbowBottomBottom(this); 46 protected SLinkElbowLeftLeft leftleft = new SLinkElbowLeftLeft(this); 47 protected SLinkElbowBottomLeft bottomleft = new SLinkElbowBottomLeft(this); 48 protected SLinkElbowTopLeft topleft = new SLinkElbowTopLeft(this); 49 protected SLinkElbowLeftTop lefttop = new SLinkElbowLeftTop(this); 50 protected SLinkElbowLeftBottom leftbottom = new SLinkElbowLeftBottom(this); 51 52 protected transient Path2D path = new Path2D(); 53 protected Vector2D offsetToMouse = null; 54 55 protected int outOffsetLength = 15; 56 57 public SLinkElbow() { 58 super(); 59 } 60 61 public void setOutOffsetLength(int length) { 62 this.outOffsetLength = length; 63 } 64 65 public Vector2D getStartWithOffset() { 66 return start.add(startDirection.vectorLength(outOffsetLength)); 67 } 68 69 public Vector2D getEndWithOffset() { 70 return end.add(endDirection.vectorLength(outOffsetLength)); 71 } 72 73 public void setMousePosition(Vector2D position) { 74 setOffsetToMouse(position.sub(start)); 75 } 76 77 public void setOffsetToMouse(Vector2D offset) { 78 this.offsetToMouse = offset; 79 } 80 81 public Vector2D getOffsetToMouse() { 82 return offsetToMouse; 83 } 84 85 public boolean contains(double x, double y) { 86 return path.contains(x, y); 87 } 88 89 public void update() { 90 path.clear(); 91 92 if(startDirection == Anchor2D.DIRECTION_BOTTOM && endDirection == Anchor2D.DIRECTION_TOP) 93 topbottom.updateBottomTop(); 94 else if(startDirection == Anchor2D.DIRECTION_TOP && endDirection == Anchor2D.DIRECTION_BOTTOM) 95 topbottom.updateTopBottom(); 96 else if(startDirection == Anchor2D.DIRECTION_LEFT && endDirection == Anchor2D.DIRECTION_RIGHT) 97 leftright.updateLeftRight(); 98 else if(startDirection == Anchor2D.DIRECTION_RIGHT && endDirection == Anchor2D.DIRECTION_LEFT) 99 leftright.updateRightLeft(); 100 else if(startDirection == Anchor2D.DIRECTION_BOTTOM && endDirection == Anchor2D.DIRECTION_BOTTOM) 101 bottombottom.updateBottomBottom(); 102 else if(startDirection == Anchor2D.DIRECTION_TOP && endDirection == Anchor2D.DIRECTION_TOP) 103 bottombottom.updateTopTop(); 104 else if(startDirection == Anchor2D.DIRECTION_LEFT && endDirection == Anchor2D.DIRECTION_LEFT) 105 leftleft.updateLeftLeft(); 106 else if(startDirection == Anchor2D.DIRECTION_RIGHT && endDirection == Anchor2D.DIRECTION_RIGHT) 107 leftleft.updateRightRight(); 108 else if(startDirection == Anchor2D.DIRECTION_BOTTOM && endDirection == Anchor2D.DIRECTION_LEFT) 109 bottomleft.updateBottomLeft(); 110 else if(startDirection == Anchor2D.DIRECTION_BOTTOM && endDirection == Anchor2D.DIRECTION_RIGHT) 111 bottomleft.updateBottomRight(); 112 else if(startDirection == Anchor2D.DIRECTION_TOP && endDirection == Anchor2D.DIRECTION_LEFT) 113 topleft.updateTopLeft(); 114 else if(startDirection == Anchor2D.DIRECTION_TOP && endDirection == Anchor2D.DIRECTION_RIGHT) 115 topleft.updateTopRight(); 116 else if(startDirection == Anchor2D.DIRECTION_LEFT && endDirection == Anchor2D.DIRECTION_TOP) 117 lefttop.updateLeftTop(); 118 else if(startDirection == Anchor2D.DIRECTION_RIGHT && endDirection == Anchor2D.DIRECTION_TOP) 119 lefttop.updateRightTop(); 120 else if(startDirection == Anchor2D.DIRECTION_LEFT && endDirection == Anchor2D.DIRECTION_BOTTOM) 121 leftbottom.updateLeftBottom(); 122 else if(startDirection == Anchor2D.DIRECTION_RIGHT && endDirection == Anchor2D.DIRECTION_BOTTOM) 123 leftbottom.updateRightBottom(); 124 else 125 topleft.updateTopLeft(); 126 } 127 128 public void draw(Graphics2D g) { 129 if(path == null || arrow == null || label == null) 130 return; 131 132 g.setColor(color); 133 134 drawShape(g); 135 label.draw(g); 136 } 137 138 public void drawShape(Graphics2D g) { 139 if(path == null || arrow == null || label == null) 140 return; 141 142 path.draw(g); 143 144 arrow.setAnchor(end); 145 arrow.setDirection(path.getEndDirection()); 146 arrow.draw(g); 147 } 148 149 } 150 | Popular Tags |