J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * 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 | */ |
| 36 | class MetalFontDesktopProperty extends com.sun.java.swing.plaf.windows.DesktopProperty { |
| 37 | /** |
| 38 | * Maps from metal font theme type as defined in MetalTheme |
| 39 | * to the corresponding desktop property name. |
| 40 | */ |
| 41 | private static final String[] propertyMapping = { |
| 42 | "win.ansiVar.font.height", |
| 43 | "win.tooltip.font.height", |
| 44 | "win.ansiVar.font.height", |
| 45 | "win.menu.font.height", |
| 46 | "win.frame.captionFont.height", |
| 47 | "win.menu.font.height" |
| 48 | }; |
| 49 | |
| 50 | /** |
| 51 | * Corresponds to a MetalTheme font type. |
| 52 | */ |
| 53 | private int type; |
| 54 | |
| 55 | |
| 56 | /** |
| 57 | * Creates a MetalFontDesktopProperty. The key used to lookup the |
| 58 | * desktop property is determined from the type of font. |
| 59 | * |
| 60 | * @param type MetalTheme font type. |
| 61 | */ |
| 62 | MetalFontDesktopProperty(int type) { |
| 63 | this(propertyMapping[type], Toolkit.getDefaultToolkit(), type); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Creates a MetalFontDesktopProperty. |
| 68 | * |
| 69 | * @param key Key used in looking up desktop value. |
| 70 | * @param toolkit Toolkit used to fetch property from, can be null |
| 71 | * in which default will be used. |
| 72 | * @param type Type of font being used, corresponds to MetalTheme font |
| 73 | * type. |
| 74 | */ |
| 75 | MetalFontDesktopProperty(String key, Toolkit kit, int type) { |
| 76 | super(key, null, kit); |
| 77 | this.type = type; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Overriden to create a Font with the size coming from the desktop |
| 82 | * and the style and name coming from DefaultMetalTheme. |
| 83 | */ |
| 84 | protected Object configureValue(Object value) { |
| 85 | if (value instanceof Integer) { |
| 86 | value = new Font(DefaultMetalTheme.getDefaultFontName(type), |
| 87 | DefaultMetalTheme.getDefaultFontStyle(type), |
| 88 | ((Integer)value).intValue()); |
| 89 | } |
| 90 | return super.configureValue(value); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Returns the default font. |
| 95 | */ |
| 96 | protected Object getDefaultValue() { |
| 97 | return new Font(DefaultMetalTheme.getDefaultFontName(type), |
| 98 | DefaultMetalTheme.getDefaultFontStyle(type), |
| 99 | DefaultMetalTheme.getDefaultFontSize(type)); |
| 100 | } |
| 101 | } |