KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)MotifTreeUI.java 1.24 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 java.awt.*;
11 import java.awt.event.*;
12
13 import java.io.*;
14 import java.util.*;
15
16 import javax.swing.*;
17 import javax.swing.plaf.*;
18 import javax.swing.tree.*;
19 import javax.swing.plaf.basic.*;
20
21 /**
22  * Motif rendition of the tree component.
23  * <p>
24  * <strong>Warning:</strong>
25  * Serialized objects of this class will not be compatible with
26  * future Swing releases. The current serialization support is appropriate
27  * for short term storage or RMI between applications running the same
28  * version of Swing. A future release of Swing will provide support for
29  * long term persistence.
30  *
31  * @version 1.16 08/28/98
32  * @author Jeff Dinkins
33  */

34 public class MotifTreeUI extends BasicTreeUI
35 {
36     static final int HALF_SIZE = 7;
37     static final int SIZE = 14;
38
39     /**
40      * creates a UI object to represent a Motif Tree widget
41      */

42     public MotifTreeUI() {
43     super();
44     }
45
46     public void installUI(JComponent c) {
47     super.installUI(c);
48     }
49
50     // BasicTreeUI overrides
51

52     protected void paintVerticalLine( Graphics g, JComponent c, int x, int top, int bottom )
53       {
54           g.fillRect( x - 1, top, 2, bottom - top + 2 );
55       }
56
57     protected void paintHorizontalLine( Graphics g, JComponent c, int y, int left, int right )
58       {
59     g.fillRect( left - 1, y, right - left, 2 );
60       }
61
62
63     /**
64      * The minus sign button icon.
65      * <p>
66      * <strong>Warning:</strong>
67      * Serialized objects of this class will not be compatible with
68      * future Swing releases. The current serialization support is appropriate
69      * for short term storage or RMI between applications running the same
70      * version of Swing. A future release of Swing will provide support for
71      * long term persistence.
72      */

73     public static class MotifExpandedIcon implements Icon, Serializable {
74     static Color bg;
75     static Color fg;
76     static Color highlight;
77     static Color shadow;
78
79     public MotifExpandedIcon() {
80         bg = UIManager.getColor("Tree.iconBackground");
81         fg = UIManager.getColor("Tree.iconForeground");
82         highlight = UIManager.getColor("Tree.iconHighlight");
83         shadow = UIManager.getColor("Tree.iconShadow");
84     }
85
86         public static Icon createExpandedIcon() {
87         return new MotifExpandedIcon();
88         }
89
90     public void paintIcon(Component c, Graphics g, int x, int y) {
91         g.setColor(highlight);
92         g.drawLine(x, y, x+SIZE-1, y);
93         g.drawLine(x, y+1, x, y+SIZE-1);
94
95         g.setColor(shadow);
96         g.drawLine(x+SIZE-1, y+1, x+SIZE-1, y+SIZE-1);
97         g.drawLine(x+1, y+SIZE-1, x+SIZE-1, y+SIZE-1);
98
99         g.setColor(bg);
100         g.fillRect(x+1, y+1, SIZE-2, SIZE-2);
101
102         g.setColor(fg);
103         g.drawLine(x+3, y+HALF_SIZE-1, x+SIZE-4, y+HALF_SIZE-1);
104         g.drawLine(x+3, y+HALF_SIZE, x+SIZE-4, y+HALF_SIZE);
105     }
106
107     public int getIconWidth() { return SIZE; }
108     public int getIconHeight() { return SIZE; }
109     }
110
111     /**
112      * The plus sign button icon.
113      * <p>
114      * <strong>Warning:</strong>
115      * Serialized objects of this class will not be compatible with
116      * future Swing releases. The current serialization support is appropriate
117      * for short term storage or RMI between applications running the same
118      * version of Swing. A future release of Swing will provide support for
119      * long term persistence.
120      */

121     public static class MotifCollapsedIcon extends MotifExpandedIcon {
122         public static Icon createCollapsedIcon() {
123         return new MotifCollapsedIcon();
124         }
125
126     public void paintIcon(Component c, Graphics g, int x, int y) {
127         super.paintIcon(c, g, x, y);
128         g.drawLine(x + HALF_SIZE-1, y + 3, x + HALF_SIZE-1, y + (SIZE - 4));
129         g.drawLine(x + HALF_SIZE, y + 3, x + HALF_SIZE, y + (SIZE - 4));
130     }
131     }
132     
133     public static ComponentUI createUI(JComponent x) {
134     return new MotifTreeUI();
135     }
136
137     /**
138      * Returns the default cell renderer that is used to do the
139      * stamping of each node.
140      */

141     public TreeCellRenderer createDefaultCellRenderer() {
142     return new MotifTreeCellRenderer();
143     }
144
145 }
146
Popular Tags