1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sourceforge.jdatebutton.swing;
24
25 import java.awt.Color;
26 import java.awt.Component;
27 import java.awt.Graphics;
28 import java.awt.Point;
29
30 import javax.swing.Icon;
31
32
33
34
35 public enum ArrowIcon implements Icon {
36
37
38
39 UP(new Point(1, 9), new Point(5, 1), new Point(9, 9)),
40
41
42
43
44 DOWN(new Point(1, 1), new Point(5, 9), new Point(9, 1)),
45
46
47
48
49 LEFT(new Point(1, 5), new Point(9, 1), new Point(9, 9)),
50
51
52
53
54 RIGHT(new Point(1, 1), new Point(1, 9), new Point(9, 5)),
55
56
57
58
59 DOUBLEUP(new Point(1, 5), new Point(5, 1), new Point(9, 5), new Point(5, 5), new Point(9, 9), new Point(1, 9), new Point(5, 5)),
60
61
62
63
64 DOUBLEDOWN(new Point(1, 1), new Point(1, 9), new Point(5, 5), new Point(9, 5), new Point(5, 9), new Point(1, 5), new Point(5, 5)),
65
66
67
68
69 DOUBLELEFT(new Point(1, 5), new Point(5, 1), new Point(5, 5), new Point(9, 1), new Point(9, 9), new Point(5, 5), new Point(5, 9)),
70
71
72
73
74 DOUBLERIGHT(new Point(1, 1), new Point(1, 9), new Point(5, 5), new Point(5, 9), new Point(9, 5), new Point(5, 1), new Point(5, 5));
75
76
77
78
79 private static final int ICON_SIZE = 10;
80
81
82
83
84 private final transient int theNumPoints;
85
86
87
88
89 private final transient int[] theXPoints;
90
91
92
93
94 private final transient int[] theYPoints;
95
96
97
98
99
100 ArrowIcon(final Point... pPoints) {
101
102 theNumPoints = pPoints.length;
103 theXPoints = new int[theNumPoints];
104 theYPoints = new int[theNumPoints];
105
106
107 for (int i = 0; i < theNumPoints; i++) {
108
109 theXPoints[i] = pPoints[i].x;
110 theYPoints[i] = pPoints[i].y;
111 }
112 }
113
114 @Override
115 public void paintIcon(final Component c,
116 final Graphics g,
117 final int x,
118 final int y) {
119
120 Graphics g2 = g.create(x, y, ICON_SIZE, ICON_SIZE);
121
122
123 g2.setColor(Color.GRAY);
124 g2.drawPolygon(theXPoints, theYPoints, theNumPoints);
125
126
127 if (c.isEnabled()) {
128
129 g2.setColor(Color.BLACK);
130 g2.fillPolygon(theXPoints, theYPoints, theNumPoints);
131 }
132
133
134 g2.dispose();
135 }
136
137 @Override
138 public int getIconWidth() {
139 return ICON_SIZE;
140 }
141
142 @Override
143 public int getIconHeight() {
144 return ICON_SIZE;
145 }
146 }