Changeset 1571 for trunk/src/org/expeditee/gio
- Timestamp:
- 08/10/23 16:16:02 (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gio/swing/SwingFontManager.java
r1125 r1571 20 20 /** Singleton instance. */ 21 21 private static SwingFontManager _instance = null; 22 22 23 private static HashMap<String,String> _font_name_lookup = null; 24 25 23 26 /** Singleton instantiator. */ 24 27 public static SwingFontManager getInstance() 25 28 { 26 29 if (_instance == null) _instance = new SwingFontManager(); 30 31 if (_font_name_lookup == null) { 32 _font_name_lookup = new HashMap<String,String>(); 33 34 java.awt.Font [] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); 35 36 for (int i=0; i<fonts.length; i++) { 37 java.awt.Font font = fonts[i]; 38 String font_name = font.getFontName(); 39 String font_family = font.getFamily(); 40 41 // Instead of String->Integer hashmap, let's choose to store the 42 // font family name, in case this is useful at a later point elsewhere 43 _font_name_lookup.put(font_name,font_family); 44 } 45 } 27 46 28 47 return _instance; … … 63 82 if (swingFont == null) registerOkay = false; 64 83 } catch (Exception e) { 84 System.err.println("Warning: createFont() failed for:\n " + fontFile.toString()); 85 e.printStackTrace(); 65 86 registerOkay = false; 66 87 } … … 75 96 return register(swingFont).clone(); 76 97 } 77 78 // If we made it here the registration failed 98 else { 99 // One reason for failing to register is that it already exists 100 101 if (swingFont != null) { 102 String font_name = swingFont.getFontName(); 103 104 Boolean font_already_registered = (_font_name_lookup.get(font_name) != null); 105 106 // Loading font was OK after all, just that the JDK already has it 107 if (font_already_registered) { 108 return register(swingFont).clone(); 109 } 110 else { 111 System.err.println("Error: failed to register font '" + font_name + "'"); 112 } 113 } 114 } 115 116 79 117 return null; 80 118 }
Note:
See TracChangeset
for help on using the changeset viewer.