KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > contrib > javapro > SortArrowIcon


1 /*
2 =====================================================================
3
4   SortArrowIcon.java
5   
6   Created by Claude Duguay
7   Copyright (c) 2002
8   
9 =====================================================================
10 */

11
12 package contrib.javapro;
13
14 import java.awt.*;
15 import javax.swing.*;
16
17 public class SortArrowIcon
18   implements Icon
19 {
20   public static final int NONE = 0;
21   public static final int DECENDING = 1;
22   public static final int ASCENDING = 2;
23
24   protected int direction;
25   protected int width = 8;
26   protected int height = 8;
27   
28   public SortArrowIcon(int direction)
29   {
30     this.direction = direction;
31   }
32   
33   public int getIconWidth()
34   {
35     return width;
36   }
37   
38   public int getIconHeight()
39   {
40     return height;
41   }
42   
43   public void paintIcon(Component c, Graphics g, int x, int y)
44   {
45     Color bg = c.getBackground();
46     Color light = bg.brighter();
47     Color shade = bg.darker();
48   
49     int w = width;
50     int h = height;
51     int m = w / 2;
52     if (direction == ASCENDING)
53     {
54       g.setColor(shade);
55       g.drawLine(x, y, x + w, y);
56       g.drawLine(x, y, x + m, y + h);
57       g.setColor(light);
58       g.drawLine(x + w, y, x + m, y + h);
59     }
60     if (direction == DECENDING)
61     {
62       g.setColor(shade);
63       g.drawLine(x + m, y, x, y + h);
64       g.setColor(light);
65       g.drawLine(x, y + h, x + w, y + h);
66       g.drawLine(x + m, y, x + w, y + h);
67     }
68   }
69 }
70
71
Popular Tags