1 /*
   2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt;
  27 
  28 import java.lang.annotation.Native;
  29 
  30 /**
  31  * The <code>DisplayMode</code> class encapsulates the bit depth, height,
  32  * width, and refresh rate of a <code>GraphicsDevice</code>. The ability to
  33  * change graphics device's display mode is platform- and
  34  * configuration-dependent and may not always be available
  35  * (see {@link GraphicsDevice#isDisplayChangeSupported}).
  36  * <p>
  37  * For more information on full-screen exclusive mode API, see the
  38  * <a href="http://docs.oracle.com/javase/tutorial/extra/fullscreen/index.html">
  39  * Full-Screen Exclusive Mode API Tutorial</a>.
  40  *
  41  * @see GraphicsDevice
  42  * @see GraphicsDevice#isDisplayChangeSupported
  43  * @see GraphicsDevice#getDisplayModes
  44  * @see GraphicsDevice#setDisplayMode
  45  * @author Michael Martak
  46  * @since 1.4
  47  */
  48 
  49 public final class DisplayMode {
  50 
  51     private Dimension size;
  52     private int bitDepth;
  53     private int refreshRate;
  54 
  55     /**
  56      * Create a new display mode object with the supplied parameters.
  57      * @param width the width of the display, in pixels
  58      * @param height the height of the display, in pixels
  59      * @param bitDepth the bit depth of the display, in bits per
  60      *        pixel.  This can be <code>BIT_DEPTH_MULTI</code> if multiple
  61      *        bit depths are available.
  62      * @param refreshRate the refresh rate of the display, in hertz.
  63      *        This can be <code>REFRESH_RATE_UNKNOWN</code> if the
  64      *        information is not available.
  65      * @see #BIT_DEPTH_MULTI
  66      * @see #REFRESH_RATE_UNKNOWN
  67      */
  68     public DisplayMode(int width, int height, int bitDepth, int refreshRate) {
  69         this.size = new Dimension(width, height);
  70         this.bitDepth = bitDepth;
  71         this.refreshRate = refreshRate;
  72     }
  73 
  74     /**
  75      * Returns the height of the display, in pixels.
  76      * @return the height of the display, in pixels
  77      */
  78     public int getHeight() {
  79         return size.height;
  80     }
  81 
  82     /**
  83      * Returns the width of the display, in pixels.
  84      * @return the width of the display, in pixels
  85      */
  86     public int getWidth() {
  87         return size.width;
  88     }
  89 
  90     /**
  91      * Value of the bit depth if multiple bit depths are supported in this
  92      * display mode.
  93      * @see #getBitDepth
  94      */
  95     @Native public final static int BIT_DEPTH_MULTI = -1;
  96 
  97     /**
  98      * Returns the bit depth of the display, in bits per pixel.  This may be
  99      * <code>BIT_DEPTH_MULTI</code> if multiple bit depths are supported in
 100      * this display mode.
 101      *
 102      * @return the bit depth of the display, in bits per pixel.
 103      * @see #BIT_DEPTH_MULTI
 104      */
 105     public int getBitDepth() {
 106         return bitDepth;
 107     }
 108 
 109     /**
 110      * Value of the refresh rate if not known.
 111      * @see #getRefreshRate
 112      */
 113     @Native public final static int REFRESH_RATE_UNKNOWN = 0;
 114 
 115     /**
 116      * Returns the refresh rate of the display, in hertz.  This may be
 117      * <code>REFRESH_RATE_UNKNOWN</code> if the information is not available.
 118      *
 119      * @return the refresh rate of the display, in hertz.
 120      * @see #REFRESH_RATE_UNKNOWN
 121      */
 122     public int getRefreshRate() {
 123         return refreshRate;
 124     }
 125 
 126     /**
 127      * Returns whether the two display modes are equal.
 128      * @return whether the two display modes are equal
 129      */
 130     public boolean equals(DisplayMode dm) {
 131         if (dm == null) {
 132             return false;
 133         }
 134         return (getHeight() == dm.getHeight()
 135             && getWidth() == dm.getWidth()
 136             && getBitDepth() == dm.getBitDepth()
 137             && getRefreshRate() == dm.getRefreshRate());
 138     }
 139 
 140     /**
 141      * {@inheritDoc}
 142      */
 143     public boolean equals(Object dm) {
 144         if (dm instanceof DisplayMode) {
 145             return equals((DisplayMode)dm);
 146         } else {
 147             return false;
 148         }
 149     }
 150 
 151     /**
 152      * {@inheritDoc}
 153      */
 154     public int hashCode() {
 155         return getWidth() + getHeight() + getBitDepth() * 7
 156             + getRefreshRate() * 13;
 157     }
 158 
 159 }