01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.admin.common;
05:
06: import java.awt.Color;
07: import java.awt.Component;
08: import java.awt.Graphics;
09:
10: import javax.swing.Icon;
11: import javax.swing.SwingConstants;
12: import javax.swing.UIManager;
13:
14: public class ArrowIcon implements Icon, SwingConstants {
15: private int direction;
16: private Color shadow;
17:
18: public ArrowIcon(int direction, Color shadow) {
19: setDirection(direction);
20: this .shadow = shadow;
21: }
22:
23: public ArrowIcon() {
24: this (SOUTH);
25: }
26:
27: public ArrowIcon(int direction) {
28: this (direction, UIManager.getColor("controlShadow"));
29: }
30:
31: public int getDirection() {
32: return direction;
33: }
34:
35: public void setDirection(int dir) {
36: direction = dir;
37: }
38:
39: public int getIconWidth() {
40: return 12;
41: }
42:
43: public int getIconHeight() {
44: return 12;
45: }
46:
47: public void paintIcon(Component c, Graphics g, int x, int y) {
48: int w = getIconWidth();
49: int h = getIconHeight();
50:
51: int size = Math.max(Math.min(h / 3, w / 3), 2);
52:
53: paintTriangle(g, x + (w - size) / 2, y + (h - size) / 2, size);
54: }
55:
56: public void paintTriangle(Graphics g, int x, int y, int size) {
57: Color oldColor = g.getColor();
58: int mid = (size / 2) - 1;
59: int j = 0;
60: int i;
61:
62: g.translate(x, y);
63: g.setColor(shadow);
64:
65: switch (direction) {
66: case NORTH:
67: for (i = 0; i < size; i++) {
68: g.drawLine(mid - i, i, mid + i, i);
69: }
70: break;
71: case SOUTH:
72: j = 0;
73: for (i = size - 1; i >= 0; i--) {
74: g.drawLine(mid - i, j, mid + i, j);
75: j++;
76: }
77: break;
78: case WEST:
79: for (i = 0; i < size; i++) {
80: g.drawLine(i, mid - i, i, mid + i);
81: }
82: break;
83: case EAST:
84: j = 0;
85: for (i = size - 1; i >= 0; i--) {
86: g.drawLine(j, mid - i, j, mid + i);
87: j++;
88: }
89: break;
90: }
91:
92: g.translate(-x, -y);
93: g.setColor(oldColor);
94: }
95: }
|