KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > icon > ColumnControlIcon


1 /*
2  * $Id: ColumnControlIcon.java,v 1.2 2004/07/16 18:43:57 rameshgupta Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing.icon;
9
10 import java.awt.BorderLayout JavaDoc;
11 import java.awt.Color JavaDoc;
12 import java.awt.Component JavaDoc;
13 import java.awt.Graphics JavaDoc;
14
15 import javax.swing.Icon JavaDoc;
16 import javax.swing.JFrame JavaDoc;
17 import javax.swing.JLabel JavaDoc;
18
19 /**
20  * Icon class for rendering icon which indicates user control of
21  * column visibility.
22  * @author Amy Fowler
23  * @version 1.0
24  */

25 public class ColumnControlIcon implements Icon JavaDoc {
26     private int width = 10;
27     private int height = 10;
28
29     /**@todo: need to support small, medium, large */
30     public ColumnControlIcon() {
31     }
32
33     public int getIconWidth() {
34         return width;
35     }
36
37     public int getIconHeight() {
38         return height;
39     }
40
41     public void paintIcon(Component JavaDoc c, Graphics JavaDoc g, int x, int y) {
42         Color JavaDoc color = c.getForeground();
43         g.setColor(color);
44
45         // draw horizontal lines
46
g.drawLine(x, y, x+8, y);
47         g.drawLine(x, y+2, x+8, y+2);
48         g.drawLine(x, y+8, x+2, y+8);
49
50         // draw vertical lines
51
g.drawLine(x, y+1, x, y+7);
52         g.drawLine(x+4, y+1, x+4, y+4);
53         g.drawLine(x+8, y+1, x+8, y+4);
54
55         // draw arrow
56
g.drawLine(x+3, y+6, x+9, y+6);
57         g.drawLine(x+4, y+7, x+8, y+7);
58         g.drawLine(x+5, y+8, x+7, y+8);
59         g.drawLine(x+6, y+9, x+6, y+9);
60
61     }
62
63     public static void main(String JavaDoc args[]) {
64         JFrame JavaDoc frame = new JFrame JavaDoc();
65         JLabel JavaDoc label = new JLabel JavaDoc(new ColumnControlIcon());
66         frame.getContentPane().add(BorderLayout.CENTER, label);
67         frame.pack();
68         frame.setVisible(true); // RG: Changed from deprecated method show();
69
}
70
71 }
72
Popular Tags