01: /*
02: * $Id: SortArrowIcon.java,v 1.3 2005/10/10 18:01:39 rbair Exp $
03: *
04: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
05: * Santa Clara, California 95054, U.S.A. All rights reserved.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20: */
21:
22: package org.jdesktop.swingx.icon;
23:
24: import java.awt.Color;
25: import java.awt.Component;
26: import java.awt.Graphics;
27:
28: import javax.swing.Icon;
29: import javax.swing.plaf.UIResource;
30:
31: public class SortArrowIcon implements Icon, UIResource {
32: private boolean ascending = true;
33: //REMIND(aim): support more configurable sizes
34: private int width = 8;
35: private int height = 8;
36:
37: public SortArrowIcon(boolean ascending) {
38: this .ascending = ascending;
39: }
40:
41: public int getIconWidth() {
42: return width;
43: }
44:
45: public int getIconHeight() {
46: return height;
47: }
48:
49: public void paintIcon(Component c, Graphics g, int x, int y) {
50: Color base = c.getBackground();
51: Color shadow = base.darker().darker();
52: Color highlight = Color.white;
53:
54: if (ascending) {
55: g.setColor(shadow);
56: int y1 = height - 1;
57: for (int x1 = 0; x1 < width / 2; x1++) {
58: g.drawLine(x + x1, y + y1, x + x1, y + y1 - 1);
59: y1 -= ((x1 + 1 == (width / 2) - 1) ? 1 : 2);
60: }
61: g.setColor(highlight);
62: y1 = height - 1;
63: for (int x1 = width - 1; x1 >= width / 2; x1--) {
64: g.drawLine(x + x1, y + y1, x + x1, y + y1 - 1);
65: y1 -= ((x1 - 1 == (width / 2)) ? 1 : 2);
66: }
67: g.drawLine(x + 1, y + height - 1, x + width - 1, y + height
68: - 1);
69: } else {
70: // descending
71: g.setColor(shadow);
72: int y1 = 1;
73: for (int x1 = 0; x1 < width / 2; x1++) {
74: g.drawLine(x + x1, y + y1, x + x1, y + y1 + 1);
75: y1 += (x1 + 1 == (width / 2 - 1)) ? 1 : 2;
76: }
77: g.setColor(highlight);
78: y1 = 1;
79: for (int x1 = width - 1; x1 >= width / 2; x1--) {
80: g.drawLine(x + x1, y + y1, x + x1, y + y1 + 1);
81: y1 += (x1 - 1 == width / 2) ? 1 : 2;
82: }
83: g.setColor(shadow);
84: g.drawLine(x + 1, y + 1, x + width - 1, y + 1);
85: }
86: }
87: }
|