jdk/src/share/classes/sun/font/FontManagerFactory.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 4824 791405fa20ff
child 7668 d4a77089c587
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4824
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3929
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4824
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4824
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3929
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4824
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4824
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4824
diff changeset
    23
 * questions.
3929
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
4824
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    71
        AccessController.doPrivileged(new PrivilegedAction() {
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    72
4824
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    73
            public Object run() {
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    74
                try {
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    75
                    String fmClassName =
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    76
                            System.getProperty("sun.font.fontmanager",
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    77
                                               DEFAULT_CLASS);
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    78
                    ClassLoader cl = ClassLoader.getSystemClassLoader();
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    79
                    Class fmClass = Class.forName(fmClassName, true, cl);
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    80
                    instance = (FontManager) fmClass.newInstance();
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    81
                } catch (ClassNotFoundException ex) {
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    82
                    InternalError err = new InternalError();
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    83
                    err.initCause(ex);
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    84
                    throw err;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    85
4824
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    86
                } catch (InstantiationException ex) {
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    87
                    InternalError err = new InternalError();
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    88
                    err.initCause(ex);
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    89
                    throw err;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    90
4824
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    91
                } catch (IllegalAccessException ex) {
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    92
                    InternalError err = new InternalError();
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    93
                    err.initCause(ex);
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    94
                    throw err;
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    95
                }
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    96
                return null;
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    97
            }
791405fa20ff 6888734: PIT: regression test fails when java.security.manager is enabled
rkennke
parents: 3929
diff changeset
    98
        });
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    99
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   100
        return instance;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   101
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   102
}