2
* Copyright (c) 2005-2010 Flamingo Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of Flamingo Kirill Grouchnikov nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
package org.pushingpixels.flamingo.internal.utils;
33
import java.awt.geom.GeneralPath;
35
import javax.swing.SwingConstants;
36
import javax.swing.SwingUtilities;
38
import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
41
* Helper implementation of {@link ResizableIcon} that draws a double arrow.
43
* @author Kirill Grouchnikov
45
public class DoubleArrowResizableIcon implements ResizableIcon {
49
private Dimension initialDim;
52
* The width of the rendered image.
57
* The height of the rendered image.
62
* Arrow direction. One of {@link SwingConstants#SOUTH},
63
* {@link SwingConstants#NORTH}, {@link SwingConstants#EAST} or
64
* {@link SwingConstants#WEST}.
66
protected int direction;
69
* Creates a new double arrow resizable icon.
72
* Initial icon dimension.
74
* Arrow direction. Currently only {@link SwingConstants#SOUTH}
77
public DoubleArrowResizableIcon(Dimension initialDim, int direction) {
78
this.initialDim = initialDim;
79
this.width = initialDim.width;
80
this.height = initialDim.height;
81
this.direction = direction;
85
* Creates a new double arrow resizable icon.
88
* Initial icon dimension.
90
* Arrow direction. Currently only {@link SwingConstants#SOUTH}
93
public DoubleArrowResizableIcon(int initialDim, int direction) {
94
this(new Dimension(initialDim, initialDim), direction);
97
public void revertToOriginalDimension() {
98
this.width = initialDim.width;
99
this.height = initialDim.height;
103
public void setDimension(Dimension newDimension) {
104
this.width = newDimension.width;
105
this.height = newDimension.height;
109
public int getIconHeight() {
114
public int getIconWidth() {
118
protected boolean toPaintEnabled(Component c) {
119
return c.isEnabled();
123
public void paintIcon(Component c, Graphics g, int x, int y) {
124
Graphics2D graphics = (Graphics2D) g.create();
125
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
126
RenderingHints.VALUE_ANTIALIAS_ON);
128
Color arrowColor = this.toPaintEnabled(c) ? Color.black : Color.gray;
129
graphics.setColor(arrowColor);
130
Stroke stroke = new BasicStroke(this.width / 8.0f,
131
BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
133
graphics.setStroke(stroke);
134
graphics.translate(x, y);
135
GeneralPath gp = new GeneralPath();
136
int arrowHeight = height / 2;
137
int arrowWidth = width / 2;
138
int deltaH = (height + 2) / 3;
139
int deltaW = (width + 2) / 3;
141
case SwingUtilities.NORTH:
142
gp.moveTo(0, height - 1);
143
gp.lineTo((float) 0.5 * (width - 1), height - 1 - arrowHeight);
144
gp.lineTo(width - 1, height - 1);
146
gp.moveTo(0, height - 1 - deltaH);
147
gp.lineTo((float) 0.5 * (width - 1), height - 1 - arrowHeight
149
gp.lineTo(width - 1, height - 1 - deltaH);
153
case SwingUtilities.SOUTH:
155
gp.lineTo((float) 0.5 * (width - 1), arrowHeight);
156
gp.lineTo(width - 1, 0);
158
gp.moveTo(0, deltaH);
159
gp.lineTo((float) 0.5 * (width - 1), arrowHeight + deltaH);
160
gp.lineTo(width - 1, deltaH);
164
case SwingUtilities.EAST:
166
gp.lineTo(arrowWidth, (float) 0.5 * (height - 1));
167
gp.lineTo(0, height - 1);
169
gp.moveTo(deltaW, 0);
170
gp.lineTo(arrowWidth + deltaW, (float) 0.5 * (height - 1));
171
gp.lineTo(deltaW, height - 1);
175
case SwingUtilities.WEST:
176
gp.moveTo(width - 1, 0);
177
gp.lineTo(width - 1 - arrowWidth, (float) 0.5 * (height - 1));
178
gp.lineTo(width - 1, height - 1);
180
gp.moveTo(width - 1 - deltaW, 0);
181
gp.lineTo(width - 1 - arrowWidth - deltaW, (float) 0.5
183
gp.lineTo(width - 1 - deltaW, height - 1);