jdk/src/java.desktop/share/classes/java/awt/DisplayMode.java
author serb
Mon, 31 Aug 2015 16:56:09 +0300
changeset 32493 31bd2a308840
parent 25859 3317bb8137f4
child 32865 f9cb6e427f9e
permissions -rw-r--r--
8076178: [macosx] Few open swing and awt reg-tests fail after their update to avoid SunToolkit.realSync Reviewed-by: azvegint, yan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 20455
diff changeset
     2
 * Copyright (c) 2000, 2014, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    28
import java.lang.annotation.Native;
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    29
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The <code>DisplayMode</code> class encapsulates the bit depth, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * width, and refresh rate of a <code>GraphicsDevice</code>. The ability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * change graphics device's display mode is platform- and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * configuration-dependent and may not always be available
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * (see {@link GraphicsDevice#isDisplayChangeSupported}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * 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: 16734
diff changeset
    38
 * <a href="http://docs.oracle.com/javase/tutorial/extra/fullscreen/index.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Full-Screen Exclusive Mode API Tutorial</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see GraphicsDevice#isDisplayChangeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see GraphicsDevice#getDisplayModes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @see GraphicsDevice#setDisplayMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    48
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public final class DisplayMode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private Dimension size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private int bitDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private int refreshRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Create a new display mode object with the supplied parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @param width the width of the display, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @param height the height of the display, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @param bitDepth the bit depth of the display, in bits per
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *        pixel.  This can be <code>BIT_DEPTH_MULTI</code> if multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *        bit depths are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @param refreshRate the refresh rate of the display, in hertz.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *        This can be <code>REFRESH_RATE_UNKNOWN</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *        information is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @see #BIT_DEPTH_MULTI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @see #REFRESH_RATE_UNKNOWN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public DisplayMode(int width, int height, int bitDepth, int refreshRate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.size = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this.bitDepth = bitDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.refreshRate = refreshRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Returns the height of the display, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @return the height of the display, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Returns the width of the display, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @return the width of the display, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Value of the bit depth if multiple bit depths are supported in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * display mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @see #getBitDepth
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    95
    @Native public final static int BIT_DEPTH_MULTI = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Returns the bit depth of the display, in bits per pixel.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <code>BIT_DEPTH_MULTI</code> if multiple bit depths are supported in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * this display mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @return the bit depth of the display, in bits per pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @see #BIT_DEPTH_MULTI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public int getBitDepth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return bitDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Value of the refresh rate if not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see #getRefreshRate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   113
    @Native public final static int REFRESH_RATE_UNKNOWN = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Returns the refresh rate of the display, in hertz.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <code>REFRESH_RATE_UNKNOWN</code> if the information is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @return the refresh rate of the display, in hertz.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @see #REFRESH_RATE_UNKNOWN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public int getRefreshRate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return refreshRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Returns whether the two display modes are equal.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 20455
diff changeset
   128
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 20455
diff changeset
   129
     * @param  dm the display mode to compare to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @return whether the two display modes are equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public boolean equals(DisplayMode dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (dm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return (getHeight() == dm.getHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            && getWidth() == dm.getWidth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            && getBitDepth() == dm.getBitDepth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            && getRefreshRate() == dm.getRefreshRate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public boolean equals(Object dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (dm instanceof DisplayMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return equals((DisplayMode)dm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return getWidth() + getHeight() + getBitDepth() * 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            + getRefreshRate() * 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}