001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005 006package armyc2.c2sd.renderer.utilities; 007 008/*import javax.xml.parsers.DocumentBuilder; 009import javax.xml.parsers.DocumentBuilderFactory; 010import javax.xml.parsers.ParserConfigurationException; 011import org.w3c.dom.*; 012import org.xml.sax.SAXException; 013import java.io.*; 014import java.util.HashMap; 015import java.util.Map;*/ 016import java.io.InputStream; 017import java.util.ArrayList; 018import java.util.HashMap; 019import java.util.Map; 020import java.util.logging.FileHandler; 021 022import org.w3c.dom.Document; 023import org.w3c.dom.Element; 024import org.w3c.dom.NodeList; 025 026import android.util.Log; 027/** 028 * Responsible for loading tactical graphic symbol definitions into a hash table. 029 * 030 * @author michael.spinelli 031 */ 032@SuppressWarnings("unused") 033public class SymbolSVGTable { 034 035 036 private static Boolean _initCalled = false; 037 private static SymbolSVGTable _instance = null; 038 //private static SymbolTableThingy 039 private static Map<String, SVGPath> _SymbolDefinitions = null; 040 041 042 043 044 045 /* 046 * Holds SymbolDefs for all symbols. (basicSymbolID, Description, 047 * MinPoint, MaxPoints, etc...) 048 * Call getInstance(). 049 * 050 * */ 051 private SymbolSVGTable() 052 { 053 054 } 055 056 public static synchronized SymbolSVGTable getInstance() 057 { 058 if(_instance == null) 059 _instance = new SymbolSVGTable(); 060 061 return _instance; 062 } 063 064 public synchronized void init(String symbolSVG) 065 { 066 if(_initCalled==false) 067 { 068 _instance = new SymbolSVGTable(); 069 _SymbolDefinitions = new HashMap<String, SVGPath>(); 070 071 072 073 String lookupXml = symbolSVG;//FileHandler.InputStreamToString(xmlStreamB); 074 075 //String lookupXml = FileHandler.fileToString("C:\\UnitFontMappings.xml"); 076 populateLookup(lookupXml); 077 078 079 _initCalled = true; 080 } 081 } 082 083 private void populateLookup(String xml) 084 { 085 try 086 { 087 Document doc = XMLParser.getDomElement(xml); 088 NodeList nl = doc.getElementsByTagName("glyph"); 089 SVGPath path; 090 for(int i = 0; i < nl.getLength(); i++) 091 { 092 String index = XMLParser.getAttribute((Element)nl.item(i), "unicode"); 093 String strPath = XMLParser.getAttribute((Element)nl.item(i), "d"); 094 095 if(strPath != null && strPath.equals("") != true && index != null && index.length() > 3 ) 096 { 097 index = index.substring(3); 098 path = new SVGPath(index, strPath); 099 index = path.getID(); 100 _SymbolDefinitions.put(index, path); 101 } 102 103 } 104 } 105 catch(Exception exc) 106 { 107 Log.e("SymbolSVGTable", exc.getMessage(), exc); 108 } 109 110 } 111 112 /** 113 * @name getSymbolDef 114 * 115 * @description Returns a SymbolDef from the SymbolDefTable that matches the passed in Symbol Id 116 * 117 * @param index String representation of the index number 118 * @return SVGPath 119 */ 120 public SVGPath getSVGPath(String index) 121 { 122 SVGPath returnVal = null; 123 try 124 { 125 if (_SymbolDefinitions.containsKey(index)) 126 returnVal = new SVGPath(_SymbolDefinitions.get(index)); 127 } 128 catch (Exception exc) 129 { 130 131 } 132 return returnVal; 133 } 134 135 public Boolean HasSVGPath(String index) 136 { 137 if (index != null && index.length() > 0) 138 return _SymbolDefinitions.containsKey(index); 139 else 140 return false; 141 } 142 143}