01: /*
02: * SortArrowIcon.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import java.awt.Color;
15: import java.awt.Component;
16: import java.awt.Graphics;
17:
18: import javax.swing.Icon;
19:
20: public class SortArrowIcon implements Icon {
21: public static final int UP = 1;
22: public static final int DOWN = 2;
23: public static final SortArrowIcon ARROW_UP = new SortArrowIcon(UP);
24: public static final SortArrowIcon ARROW_DOWN = new SortArrowIcon(
25: DOWN);
26: public static final SortArrowIcon SMALL_ARROW_UP = new SortArrowIcon(
27: UP, 6);
28: public static final SortArrowIcon SMALL_ARROW_DOWN = new SortArrowIcon(
29: DOWN, 6);
30: protected int direction;
31: protected int width = 8;
32: protected int height = 8;
33:
34: private SortArrowIcon(int dir, int size) {
35: this .direction = dir;
36: this .width = size;
37: this .height = size;
38: }
39:
40: private SortArrowIcon(int dir) {
41: this .direction = dir;
42: }
43:
44: public int getIconWidth() {
45: return width;
46: }
47:
48: public int getIconHeight() {
49: return height;
50: }
51:
52: public void paintIcon(Component c, Graphics g, int x, int y) {
53: Color bg = c.getBackground();
54: Color fg = c.getForeground();
55: Color light = bg.brighter();
56: Color shade = bg.darker();
57:
58: int w = width;
59: int h = height;
60: int m = w / 2;
61: if (direction == UP) {
62: g.setColor(shade);
63: g.drawLine(x, y, x + w, y);
64: g.drawLine(x, y, x + m, y + h);
65: g.setColor(light);
66: g.drawLine(x + w, y, x + m, y + h);
67: }
68: if (direction == DOWN) {
69: g.setColor(shade);
70: g.drawLine(x + m, y, x, y + h);
71: g.setColor(light);
72: g.drawLine(x, y + h, x + w, y + h);
73: g.drawLine(x + m, y, x + w, y + h);
74: }
75: g.setColor(fg);
76: }
77: }
|