01: /*
02: * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25: package sun.swing.plaf.windows;
26:
27: import java.awt.Color;
28: import java.awt.Component;
29: import java.awt.Graphics;
30: import java.io.Serializable;
31: import javax.swing.Icon;
32: import javax.swing.UIManager;
33: import javax.swing.plaf.UIResource;
34:
35: /**
36: * Classic sort icons.
37: *
38: * @version 1.8, 05/05/07
39: */
40: public class ClassicSortArrowIcon implements Icon, UIResource,
41: Serializable {
42: private static final int X_OFFSET = 9;
43: private boolean ascending;
44:
45: public ClassicSortArrowIcon(boolean ascending) {
46: this .ascending = ascending;
47: }
48:
49: public void paintIcon(Component c, Graphics g, int x, int y) {
50: x += X_OFFSET;
51: if (ascending) {
52: g.setColor(UIManager.getColor("Table.sortIconHighlight"));
53: drawSide(g, x + 3, y, -1);
54:
55: g.setColor(UIManager.getColor("Table.sortIconLight"));
56: drawSide(g, x + 4, y, 1);
57:
58: g.fillRect(x + 1, y + 6, 6, 1);
59: } else {
60: g.setColor(UIManager.getColor("Table.sortIconHighlight"));
61: drawSide(g, x + 3, y + 6, -1);
62: g.fillRect(x + 1, y, 6, 1);
63:
64: g.setColor(UIManager.getColor("Table.sortIconLight"));
65: drawSide(g, x + 4, y + 6, 1);
66: }
67: }
68:
69: private void drawSide(Graphics g, int x, int y, int xIncrement) {
70: int yIncrement = 2;
71: if (ascending) {
72: g.fillRect(x, y, 1, 2);
73: y++;
74: } else {
75: g.fillRect(x, --y, 1, 2);
76: yIncrement = -2;
77: y -= 2;
78: }
79: x += xIncrement;
80: for (int i = 0; i < 2; i++) {
81: g.fillRect(x, y, 1, 3);
82: x += xIncrement;
83: y += yIncrement;
84: }
85: if (!ascending) {
86: y++;
87: }
88: g.fillRect(x, y, 1, 2);
89: }
90:
91: public int getIconWidth() {
92: return X_OFFSET + 8;
93: }
94:
95: public int getIconHeight() {
96: return 9;
97: }
98: }
|