01 /*
02 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
03 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04 *
05 * This code is free software; you can redistribute it and/or modify it
06 * under the terms of the GNU General Public License version 2 only, as
07 * published by the Free Software Foundation. Sun designates this
08 * particular file as subject to the "Classpath" exception as provided
09 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25 package javax.swing.plaf.metal;
26
27 import java.awt.*;
28 import java.beans.*;
29 import javax.swing.*;
30
31 /**
32 * DesktopProperty that only uses font height in configuring font. This
33 * is only used on Windows.
34 *
35 * @version @(#)MetalFontDesktopProperty.java 1.11 07/05/05
36 */
37 class MetalFontDesktopProperty extends
38 com.sun.java.swing.plaf.windows.DesktopProperty {
39 /**
40 * Maps from metal font theme type as defined in MetalTheme
41 * to the corresponding desktop property name.
42 */
43 private static final String[] propertyMapping = {
44 "win.ansiVar.font.height", "win.tooltip.font.height",
45 "win.ansiVar.font.height", "win.menu.font.height",
46 "win.frame.captionFont.height", "win.menu.font.height" };
47
48 /**
49 * Corresponds to a MetalTheme font type.
50 */
51 private int type;
52
53 /**
54 * Creates a MetalFontDesktopProperty. The key used to lookup the
55 * desktop property is determined from the type of font.
56 *
57 * @param type MetalTheme font type.
58 */
59 MetalFontDesktopProperty(int type) {
60 this (propertyMapping[type], Toolkit.getDefaultToolkit(), type);
61 }
62
63 /**
64 * Creates a MetalFontDesktopProperty.
65 *
66 * @param key Key used in looking up desktop value.
67 * @param toolkit Toolkit used to fetch property from, can be null
68 * in which default will be used.
69 * @param type Type of font being used, corresponds to MetalTheme font
70 * type.
71 */
72 MetalFontDesktopProperty(String key, Toolkit kit, int type) {
73 super (key, null, kit);
74 this .type = type;
75 }
76
77 /**
78 * Overriden to create a Font with the size coming from the desktop
79 * and the style and name coming from DefaultMetalTheme.
80 */
81 protected Object configureValue(Object value) {
82 if (value instanceof Integer) {
83 value = new Font(
84 DefaultMetalTheme.getDefaultFontName(type),
85 DefaultMetalTheme.getDefaultFontStyle(type),
86 ((Integer) value).intValue());
87 }
88 return super .configureValue(value);
89 }
90
91 /**
92 * Returns the default font.
93 */
94 protected Object getDefaultValue() {
95 return new Font(DefaultMetalTheme.getDefaultFontName(type),
96 DefaultMetalTheme.getDefaultFontStyle(type),
97 DefaultMetalTheme.getDefaultFontSize(type));
98 }
99 }
|