KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > DisplayMode


1 /*
2  * @(#)DisplayMode.java 1.8 04/01/13
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt;
9
10 /**
11  * The <code>DisplayMode</code> class encapsulates the bit depth, height,
12  * width, and refresh rate of a <code>GraphicsDevice</code>. Display modes
13  * are hardware-dependent and may not always be available.
14  * @see GraphicsDevice
15  * @author Michael Martak
16  * @since 1.4
17  */

18 public final class DisplayMode {
19     
20     private Dimension JavaDoc size;
21     private int bitDepth;
22     private int refreshRate;
23         
24     /**
25      * Create a new display mode object with the supplied parameters.
26      * @param width the width of the display, in pixels
27      * @param height the height of the display, in pixels
28      * @param bitDepth the bit depth of the display, in bits per
29      * pixel. This can be <code>BIT_DEPTH_MULTI</code> if multiple
30      * bit depths are available.
31      * @param refreshRate the refresh rate of the display, in hertz.
32      * This can be <code>REFRESH_RATE_UNKNOWN</code> if the
33      * information is not available.
34      * @see #BIT_DEPTH_MULTI
35      * @see #REFRESH_RATE_UNKNOWN
36      */

37     public DisplayMode(int width, int height, int bitDepth, int refreshRate) {
38         this.size = new Dimension JavaDoc(width, height);
39         this.bitDepth = bitDepth;
40         this.refreshRate = refreshRate;
41     }
42     
43     /**
44      * @return the height of the display, in pixels
45      */

46     public int getHeight() {
47         return size.height;
48     }
49     
50     /**
51      * @return the width of the display, in pixels
52      */

53     public int getWidth() {
54         return size.width;
55     }
56     
57     /**
58      * Value of the bit depth if multiple bit depths are supported in this
59      * dislay mode.
60      * @see #getBitDepth
61      */

62     public final static int BIT_DEPTH_MULTI = -1;
63     /**
64      * @return the bit depth of the display, in bits per pixel. This may be
65      * <code>BIT_DEPTH_MULTI</code> if multiple bit depths are supported in
66      * this display mode.
67      * @see #BIT_DEPTH_MULTI
68      */

69     public int getBitDepth() {
70         return bitDepth;
71     }
72     
73     /**
74      * Value of the refresh rate if not known
75      * @see #getRefreshRate
76      */

77     public final static int REFRESH_RATE_UNKNOWN = 0;
78     /**
79      * @return the refresh rate of the display, in hertz. This may be
80      * <code>REFRESH_RATE_UNKNOWN</code> if the information is not available.
81      * @see #REFRESH_RATE_UNKNOWN
82      */

83     public int getRefreshRate() {
84         return refreshRate;
85     }
86
87     /**
88      * @return whether the two display modes are equal
89      */

90     public boolean equals(DisplayMode JavaDoc dm) {
91     if (dm == null) {
92         return false;
93     }
94         return (getHeight() == dm.getHeight()
95             && getWidth() == dm.getWidth()
96             && getBitDepth() == dm.getBitDepth()
97             && getRefreshRate() == dm.getRefreshRate());
98     }
99     
100     /**
101      * @return whether the two display modes are equal
102      */

103     public boolean equals(Object JavaDoc dm) {
104     if (dm instanceof DisplayMode JavaDoc) {
105         return equals((DisplayMode JavaDoc)dm);
106     } else {
107         return false;
108     }
109     }
110     
111     /**
112      * @return a hash code value for this object
113      */

114     public int hashCode() {
115         return getWidth() + getHeight() + getBitDepth() * 7
116             + getRefreshRate() * 13;
117     }
118     
119 }
120
Popular Tags