1 19 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.widget; 20 21 import java.awt.BasicStroke ; 22 import java.awt.Color ; 23 import java.awt.Graphics2D ; 24 import java.awt.Polygon ; 25 import java.awt.Rectangle ; 26 import java.awt.Stroke ; 27 28 import org.netbeans.api.visual.widget.Scene; 29 import org.netbeans.api.visual.widget.Widget; 30 31 38 public class ArrowWidget extends Widget { 39 40 private int _width = -1; 41 private int _height = 10; 42 private int _x = 0; 43 private int _y = 0; 44 private int _thickness = 1; 45 private Color _color = WidgetConstants.INPUT_OUTPUT_ARROW_COLOR; 46 private boolean mToEast; 47 private ParameterType _type; 48 private Stroke _stroke; 49 50 public static enum ParameterType { 51 52 INPUT, OUTPUT, FAULT 53 } 54 55 public ArrowWidget(Scene scene) { 56 super(scene); 57 } 58 59 60 61 public ArrowWidget(Scene scene, boolean toEast, ParameterType type) { 62 this(scene); 63 this.mToEast = toEast; 64 _type = type; 65 if (_type == ParameterType.INPUT) { 66 _stroke = new BasicStroke (_thickness); 67 } else { 68 _stroke = new BasicStroke (_thickness, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1, new float[]{5, 10, 5,10}, 0); 69 } 70 } 71 72 73 74 @Override 75 protected Rectangle calculateClientArea() { 76 Rectangle r = super.calculateClientArea(); 77 r.height = _height; 78 return r; 79 } 80 81 @Override 82 protected void paintWidget() { 83 Graphics2D gr = getGraphics(); 84 drawArrow(gr, _x, _y, getBounds().width, _height, _color, _stroke); 85 } 86 87 private void drawArrow(Graphics2D g, int x, int y , int width, int height, Color color, Stroke stroke) { 88 double heightOfTriangle = Math.sqrt(height * height * 5 / 4); 89 int heightOfTriangleInInt = new Double (heightOfTriangle).intValue(); 90 91 int x1 = x; 92 int width1 = width - heightOfTriangleInInt; 93 if (!mToEast) { 94 x1 = x + heightOfTriangleInInt; 95 } 96 Color origColor = g.getColor(); 97 Stroke origStroke = g.getStroke(); 98 99 g.setColor(color); 100 g.setStroke(stroke); 101 int y1 = y + height / 2; 102 g.drawLine(x1, y1, x1 + width1, y1); 103 104 Polygon p = new Polygon (); 105 106 int px1 = mToEast ? x + width1 : x + heightOfTriangleInInt; 107 int px2 = mToEast ? x + width : x; 108 int py1 = y; 109 int py2 = y + height; 110 int pyMidPoint = y + height / 2; 111 112 p.addPoint(px1, py1); 113 p.addPoint(px2, pyMidPoint); p.addPoint(px1, py2); 115 g.fillPolygon(p); 116 g.setColor(origColor); 117 g.setStroke(origStroke); 118 } 119 120 121 122 123 public Color getColor() { 124 return _color; 125 } 126 127 128 129 130 public void setColor(Color color) { 131 this._color = color; 132 } 133 134 135 136 137 public int getHeight() { 138 return _height; 139 } 140 141 142 143 144 public void setHeight(int height) { 145 this._height = height; 146 } 147 148 149 150 151 public int getThickness() { 152 return _thickness; 153 } 154 155 156 157 158 public void setThickness(int thickness) { 159 this._thickness = thickness; 160 } 161 162 163 164 165 public int getWidth() { 166 return _width; 167 } 168 169 170 171 172 public void setWidth(int width) { 173 this._width = width; 174 } 175 176 177 178 179 public int getX() { 180 return _x; 181 } 182 183 184 185 186 public void setX(int x) { 187 this._x = x; 188 } 189 190 191 192 193 public int getY() { 194 return _y; 195 } 196 197 198 199 200 public void setY(int y) { 201 this._y = y; 202 } 203 204 } 205 | Popular Tags |