blob: 0b14c4858499a168ea309463784154ac47c436d3 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * 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 */
25package sun.swing.plaf.windows;
26
27import java.awt.Color;
28import java.awt.Component;
29import java.awt.Graphics;
30import java.io.Serializable;
31import javax.swing.Icon;
32import javax.swing.UIManager;
33import javax.swing.plaf.UIResource;
34
35/**
36 * Classic sort icons.
37 *
38 */
39public class ClassicSortArrowIcon implements Icon, UIResource, Serializable{
40 private static final int X_OFFSET = 9;
41 private boolean ascending;
42
43 public ClassicSortArrowIcon(boolean ascending) {
44 this.ascending = ascending;
45 }
46
47 public void paintIcon(Component c, Graphics g, int x, int y) {
48 x += X_OFFSET;
49 if (ascending) {
50 g.setColor(UIManager.getColor("Table.sortIconHighlight"));
51 drawSide(g, x + 3, y, -1);
52
53 g.setColor(UIManager.getColor("Table.sortIconLight"));
54 drawSide(g, x + 4, y, 1);
55
56 g.fillRect(x + 1, y + 6, 6, 1);
57 }
58 else {
59 g.setColor(UIManager.getColor("Table.sortIconHighlight"));
60 drawSide(g, x + 3, y + 6, -1);
61 g.fillRect(x + 1, y, 6, 1);
62
63 g.setColor(UIManager.getColor("Table.sortIconLight"));
64 drawSide(g, x + 4, y + 6, 1);
65 }
66 }
67
68 private void drawSide(Graphics g, int x, int y, int xIncrement) {
69 int yIncrement = 2;
70 if (ascending) {
71 g.fillRect(x, y, 1, 2);
72 y++;
73 }
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 public int getIconHeight() {
95 return 9;
96 }
97}