jdk/src/share/classes/java/awt/DisplayMode.java
author erikj
Thu, 07 Jun 2012 18:05:09 -0700
changeset 12813 c10ab96dcf41
parent 5506 202f599c92aa
child 16734 da1901d79073
permissions -rw-r--r--
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI Reviewed-by: ohair, ohrstrom, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2006, 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
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    28
import javax.tools.annotation.GenerateNativeHeader;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <a href="http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html">
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
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    49
/* No native methods here, but the constants are needed in the supporting JNI code */
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    50
@GenerateNativeHeader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public final class DisplayMode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private Dimension size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private int bitDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private int refreshRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Create a new display mode object with the supplied parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @param width the width of the display, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param height the height of the display, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param bitDepth the bit depth of the display, in bits per
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *        pixel.  This can be <code>BIT_DEPTH_MULTI</code> if multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *        bit depths are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param refreshRate the refresh rate of the display, in hertz.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *        This can be <code>REFRESH_RATE_UNKNOWN</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *        information is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @see #BIT_DEPTH_MULTI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @see #REFRESH_RATE_UNKNOWN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public DisplayMode(int width, int height, int bitDepth, int refreshRate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.size = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.bitDepth = bitDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.refreshRate = refreshRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Returns the height of the display, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @return the height of the display, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Returns the width of the display, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @return the width of the display, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Value of the bit depth if multiple bit depths are supported in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * display mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see #getBitDepth
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public final static int BIT_DEPTH_MULTI = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Returns the bit depth of the display, in bits per pixel.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <code>BIT_DEPTH_MULTI</code> if multiple bit depths are supported in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * this display mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @return the bit depth of the display, in bits per pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see #BIT_DEPTH_MULTI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public int getBitDepth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return bitDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Value of the refresh rate if not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @see #getRefreshRate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public final static int REFRESH_RATE_UNKNOWN = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the refresh rate of the display, in hertz.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <code>REFRESH_RATE_UNKNOWN</code> if the information is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return the refresh rate of the display, in hertz.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @see #REFRESH_RATE_UNKNOWN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public int getRefreshRate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return refreshRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns whether the two display modes are equal.
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
}