01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: ArrowIcon.java,v 1.8 2005/02/16 11:28:11 jesper Exp $
23: package net.infonode.gui.icon.button;
24:
25: import net.infonode.util.Direction;
26:
27: import java.awt.*;
28:
29: public class ArrowIcon extends AbstractButtonIcon {
30: private Direction direction;
31:
32: public ArrowIcon(Direction direction) {
33: this .direction = direction;
34: }
35:
36: public ArrowIcon(Color color, Direction direction) {
37: super (color);
38: this .direction = direction;
39: }
40:
41: public ArrowIcon(Color color, int size, Direction direction) {
42: super (color, size);
43: this .direction = direction;
44: }
45:
46: public ArrowIcon(int size, Direction direction) {
47: this (size, direction, true);
48: }
49:
50: public ArrowIcon(int size, Direction direction, boolean enabled) {
51: super (size, enabled);
52: this .direction = direction;
53: }
54:
55: public Direction getDirection() {
56: return direction;
57: }
58:
59: protected void paintIcon(Component c, Graphics g, int x1, int y1,
60: int x2, int y2) {
61: int size = (x2 - x1 + 1) + ((x2 - x1 + 1) % 2) - 1;
62: int offset = (direction.isHorizontal() ? x1 : y1)
63: + (direction == Direction.RIGHT
64: || direction == Direction.DOWN ? (size + 1) / 4
65: : (size - (size + 1) / 2) / 2);
66: int o2 = direction.isHorizontal() ? y1 : x1;
67: int[] c1 = direction == Direction.DOWN
68: || direction == Direction.RIGHT ? new int[] { offset,
69: offset, offset + size / 2 + 1 } : new int[] {
70: offset + size / 2 + 1, offset + size / 2 + 1,
71: offset - (direction == Direction.UP ? 1 : 0) };
72: int[] c2 = { o2 + (direction == Direction.DOWN ? 0 : -1),
73: o2 + size + (direction == Direction.UP ? 1 : 0),
74: o2 + size / 2 };
75: g.fillPolygon(direction.isHorizontal() ? c1 : c2, direction
76: .isHorizontal() ? c2 : c1, 3);
77: }
78: }
|