1. /*
  2. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.swing.plaf.metal;
  6. import java.awt.*;
  7. import java.beans.*;
  8. import javax.swing.*;
  9. /**
  10. * DesktopProperty that only uses font height in configuring font. This
  11. * is only used on Windows.
  12. *
  13. * @version @(#)MetalFontDesktopProperty.java 1.4 03/12/19
  14. */
  15. class MetalFontDesktopProperty extends com.sun.java.swing.plaf.windows.DesktopProperty {
  16. /**
  17. * Maps from metal font theme type as defined in MetalTheme
  18. * to the corresponding desktop property name.
  19. */
  20. private static final String[] propertyMapping = {
  21. "win.ansiVar.font.height",
  22. "win.tooltip.font.height",
  23. "win.ansiVar.font.height",
  24. "win.menu.font.height",
  25. "win.frame.captionFont.height",
  26. "win.menu.font.height"
  27. };
  28. /**
  29. * Corresponds to a MetalTheme font type.
  30. */
  31. private int type;
  32. /**
  33. * Creates a MetalFontDesktopProperty. The key used to lookup the
  34. * desktop property is determined from the type of font.
  35. *
  36. * @param type MetalTheme font type.
  37. */
  38. MetalFontDesktopProperty(int type) {
  39. this(propertyMapping[type], Toolkit.getDefaultToolkit(), type);
  40. }
  41. /**
  42. * Creates a MetalFontDesktopProperty.
  43. *
  44. * @param key Key used in looking up desktop value.
  45. * @param toolkit Toolkit used to fetch property from, can be null
  46. * in which default will be used.
  47. * @param type Type of font being used, corresponds to MetalTheme font
  48. * type.
  49. */
  50. MetalFontDesktopProperty(String key, Toolkit kit, int type) {
  51. super(key, null, kit);
  52. this.type = type;
  53. }
  54. /**
  55. * Overriden to create a Font with the size coming from the desktop
  56. * and the style and name coming from DefaultMetalTheme.
  57. */
  58. protected Object configureValue(Object value) {
  59. if (value instanceof Integer) {
  60. value = new Font(DefaultMetalTheme.getDefaultFontName(type),
  61. DefaultMetalTheme.getDefaultFontStyle(type),
  62. ((Integer)value).intValue());
  63. }
  64. return super.configureValue(value);
  65. }
  66. /**
  67. * Returns the default font.
  68. */
  69. protected Object getDefaultValue() {
  70. return new Font(DefaultMetalTheme.getDefaultFontName(type),
  71. DefaultMetalTheme.getDefaultFontStyle(type),
  72. DefaultMetalTheme.getDefaultFontSize(type));
  73. }
  74. }