1 /*
2  * Copyright (c) 2001, 2017, Oracle and/or its affiliates. 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.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package javax.swing.plaf.metal;
27 
28 import java.awt.Font;
29 
30 import sun.swing.plaf.DesktopProperty;
31 
32 /**
33  * DesktopProperty that only uses font height in configuring font. This
34  * is only used on Windows.
35  */
36 final class MetalFontDesktopProperty extends 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      */
MetalFontDesktopProperty(int type)62     MetalFontDesktopProperty(int type) {
63         this(propertyMapping[type], type);
64     }
65 
66     /**
67      * Creates a MetalFontDesktopProperty.
68      *
69      * @param key Key used in looking up desktop value.
70      * @param type Type of font being used, corresponds to MetalTheme font
71      *        type.
72      */
MetalFontDesktopProperty(String key, int type)73     MetalFontDesktopProperty(String key, int type) {
74         super(key, null);
75         this.type = type;
76     }
77 
78     /**
79      * Overriden to create a Font with the size coming from the desktop
80      * and the style and name coming from DefaultMetalTheme.
81      */
configureValue(Object value)82     protected Object configureValue(Object value) {
83         if (value instanceof Integer) {
84             value = new Font(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      */
getDefaultValue()94     protected Object getDefaultValue() {
95         return new Font(DefaultMetalTheme.getDefaultFontName(type),
96                         DefaultMetalTheme.getDefaultFontStyle(type),
97                         DefaultMetalTheme.getDefaultFontSize(type));
98     }
99 }
100