1 /*
   2  * Copyright (c) 2001, 2009, 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 toolkit Toolkit used to fetch property from, can be null
  69      *        in which default will be used.
  70      * @param type Type of font being used, corresponds to MetalTheme font
  71      *        type.
  72      */
  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      */
  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      */
  94     protected Object getDefaultValue() {
  95         return new Font(DefaultMetalTheme.getDefaultFontName(type),
  96                         DefaultMetalTheme.getDefaultFontStyle(type),
  97                         DefaultMetalTheme.getDefaultFontSize(type));
  98     }
  99 }