KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ClassMemberFilters.java
3  *
4  * Created on November 9, 2006, 5:40 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.java.navigation;
11
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.Collections JavaDoc;
16 import javax.lang.model.element.ElementKind;
17 import javax.lang.model.element.Modifier;
18 import javax.swing.ImageIcon JavaDoc;
19 import javax.swing.JComponent JavaDoc;
20 import org.netbeans.modules.java.navigation.ElementNode.Description;
21 import org.netbeans.modules.java.navigation.base.FiltersDescription;
22 import org.netbeans.modules.java.navigation.base.FiltersManager;
23 import org.openide.util.NbBundle;
24 import org.openide.util.Utilities;
25
26 /** Creates filtering for the ClassMemberPanel
27  *
28  * @author phrebejk
29  */

30 public final class ClassMemberFilters {
31     
32     private ClassMemberPanelUI ui;
33     
34     /** constants for defined filters */
35     private static final String JavaDoc SHOW_NON_PUBLIC = "show_non_public";
36     private static final String JavaDoc SHOW_STATIC = "show_static";
37     private static final String JavaDoc SHOW_FIELDS = "show_fields";
38     private static final String JavaDoc SHOW_INHERITED = "show_inherited";
39     
40     private FiltersManager filters;
41     
42     private boolean naturalSort = false;
43     
44     /** Creates a new instance of ClassMemberFilters */
45     ClassMemberFilters( ClassMemberPanelUI ui ) {
46         this.ui = ui;
47     }
48     
49     public FiltersManager getInstance() {
50         if (filters == null) {
51             filters = createFilters();
52         }
53         return filters;
54     }
55     
56     public JComponent JavaDoc getComponent() {
57         FiltersManager f = getInstance();
58         return f.getComponent();
59         
60     }
61     
62     public Collection JavaDoc<Description> filter( Collection JavaDoc<Description> original ) {
63         
64         boolean non_public = filters.isSelected(SHOW_NON_PUBLIC);
65         boolean statik = filters.isSelected(SHOW_STATIC);
66         boolean fields = filters.isSelected(SHOW_FIELDS);
67         // XXX Enable later boolean inherited = filters.isSelected(SHOW_INHERITED);
68

69                
70         ArrayList JavaDoc<Description> result = new ArrayList JavaDoc<Description>(original.size());
71         for (Description description : original) {
72             
73             if ( !non_public &&
74                  !description.modifiers.contains(Modifier.PUBLIC)
75                  /* Fix for #89777 && !description.modifiers.contains(Modifier.PROTECTED) */ ) {
76                 continue;
77             }
78             
79             if ( !statik && description.modifiers.contains(Modifier.STATIC)) {
80                 continue;
81             }
82             
83             if ( !fields && description.kind == ElementKind.FIELD ) {
84                 continue;
85             }
86             
87             // XXX Inherited members
88

89             result.add(description);
90         }
91                 
92         Collections.sort( result, isNaturalSort() ? Description.POSITION_COMPARATOR : Description.ALPHA_COMPARATOR );
93         
94         return result;
95     }
96     
97     public boolean isNaturalSort() {
98         return naturalSort;
99     }
100     
101     public void setNaturalSort( boolean naturalSort ) {
102         this.naturalSort = naturalSort;
103         ui.sort();
104     }
105     
106     // Privare methods ---------------------------------------------------------
107

108     /** Creates filter descriptions and filters itself */
109     private static FiltersManager createFilters () {
110         FiltersDescription desc = new FiltersDescription();
111         
112         // XXX to be enabled later
113
// desc.addFilter(SHOW_INHERITED,
114
// NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowInherited"), //NOI18N
115
// NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowInheritedTip"), //NOI18N
116
// false,
117
// new ImageIcon (Utilities.loadImage("org/netbeans/modules/java/navigation/resources/filterHideInherited.png")), //NOI18N
118
// null
119
// );
120
desc.addFilter(SHOW_FIELDS,
121                 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFields"), //NOI18N
122
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFieldsTip"), //NOI18N
123
true,
124                 new ImageIcon JavaDoc (Utilities.loadImage("org/netbeans/modules/java/navigation/resources/filterHideFields.gif")), //NOI18N
125
null
126         );
127         desc.addFilter(SHOW_STATIC,
128                 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowStatic"), //NOI18N
129
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowStaticTip"), //NOI18N
130
true,
131                 new ImageIcon JavaDoc (Utilities.loadImage("org/netbeans/modules/java/navigation/resources/filterHideStatic.png")), //NOI18N
132
null
133         );
134         desc.addFilter(SHOW_NON_PUBLIC,
135                 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowNonPublic"), //NOI18N
136
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowNonPublicTip"), //NOI18N
137
true,
138                 new ImageIcon JavaDoc (Utilities.loadImage("org/netbeans/modules/java/navigation/resources/filterHideNonPublic.png")), //NOI18N
139
null
140         );
141         
142         return FiltersDescription.createManager(desc);
143     }
144     
145     
146         
147 }
148
Popular Tags