KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > tree > DefaultTreeCellRenderer


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: DefaultTreeCellRenderer.java,v $
11    Revision 1.5 2004/05/05 12:43:22 bobintetley
12    Patches/new files from Laurent Martell
13
14    Revision 1.4 2004/04/15 13:23:03 bobintetley
15    Default JTree images in cell renderer for folder/doc like Swing
16
17    Revision 1.3 2003/12/14 09:13:39 bobintetley
18    Added CVS log to source headers
19
20 */

21
22 package swingwtx.swing.tree;
23
24 import swingwtx.swing.*;
25 import swingwt.awt.*;
26
27 public class DefaultTreeCellRenderer extends JLabel implements TreeCellRenderer {
28     
29     protected boolean hasFocus;
30     protected boolean selected;
31     
32     public Component getTreeCellRendererComponent(swingwtx.swing.JTree tree,
33             Object JavaDoc value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
34          
35          this.hasFocus = hasFocus;
36          this.selected = selected;
37                 
38          // Default tree images
39
if (leaf)
40              if (expanded)
41                 setIcon(openIcon);
42              else
43                 setIcon(closedIcon);
44          else
45              setIcon(leafIcon);
46          
47          setText(value.toString());
48          return this;
49     }
50     
51     public Color getTextSelectionColor() { return SystemColor.controlHighlight; }
52     public Color getTextNonSelectionColor() { return SystemColor.controlText; }
53
54     ImageIcon leafIcon = new ImageIcon(getClass().getResource("/swingwtx/swing/tree/doc.gif"));
55     ImageIcon openIcon = new ImageIcon(getClass().getResource("/swingwtx/swing/tree/folderopen.gif"));
56     ImageIcon closedIcon = new ImageIcon(getClass().getResource("/swingwtx/swing/tree/folder.gif"));
57                                                                                                                                          
58     public Icon getLeafIcon() { return leafIcon; }
59     public Icon getOpenIcon() { return openIcon; }
60     public Icon getClosedIcon() { return closedIcon; }
61
62 }
63
Popular Tags