1 19 20 package org.netbeans.modules.options.keymap; 21 22 import java.awt.Component ; 23 import javax.swing.JTree ; 24 import javax.swing.tree.DefaultTreeCellRenderer ; 25 import org.netbeans.modules.options.keymap.Utils; 26 import org.openide.ErrorManager; 27 28 32 public class KeymapListRenderer extends DefaultTreeCellRenderer { 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 (); 41 this.keymapViewModel = keymapViewModel; 42 setLeafIcon (null); 44 } 45 46 public Component getTreeCellRendererComponent ( 47 JTree tree, 48 Object 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 if (leaf) { 59 String displayName = ((ActionImpl) value).getDisplayName (); 60 StringBuffer text = new StringBuffer (displayName); 61 if (log.isLoggable (1)) { 62 text.append (" <"); 63 text.append (((ActionImpl) value).getId ()); 64 text.append ("> "); 65 } 66 String [] 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 setText (text.toString ()); 81 } 89 return this; 90 } 91 } | Popular Tags |