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