jdk/src/share/classes/sun/font/FontManagerFactory.java
author rkennke
Fri, 07 Aug 2009 19:36:28 +0200
changeset 3929 de1a48b7aa41
child 4824 791405fa20ff
permissions -rw-r--r--
6869705: Missing files of CR6795908, FontManager refactoring Reviewed-by: prr, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     1
/*
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     4
 *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    10
 *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    15
 * accompanied this code).
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    16
 *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    20
 *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    23
 * have any questions.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    24
 */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    25
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    26
package sun.font;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    27
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    28
import java.awt.AWTError;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    29
import java.awt.Font;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    30
import java.awt.GraphicsEnvironment;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    31
import java.awt.Toolkit;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    32
import java.security.AccessController;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    33
import java.security.PrivilegedAction;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    34
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    35
import sun.security.action.GetPropertyAction;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    36
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    37
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    38
/**
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    39
 * Factory class used to retrieve a valid FontManager instance for the current
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    40
 * platform.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    41
 *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    42
 * A default implementation is given for Linux, Solaris and Windows.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    43
 * You can alter the behaviour of the {@link #getInstance()} method by setting
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    44
 * the {@code sun.font.fontmanager} property. For example:
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    45
 * {@code sun.font.fontmanager=sun.awt.X11FontManager}
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    46
 */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    47
public final class FontManagerFactory {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    48
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    49
    /** Our singleton instance. */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    50
    private static FontManager instance = null;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    51
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    52
    private static final String DEFAULT_CLASS;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    53
    static {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    54
        if (FontUtilities.isWindows)
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    55
            DEFAULT_CLASS = "sun.awt.Win32FontManager";
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    56
        else
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    57
            DEFAULT_CLASS = "sun.awt.X11FontManager";
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    58
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    59
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    60
    /**
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    61
     * Get a valid FontManager implementation for the current platform.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    62
     *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    63
     * @return a valid FontManager instance for the current platform
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    64
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    65
    public static synchronized FontManager getInstance() {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    66
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    67
        if (instance != null) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    68
            return instance;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    69
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    70
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    71
        String fmClassName = AccessController.doPrivileged(
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    72
                new GetPropertyAction("sun.font.fontmanager",
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    73
                                      DEFAULT_CLASS));
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    74
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    75
        try {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    76
            @SuppressWarnings("unchecked")
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    77
            ClassLoader cl = (ClassLoader)
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    78
                AccessController.doPrivileged(new PrivilegedAction() {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    79
                    public Object run() {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    80
                        return ClassLoader.getSystemClassLoader();
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    81
                    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    82
                });
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    83
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    84
            @SuppressWarnings("unchecked")
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    85
            Class fmClass = Class.forName(fmClassName, true, cl);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    86
            instance = (FontManager) fmClass.newInstance();
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    87
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    88
        } catch (ClassNotFoundException ex) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    89
            InternalError err = new InternalError();
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    90
            err.initCause(ex);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    91
            throw err;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    92
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    93
        } catch (InstantiationException ex) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    94
            InternalError err = new InternalError();
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    95
            err.initCause(ex);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    96
            throw err;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    97
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    98
        } catch (IllegalAccessException ex) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    99
            InternalError err = new InternalError();
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   100
            err.initCause(ex);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   101
            throw err;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   102
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   103
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   104
        return instance;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   105
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   106
}