# HG changeset patch # User Frank Benoit # Date 1207924278 -7200 # Node ID 115258985f10e61036cc7f2fb81a7da026262d4e # Parent 7a3e6c1a4eae5ca45b812ae87b5a2ed523e5b645 JHashMapT into FontRegistry diff -r 7a3e6c1a4eae -r 115258985f10 dwtx/dwtxhelper/JHashMap.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/dwtxhelper/JHashMap.d Fri Apr 11 16:31:18 2008 +0200 @@ -0,0 +1,21 @@ +module dwtx.dwtxhelper.JHashMap; + +import tango.util.collection.HashMap; +import tango.core.Traits; + +class JHashMapT(K,V) : HashMap!(K,V) { + this(){ + super(); + } + + static if( is(V==class) || is(V==interface) || isDynamicArrayType!(V) ){ + public V find( K key ){ + if( containsKey(key) ){ + return get(key); + } + return null; + } + } +} + +alias JHashMapT!(Object,Object) JHashMap; diff -r 7a3e6c1a4eae -r 115258985f10 dwtx/jface/resource/FontRegistry.d --- a/dwtx/jface/resource/FontRegistry.d Fri Apr 11 16:20:43 2008 +0200 +++ b/dwtx/jface/resource/FontRegistry.d Fri Apr 11 16:31:18 2008 +0200 @@ -19,7 +19,7 @@ import dwtx.jface.resource.DataFormatException; import tango.util.collection.ArraySeq; -import tango.util.collection.HashMap; +import dwtx.dwtxhelper.JHashMap; import tango.util.collection.model.Map; import tango.util.collection.model.Seq; import tango.util.collection.model.Set; @@ -196,14 +196,14 @@ * (key type: String, * value type: FontRecord. */ - private Map!(String,FontRecord) stringToFontRecord; + private JHashMapT!(String,FontRecord) stringToFontRecord; /** * Table of known font data, keyed by symbolic font name * (key type: String, * value type: dwt.graphics.FontData[]). */ - private Map!(String,FontData[]) stringToFontData; + private JHashMapT!(String,FontData[]) stringToFontData; /** * Collection of Fonts that are now stale to be disposed @@ -301,10 +301,10 @@ clearCaches(); } }; - stringToFontRecord = new HashMap!(String,FontRecord); + stringToFontRecord = new JHashMapT!(String,FontRecord); //stringToFontRecord.capacity(7); - stringToFontData = new HashMap!(String,FontData[]); + stringToFontData = new JHashMapT!(String,FontData[]); //stringToFontData.capacity(7); staleFonts = new ArraySeq!(Font); @@ -346,21 +346,21 @@ const char[] prefix = "dwtx.jface.resource.jfacefonts_"; const char[] postfix = ".properties"; version( linux ){ - char[] propdata = import( prefix ~ "linux_gtk" ~ postfix ); + ImportData propdata = getImportData!( prefix ~ "linux_gtk" ~ postfix ); } else version( Windows ){ - char[] propdata; + ImportData propdata; if( OS.IsWin95 && OS.WIN32_VERSION >= OS.VERSION (4, 10 )){ - propdata = import( prefix ~ "windows98" ~ postfix ); + propdata = getImportData!( prefix ~ "windows98" ~ postfix ); } else if( OS.WIN32_VERSION >= OS.VERSION (5, 1 )){ - propdata = import( prefix ~ "windowsxp" ~ postfix ); + propdata = getImportData!( prefix ~ "windowsxp" ~ postfix ); } else if( OS.WIN32_VERSION >= OS.VERSION (5, 0)){ - propdata = import( prefix ~ "windows2000" ~ postfix ); + propdata = getImportData!( prefix ~ "windows2000" ~ postfix ); } else if( OS.WIN32_VERSION >= OS.VERSION (4, 0)){ - propdata = import( prefix ~ "windowsnt" ~ postfix ); + propdata = getImportData!( prefix ~ "windowsnt" ~ postfix ); } else{ assert( false, "TODO: detect windows version" ); @@ -592,8 +592,7 @@ */ private FontRecord defaultFontRecord() { - FontRecord record = cast(FontRecord) stringToFontRecord - .get(JFaceResources.DEFAULT_FONT); + FontRecord record = cast(FontRecord) stringToFontRecord.find(JFaceResources.DEFAULT_FONT); if (record is null) { Font defaultFont = calculateDefaultFont(); record = createFont(JFaceResources.DEFAULT_FONT, defaultFont @@ -622,7 +621,7 @@ public FontData[] getFontData(String symbolicName) { Assert.isTrue(symbolicName.length > 0); - auto result = stringToFontData.get(symbolicName); + auto result = stringToFontData.find(symbolicName); if (result.length is 0) { return defaultFontData(); } @@ -678,12 +677,12 @@ */ private FontRecord getFontRecord(String symbolicName) { Assert.isNotNull(symbolicName); - Object result1 = stringToFontRecord.get(symbolicName); + Object result1 = stringToFontRecord.find(symbolicName); if (result1 !is null) { return cast(FontRecord) result1; } - auto result = stringToFontData.get(symbolicName); + auto result = stringToFontData.find(symbolicName); FontRecord fontRecord; @@ -807,12 +806,12 @@ Assert.isNotNull(symbolicName); Assert.isTrue(fontData.length > 0 ); - FontData[] existing = stringToFontData.get(symbolicName); + FontData[] existing = stringToFontData.find(symbolicName); if (ArrayEquals(existing, fontData)) { return; } - FontRecord oldFont = stringToFontRecord.get(symbolicName); + FontRecord oldFont = stringToFontRecord.find(symbolicName); stringToFontRecord.removeKey(symbolicName); stringToFontData.add(symbolicName, fontData); if (update) { @@ -844,7 +843,7 @@ throw new MissingResourceException( "Wrong key format ", bundleName, key); //$NON-NLS-1$ } - FontData[] elements = stringToFontData.get(name); + FontData[] elements = stringToFontData.find(name); if (elements is null) { elements = new FontData[8]; stringToFontData.add(name, elements);