jdk/src/share/classes/java/awt/DisplayMode.java
author dxu
Thu, 04 Apr 2013 15:39:17 -0700
changeset 16734 da1901d79073
parent 12813 c10ab96dcf41
child 20455 f6f9a0c2796b
permissions -rw-r--r--
8000406: change files using @GenerateNativeHeader to use @Native Summary: Use @Native annotation to mark constants interested by native codes Reviewed-by: alanb, anthony, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
     2
 * Copyright (c) 2000, 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: 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
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
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return whether the two display modes are equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public boolean equals(DisplayMode dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (dm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return (getHeight() == dm.getHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            && getWidth() == dm.getWidth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            && getBitDepth() == dm.getBitDepth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            && getRefreshRate() == dm.getRefreshRate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public boolean equals(Object dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (dm instanceof DisplayMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return equals((DisplayMode)dm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return getWidth() + getHeight() + getBitDepth() * 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            + getRefreshRate() * 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
}