1:
43:
44: package ;
45:
46: import ;
47: import ;
48: import ;
49:
50: import ;
51: import ;
52:
53:
61: public class BevelArrowIcon implements Icon {
62:
63:
64: public static final int UP = 0;
65:
66:
67: public static final int DOWN = 1;
68:
69:
70: private static final int DEFAULT_SIZE = 11;
71:
72:
73: private Color edge1;
74:
75:
76: private Color edge2;
77:
78:
79: private Color fill;
80:
81:
82: private int size;
83:
84:
85: private int direction;
86:
87:
94: public BevelArrowIcon(final int direction,
95: final boolean isRaisedView,
96: final boolean isPressedView) {
97: if (isRaisedView) {
98: if (isPressedView) {
99: init(UIManager.getColor("controlLtHighlight"),
100: UIManager.getColor("controlDkShadow"),
101: UIManager.getColor("controlShadow"),
102: DEFAULT_SIZE, direction);
103: }
104: else {
105: init(UIManager.getColor("controlHighlight"),
106: UIManager.getColor("controlShadow"),
107: UIManager.getColor("control"),
108: DEFAULT_SIZE, direction);
109: }
110: }
111: else {
112: if (isPressedView) {
113: init(UIManager.getColor("controlDkShadow"),
114: UIManager.getColor("controlLtHighlight"),
115: UIManager.getColor("controlShadow"),
116: DEFAULT_SIZE, direction);
117: }
118: else {
119: init(UIManager.getColor("controlShadow"),
120: UIManager.getColor("controlHighlight"),
121: UIManager.getColor("control"),
122: DEFAULT_SIZE, direction);
123: }
124: }
125: }
126:
127:
136: public BevelArrowIcon(final Color edge1,
137: final Color edge2,
138: final Color fill,
139: final int size,
140: final int direction) {
141: init(edge1, edge2, fill, size, direction);
142: }
143:
144:
152: public void paintIcon(final Component c,
153: final Graphics g,
154: final int x,
155: final int y) {
156: switch (this.direction) {
157: case DOWN: drawDownArrow(g, x, y); break;
158: case UP: drawUpArrow(g, x, y); break;
159: }
160: }
161:
162:
167: public int getIconWidth() {
168: return this.size;
169: }
170:
171:
175: public int getIconHeight() {
176: return this.size;
177: }
178:
179:
188: private void init(final Color edge1,
189: final Color edge2,
190: final Color fill,
191: final int size,
192: final int direction) {
193: this.edge1 = edge1;
194: this.edge2 = edge2;
195: this.fill = fill;
196: this.size = size;
197: this.direction = direction;
198: }
199:
200:
207: private void drawDownArrow(final Graphics g, final int xo, final int yo) {
208: g.setColor(this.edge1);
209: g.drawLine(xo, yo, xo + this.size - 1, yo);
210: g.drawLine(xo, yo + 1, xo + this.size - 3, yo + 1);
211: g.setColor(this.edge2);
212: g.drawLine(xo + this.size - 2, yo + 1, xo + this.size - 1, yo + 1);
213: int x = xo + 1;
214: int y = yo + 2;
215: int dx = this.size - 6;
216: while (y + 1 < yo + this.size) {
217: g.setColor(this.edge1);
218: g.drawLine(x, y, x + 1, y);
219: g.drawLine(x, y + 1, x + 1, y + 1);
220: if (0 < dx) {
221: g.setColor(this.fill);
222: g.drawLine(x + 2, y, x + 1 + dx, y);
223: g.drawLine(x + 2, y + 1, x + 1 + dx, y + 1);
224: }
225: g.setColor(this.edge2);
226: g.drawLine(x + dx + 2, y, x + dx + 3, y);
227: g.drawLine(x + dx + 2, y + 1, x + dx + 3, y + 1);
228: x += 1;
229: y += 2;
230: dx -= 2;
231: }
232: g.setColor(this.edge1);
233: g.drawLine(
234: xo + (this.size / 2), yo + this.size - 1, xo + (this.size / 2), yo + this.size - 1
235: );
236: }
237:
238:
245: private void drawUpArrow(final Graphics g, final int xo, final int yo) {
246: g.setColor(this.edge1);
247: int x = xo + (this.size / 2);
248: g.drawLine(x, yo, x, yo);
249: x--;
250: int y = yo + 1;
251: int dx = 0;
252: while (y + 3 < yo + this.size) {
253: g.setColor(this.edge1);
254: g.drawLine(x, y, x + 1, y);
255: g.drawLine(x, y + 1, x + 1, y + 1);
256: if (0 < dx) {
257: g.setColor(this.fill);
258: g.drawLine(x + 2, y, x + 1 + dx, y);
259: g.drawLine(x + 2, y + 1, x + 1 + dx, y + 1);
260: }
261: g.setColor(this.edge2);
262: g.drawLine(x + dx + 2, y, x + dx + 3, y);
263: g.drawLine(x + dx + 2, y + 1, x + dx + 3, y + 1);
264: x -= 1;
265: y += 2;
266: dx += 2;
267: }
268: g.setColor(this.edge1);
269: g.drawLine(xo, yo + this.size - 3, xo + 1, yo + this.size - 3);
270: g.setColor(this.edge2);
271: g.drawLine(xo + 2, yo + this.size - 2, xo + this.size - 1, yo + this.size - 2);
272: g.drawLine(xo, yo + this.size - 1, xo + this.size, yo + this.size - 1);
273: }
274:
275: }