001/* 002 * To change this template, choose Tools | Templates and open the template in the editor. 003 */ 004package armyc2.c2sd.renderer.utilities; 005 006import armyc2.c2sd.renderer.R; 007 008import android.content.Context; 009import android.util.Log; 010 011import java.io.BufferedInputStream; 012import java.io.DataInputStream; 013import java.io.IOException; 014import java.util.HashMap; 015import java.util.Map; 016import java.util.logging.Level; 017 018/** 019 * 020 * @author michael.spinelli 021 */ 022public class TacticalGraphicLookup 023{ 024 025 private Map<String, Integer> symbolMap = new HashMap<String, Integer>(); 026 027 private static TacticalGraphicLookup _instance = null; 028 029 private TacticalGraphicLookup() 030 { 031 032 } 033 034 public static synchronized TacticalGraphicLookup getInstance() 035 { 036 if (_instance == null) { 037 _instance = new TacticalGraphicLookup(); 038 } 039 return _instance; 040 } 041 042 public synchronized void init(Context context) 043 { 044 try { 045 DataInputStream dis = new DataInputStream(new BufferedInputStream(context.getResources().openRawResource(R.raw.tacticalgraphic))); 046 readBinary(dis); 047 dis.close(); 048 } catch (IOException e) { 049 Log.e("TacticalGraphicLookup", "Could not load", e); 050 } 051 } 052 053 /** 054 * given the milstd symbol code, find the font index for the symbol. 055 * 056 * @param symbolCode 057 * @return 058 */ 059 public int getCharCodeFromSymbol(String symbolCode) 060 { 061 int symStd = RendererSettings.getInstance().getSymbologyStandard(); 062 063 return getCharCodeFromSymbol(symbolCode, symStd); 064 065 } 066 067 public int getCharCodeFromSymbol(String symbolCode, int symStd) 068 { 069 070 try { 071 String basicID = symbolCode; 072 int charCode = -1; 073 if (SymbolUtilities.is3dAirspace(symbolCode) == false) { 074 basicID = SymbolUtilities.getBasicSymbolID(symbolCode); 075 } 076 if (symbolMap.containsKey(basicID)) { 077 charCode = symbolMap.get(basicID); 078 if (charCode == 59053) { 079 if (symStd == 1) { 080 charCode = 59052; 081 } 082 } 083 } 084 return charCode; 085 } catch (Exception exc) { 086 ErrorLogger.LogException("TacticalGraphicLookup", "getCharCodeFromSymbol", exc, Level.WARNING); 087 } 088 return -1; 089 090 } 091 092 public void readBinary(DataInputStream dis) throws IOException 093 { 094 int size = dis.readInt(); 095 for (int i = 0; i < size; i++) { 096 String key = dis.readUTF(); 097 boolean wasValueWritten = dis.readBoolean(); 098 if (wasValueWritten) { 099 symbolMap.put(key, dis.readInt()); 100 } 101 } 102 } 103}