1 /**
2 * JDateButton: Java Swing Date Button
3 * Copyright 2012,2014 Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ------------------------------------------------------------
17 * SubVersion Revision Information:
18 * $URL: https://svn.code.sf.net/p/jdatebutton/code/tags/v2.1.0-b3/jdatebutton-swing/src/main/java/net/sourceforge/jdatebutton/swing/ArrowIcon.java $
19 * $Revision: 34 $
20 * $Author: tonywasher $
21 * $Date: 2015-12-01 16:21:13 +0000 (Tue, 01 Dec 2015) $
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 * Arrow Icons.
34 */
35 public enum ArrowIcon implements Icon {
36 /**
37 * Up Arrow.
38 */
39 UP(new Point(1, 9), new Point(5, 1), new Point(9, 9)),
40
41 /**
42 * Down Arrow.
43 */
44 DOWN(new Point(1, 1), new Point(5, 9), new Point(9, 1)),
45
46 /**
47 * Left Arrow.
48 */
49 LEFT(new Point(1, 5), new Point(9, 1), new Point(9, 9)),
50
51 /**
52 * Right Arrow.
53 */
54 RIGHT(new Point(1, 1), new Point(1, 9), new Point(9, 5)),
55
56 /**
57 * DoubleUp Arrow.
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 * DoubleDown Arrow.
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 * DoubleLeft Arrow.
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 * DoubleRight Arrow.
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 * The size of the icon.
78 */
79 private static final int ICON_SIZE = 10;
80
81 /**
82 * The number of points.
83 */
84 private final transient int theNumPoints;
85
86 /**
87 * X locations of points.
88 */
89 private final transient int[] theXPoints;
90
91 /**
92 * Y Locations of points.
93 */
94 private final transient int[] theYPoints;
95
96 /**
97 * Constructor.
98 * @param pPoints the icon points
99 */
100 ArrowIcon(final Point... pPoints) {
101 /* Allocate arrays */
102 theNumPoints = pPoints.length;
103 theXPoints = new int[theNumPoints];
104 theYPoints = new int[theNumPoints];
105
106 /* Loop through the points */
107 for (int i = 0; i < theNumPoints; i++) {
108 /* Store locations */
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 /* Allocate new graphics context */
120 Graphics g2 = g.create(x, y, ICON_SIZE, ICON_SIZE);
121
122 /* Initialise graphics */
123 g2.setColor(Color.GRAY);
124 g2.drawPolygon(theXPoints, theYPoints, theNumPoints);
125
126 /* If the component is enabled */
127 if (c.isEnabled()) {
128 /* Colour in the polygon */
129 g2.setColor(Color.BLACK);
130 g2.fillPolygon(theXPoints, theYPoints, theNumPoints);
131 }
132
133 /* Dispose of the graphics context */
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 }