1 6 7 package org.netbeans.modules.java.navigation; 8 9 import java.awt.BorderLayout ; 10 import java.awt.Rectangle ; 11 import javax.swing.Action ; 12 import javax.swing.KeyStroke ; 13 import java.awt.Toolkit ; 14 import java.awt.event.KeyEvent ; 15 import javax.swing.JLabel ; 16 import javax.swing.SwingUtilities ; 17 import javax.swing.border.EmptyBorder ; 18 import javax.swing.KeyStroke ; 19 import javax.swing.event.ChangeEvent ; 20 import org.netbeans.modules.java.navigation.ClassMemberFilters; 21 import org.netbeans.modules.java.navigation.ElementNode; 22 import org.netbeans.modules.java.navigation.ElementNode.Description; 23 import org.netbeans.modules.java.navigation.ElementNode.Description; 24 import org.netbeans.modules.java.navigation.actions.FilterSubmenuAction; 25 import org.netbeans.modules.java.navigation.actions.SortActionSupport.SortByNameAction; 26 import org.netbeans.modules.java.navigation.actions.SortActionSupport.SortBySourceAction; 27 import org.netbeans.modules.java.navigation.base.FiltersManager; 28 import org.openide.nodes.Node; 29 import org.openide.util.NbBundle; 30 import org.openide.util.Utilities; 31 import org.netbeans.modules.java.navigation.base.TapPanel; 32 import org.openide.explorer.ExplorerManager; 33 import org.openide.explorer.view.BeanTreeView; 34 import org.openide.filesystems.FileObject; 35 import org.openide.util.Lookup; 36 37 41 public class ClassMemberPanelUI extends javax.swing.JPanel 42 implements ExplorerManager.Provider, FiltersManager.FilterChangeListener { 43 44 private ExplorerManager manager = new ExplorerManager(); 45 private BeanTreeView elementView; 46 private TapPanel filtersPanel; 47 private JLabel filtersLbl; 48 private Lookup lookup = null; private ClassMemberFilters filters; 50 51 private Action [] actions; 53 private static final Rectangle ZERO = new Rectangle (0,0,1,1); 54 55 56 57 public ClassMemberPanelUI() { 58 59 initComponents(); 60 61 elementView = createBeanTreeView(); 63 add(elementView, BorderLayout.CENTER); 64 65 filtersPanel = new TapPanel(); 67 filtersLbl = new JLabel (NbBundle.getMessage(ClassMemberPanelUI.class, "LBL_Filter")); filtersLbl.setBorder(new EmptyBorder (0, 5, 5, 0)); 69 filtersPanel.add(filtersLbl); 70 filtersPanel.setOrientation(TapPanel.DOWN); 71 KeyStroke toggleKey = KeyStroke.getKeyStroke(KeyEvent.VK_T, 73 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); 74 String keyText = Utilities.keyToString(toggleKey); 75 filtersPanel.setToolTipText(NbBundle.getMessage(ClassMemberPanelUI.class, "TIP_TapPanel", keyText)); 76 77 filters = new ClassMemberFilters( this ); 78 filters.getInstance().hookChangeListener(this); 79 filtersPanel.add(filters.getComponent()); 80 81 actions = new Action [] { 82 new SortByNameAction( filters ), 83 new SortBySourceAction( filters ), 84 null, 85 new FilterSubmenuAction(filters.getInstance()) 86 }; 87 88 add(filtersPanel, BorderLayout.SOUTH); 89 90 manager.setRootContext(ElementNode.getWaitNode()); 91 92 } 93 94 @Override 95 public boolean requestFocusInWindow() { 96 boolean result = super.requestFocusInWindow(); 97 elementView.requestFocusInWindow(); 98 return result; 99 } 100 101 public org.openide.util.Lookup getLookup() { 102 return lookup; 104 } 105 106 public org.netbeans.modules.java.navigation.ElementScanningTask getTask() { 107 108 return new ElementScanningTask(this); 109 110 } 111 112 113 public void showWaitNode() { 114 SwingUtilities.invokeLater(new Runnable () { 115 public void run() { 116 elementView.setRootVisible(true); 117 manager.setRootContext(ElementNode.getWaitNode()); 118 } 119 }); 120 } 121 122 public void refresh( final Description description ) { 123 124 final ElementNode rootNode = getRootNode(); 125 126 if ( rootNode != null && rootNode.getDescritption().fileObject.equals( description.fileObject) ) { 127 SwingUtilities.invokeLater(new Runnable () { 130 public void run() { 131 rootNode.updateRecursively( description ); 132 } 133 } ); 134 } 135 else { 136 SwingUtilities.invokeLater(new Runnable () { 139 140 public void run() { 141 elementView.setRootVisible(false); 142 manager.setRootContext(new ElementNode( description ) ); 143 elementView.expandAll(); 144 } 145 } ); 146 147 } 148 } 149 150 public void sort() { 151 getRootNode().refreshRecursively(); 152 } 153 154 public ClassMemberFilters getFilters() { 155 return filters; 156 } 157 158 public void expandNode( Node n ) { 159 elementView.expandNode(n); 160 } 161 162 public Action [] getActions() { 163 return actions; 164 } 165 166 public FileObject getFileObject() { 167 return getRootNode().getDescritption().fileObject; 168 } 169 170 172 public void filterStateChanged(ChangeEvent e) { 173 ElementNode root = getRootNode(); 174 175 if ( root != null ) { 176 root.refreshRecursively(); 177 } 178 } 179 180 185 private void initComponents() { 187 188 setLayout(new java.awt.BorderLayout ()); 189 } 191 192 195 197 private ElementNode getRootNode() { 198 199 Node n = manager.getRootContext(); 200 if ( n instanceof ElementNode ) { 201 return (ElementNode)n; 202 } 203 else { 204 return null; 205 } 206 } 207 208 private BeanTreeView createBeanTreeView() { 209 216 BeanTreeView btv = new BeanTreeView(); return btv; 221 222 } 223 224 225 227 public ExplorerManager getExplorerManager() { 228 return manager; 229 } 230 231 232 } 233 | Popular Tags |