KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > navigation > ClassMemberPanelUI


1 /*
2  * ClassMemberPanelUi.java
3  *
4  * Created on November 8, 2006, 4:03 PM
5  */

6
7 package org.netbeans.modules.java.navigation;
8
9 import java.awt.BorderLayout JavaDoc;
10 import java.awt.Rectangle JavaDoc;
11 import javax.swing.Action JavaDoc;
12 import javax.swing.KeyStroke JavaDoc;
13 import java.awt.Toolkit JavaDoc;
14 import java.awt.event.KeyEvent JavaDoc;
15 import javax.swing.JLabel JavaDoc;
16 import javax.swing.SwingUtilities JavaDoc;
17 import javax.swing.border.EmptyBorder JavaDoc;
18 import javax.swing.KeyStroke JavaDoc;
19 import javax.swing.event.ChangeEvent JavaDoc;
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 /**
38  *
39  * @author phrebejk
40  */

41 public class ClassMemberPanelUI extends javax.swing.JPanel JavaDoc
42         implements ExplorerManager.Provider, FiltersManager.FilterChangeListener {
43     
44     private ExplorerManager manager = new ExplorerManager();
45     private BeanTreeView elementView;
46     private TapPanel filtersPanel;
47     private JLabel JavaDoc filtersLbl;
48     private Lookup lookup = null; // XXX may need better lookup
49
private ClassMemberFilters filters;
50     
51     private Action JavaDoc[] actions; // General actions for the panel
52

53     private static final Rectangle JavaDoc ZERO = new Rectangle JavaDoc(0,0,1,1);
54
55     
56     /** Creates new form ClassMemberPanelUi */
57     public ClassMemberPanelUI() {
58                       
59         initComponents();
60         
61         // Tree view of the elements
62
elementView = createBeanTreeView();
63         add(elementView, BorderLayout.CENTER);
64                
65         // filters
66
filtersPanel = new TapPanel();
67         filtersLbl = new JLabel JavaDoc(NbBundle.getMessage(ClassMemberPanelUI.class, "LBL_Filter")); //NOI18N
68
filtersLbl.setBorder(new EmptyBorder JavaDoc(0, 5, 5, 0));
69         filtersPanel.add(filtersLbl);
70         filtersPanel.setOrientation(TapPanel.DOWN);
71         // tooltip
72
KeyStroke JavaDoc toggleKey = KeyStroke.getKeyStroke(KeyEvent.VK_T,
73                 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
74         String JavaDoc 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 JavaDoc[] {
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 JavaDoc
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         // XXX Check for chenge of FileObject
103
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 JavaDoc() {
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             // update
128
//System.out.println("UPDATE ======" + description.fileObject.getName() );
129
SwingUtilities.invokeLater(new Runnable JavaDoc() {
130                 public void run() {
131                     rootNode.updateRecursively( description );
132                 }
133             } );
134         }
135         else {
136             //System.out.println("REFRES =====" + description.fileObject.getName() );
137
// New fileobject => refresh completely
138
SwingUtilities.invokeLater(new Runnable JavaDoc() {
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 JavaDoc[] getActions() {
163         return actions;
164     }
165     
166     public FileObject getFileObject() {
167         return getRootNode().getDescritption().fileObject;
168     }
169     
170     // FilterChangeListener ----------------------------------------------------
171

172     public void filterStateChanged(ChangeEvent JavaDoc e) {
173         ElementNode root = getRootNode();
174         
175         if ( root != null ) {
176             root.refreshRecursively();
177         }
178     }
179     
180     /** This method is called from within the constructor to
181      * initialize the form.
182      * WARNING: Do NOT modify this code. The content of this method is
183      * always regenerated by the Form Editor.
184      */

185     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
186
private void initComponents() {
187
188         setLayout(new java.awt.BorderLayout JavaDoc());
189     }// </editor-fold>//GEN-END:initComponents
190

191     
192     // Variables declaration - do not modify//GEN-BEGIN:variables
193
// End of variables declaration//GEN-END:variables
194

195     // Private methods ---------------------------------------------------------
196

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 // ActionMap map = getActionMap();
210
// map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager));
211
// map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager));
212
// map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager));
213
// map.put("delete", new DelegatingAction(ActionProvider.COMMAND_DELETE, ExplorerUtils.actionDelete(manager, true)));
214
//
215

216         BeanTreeView btv = new BeanTreeView(); // Add the BeanTreeView
217
// btv.setDragSource (true);
218
// btv.setRootVisible(false);
219
// associateLookup( ExplorerUtils.createLookup(manager, map) );
220
return btv;
221         
222     }
223     
224     
225     // ExplorerManager.Provider imlementation ----------------------------------
226

227     public ExplorerManager getExplorerManager() {
228         return manager;
229     }
230     
231     
232 }
233
Popular Tags