KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > options > keymap > KeymapListRenderer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.options.keymap;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.JTree JavaDoc;
24 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
25 import org.netbeans.modules.options.keymap.Utils;
26 import org.openide.ErrorManager;
27
28 /**
29  *
30  * @author Jan Jancura
31  */

32 public class KeymapListRenderer extends DefaultTreeCellRenderer JavaDoc {
33
34     private KeymapViewModel keymapViewModel;
35     private static ErrorManager log = ErrorManager.getDefault ().getInstance
36         (KeymapListRenderer.class.getName ());
37
38
39     public KeymapListRenderer (KeymapViewModel keymapViewModel) {
40         if (keymapViewModel == null) throw new NullPointerException JavaDoc ();
41         this.keymapViewModel = keymapViewModel;
42         //Image i = Utilities.loadImage ("org/openide/resources/actions/empty.gif");
43
setLeafIcon (null);
44     }
45     
46     public Component JavaDoc getTreeCellRendererComponent (
47         JTree JavaDoc tree,
48         Object JavaDoc value,
49         boolean sel,
50         boolean expanded,
51         boolean leaf,
52         int row,
53         boolean hasFocus
54     ) {
55         super.getTreeCellRendererComponent (tree, value, sel, expanded, leaf, row, hasFocus);
56     
57     // There needs to be a way to specify disabled icons.
58
if (leaf) {
59             String JavaDoc displayName = ((ActionImpl) value).getDisplayName ();
60             StringBuffer JavaDoc text = new StringBuffer JavaDoc (displayName);
61             if (log.isLoggable (1)) {
62                 text.append (" <");
63                 text.append (((ActionImpl) value).getId ());
64                 text.append ("> ");
65             }
66             String JavaDoc[] shortcuts = keymapViewModel.getShortcuts ((ActionImpl) value);
67             if (shortcuts.length == 1)
68                 text.append (" [").append (shortcuts [0]).append ("]");
69             else
70             if (shortcuts.length > 1) {
71                 int i, k = shortcuts.length;
72                 text.append (" [").append (shortcuts [0]);
73                 for (i = 1; i < k; i++)
74                     text.append (",").append (shortcuts [i]);
75                 text.append ("]");
76             }
77 // if (value instanceof Action) {
78
// text += " " + ((Action) value).getValue (Action.NAME);
79
// }
80
setText (text.toString ());
81 // Icon icon = getLeafIcon (); //Utils.getIcon (value);
82
// if (icon != null) {
83
// if (tree.isEnabled ())
84
// setIcon (icon);
85
// else
86
// setDisabledIcon (icon);
87
// }
88
}
89     return this;
90     }
91 }
Popular Tags