How to search a SymbolDictionary

Searching a SymbolDictionary using Keywords or Filters

This section explains how to use keywords and filters to search for military symbols in a symbol dictionary.

The following steps show how to obtain keywords and filters for searching for symbols. These filters and keywords would typically be used to populate GUI components for users to narrow their symbol search:

//create a symbol dictionary
symDictionary = new SymbolDictionary(SymbolDictionary.DictionaryType.Mil2525C);
		
//get the available keywords and put them in the selection list
List<String> keywords = new ArrayList<String>();
keywords = symDictionary.getKeywords();
lstKeywords.setListData(keywords.toArray());
		
//get the filters and their values and pop them into the tree view
Map<String, List<String>> filters;
filters = symDictionary.getFilters();
DefaultMutableTreeNode baseNode = new DefaultMutableTreeNode("Filters");
DefaultMutableTreeNode filterNode;		
		
//go through all filters
for (String flt : filters.keySet()){
 //test filter output
	System.out.println("filter: " + flt);
			
	//create filter for the tree
	filterNode = new DefaultMutableTreeNode(flt);
			
	//get the filter values for each of the filters
	List<String> filterValues;	
	filterValues = filters.get(flt);
	for(String val : filterValues){
	 //add the filter value to the tree
		filterNode.add(new DefaultMutableTreeNode(val));
	}
			
	//add filter section to tree
	baseNode.add(filterNode);
}
		
//apply filters to the tree control
treeFilters.setModel(new DefaultTreeModel(baseNode));

Once a user has chosen their search criteria using the GUI, the keywords and filters can be used to get a list of potential symbols back to allow the use to make choose their symbol. The following example shows how to search using filters only. Using different overloads for the FindSymbols method, it is also possible to search using keywords and filters or keywords only.

//make a filter for Category=Atmospheric
Map<String,List<String>> selectedFilters = new HashMap<String,List<String>>();
		
//add the key so we can add to the list of filters
List<String> filterVals = new ArrayList<String>();
filterVals.add("Atmospheric");
selectedFilters.put("Category", filterVals);
		
//get the symbol properties for our filter
symbols = new ArrayList<SymbolProperties>();
		
try {
 symbols = symDictionary.findSymbols(selectedFilters);
} catch (IOException e) {
	e.printStackTrace();
}
		
//get the symbol names for Category=Atmospheric
List<String> symbolNames = new ArrayList<String>();
for (SymbolProperties symbolProps : symbols){
	System.out.println("Symbol Name : " + symbolProps.getName());
}
2/7/2013