comparison dwtx/jface/resource/FontRegistry.d @ 49:115258985f10

JHashMapT into FontRegistry
author Frank Benoit <benoit@tionex.de>
date Fri, 11 Apr 2008 16:31:18 +0200
parents ea8ff534f622
children 41c2c84fd73c
comparison
equal deleted inserted replaced
48:7a3e6c1a4eae 49:115258985f10
17 import dwtx.jface.resource.StringConverter; 17 import dwtx.jface.resource.StringConverter;
18 import dwtx.jface.resource.JFaceResources; 18 import dwtx.jface.resource.JFaceResources;
19 import dwtx.jface.resource.DataFormatException; 19 import dwtx.jface.resource.DataFormatException;
20 20
21 import tango.util.collection.ArraySeq; 21 import tango.util.collection.ArraySeq;
22 import tango.util.collection.HashMap; 22 import dwtx.dwtxhelper.JHashMap;
23 import tango.util.collection.model.Map; 23 import tango.util.collection.model.Map;
24 import tango.util.collection.model.Seq; 24 import tango.util.collection.model.Seq;
25 import tango.util.collection.model.Set; 25 import tango.util.collection.model.Set;
26 import tango.util.collection.model.SetView; 26 import tango.util.collection.model.SetView;
27 import tango.util.collection.HashSet; 27 import tango.util.collection.HashSet;
194 /** 194 /**
195 * Table of known fonts, keyed by symbolic font name 195 * Table of known fonts, keyed by symbolic font name
196 * (key type: <code>String</code>, 196 * (key type: <code>String</code>,
197 * value type: <code>FontRecord</code>. 197 * value type: <code>FontRecord</code>.
198 */ 198 */
199 private Map!(String,FontRecord) stringToFontRecord; 199 private JHashMapT!(String,FontRecord) stringToFontRecord;
200 200
201 /** 201 /**
202 * Table of known font data, keyed by symbolic font name 202 * Table of known font data, keyed by symbolic font name
203 * (key type: <code>String</code>, 203 * (key type: <code>String</code>,
204 * value type: <code>dwt.graphics.FontData[]</code>). 204 * value type: <code>dwt.graphics.FontData[]</code>).
205 */ 205 */
206 private Map!(String,FontData[]) stringToFontData; 206 private JHashMapT!(String,FontData[]) stringToFontData;
207 207
208 /** 208 /**
209 * Collection of Fonts that are now stale to be disposed 209 * Collection of Fonts that are now stale to be disposed
210 * when it is safe to do so (i.e. on shutdown). 210 * when it is safe to do so (i.e. on shutdown).
211 * @see List 211 * @see List
299 displayRunnable = new class Runnable { 299 displayRunnable = new class Runnable {
300 public void run() { 300 public void run() {
301 clearCaches(); 301 clearCaches();
302 } 302 }
303 }; 303 };
304 stringToFontRecord = new HashMap!(String,FontRecord); 304 stringToFontRecord = new JHashMapT!(String,FontRecord);
305 //stringToFontRecord.capacity(7); 305 //stringToFontRecord.capacity(7);
306 306
307 stringToFontData = new HashMap!(String,FontData[]); 307 stringToFontData = new JHashMapT!(String,FontData[]);
308 //stringToFontData.capacity(7); 308 //stringToFontData.capacity(7);
309 309
310 staleFonts = new ArraySeq!(Font); 310 staleFonts = new ArraySeq!(Font);
311 } 311 }
312 312
344 // } 344 // }
345 String errorLocation = "dwtx.jface.resource.FontRegistry properties"; 345 String errorLocation = "dwtx.jface.resource.FontRegistry properties";
346 const char[] prefix = "dwtx.jface.resource.jfacefonts_"; 346 const char[] prefix = "dwtx.jface.resource.jfacefonts_";
347 const char[] postfix = ".properties"; 347 const char[] postfix = ".properties";
348 version( linux ){ 348 version( linux ){
349 char[] propdata = import( prefix ~ "linux_gtk" ~ postfix ); 349 ImportData propdata = getImportData!( prefix ~ "linux_gtk" ~ postfix );
350 } 350 }
351 else version( Windows ){ 351 else version( Windows ){
352 char[] propdata; 352 ImportData propdata;
353 if( OS.IsWin95 && OS.WIN32_VERSION >= OS.VERSION (4, 10 )){ 353 if( OS.IsWin95 && OS.WIN32_VERSION >= OS.VERSION (4, 10 )){
354 propdata = import( prefix ~ "windows98" ~ postfix ); 354 propdata = getImportData!( prefix ~ "windows98" ~ postfix );
355 } 355 }
356 else if( OS.WIN32_VERSION >= OS.VERSION (5, 1 )){ 356 else if( OS.WIN32_VERSION >= OS.VERSION (5, 1 )){
357 propdata = import( prefix ~ "windowsxp" ~ postfix ); 357 propdata = getImportData!( prefix ~ "windowsxp" ~ postfix );
358 } 358 }
359 else if( OS.WIN32_VERSION >= OS.VERSION (5, 0)){ 359 else if( OS.WIN32_VERSION >= OS.VERSION (5, 0)){
360 propdata = import( prefix ~ "windows2000" ~ postfix ); 360 propdata = getImportData!( prefix ~ "windows2000" ~ postfix );
361 } 361 }
362 else if( OS.WIN32_VERSION >= OS.VERSION (4, 0)){ 362 else if( OS.WIN32_VERSION >= OS.VERSION (4, 0)){
363 propdata = import( prefix ~ "windowsnt" ~ postfix ); 363 propdata = getImportData!( prefix ~ "windowsnt" ~ postfix );
364 } 364 }
365 else{ 365 else{
366 assert( false, "TODO: detect windows version" ); 366 assert( false, "TODO: detect windows version" );
367 } 367 }
368 } 368 }
590 /** 590 /**
591 * Returns the default font record. 591 * Returns the default font record.
592 */ 592 */
593 private FontRecord defaultFontRecord() { 593 private FontRecord defaultFontRecord() {
594 594
595 FontRecord record = cast(FontRecord) stringToFontRecord 595 FontRecord record = cast(FontRecord) stringToFontRecord.find(JFaceResources.DEFAULT_FONT);
596 .get(JFaceResources.DEFAULT_FONT);
597 if (record is null) { 596 if (record is null) {
598 Font defaultFont = calculateDefaultFont(); 597 Font defaultFont = calculateDefaultFont();
599 record = createFont(JFaceResources.DEFAULT_FONT, defaultFont 598 record = createFont(JFaceResources.DEFAULT_FONT, defaultFont
600 .getFontData()); 599 .getFontData());
601 defaultFont.dispose(); 600 defaultFont.dispose();
620 * @return the font 619 * @return the font
621 */ 620 */
622 public FontData[] getFontData(String symbolicName) { 621 public FontData[] getFontData(String symbolicName) {
623 622
624 Assert.isTrue(symbolicName.length > 0); 623 Assert.isTrue(symbolicName.length > 0);
625 auto result = stringToFontData.get(symbolicName); 624 auto result = stringToFontData.find(symbolicName);
626 if (result.length is 0) { 625 if (result.length is 0) {
627 return defaultFontData(); 626 return defaultFontData();
628 } 627 }
629 628
630 return result; 629 return result;
676 * @param symbolicName The key for the record. 675 * @param symbolicName The key for the record.
677 * @return FontRecird 676 * @return FontRecird
678 */ 677 */
679 private FontRecord getFontRecord(String symbolicName) { 678 private FontRecord getFontRecord(String symbolicName) {
680 Assert.isNotNull(symbolicName); 679 Assert.isNotNull(symbolicName);
681 Object result1 = stringToFontRecord.get(symbolicName); 680 Object result1 = stringToFontRecord.find(symbolicName);
682 if (result1 !is null) { 681 if (result1 !is null) {
683 return cast(FontRecord) result1; 682 return cast(FontRecord) result1;
684 } 683 }
685 684
686 auto result = stringToFontData.get(symbolicName); 685 auto result = stringToFontData.find(symbolicName);
687 686
688 FontRecord fontRecord; 687 FontRecord fontRecord;
689 688
690 if (result is null) { 689 if (result is null) {
691 fontRecord = defaultFontRecord(); 690 fontRecord = defaultFontRecord();
805 private void put(String symbolicName, FontData[] fontData, bool update) { 804 private void put(String symbolicName, FontData[] fontData, bool update) {
806 805
807 Assert.isNotNull(symbolicName); 806 Assert.isNotNull(symbolicName);
808 Assert.isTrue(fontData.length > 0 ); 807 Assert.isTrue(fontData.length > 0 );
809 808
810 FontData[] existing = stringToFontData.get(symbolicName); 809 FontData[] existing = stringToFontData.find(symbolicName);
811 if (ArrayEquals(existing, fontData)) { 810 if (ArrayEquals(existing, fontData)) {
812 return; 811 return;
813 } 812 }
814 813
815 FontRecord oldFont = stringToFontRecord.get(symbolicName); 814 FontRecord oldFont = stringToFontRecord.find(symbolicName);
816 stringToFontRecord.removeKey(symbolicName); 815 stringToFontRecord.removeKey(symbolicName);
817 stringToFontData.add(symbolicName, fontData); 816 stringToFontData.add(symbolicName, fontData);
818 if (update) { 817 if (update) {
819 fireMappingChanged(symbolicName, new ArrayWrapperT!(FontData)(existing), new ArrayWrapperT!(FontData)(fontData)); 818 fireMappingChanged(symbolicName, new ArrayWrapperT!(FontData)(existing), new ArrayWrapperT!(FontData)(fontData));
820 } 819 }
842 } catch (IllegalArgumentException e) { 841 } catch (IllegalArgumentException e) {
843 //Panic the file can not be parsed. 842 //Panic the file can not be parsed.
844 throw new MissingResourceException( 843 throw new MissingResourceException(
845 "Wrong key format ", bundleName, key); //$NON-NLS-1$ 844 "Wrong key format ", bundleName, key); //$NON-NLS-1$
846 } 845 }
847 FontData[] elements = stringToFontData.get(name); 846 FontData[] elements = stringToFontData.find(name);
848 if (elements is null) { 847 if (elements is null) {
849 elements = new FontData[8]; 848 elements = new FontData[8];
850 stringToFontData.add(name, elements); 849 stringToFontData.add(name, elements);
851 } 850 }
852 if (i > elements.length) { 851 if (i > elements.length) {