2
|
1 |
/*
|
|
2 |
* Copyright 2000-2006 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package java.awt;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* The <code>DisplayMode</code> class encapsulates the bit depth, height,
|
|
30 |
* width, and refresh rate of a <code>GraphicsDevice</code>. The ability to
|
|
31 |
* change graphics device's display mode is platform- and
|
|
32 |
* configuration-dependent and may not always be available
|
|
33 |
* (see {@link GraphicsDevice#isDisplayChangeSupported}).
|
|
34 |
* <p>
|
|
35 |
* For more information on full-screen exclusive mode API, see the
|
|
36 |
* <a href="http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html">
|
|
37 |
* Full-Screen Exclusive Mode API Tutorial</a>.
|
|
38 |
*
|
|
39 |
* @see GraphicsDevice
|
|
40 |
* @see GraphicsDevice#isDisplayChangeSupported
|
|
41 |
* @see GraphicsDevice#getDisplayModes
|
|
42 |
* @see GraphicsDevice#setDisplayMode
|
|
43 |
* @author Michael Martak
|
|
44 |
* @since 1.4
|
|
45 |
*/
|
|
46 |
public final class DisplayMode {
|
|
47 |
|
|
48 |
private Dimension size;
|
|
49 |
private int bitDepth;
|
|
50 |
private int refreshRate;
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Create a new display mode object with the supplied parameters.
|
|
54 |
* @param width the width of the display, in pixels
|
|
55 |
* @param height the height of the display, in pixels
|
|
56 |
* @param bitDepth the bit depth of the display, in bits per
|
|
57 |
* pixel. This can be <code>BIT_DEPTH_MULTI</code> if multiple
|
|
58 |
* bit depths are available.
|
|
59 |
* @param refreshRate the refresh rate of the display, in hertz.
|
|
60 |
* This can be <code>REFRESH_RATE_UNKNOWN</code> if the
|
|
61 |
* information is not available.
|
|
62 |
* @see #BIT_DEPTH_MULTI
|
|
63 |
* @see #REFRESH_RATE_UNKNOWN
|
|
64 |
*/
|
|
65 |
public DisplayMode(int width, int height, int bitDepth, int refreshRate) {
|
|
66 |
this.size = new Dimension(width, height);
|
|
67 |
this.bitDepth = bitDepth;
|
|
68 |
this.refreshRate = refreshRate;
|
|
69 |
}
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Returns the height of the display, in pixels.
|
|
73 |
* @return the height of the display, in pixels
|
|
74 |
*/
|
|
75 |
public int getHeight() {
|
|
76 |
return size.height;
|
|
77 |
}
|
|
78 |
|
|
79 |
/**
|
|
80 |
* Returns the width of the display, in pixels.
|
|
81 |
* @return the width of the display, in pixels
|
|
82 |
*/
|
|
83 |
public int getWidth() {
|
|
84 |
return size.width;
|
|
85 |
}
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Value of the bit depth if multiple bit depths are supported in this
|
|
89 |
* display mode.
|
|
90 |
* @see #getBitDepth
|
|
91 |
*/
|
|
92 |
public final static int BIT_DEPTH_MULTI = -1;
|
|
93 |
|
|
94 |
/**
|
|
95 |
* Returns the bit depth of the display, in bits per pixel. This may be
|
|
96 |
* <code>BIT_DEPTH_MULTI</code> if multiple bit depths are supported in
|
|
97 |
* this display mode.
|
|
98 |
*
|
|
99 |
* @return the bit depth of the display, in bits per pixel.
|
|
100 |
* @see #BIT_DEPTH_MULTI
|
|
101 |
*/
|
|
102 |
public int getBitDepth() {
|
|
103 |
return bitDepth;
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Value of the refresh rate if not known.
|
|
108 |
* @see #getRefreshRate
|
|
109 |
*/
|
|
110 |
public final static int REFRESH_RATE_UNKNOWN = 0;
|
|
111 |
|
|
112 |
/**
|
|
113 |
* Returns the refresh rate of the display, in hertz. This may be
|
|
114 |
* <code>REFRESH_RATE_UNKNOWN</code> if the information is not available.
|
|
115 |
*
|
|
116 |
* @return the refresh rate of the display, in hertz.
|
|
117 |
* @see #REFRESH_RATE_UNKNOWN
|
|
118 |
*/
|
|
119 |
public int getRefreshRate() {
|
|
120 |
return refreshRate;
|
|
121 |
}
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Returns whether the two display modes are equal.
|
|
125 |
* @return whether the two display modes are equal
|
|
126 |
*/
|
|
127 |
public boolean equals(DisplayMode dm) {
|
|
128 |
if (dm == null) {
|
|
129 |
return false;
|
|
130 |
}
|
|
131 |
return (getHeight() == dm.getHeight()
|
|
132 |
&& getWidth() == dm.getWidth()
|
|
133 |
&& getBitDepth() == dm.getBitDepth()
|
|
134 |
&& getRefreshRate() == dm.getRefreshRate());
|
|
135 |
}
|
|
136 |
|
|
137 |
/**
|
|
138 |
* {@inheritDoc}
|
|
139 |
*/
|
|
140 |
public boolean equals(Object dm) {
|
|
141 |
if (dm instanceof DisplayMode) {
|
|
142 |
return equals((DisplayMode)dm);
|
|
143 |
} else {
|
|
144 |
return false;
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
|
148 |
/**
|
|
149 |
* {@inheritDoc}
|
|
150 |
*/
|
|
151 |
public int hashCode() {
|
|
152 |
return getWidth() + getHeight() + getBitDepth() * 7
|
|
153 |
+ getRefreshRate() * 13;
|
|
154 |
}
|
|
155 |
|
|
156 |
}
|