1 9 10 package org.netbeans.modules.java.navigation; 11 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Collections ; 16 import javax.lang.model.element.ElementKind; 17 import javax.lang.model.element.Modifier; 18 import javax.swing.ImageIcon ; 19 import javax.swing.JComponent ; 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 30 public final class ClassMemberFilters { 31 32 private ClassMemberPanelUI ui; 33 34 35 private static final String SHOW_NON_PUBLIC = "show_non_public"; 36 private static final String SHOW_STATIC = "show_static"; 37 private static final String SHOW_FIELDS = "show_fields"; 38 private static final String SHOW_INHERITED = "show_inherited"; 39 40 private FiltersManager filters; 41 42 private boolean naturalSort = false; 43 44 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 getComponent() { 57 FiltersManager f = getInstance(); 58 return f.getComponent(); 59 60 } 61 62 public Collection <Description> filter( Collection <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 69 70 ArrayList <Description> result = new ArrayList <Description>(original.size()); 71 for (Description description : original) { 72 73 if ( !non_public && 74 !description.modifiers.contains(Modifier.PUBLIC) 75 ) { 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 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 108 109 private static FiltersManager createFilters () { 110 FiltersDescription desc = new FiltersDescription(); 111 112 desc.addFilter(SHOW_FIELDS, 121 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFields"), NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFieldsTip"), true, 124 new ImageIcon (Utilities.loadImage("org/netbeans/modules/java/navigation/resources/filterHideFields.gif")), null 126 ); 127 desc.addFilter(SHOW_STATIC, 128 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowStatic"), NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowStaticTip"), true, 131 new ImageIcon (Utilities.loadImage("org/netbeans/modules/java/navigation/resources/filterHideStatic.png")), null 133 ); 134 desc.addFilter(SHOW_NON_PUBLIC, 135 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowNonPublic"), NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowNonPublicTip"), true, 138 new ImageIcon (Utilities.loadImage("org/netbeans/modules/java/navigation/resources/filterHideNonPublic.png")), null 140 ); 141 142 return FiltersDescription.createManager(desc); 143 } 144 145 146 147 } 148 | Popular Tags |