Changeset 7896 in josm for trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
- Timestamp:
- 2014-12-27T05:25:53+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
r7539 r7896 23 23 import java.lang.reflect.InvocationTargetException; 24 24 import java.util.Arrays; 25 import java.util.Enumeration; 25 26 import java.util.List; 26 27 import java.util.concurrent.Callable; … … 31 32 import javax.swing.Icon; 32 33 import javax.swing.ImageIcon; 34 import javax.swing.JComponent; 33 35 import javax.swing.JLabel; 34 36 import javax.swing.JOptionPane; … … 37 39 import javax.swing.SwingUtilities; 38 40 import javax.swing.Timer; 41 import javax.swing.UIManager; 42 import javax.swing.plaf.FontUIResource; 39 43 40 44 import org.openstreetmap.josm.Main; 41 45 import org.openstreetmap.josm.gui.ExtendedDialog; 42 46 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 47 import org.openstreetmap.josm.tools.CheckParameterUtil; 43 48 import org.openstreetmap.josm.tools.GBC; 44 49 import org.openstreetmap.josm.tools.ImageProvider; … … 297 302 298 303 /** 304 * Gets the font used to display monospaced text in a component, if possible. 305 * @param component The component 306 * @return the font used to display monospaced text in a component, if possible 307 * @since 7896 308 */ 309 public static Font getMonospacedFont(JComponent component) { 310 // Special font for Khmer script 311 if ("km".equals(Main.pref.get("language"))) { 312 return component.getFont(); 313 } else { 314 return new Font("Monospaced", component.getFont().getStyle(), component.getFont().getSize()); 315 } 316 } 317 318 /** 299 319 * Gets the font used to display JOSM title in about dialog and splash screen. 300 320 * @return By order or priority, the first font available in local fonts: … … 303 323 * 3. Arial Bold 20 304 324 * 4. SansSerif Bold 20 325 * Except if current language is Khmer, where it will be current font at size 20 305 326 * @since 5797 306 327 */ 307 328 public static Font getTitleFont() { 308 329 List<String> fonts = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); 330 // Special font for Khmer script 331 if ("km".equals(Main.pref.get("language"))) { 332 return UIManager.getFont("Label.font").deriveFont(20.0f); 333 } 309 334 // Helvetica is the preferred choice but is not available by default on Windows 310 335 // (https://www.microsoft.com/typography/fonts/product.aspx?pid=161) … … 346 371 return Main.isPlatformOsx() ? KeyEvent.META_DOWN_MASK : KeyEvent.CTRL_DOWN_MASK; 347 372 } 373 374 /** 375 * Sets a global font for all UI, replacing default font of current look and feel. 376 * @param name Font name. It is up to the caller to make sure the font exists 377 * @since 7896 378 * @throws IllegalArgumentException if name is null 379 */ 380 public static void setUIFont(String name) { 381 CheckParameterUtil.ensureParameterNotNull(name, "name"); 382 Main.info("Setting "+name+" as the default UI font"); 383 Enumeration<?> keys = UIManager.getDefaults().keys(); 384 while (keys.hasMoreElements()) { 385 Object key = keys.nextElement(); 386 Object value = UIManager.get(key); 387 if (value != null && value instanceof FontUIResource) { 388 FontUIResource fui = (FontUIResource)value; 389 UIManager.put(key, new FontUIResource(name, fui.getStyle(), fui.getSize())); 390 } 391 } 392 } 348 393 }
Note:
See TracChangeset
for help on using the changeset viewer.