001: /*
002: * ArrowIcon.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing.table;
023:
024: import java.awt.Color;
025: import java.awt.Component;
026: import java.awt.Graphics;
027:
028: import javax.swing.UIManager;
029: import javax.swing.Icon;
030:
031: /* ----------------------------------------------------------
032: * CVS NOTE: Changes to the CVS repository prior to the
033: * release of version 3.0.0beta1 has meant a
034: * resetting of CVS revision numbers.
035: * ----------------------------------------------------------
036: */
037:
038: /**
039: * A simple arrow icon for all directions.
040: *
041: * @author Takis Diakoumis
042: * @version $Revision: 1.5 $
043: * @date $Date: 2006/07/15 15:39:46 $
044: */
045: public class ArrowIcon implements Icon {
046:
047: // direction constants
048: public static final int UP = 0;
049: public static final int DOWN = 1;
050: public static final int RIGHT = 2;
051: public static final int LEFT = 2;
052:
053: private static final int DEFAULT_SIZE = 10;
054:
055: private int direction;
056: private Color fillColour;
057:
058: public ArrowIcon(int direction) {
059: fillColour = UIManager.getColor("controlShadow");
060: this .direction = direction;
061: }
062:
063: public ArrowIcon(Color fillColour, int direction) {
064: this .fillColour = fillColour;
065: this .direction = direction;
066: }
067:
068: public void paintIcon(Component c, Graphics g, int x, int y) {
069:
070: switch (direction) {
071:
072: case DOWN:
073: drawDownArrow(g, x - 1, y);
074: break;
075:
076: case UP:
077: drawUpArrow(g, x - 1, y);
078: break;
079:
080: case RIGHT:
081: drawRightArrow(g, x - 1, y);
082: break;
083:
084: }
085:
086: }
087:
088: public int getIconWidth() {
089: return DEFAULT_SIZE;
090: }
091:
092: public int getIconHeight() {
093: return DEFAULT_SIZE;
094: }
095:
096: private void drawRightArrow(Graphics g, int xo, int yo) {
097: g.setColor(fillColour);
098:
099: int x = 0, y = 0;
100:
101: for (int i = 1; i <= DEFAULT_SIZE; i++) {
102:
103: y = yo + i + 1;
104:
105: if (i > DEFAULT_SIZE / 2) {
106:
107: for (int j = DEFAULT_SIZE - i; j >= 1; j--) {
108: x = xo + j;
109: g.drawLine(x, y, x, y);
110: }
111:
112: }
113:
114: else {
115:
116: for (int j = 1; j <= i; j++) {
117: x = xo + j;
118: g.drawLine(x, y, x, y);
119: }
120:
121: }
122:
123: }
124: }
125:
126: private void drawDownArrow(Graphics g, int xo, int yo) {
127: g.setColor(fillColour);
128:
129: int x = 0, y = 0;
130:
131: for (int i = 1; i <= DEFAULT_SIZE; i++) {
132:
133: y = yo + i + 2;
134:
135: for (int j = i; j <= DEFAULT_SIZE; j++) {
136:
137: if (j > DEFAULT_SIZE - i) {
138: break;
139: }
140:
141: x = xo + j;
142: g.drawLine(x, y, x, y);
143:
144: }
145:
146: }
147: }
148:
149: private void drawUpArrow(Graphics g, int xo, int yo) {
150: g.setColor(fillColour);
151:
152: int yOffset = yo + 2 + (DEFAULT_SIZE / 2);
153: int x = 0, y = 0;
154:
155: for (int i = DEFAULT_SIZE; i >= 1; i--) {
156:
157: y = yOffset - i;
158:
159: for (int j = i; j <= DEFAULT_SIZE; j++) {
160:
161: if (j > DEFAULT_SIZE - i) {
162: break;
163: }
164:
165: x = xo + j;
166: g.drawLine(x, y, x, y);
167:
168: }
169:
170: }
171:
172: }
173:
174: }
|