KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > metal > MetalFontDesktopProperty


1 /*
2  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4  */

5 package javax.swing.plaf.metal;
6
7 import java.awt.*;
8 import java.beans.*;
9 import javax.swing.*;
10
11 /**
12  * DesktopProperty that only uses font height in configuring font. This
13  * is only used on Windows.
14  *
15  * @version @(#)MetalFontDesktopProperty.java 1.4 03/12/19
16  */

17 class MetalFontDesktopProperty extends com.sun.java.swing.plaf.windows.DesktopProperty {
18     /**
19      * Maps from metal font theme type as defined in MetalTheme
20      * to the corresponding desktop property name.
21      */

22     private static final String JavaDoc[] propertyMapping = {
23         "win.ansiVar.font.height",
24         "win.tooltip.font.height",
25         "win.ansiVar.font.height",
26         "win.menu.font.height",
27         "win.frame.captionFont.height",
28         "win.menu.font.height"
29     };
30
31     /**
32      * Corresponds to a MetalTheme font type.
33      */

34     private int type;
35
36
37     /**
38      * Creates a MetalFontDesktopProperty. The key used to lookup the
39      * desktop property is determined from the type of font.
40      *
41      * @param type MetalTheme font type.
42      */

43     MetalFontDesktopProperty(int type) {
44         this(propertyMapping[type], Toolkit.getDefaultToolkit(), type);
45     }
46
47     /**
48      * Creates a MetalFontDesktopProperty.
49      *
50      * @param key Key used in looking up desktop value.
51      * @param toolkit Toolkit used to fetch property from, can be null
52      * in which default will be used.
53      * @param type Type of font being used, corresponds to MetalTheme font
54      * type.
55      */

56     MetalFontDesktopProperty(String JavaDoc key, Toolkit kit, int type) {
57         super(key, null, kit);
58         this.type = type;
59     }
60
61     /**
62      * Overriden to create a Font with the size coming from the desktop
63      * and the style and name coming from DefaultMetalTheme.
64      */

65     protected Object JavaDoc configureValue(Object JavaDoc value) {
66         if (value instanceof Integer JavaDoc) {
67             value = new Font(DefaultMetalTheme.getDefaultFontName(type),
68                              DefaultMetalTheme.getDefaultFontStyle(type),
69                              ((Integer JavaDoc)value).intValue());
70         }
71         return super.configureValue(value);
72     }
73
74     /**
75      * Returns the default font.
76      */

77     protected Object JavaDoc getDefaultValue() {
78         return new Font(DefaultMetalTheme.getDefaultFontName(type),
79                         DefaultMetalTheme.getDefaultFontStyle(type),
80                         DefaultMetalTheme.getDefaultFontSize(type));
81     }
82 }
83
Popular Tags