jdk/src/java.desktop/share/classes/java/awt/GraphicsDevice.java
author prr
Sat, 19 Sep 2015 15:45:59 -0700
changeset 32865 f9cb6e427f9e
parent 25859 3317bb8137f4
child 35667 ed476aba94de
permissions -rw-r--r--
8136783: Run blessed-modifier-order script on java.desktop Reviewed-by: martin, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
20463
ed2ea3722c31 7068423: Spec for java.awt.GraphicsDevice.getFullScreenWindow() needs clarification
bagiras
parents: 20455
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
    23
 * questions.
2
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.ColorModel;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
    30
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
    31
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.awt.AppContext;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
    33
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The <code>GraphicsDevice</code> class describes the graphics devices
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * that might be available in a particular graphics environment.  These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * include screen and printer devices. Note that there can be many screens
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * and many printers in an instance of {@link GraphicsEnvironment}. Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * graphics device has one or more {@link GraphicsConfiguration} objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * associated with it.  These objects specify the different configurations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * in which the <code>GraphicsDevice</code> can be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * In a multi-screen environment, the <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * objects can be used to render components on multiple screens.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * following code sample demonstrates how to create a <code>JFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * object for each <code>GraphicsConfiguration</code> on each screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * device in the <code>GraphicsEnvironment</code>:
21777
c0a423e43b0d 8025235: [javadoc] fix some errors in 2D
yan
parents: 21260
diff changeset
    49
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   GraphicsEnvironment ge = GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *   GraphicsDevice[] gs = ge.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   for (int j = 0; j < gs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *      GraphicsDevice gd = gs[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *      GraphicsConfiguration[] gc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      gd.getConfigurations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *      for (int i=0; i < gc.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *         JFrame f = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *         JFrame(gs[j].getDefaultConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *         Canvas c = new Canvas(gc[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *         Rectangle gcBounds = gc[i].getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *         int xoffs = gcBounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *         int yoffs = gcBounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *         f.getContentPane().add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *         f.setLocation((i*50)+xoffs, (i*60)+yoffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *         f.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *   }
21777
c0a423e43b0d 8025235: [javadoc] fix some errors in 2D
yan
parents: 21260
diff changeset
    69
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * For more information on full-screen exclusive mode API, see the
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 18758
diff changeset
    72
 * <a href="http://docs.oracle.com/javase/tutorial/extra/fullscreen/index.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Full-Screen Exclusive Mode API Tutorial</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @see GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
public abstract class GraphicsDevice {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private Window fullScreenWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private AppContext fullScreenAppContext; // tracks which AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                             // created the FS window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // this lock is used for making synchronous changes to the AppContext's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // current full screen window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private final Object fsAppContextLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private Rectangle windowedModeBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * This is an abstract class that cannot be instantiated directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Instances must be obtained from a suitable factory or query method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @see GraphicsEnvironment#getScreenDevices
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @see GraphicsEnvironment#getDefaultScreenDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @see GraphicsConfiguration#getDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected GraphicsDevice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Device is a raster screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   102
    public static final int TYPE_RASTER_SCREEN          = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Device is a printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   107
    public static final int TYPE_PRINTER                = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Device is an image buffer.  This buffer can reside in device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * or system memory but it is not physically viewable by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   113
    public static final int TYPE_IMAGE_BUFFER           = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   115
    /**
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   116
     * Kinds of translucency supported by the underlying system.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   117
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   118
     * @see #isWindowTranslucencySupported
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   119
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   120
     * @since 1.7
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   121
     */
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   122
    public static enum WindowTranslucency {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   123
        /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   124
         * Represents support in the underlying system for windows each pixel
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   125
         * of which is guaranteed to be either completely opaque, with
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   126
         * an alpha value of 1.0, or completely transparent, with an alpha
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   127
         * value of 0.0.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   128
         */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   129
        PERPIXEL_TRANSPARENT,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   130
        /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   131
         * Represents support in the underlying system for windows all of
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   132
         * the pixels of which have the same alpha value between or including
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   133
         * 0.0 and 1.0.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   134
         */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   135
        TRANSLUCENT,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   136
        /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   137
         * Represents support in the underlying system for windows that
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   138
         * contain or might contain pixels with arbitrary alpha values
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   139
         * between and including 0.0 and 1.0.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   140
         */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   141
        PERPIXEL_TRANSLUCENT;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   142
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   143
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Returns the type of this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @return the type of this <code>GraphicsDevice</code>, which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * either be TYPE_RASTER_SCREEN, TYPE_PRINTER or TYPE_IMAGE_BUFFER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see #TYPE_RASTER_SCREEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see #TYPE_PRINTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see #TYPE_IMAGE_BUFFER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public abstract int getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Returns the identification string associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * A particular program might use more than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <code>GraphicsDevice</code> in a <code>GraphicsEnvironment</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * This method returns a <code>String</code> identifying a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * particular <code>GraphicsDevice</code> in the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <code>GraphicsEnvironment</code>.  Although there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * no public method to set this <code>String</code>, a programmer can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * use the <code>String</code> for debugging purposes.  Vendors of
21244
7c2ac5ca05a2 8026021: more fix of javadoc errors and warnings reported by doclint, see the description
cl
parents: 20463
diff changeset
   165
     * the Java&trade; Runtime Environment can
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * format the return value of the <code>String</code>.  To determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * how to interpret the value of the <code>String</code>, contact the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * vendor of your Java Runtime.  To find out who the vendor is, from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * your program, call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * {@link System#getProperty(String) getProperty} method of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * System class with "java.vendor".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return a <code>String</code> that is the identification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * of this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public abstract String getIDstring();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Returns all of the <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * objects associated with this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return an array of <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * objects that are associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public abstract GraphicsConfiguration[] getConfigurations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Returns the default <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * associated with this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return the default <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * of this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public abstract GraphicsConfiguration getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Returns the "best" configuration possible that passes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * criteria defined in the {@link GraphicsConfigTemplate}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param gct the <code>GraphicsConfigTemplate</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * used to obtain a valid <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return a <code>GraphicsConfiguration</code> that passes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * the criteria defined in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <code>GraphicsConfigTemplate</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @see GraphicsConfigTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
           getBestConfiguration(GraphicsConfigTemplate gct) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        GraphicsConfiguration[] configs = getConfigurations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return gct.getBestConfiguration(configs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Returns <code>true</code> if this <code>GraphicsDevice</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * supports full-screen exclusive mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * If a SecurityManager is installed, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * <code>checkPermission</code> method will be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * with <code>AWTPermission("fullScreenExclusive")</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <code>isFullScreenSupported</code> returns true only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * that permission is granted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @return whether full-screen exclusive mode is available for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * this graphics device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public boolean isFullScreenSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Enter full-screen mode, or return to windowed mode.  The entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * full-screen mode may be either exclusive or simulated.  Exclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * mode is only available if <code>isFullScreenSupported</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * returns <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Exclusive mode implies:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <li>Windows cannot overlap the full-screen window.  All other application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * windows will always appear beneath the full-screen window in the Z-order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <li>There can be only one full-screen window on a device at any time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * so calling this method while there is an existing full-screen Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * will cause the existing full-screen window to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * return to windowed mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <li>Input method windows are disabled.  It is advisable to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <code>Component.enableInputMethods(false)</code> to make a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * a non-client of the input method framework.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <p>
9200
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 5506
diff changeset
   246
     * The simulated full-screen mode places and resizes the window to the maximum
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 5506
diff changeset
   247
     * possible visible area of the screen. However, the native windowing system
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 5506
diff changeset
   248
     * may modify the requested geometry-related data, so that the {@code Window} object
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 5506
diff changeset
   249
     * is placed and sized in a way that corresponds closely to the desktop settings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * <p>
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2759
diff changeset
   251
     * When entering full-screen mode, if the window to be used as a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * full-screen window is not visible, this method will make it visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * It will remain visible when returning to windowed mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <p>
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   255
     * When entering full-screen mode, all the translucency effects are reset for
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   256
     * the window. Its shape is set to {@code null}, the opacity value is set to
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   257
     * 1.0f, and the background color alpha is set to 255 (completely opaque).
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   258
     * These values are not restored when returning to windowed mode.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   259
     * <p>
9477
b1b027066790 7032830: GraphicsDevice.setFullScreenWindow() works strange for decorated windows on OEL.
dcherepanov
parents: 9200
diff changeset
   260
     * It is unspecified and platform-dependent how decorated windows operate
b1b027066790 7032830: GraphicsDevice.setFullScreenWindow() works strange for decorated windows on OEL.
dcherepanov
parents: 9200
diff changeset
   261
     * in full-screen mode. For this reason, it is recommended to turn off
b1b027066790 7032830: GraphicsDevice.setFullScreenWindow() works strange for decorated windows on OEL.
dcherepanov
parents: 9200
diff changeset
   262
     * the decorations in a {@code Frame} or {@code Dialog} object by using the
b1b027066790 7032830: GraphicsDevice.setFullScreenWindow() works strange for decorated windows on OEL.
dcherepanov
parents: 9200
diff changeset
   263
     * {@code setUndecorated} method.
b1b027066790 7032830: GraphicsDevice.setFullScreenWindow() works strange for decorated windows on OEL.
dcherepanov
parents: 9200
diff changeset
   264
     * <p>
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   265
     * When returning to windowed mode from an exclusive full-screen window,
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   266
     * any display changes made by calling {@code setDisplayMode} are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * automatically restored to their original state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   269
     * @param w a window to use as the full-screen window; {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * if returning to windowed mode.  Some platforms expect the
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2759
diff changeset
   271
     * fullscreen window to be a top-level component (i.e., a {@code Frame});
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2759
diff changeset
   272
     * therefore it is preferable to use a {@code Frame} here rather than a
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2759
diff changeset
   273
     * {@code Window}.
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   274
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @see #isFullScreenSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see #getFullScreenWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see #setDisplayMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @see Component#enableInputMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @see Component#setVisible
9477
b1b027066790 7032830: GraphicsDevice.setFullScreenWindow() works strange for decorated windows on OEL.
dcherepanov
parents: 9200
diff changeset
   280
     * @see Frame#setUndecorated
b1b027066790 7032830: GraphicsDevice.setFullScreenWindow() works strange for decorated windows on OEL.
dcherepanov
parents: 9200
diff changeset
   281
     * @see Dialog#setUndecorated
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   282
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public void setFullScreenWindow(Window w) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   286
        if (w != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   287
            if (w.getShape() != null) {
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   288
                w.setShape(null);
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   289
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   290
            if (w.getOpacity() < 1.0f) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   291
                w.setOpacity(1.0f);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   292
            }
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 2808
diff changeset
   293
            if (!w.isOpaque()) {
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 2808
diff changeset
   294
                Color bgColor = w.getBackground();
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   295
                bgColor = new Color(bgColor.getRed(), bgColor.getGreen(),
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   296
                                    bgColor.getBlue(), 255);
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   297
                w.setBackground(bgColor);
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   298
            }
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents: 9477
diff changeset
   299
            // Check if this window is in fullscreen mode on another device.
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents: 9477
diff changeset
   300
            final GraphicsConfiguration gc = w.getGraphicsConfiguration();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents: 9477
diff changeset
   301
            if (gc != null && gc.getDevice() != this
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents: 9477
diff changeset
   302
                    && gc.getDevice().getFullScreenWindow() == w) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents: 9477
diff changeset
   303
                gc.getDevice().setFullScreenWindow(null);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents: 9477
diff changeset
   304
            }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   305
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (fullScreenWindow != null && windowedModeBounds != null) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   307
            // if the window went into fs mode before it was realized it may
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   308
            // have (0,0) dimensions
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   309
            if (windowedModeBounds.width  == 0) windowedModeBounds.width  = 1;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   310
            if (windowedModeBounds.height == 0) windowedModeBounds.height = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            fullScreenWindow.setBounds(windowedModeBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // Set the full screen window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        synchronized (fsAppContextLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            // Associate fullscreen window with current AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            if (w == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                fullScreenAppContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                fullScreenAppContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            fullScreenWindow = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (fullScreenWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            windowedModeBounds = fullScreenWindow.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            // Note that we use the graphics configuration of the device,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            // not the window's, because we're setting the fs window for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            // this device.
21260
e0c794c510dc 8019591: JCK: testICSEthrowing_fullScreen fails: no ICSE thrown
serb
parents: 21244
diff changeset
   328
            final GraphicsConfiguration gc = getDefaultConfiguration();
e0c794c510dc 8019591: JCK: testICSEthrowing_fullScreen fails: no ICSE thrown
serb
parents: 21244
diff changeset
   329
            final Rectangle screenBounds = gc.getBounds();
e0c794c510dc 8019591: JCK: testICSEthrowing_fullScreen fails: no ICSE thrown
serb
parents: 21244
diff changeset
   330
            if (SunToolkit.isDispatchThreadForAppContext(fullScreenWindow)) {
e0c794c510dc 8019591: JCK: testICSEthrowing_fullScreen fails: no ICSE thrown
serb
parents: 21244
diff changeset
   331
                // Update graphics configuration here directly and do not wait
e0c794c510dc 8019591: JCK: testICSEthrowing_fullScreen fails: no ICSE thrown
serb
parents: 21244
diff changeset
   332
                // asynchronous notification from the peer. Note that
e0c794c510dc 8019591: JCK: testICSEthrowing_fullScreen fails: no ICSE thrown
serb
parents: 21244
diff changeset
   333
                // setBounds() will reset a GC, if it was set incorrectly.
e0c794c510dc 8019591: JCK: testICSEthrowing_fullScreen fails: no ICSE thrown
serb
parents: 21244
diff changeset
   334
                fullScreenWindow.setGraphicsConfiguration(gc);
e0c794c510dc 8019591: JCK: testICSEthrowing_fullScreen fails: no ICSE thrown
serb
parents: 21244
diff changeset
   335
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            fullScreenWindow.setBounds(screenBounds.x, screenBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                       screenBounds.width, screenBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            fullScreenWindow.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            fullScreenWindow.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
21597
f8db6d6a6f71 8028283: Revert JavaDoc changes pushed for JDK-7068423
bagiras
parents: 21260
diff changeset
   344
     * Returns the <code>Window</code> object representing the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * full-screen window if the device is in full-screen mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
21597
f8db6d6a6f71 8028283: Revert JavaDoc changes pushed for JDK-7068423
bagiras
parents: 21260
diff changeset
   347
     * @return the full-screen window, or <code>null</code> if the device is
f8db6d6a6f71 8028283: Revert JavaDoc changes pushed for JDK-7068423
bagiras
parents: 21260
diff changeset
   348
     * not in full-screen mode.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @see #setFullScreenWindow(Window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public Window getFullScreenWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        Window returnWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        synchronized (fsAppContextLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            // Only return a handle to the current fs window if we are in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            // same AppContext that set the fs window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (fullScreenAppContext == AppContext.getAppContext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                returnWindow = fullScreenWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return returnWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Returns <code>true</code> if this <code>GraphicsDevice</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * supports low-level display changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * On some platforms low-level display changes may only be allowed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * full-screen exclusive mode (i.e., if {@link #isFullScreenSupported()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * returns {@code true} and the application has already entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * full-screen mode using {@link #setFullScreenWindow}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @return whether low-level display changes are supported for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see #isFullScreenSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @see #setDisplayMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @see #setFullScreenWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public boolean isDisplayChangeSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * Sets the display mode of this graphics device. This is only allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * if {@link #isDisplayChangeSupported()} returns {@code true} and may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * require first entering full-screen exclusive mode using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * {@link #setFullScreenWindow} providing that full-screen exclusive mode is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * supported (i.e., {@link #isFullScreenSupported()} returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * {@code true}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * The display mode must be one of the display modes returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * {@link #getDisplayModes()}, with one exception: passing a display mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * with {@link DisplayMode#REFRESH_RATE_UNKNOWN} refresh rate will result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * selecting a display mode from the list of available display modes with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * matching width, height and bit depth.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * However, passing a display mode with {@link DisplayMode#BIT_DEPTH_MULTI}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * for bit depth is only allowed if such mode exists in the list returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * {@link #getDisplayModes()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Example code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Frame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * DisplayMode newDisplayMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * GraphicsDevice gd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * // create a Frame, select desired DisplayMode from the list of modes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * // returned by gd.getDisplayModes() ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * if (gd.isFullScreenSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *     gd.setFullScreenWindow(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *    // proceed in non-full-screen mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *    frame.setSize(...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *    frame.setLocation(...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *    frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * if (gd.isDisplayChangeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *     gd.setDisplayMode(newDisplayMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @param dm The new display mode of this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @exception IllegalArgumentException if the <code>DisplayMode</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * supplied is <code>null</code>, or is not available in the array returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * by <code>getDisplayModes</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @exception UnsupportedOperationException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <code>isDisplayChangeSupported</code> returns <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @see #getDisplayMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @see #getDisplayModes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @see #isDisplayChangeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public void setDisplayMode(DisplayMode dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        throw new UnsupportedOperationException("Cannot change display mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Returns the current display mode of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * The returned display mode is allowed to have a refresh rate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * {@link DisplayMode#REFRESH_RATE_UNKNOWN} if it is indeterminate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Likewise, the returned display mode is allowed to have a bit depth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * {@link DisplayMode#BIT_DEPTH_MULTI} if it is indeterminate or if multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * bit depths are supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @return the current display mode of this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @see #setDisplayMode(DisplayMode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public DisplayMode getDisplayMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        GraphicsConfiguration gc = getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        Rectangle r = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        ColorModel cm = gc.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return new DisplayMode(r.width, r.height, cm.getPixelSize(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Returns all display modes available for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * The returned display modes are allowed to have a refresh rate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * {@link DisplayMode#REFRESH_RATE_UNKNOWN} if it is indeterminate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Likewise, the returned display modes are allowed to have a bit depth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * {@link DisplayMode#BIT_DEPTH_MULTI} if it is indeterminate or if multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * bit depths are supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @return all of the display modes available for this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public DisplayMode[] getDisplayModes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return new DisplayMode[] { getDisplayMode() };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * This method returns the number of bytes available in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * accelerated memory on this device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Some images are created or cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * in accelerated memory on a first-come,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * first-served basis.  On some operating systems,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * this memory is a finite resource.  Calling this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * and scheduling the creation and flushing of images carefully may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * enable applications to make the most efficient use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * that finite resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Note that the number returned is a snapshot of how much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * memory is available; some images may still have problems
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * being allocated into that memory.  For example, depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * on operating system, driver, memory configuration, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * thread situations, the full extent of the size reported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * may not be available for a given image.  There are further
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * inquiry methods on the {@link ImageCapabilities} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * associated with a VolatileImage that can be used to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * whether a particular VolatileImage has been created in accelerated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @return number of bytes available in accelerated memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * A negative return value indicates that the amount of accelerated memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * on this GraphicsDevice is indeterminate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @see java.awt.image.VolatileImage#flush
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @see ImageCapabilities#isAccelerated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public int getAvailableAcceleratedMemory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   502
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   503
    /**
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   504
     * Returns whether the given level of translucency is supported by
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   505
     * this graphics device.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   506
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   507
     * @param translucencyKind a kind of translucency support
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   508
     * @return whether the given translucency kind is supported
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   509
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   510
     * @since 1.7
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   511
     */
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2451
diff changeset
   512
    public boolean isWindowTranslucencySupported(WindowTranslucency translucencyKind) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   513
        switch (translucencyKind) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   514
            case PERPIXEL_TRANSPARENT:
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   515
                return isWindowShapingSupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   516
            case TRANSLUCENT:
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   517
                return isWindowOpacitySupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   518
            case PERPIXEL_TRANSLUCENT:
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   519
                return isWindowPerpixelTranslucencySupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   520
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   521
        return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   522
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   523
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   524
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   525
     * Returns whether the windowing system supports changing the shape
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   526
     * of top-level windows.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   527
     * Note that this method may sometimes return true, but the native
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   528
     * windowing system may still not support the concept of
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   529
     * shaping (due to the bugs in the windowing system).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   530
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   531
    static boolean isWindowShapingSupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   532
        Toolkit curToolkit = Toolkit.getDefaultToolkit();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   533
        if (!(curToolkit instanceof SunToolkit)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   534
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   535
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   536
        return ((SunToolkit)curToolkit).isWindowShapingSupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   537
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   538
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   539
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   540
     * Returns whether the windowing system supports changing the opacity
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   541
     * value of top-level windows.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   542
     * Note that this method may sometimes return true, but the native
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   543
     * windowing system may still not support the concept of
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   544
     * translucency (due to the bugs in the windowing system).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   545
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   546
    static boolean isWindowOpacitySupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   547
        Toolkit curToolkit = Toolkit.getDefaultToolkit();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   548
        if (!(curToolkit instanceof SunToolkit)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   549
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   550
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   551
        return ((SunToolkit)curToolkit).isWindowOpacitySupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   552
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   553
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   554
    boolean isWindowPerpixelTranslucencySupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   555
        /*
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   556
         * Per-pixel alpha is supported if all the conditions are TRUE:
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   557
         *    1. The toolkit is a sort of SunToolkit
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   558
         *    2. The toolkit supports translucency in general
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   559
         *        (isWindowTranslucencySupported())
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   560
         *    3. There's at least one translucency-capable
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   561
         *        GraphicsConfiguration
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   562
         */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   563
        Toolkit curToolkit = Toolkit.getDefaultToolkit();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   564
        if (!(curToolkit instanceof SunToolkit)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   565
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   566
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   567
        if (!((SunToolkit)curToolkit).isWindowTranslucencySupported()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   568
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   569
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   570
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   571
        // TODO: cache translucency capable GC
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   572
        return getTranslucencyCapableGC() != null;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   573
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   574
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   575
    GraphicsConfiguration getTranslucencyCapableGC() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   576
        // If the default GC supports translucency return true.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   577
        // It is important to optimize the verification this way,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   578
        // see CR 6661196 for more details.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   579
        GraphicsConfiguration defaultGC = getDefaultConfiguration();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   580
        if (defaultGC.isTranslucencyCapable()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   581
            return defaultGC;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   582
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   583
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   584
        // ... otherwise iterate through all the GCs.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   585
        GraphicsConfiguration[] configs = getConfigurations();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   586
        for (int j = 0; j < configs.length; j++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   587
            if (configs[j].isTranslucencyCapable()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   588
                return configs[j];
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   589
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   590
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   591
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   592
        return null;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   593
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
}