1 package org.wcb.util;
2 /***
3 * Copyright (C) 1999 Walter Bogaardt
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 *
19 */
20
21 import java.awt.Color;
22 import java.awt.Component;
23 import java.awt.Graphics;
24 import javax.swing.UIManager;
25 import javax.swing.Icon;
26
27
28
29
30 public class BevelArrowIcon implements Icon {
31 public static final int UP = 0;
32 public static final int DOWN = 1;
33
34 private static final int DEFAULT_SIZE = 11;
35
36 private Color edge1;
37 private Color edge2;
38 private Color fill;
39 private int size;
40 private int direction;
41
42 public BevelArrowIcon(int direction, boolean isRaisedView, boolean isPressedView) {
43 if (isRaisedView) {
44 if (isPressedView) {
45 init( UIManager.getColor("controlLtHighlight"),
46 UIManager.getColor("controlDkShadow"),
47 UIManager.getColor("controlShadow"),
48 DEFAULT_SIZE, direction);
49 } else {
50 init( UIManager.getColor("controlHighlight"),
51 UIManager.getColor("controlShadow"),
52 UIManager.getColor("control"),
53 DEFAULT_SIZE, direction);
54 }
55 } else {
56 if (isPressedView) {
57 init( UIManager.getColor("controlDkShadow"),
58 UIManager.getColor("controlLtHighlight"),
59 UIManager.getColor("controlShadow"),
60 DEFAULT_SIZE, direction);
61 } else {
62 init( UIManager.getColor("controlShadow"),
63 UIManager.getColor("controlHighlight"),
64 UIManager.getColor("control"),
65 DEFAULT_SIZE, direction);
66 }
67 }
68 }
69
70 public BevelArrowIcon(Color edge1, Color edge2, Color fill,
71 int size, int direction) {
72 init(edge1, edge2, fill, size, direction);
73 }
74
75
76 public void paintIcon(Component c, Graphics g, int x, int y) {
77 switch (direction) {
78 case DOWN: drawDownArrow(g, x, y); break;
79 case UP: drawUpArrow(g, x, y); break;
80 }
81 }
82
83 public int getIconWidth() {
84 return size;
85 }
86
87 public int getIconHeight() {
88 return size;
89 }
90
91
92 private void init(Color edge1, Color edge2, Color fill,
93 int size, int direction) {
94 this.edge1 = edge1;
95 this.edge2 = edge2;
96 this.fill = fill;
97 this.size = size;
98 this.direction = direction;
99 }
100
101 private void drawDownArrow(Graphics g, int xo, int yo) {
102 g.setColor(edge1);
103 g.drawLine(xo, yo, xo+size-1, yo);
104 g.drawLine(xo, yo+1, xo+size-3, yo+1);
105 g.setColor(edge2);
106 g.drawLine(xo+size-2, yo+1, xo+size-1, yo+1);
107 int x = xo+1;
108 int y = yo+2;
109 int dx = size-6;
110 while (y+1 < yo+size) {
111 g.setColor(edge1);
112 g.drawLine(x, y, x+1, y);
113 g.drawLine(x, y+1, x+1, y+1);
114 if (0 < dx) {
115 g.setColor(fill);
116 g.drawLine(x+2, y, x+1+dx, y);
117 g.drawLine(x+2, y+1, x+1+dx, y+1);
118 }
119 g.setColor(edge2);
120 g.drawLine(x+dx+2, y, x+dx+3, y);
121 g.drawLine(x+dx+2, y+1, x+dx+3, y+1);
122 x += 1;
123 y += 2;
124 dx -= 2;
125 }
126 g.setColor(edge1);
127 g.drawLine(xo+(size/2), yo+size-1, xo+(size/2), yo+size-1);
128 }
129
130 private void drawUpArrow(Graphics g, int xo, int yo) {
131 g.setColor(edge1);
132 int x = xo+(size/2);
133 g.drawLine(x, yo, x, yo);
134 x--;
135 int y = yo+1;
136 int dx = 0;
137 while (y+3 < yo+size) {
138 g.setColor(edge1);
139 g.drawLine(x, y, x+1, y);
140 g.drawLine(x, y+1, x+1, y+1);
141 if (0 < dx) {
142 g.setColor(fill);
143 g.drawLine(x+2, y, x+1+dx, y);
144 g.drawLine(x+2, y+1, x+1+dx, y+1);
145 }
146 g.setColor(edge2);
147 g.drawLine(x+dx+2, y, x+dx+3, y);
148 g.drawLine(x+dx+2, y+1, x+dx+3, y+1);
149 x -= 1;
150 y += 2;
151 dx += 2;
152 }
153 g.setColor(edge1);
154 g.drawLine(xo, yo+size-3, xo+1, yo+size-3);
155 g.setColor(edge2);
156 g.drawLine(xo+2, yo+size-2, xo+size-1, yo+size-2);
157 g.drawLine(xo, yo+size-1, xo+size, yo+size-1);
158 }
159
160
161 }