jdk/src/share/classes/java/awt/GraphicsEnvironment.java
author rkennke
Wed, 22 Jul 2009 15:52:41 +0200
changeset 3925 945d08ef1c7b
parent 3016 2b51287517f1
child 3928 be186a33df9b
permissions -rw-r--r--
6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException Summary: Try to load GraphicsEnvironment with bootclassloader first, only then try app classloader. Reviewed-by: prr, tdv, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.image.BufferedImage;
3925
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    30
import java.security.AccessController;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.java2d.HeadlessGraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.java2d.SunGraphicsEnvironment;
3925
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    34
import sun.security.action.GetPropertyAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The <code>GraphicsEnvironment</code> class describes the collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * of {@link GraphicsDevice} objects and {@link java.awt.Font} objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * available to a Java(tm) application on a particular platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The resources in this <code>GraphicsEnvironment</code> might be local
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * or on a remote machine.  <code>GraphicsDevice</code> objects can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * screens, printers or image buffers and are the destination of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * {@link Graphics2D} drawing methods.  Each <code>GraphicsDevice</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * has a number of {@link GraphicsConfiguration} objects associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * it.  These objects specify the different configurations in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <code>GraphicsDevice</code> can be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public abstract class GraphicsEnvironment {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static GraphicsEnvironment localEnv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * The headless state of the Toolkit and GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static Boolean headless;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * The headless state assumed by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static Boolean defaultHeadless;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * This is an abstract class and cannot be instantiated directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Instances must be obtained from a suitable factory or query method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected GraphicsEnvironment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Returns the local <code>GraphicsEnvironment</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @return the local <code>GraphicsEnvironment</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (localEnv == null) {
3925
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    78
            localEnv = createGE();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return localEnv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
3925
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    85
     * Creates and returns the GraphicsEnvironment, according to the
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    86
     * system property 'java.awt.graphicsenv'.
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    87
     *
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    88
     * @return the graphics environment
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    89
     */
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    90
    private static GraphicsEnvironment createGE() {
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    91
        GraphicsEnvironment ge;
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    92
        String nm = AccessController.doPrivileged(new GetPropertyAction("java.awt.graphicsenv", null));
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    93
        try {
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    94
//          long t0 = System.currentTimeMillis();
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    95
            Class geCls;
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    96
            try {
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    97
                // First we try if the bootclassloader finds the requested
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    98
                // class. This way we can avoid to run in a privileged block.
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
    99
                geCls = Class.forName(nm);
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   100
            } catch (ClassNotFoundException ex) {
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   101
                // If the bootclassloader fails, we try again with the
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   102
                // application classloader.
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   103
                ClassLoader cl = ClassLoader.getSystemClassLoader();
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   104
                geCls = Class.forName(nm, true, cl);
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   105
            }
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   106
            ge = (GraphicsEnvironment) geCls.newInstance();
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   107
//          long t1 = System.currentTimeMillis();
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   108
//          System.out.println("GE creation took " + (t1-t0)+ "ms.");
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   109
            if (isHeadless()) {
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   110
                localEnv = new HeadlessGraphicsEnvironment(localEnv);
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   111
            }
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   112
        } catch (ClassNotFoundException e) {
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   113
            throw new Error("Could not find class: "+nm);
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   114
        } catch (InstantiationException e) {
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   115
            throw new Error("Could not instantiate Graphics Environment: "
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   116
                            + nm);
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   117
        } catch (IllegalAccessException e) {
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   118
            throw new Error ("Could not access Graphics Environment: "
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   119
                             + nm);
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   120
        }
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   121
        return ge;
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   122
    }
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   123
945d08ef1c7b 6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
rkennke
parents: 3016
diff changeset
   124
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Tests whether or not a display, keyboard, and mouse can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * supported in this environment.  If this method returns true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * a HeadlessException is thrown from areas of the Toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * and GraphicsEnvironment that are dependent on a display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * keyboard, or mouse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @return <code>true</code> if this environment cannot support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * a display, keyboard, and mouse; <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see java.awt.HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public static boolean isHeadless() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return getHeadlessProperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @return warning message if headless state is assumed by default;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * null otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static String getHeadlessMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (headless == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            getHeadlessProperty(); // initialize the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return defaultHeadless != Boolean.TRUE ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            "\nNo X11 DISPLAY variable was set, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            "but this program performed an operation which requires it.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @return the value of the property "java.awt.headless"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static boolean getHeadlessProperty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (headless == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    String nm = System.getProperty("java.awt.headless");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    if (nm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                        /* No need to ask for DISPLAY when run in a browser */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                        if (System.getProperty("javaplugin.version") != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                            headless = defaultHeadless = Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                            String osName = System.getProperty("os.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                            headless = defaultHeadless =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                Boolean.valueOf(("Linux".equals(osName) || "SunOS".equals(osName)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                                (System.getenv("DISPLAY") == null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    } else if (nm.equals("true")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                        headless = Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        headless = Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return headless.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Check for headless state and throw HeadlessException if headless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    static void checkHeadless() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Returns whether or not a display, keyboard, and mouse can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * supported in this graphics environment.  If this returns true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <code>HeadlessException</code> will be thrown from areas of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * graphics environment that are dependent on a display, keyboard, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * mouse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return <code>true</code> if a display, keyboard, and mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * can be supported in this environment; <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @see java.awt.HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @see #isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public boolean isHeadlessInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // By default (local graphics environment), simply check the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // headless property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return getHeadlessProperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Returns an array of all of the screen <code>GraphicsDevice</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return an array containing all the <code>GraphicsDevice</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * objects that represent screen devices
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @exception HeadlessException if isHeadless() returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see #isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public abstract GraphicsDevice[] getScreenDevices()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        throws HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Returns the default screen <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @return the <code>GraphicsDevice</code> that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * default screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @exception HeadlessException if isHeadless() returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see #isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public abstract GraphicsDevice getDefaultScreenDevice()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        throws HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Returns a <code>Graphics2D</code> object for rendering into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * specified {@link BufferedImage}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param img the specified <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @return a <code>Graphics2D</code> to be used for rendering into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * the specified <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @throws NullPointerException if <code>img</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public abstract Graphics2D createGraphics(BufferedImage img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Returns an array containing a one-point size instance of all fonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * available in this <code>GraphicsEnvironment</code>.  Typical usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * would be to allow a user to select a particular font.  Then, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * application can size the font and set various font attributes by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * calling the <code>deriveFont</code> method on the choosen instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * This method provides for the application the most precise control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * over which <code>Font</code> instance is used to render text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * If a font in this <code>GraphicsEnvironment</code> has multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * programmable variations, only one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * instance of that <code>Font</code> is returned in the array, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * other variations must be derived by the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * If a font in this environment has multiple programmable variations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * such as Multiple-Master fonts, only one instance of that font is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * returned in the <code>Font</code> array.  The other variations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * must be derived by the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @return an array of <code>Font</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @see #getAvailableFontFamilyNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @see java.awt.Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see java.awt.Font#deriveFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see java.awt.Font#getFontName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public abstract Font[] getAllFonts();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Returns an array containing the names of all font families in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <code>GraphicsEnvironment</code> localized for the default locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * as returned by <code>Locale.getDefault()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Typical usage would be for presentation to a user for selection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * a particular family name. An application can then specify this name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * when creating a font, in conjunction with a style, such as bold or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * italic, giving the font system flexibility in choosing its own best
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * match among multiple fonts in the same font family.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @return an array of <code>String</code> containing font family names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * localized for the default locale, or a suitable alternative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * name if no name exists for this locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @see #getAllFonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @see java.awt.Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @see java.awt.Font#getFamily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public abstract String[] getAvailableFontFamilyNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Returns an array containing the names of all font families in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * <code>GraphicsEnvironment</code> localized for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Typical usage would be for presentation to a user for selection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * a particular family name. An application can then specify this name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * when creating a font, in conjunction with a style, such as bold or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * italic, giving the font system flexibility in choosing its own best
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * match among multiple fonts in the same font family.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param l a {@link Locale} object that represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * particular geographical, political, or cultural region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Specifying <code>null</code> is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * specifying <code>Locale.getDefault()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @return an array of <code>String</code> containing font family names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * localized for the specified <code>Locale</code>, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * suitable alternative name if no name exists for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @see #getAllFonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @see java.awt.Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @see java.awt.Font#getFamily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public abstract String[] getAvailableFontFamilyNames(Locale l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Registers a <i>created</i> <code>Font</code>in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * <code>GraphicsEnvironment</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * A created font is one that was returned from calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * {@link Font#createFont}, or derived from a created font by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * calling {@link Font#deriveFont}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * After calling this method for such a font, it is available to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * be used in constructing new <code>Font</code>s by name or family name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * and is enumerated by {@link #getAvailableFontFamilyNames} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * {@link #getAllFonts} within the execution context of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * application or applet. This means applets cannot register fonts in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * a way that they are visible to other applets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Reasons that this method might not register the font and therefore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * return <code>false</code> are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <li>The font is not a <i>created</i> <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <li>The font conflicts with a non-created <code>Font</code> already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * in this <code>GraphicsEnvironment</code>. For example if the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * is that of a system font, or a logical font as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * documentation of the {@link Font} class. It is implementation dependent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * whether a font may also conflict if it has the same family name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * as a system font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <p>Notice that an application can supersede the registration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * of an earlier created font with a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return true if the <code>font</code> is successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * registered in this <code>GraphicsEnvironment</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @throws NullPointerException if <code>font</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public boolean registerFont(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (font == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            throw new NullPointerException("font cannot be null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return sun.font.FontManager.registerFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Indicates a preference for locale-specific fonts in the mapping of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * logical fonts to physical fonts. Calling this method indicates that font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * rendering should primarily use fonts specific to the primary writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * system (the one indicated by the default encoding and the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * default locale). For example, if the primary writing system is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Japanese, then characters should be rendered using a Japanese font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * if possible, and other fonts should only be used for characters for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * which the Japanese font doesn't have glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * The actual change in font rendering behavior resulting from a call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * to this method is implementation dependent; it may have no effect at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * all, or the requested behavior may already match the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * The behavior may differ between font rendering in lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * and peered components.  Since calling this method requests a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * different font, clients should expect different metrics, and may need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * to recalculate window sizes and layout. Therefore this method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * be called before user interface initialisation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public void preferLocaleFonts() {
2372
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 2
diff changeset
   380
        if (!(this instanceof SunGraphicsEnvironment)) {
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 2
diff changeset
   381
            return;
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 2
diff changeset
   382
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        sun.font.FontManager.preferLocaleFonts();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Indicates a preference for proportional over non-proportional (e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * dual-spaced CJK fonts) fonts in the mapping of logical fonts to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * physical fonts. If the default mapping contains fonts for which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * proportional and non-proportional variants exist, then calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * this method indicates the mapping should use a proportional variant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * The actual change in font rendering behavior resulting from a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * this method is implementation dependent; it may have no effect at all.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * The behavior may differ between font rendering in lightweight and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * peered components. Since calling this method requests a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * different font, clients should expect different metrics, and may need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * to recalculate window sizes and layout. Therefore this method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * be called before user interface initialisation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public void preferProportionalFonts() {
2372
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 2
diff changeset
   403
        if (!(this instanceof SunGraphicsEnvironment)) {
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 2
diff changeset
   404
            return;
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 2
diff changeset
   405
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        sun.font.FontManager.preferProportionalFonts();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Returns the Point where Windows should be centered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * It is recommended that centered Windows be checked to ensure they fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * within the available display area using getMaximumWindowBounds().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @return the point where Windows should be centered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @exception HeadlessException if isHeadless() returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see #getMaximumWindowBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public Point getCenterPoint() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    // Default implementation: return the center of the usable bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    // default screen device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        Rectangle usableBounds =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         SunGraphicsEnvironment.getUsableBounds(getDefaultScreenDevice());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        return new Point((usableBounds.width / 2) + usableBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                         (usableBounds.height / 2) + usableBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Returns the maximum bounds for centered Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * These bounds account for objects in the native windowing system such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * task bars and menu bars.  The returned bounds will reside on a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * display with one exception: on multi-screen systems where Windows should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * be centered across all displays, this method returns the bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * entire display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * To get the usable bounds of a single display, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * <code>GraphicsConfiguration.getBounds()</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * <code>Toolkit.getScreenInsets()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @return  the maximum bounds for centered Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @exception HeadlessException if isHeadless() returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @see #getCenterPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @see GraphicsConfiguration#getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @see Toolkit#getScreenInsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public Rectangle getMaximumWindowBounds() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    // Default implementation: return the usable bounds of the default screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    // device.  This is correct for Microsoft Windows and non-Xinerama X11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return SunGraphicsEnvironment.getUsableBounds(getDefaultScreenDevice());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
}