001 /*
002 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.awt;
027
028 /**
029 * The <code>DisplayMode</code> class encapsulates the bit depth, height,
030 * width, and refresh rate of a <code>GraphicsDevice</code>. The ability to
031 * change graphics device's display mode is platform- and
032 * configuration-dependent and may not always be available
033 * (see {@link GraphicsDevice#isDisplayChangeSupported}).
034 * <p>
035 * For more information on full-screen exclusive mode API, see the
036 * <a href="http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html">
037 * Full-Screen Exclusive Mode API Tutorial</a>.
038 *
039 * @see GraphicsDevice
040 * @see GraphicsDevice#isDisplayChangeSupported
041 * @see GraphicsDevice#getDisplayModes
042 * @see GraphicsDevice#setDisplayMode
043 * @author Michael Martak
044 * @since 1.4
045 */
046 public final class DisplayMode {
047
048 private Dimension size;
049 private int bitDepth;
050 private int refreshRate;
051
052 /**
053 * Create a new display mode object with the supplied parameters.
054 * @param width the width of the display, in pixels
055 * @param height the height of the display, in pixels
056 * @param bitDepth the bit depth of the display, in bits per
057 * pixel. This can be <code>BIT_DEPTH_MULTI</code> if multiple
058 * bit depths are available.
059 * @param refreshRate the refresh rate of the display, in hertz.
060 * This can be <code>REFRESH_RATE_UNKNOWN</code> if the
061 * information is not available.
062 * @see #BIT_DEPTH_MULTI
063 * @see #REFRESH_RATE_UNKNOWN
064 */
065 public DisplayMode(int width, int height, int bitDepth,
066 int refreshRate) {
067 this .size = new Dimension(width, height);
068 this .bitDepth = bitDepth;
069 this .refreshRate = refreshRate;
070 }
071
072 /**
073 * Returns the height of the display, in pixels.
074 * @return the height of the display, in pixels
075 */
076 public int getHeight() {
077 return size.height;
078 }
079
080 /**
081 * Returns the width of the display, in pixels.
082 * @return the width of the display, in pixels
083 */
084 public int getWidth() {
085 return size.width;
086 }
087
088 /**
089 * Value of the bit depth if multiple bit depths are supported in this
090 * display mode.
091 * @see #getBitDepth
092 */
093 public final static int BIT_DEPTH_MULTI = -1;
094
095 /**
096 * Returns the bit depth of the display, in bits per pixel. This may be
097 * <code>BIT_DEPTH_MULTI</code> if multiple bit depths are supported in
098 * this display mode.
099 *
100 * @return the bit depth of the display, in bits per pixel.
101 * @see #BIT_DEPTH_MULTI
102 */
103 public int getBitDepth() {
104 return bitDepth;
105 }
106
107 /**
108 * Value of the refresh rate if not known.
109 * @see #getRefreshRate
110 */
111 public final static int REFRESH_RATE_UNKNOWN = 0;
112
113 /**
114 * Returns the refresh rate of the display, in hertz. This may be
115 * <code>REFRESH_RATE_UNKNOWN</code> if the information is not available.
116 *
117 * @return the refresh rate of the display, in hertz.
118 * @see #REFRESH_RATE_UNKNOWN
119 */
120 public int getRefreshRate() {
121 return refreshRate;
122 }
123
124 /**
125 * Returns whether the two display modes are equal.
126 * @return whether the two display modes are equal
127 */
128 public boolean equals(DisplayMode dm) {
129 if (dm == null) {
130 return false;
131 }
132 return (getHeight() == dm.getHeight()
133 && getWidth() == dm.getWidth()
134 && getBitDepth() == dm.getBitDepth() && getRefreshRate() == dm
135 .getRefreshRate());
136 }
137
138 /**
139 * {@inheritDoc}
140 */
141 public boolean equals(Object dm) {
142 if (dm instanceof DisplayMode) {
143 return equals((DisplayMode) dm);
144 } else {
145 return false;
146 }
147 }
148
149 /**
150 * {@inheritDoc}
151 */
152 public int hashCode() {
153 return getWidth() + getHeight() + getBitDepth() * 7
154 + getRefreshRate() * 13;
155 }
156
157 }
|