1 /*
2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. 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.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * 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  */
39 @SuppressWarnings("serial") // JDK-implementation class
40 public class ClassicSortArrowIcon implements Icon, UIResource, Serializable{
41     private static final int X_OFFSET = 9;
42     private boolean ascending;
43 
ClassicSortArrowIcon(boolean ascending)44     public ClassicSortArrowIcon(boolean ascending) {
45         this.ascending = ascending;
46     }
47 
paintIcon(Component c, Graphics g, int x, int y)48     public void paintIcon(Component c, Graphics g, int x, int y) {
49         x += X_OFFSET;
50         if (ascending) {
51             g.setColor(UIManager.getColor("Table.sortIconHighlight"));
52             drawSide(g, x + 3, y, -1);
53 
54             g.setColor(UIManager.getColor("Table.sortIconLight"));
55             drawSide(g, x + 4, y, 1);
56 
57             g.fillRect(x + 1, y + 6, 6, 1);
58         }
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 
drawSide(Graphics g, int x, int y, int xIncrement)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         }
75         else {
76             g.fillRect(x, --y, 1, 2);
77             yIncrement = -2;
78             y -= 2;
79         }
80         x += xIncrement;
81         for (int i = 0; i < 2; i++) {
82             g.fillRect(x, y, 1, 3);
83             x += xIncrement;
84             y += yIncrement;
85         }
86         if (!ascending) {
87             y++;
88         }
89         g.fillRect(x, y, 1, 2);
90     }
91 
getIconWidth()92     public int getIconWidth() {
93         return X_OFFSET + 8;
94     }
getIconHeight()95     public int getIconHeight() {
96         return 9;
97     }
98 }
99