KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > motif > MotifTreeCellRenderer


1 /*
2  * @(#)MotifTreeCellRenderer.java 1.16 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.java.swing.plaf.motif;
9
10 import javax.swing.*;
11 import javax.swing.plaf.*;
12 import javax.swing.tree.*;
13 import java.awt.*;
14 import java.awt.event.*;
15 import java.beans.*;
16 import java.io.*;
17 import java.util.*;
18
19 /**
20  * Motif rendered to display a tree cell.
21  * <p>
22  * <strong>Warning:</strong>
23  * Serialized objects of this class will not be compatible with
24  * future Swing releases. The current serialization support is appropriate
25  * for short term storage or RMI between applications running the same
26  * version of Swing. A future release of Swing will provide support for
27  * long term persistence.
28  *
29  * @version 1.16 12/19/03
30  * @author Jeff Dinkins
31  */

32 public class MotifTreeCellRenderer extends DefaultTreeCellRenderer
33 {
34     static final int LEAF_SIZE = 13;
35     static final Icon LEAF_ICON = new IconUIResource(new TreeLeafIcon());
36
37     public MotifTreeCellRenderer() {
38     super();
39     }
40
41     public static Icon loadLeafIcon() {
42     return LEAF_ICON;
43     }
44
45     /**
46      * Icon for a node with no children.
47      * <p>
48      * <strong>Warning:</strong>
49      * Serialized objects of this class will not be compatible with
50      * future Swing releases. The current serialization support is appropriate
51      * for short term storage or RMI between applications running the same
52      * version of Swing. A future release of Swing will provide support for
53      * long term persistence.
54      */

55     public static class TreeLeafIcon implements Icon, Serializable {
56
57     Color bg;
58     Color shadow;
59     Color highlight;
60
61     public TreeLeafIcon() {
62         bg = UIManager.getColor("Tree.iconBackground");
63         shadow = UIManager.getColor("Tree.iconShadow");
64         highlight = UIManager.getColor("Tree.iconHighlight");
65     }
66
67     public void paintIcon(Component c, Graphics g, int x, int y) {
68         g.setColor(bg);
69
70         y -= 3;
71         g.fillRect(x + 4, y + 7, 5, 5);
72
73         g.drawLine(x + 6, y + 6, x + 6, y + 6);
74         g.drawLine(x + 3, y + 9, x + 3, y + 9);
75         g.drawLine(x + 6, y + 12, x + 6, y + 12);
76         g.drawLine(x + 9, y + 9, x + 9, y + 9);
77
78         g.setColor(highlight);
79         g.drawLine(x + 2, y + 9, x + 5, y + 6);
80         g.drawLine(x + 3, y + 10, x + 5, y + 12);
81
82         g.setColor(shadow);
83         g.drawLine(x + 6, y + 13, x + 10, y + 9);
84         g.drawLine(x + 9, y + 8, x + 7, y + 6);
85     }
86     
87     public int getIconWidth() {
88         return LEAF_SIZE;
89     }
90     
91     public int getIconHeight() {
92         return LEAF_SIZE;
93     }
94     
95     }
96 }
97
Popular Tags