1 19 20 package org.netbeans.modules.search; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Set ; 29 import javax.swing.BorderFactory ; 30 import javax.swing.UIManager ; 31 import javax.swing.border.Border ; 32 import org.openide.util.Lookup; 33 import org.openidex.search.SearchType; 34 35 39 final class Utils { 40 41 46 private static Lookup.Result result; 47 48 private Utils() { } 49 50 59 private static Lookup.Result getSearchTypes0() { 60 if (result == null) { 61 result = Lookup.getDefault().lookup( 62 new Lookup.Template(SearchType.class)); 63 } 64 return result; 65 } 66 67 73 static Collection getSearchTypes() { 74 return getSearchTypes0().allInstances(); 75 } 76 77 87 static Class searchTypeForName(String className) { 88 Set allClasses = getSearchTypes0().allClasses(); 89 for (Iterator i = allClasses.iterator(); i.hasNext(); ) { 90 Class c = (Class ) i.next(); 91 if (c.getName().equals(className)) { 92 return c; 93 } 94 } 95 return null; 96 } 97 98 110 static Map sortCriteriaBySearchType(SearchCriterion[] criteria) { 111 112 if (criteria == null || criteria.length == 0) { 113 return null; 114 } 115 116 Map map = new HashMap (6, 0.75f); 117 for (int i = 0; i < criteria.length; i++) { 118 SearchCriterion c = criteria[i]; 119 String className = c.searchTypeClassName; 120 Collection criteriaOfType; 121 Object o = map.get(className); 122 if (o == null) { 123 criteriaOfType = new ArrayList (4); 124 criteriaOfType.add(c); 125 map.put(className, criteriaOfType); 126 } else { 127 criteriaOfType = (Collection ) o; 128 criteriaOfType.add(c); 129 } 130 } 131 return map; 132 } 133 134 141 static final Border getExplorerViewBorder() { 142 Border border; 143 border = (Border ) UIManager.get("Nb.ScrollPane.border"); if (border == null) { 145 border = BorderFactory.createEtchedBorder(); 146 } 147 return border; 148 } 149 150 156 static List cloneSearchTypes(List searchTypes) { 157 List clonedSearchTypes = new ArrayList (searchTypes.size()); 158 for (Iterator it = searchTypes.iterator(); it.hasNext(); ) { 159 clonedSearchTypes.add(((SearchType) it.next()).clone()); 160 } 161 return clonedSearchTypes; 162 } 163 164 165 } 166 | Popular Tags |