1 31 32 package org.antlr.xjlib.appkit.gview.shape; 33 34 import org.antlr.xjlib.appkit.gview.base.Vector2D; 35 import org.antlr.xjlib.foundation.XJXMLSerializable; 36 37 import java.awt.*; 38 39 public class SArrow implements XJXMLSerializable { 40 41 protected Vector2D anchor = null; 42 protected Vector2D direction = null; 43 44 protected double length = 10; 45 protected double angle = 45; 46 47 public SArrow() { 48 49 } 50 51 public void setAnchor(double x, double y) { 52 anchor = new Vector2D(x, y); 53 } 54 55 public void setAnchor(Vector2D anchor) { 56 this.anchor = anchor; 57 } 58 59 public Vector2D getAnchor() { 60 return anchor; 61 } 62 63 public void setDirection(Vector2D direction) { 64 if(direction != null) 65 this.direction = direction.copy(); 66 else 67 this.direction = null; 68 } 69 70 public Vector2D getDirection() { 71 return direction; 72 } 73 74 public void setLength(double length) { 75 this.length = length; 76 } 77 78 public double getLength() { 79 return length; 80 } 81 82 public void setAngle(double angle) { 83 this.angle = angle; 84 } 85 86 public double getAngle() { 87 return angle; 88 } 89 90 public void draw(Graphics g) { 91 if(direction == null || anchor == null) 92 return; 93 94 Vector2D v = direction.copy(); 95 v.setLength(length); 96 97 v.rotate(angle*0.5); 98 g.drawLine((int)anchor.getX(), (int)anchor.getY(), (int)(anchor.getX()+v.getX()), (int)(anchor.getY()+v.getY())); 99 100 v.rotate(-angle); 101 g.drawLine((int)anchor.getX(), (int)anchor.getY(), (int)(anchor.getX()+v.getX()), (int)(anchor.getY()+v.getY())); 102 } 103 104 } 105 | Popular Tags |