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 package javax.swing.plaf.metal;
  26 
  27 import java.awt.*;
  28 
  29 /**
  30  * DesktopProperty that only uses font height in configuring font. This
  31  * is only used on Windows.
  32  *
  33  */
  34 class MetalFontDesktopProperty extends com.sun.java.swing.plaf.windows.DesktopProperty {
  35     /**
  36      * Maps from metal font theme type as defined in MetalTheme
  37      * to the corresponding desktop property name.
  38      */
  39     private static final String[] propertyMapping = {
  40         "win.ansiVar.font.height",
  41         "win.tooltip.font.height",
  42         "win.ansiVar.font.height",
  43         "win.menu.font.height",
  44         "win.frame.captionFont.height",
  45         "win.menu.font.height"
  46     };
  47 
  48     /**
  49      * Corresponds to a MetalTheme font type.
  50      */
  51     private int type;
  52 
  53 
  54     /**
  55      * Creates a MetalFontDesktopProperty. The key used to lookup the
  56      * desktop property is determined from the type of font.
  57      *
  58      * @param type MetalTheme font type.
  59      */
  60     MetalFontDesktopProperty(int type) {
  61         this(propertyMapping[type], type);
  62     }
  63 
  64     /**
  65      * Creates a MetalFontDesktopProperty.
  66      *
  67      * @param key Key used in looking up desktop value.
  68      * @param type Type of font being used, corresponds to MetalTheme font
  69      *        type.
  70      */
  71     MetalFontDesktopProperty(String key, int type) {
  72         super(key, null);
  73         this.type = type;
  74     }
  75 
  76     /**
  77      * Overriden to create a Font with the size coming from the desktop
  78      * and the style and name coming from DefaultMetalTheme.
  79      */
  80     protected Object configureValue(Object value) {
  81         if (value instanceof Integer) {
  82             value = new Font(DefaultMetalTheme.getDefaultFontName(type),
  83                              DefaultMetalTheme.getDefaultFontStyle(type),
  84                              ((Integer)value).intValue());
  85         }
  86         return super.configureValue(value);
  87     }
  88 
  89     /**
  90      * Returns the default font.
  91      */
  92     protected Object getDefaultValue() {
  93         return new Font(DefaultMetalTheme.getDefaultFontName(type),
  94                         DefaultMetalTheme.getDefaultFontStyle(type),
  95                         DefaultMetalTheme.getDefaultFontSize(type));
  96     }
  97 }