Path: blob/master/src/java.desktop/share/classes/java/awt/DisplayMode.java
41152 views
/*1* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.awt;2627import java.lang.annotation.Native;2829/**30* The {@code DisplayMode} class encapsulates the bit depth, height,31* width, and refresh rate of a {@code GraphicsDevice}. The ability to32* change graphics device's display mode is platform- and33* configuration-dependent and may not always be available34* (see {@link GraphicsDevice#isDisplayChangeSupported}).35* <p>36* For more information on full-screen exclusive mode API, see the37* <a href="https://docs.oracle.com/javase/tutorial/extra/fullscreen/index.html">38* Full-Screen Exclusive Mode API Tutorial</a>.39*40* @see GraphicsDevice41* @see GraphicsDevice#isDisplayChangeSupported42* @see GraphicsDevice#getDisplayModes43* @see GraphicsDevice#setDisplayMode44* @author Michael Martak45* @since 1.446*/4748public final class DisplayMode {4950private Dimension size;51private int bitDepth;52private int refreshRate;5354/**55* Create a new display mode object with the supplied parameters.56* @param width the width of the display, in pixels57* @param height the height of the display, in pixels58* @param bitDepth the bit depth of the display, in bits per59* pixel. This can be {@code BIT_DEPTH_MULTI} if multiple60* bit depths are available.61* @param refreshRate the refresh rate of the display, in hertz.62* This can be {@code REFRESH_RATE_UNKNOWN} if the63* information is not available.64* @see #BIT_DEPTH_MULTI65* @see #REFRESH_RATE_UNKNOWN66*/67public DisplayMode(int width, int height, int bitDepth, int refreshRate) {68this.size = new Dimension(width, height);69this.bitDepth = bitDepth;70this.refreshRate = refreshRate;71}7273/**74* Returns the height of the display, in pixels.75* @return the height of the display, in pixels76*/77public int getHeight() {78return size.height;79}8081/**82* Returns the width of the display, in pixels.83* @return the width of the display, in pixels84*/85public int getWidth() {86return size.width;87}8889/**90* Value of the bit depth if multiple bit depths are supported in this91* display mode.92* @see #getBitDepth93*/94@Native public static final int BIT_DEPTH_MULTI = -1;9596/**97* Returns the bit depth of the display, in bits per pixel. This may be98* {@code BIT_DEPTH_MULTI} if multiple bit depths are supported in99* this display mode.100*101* @return the bit depth of the display, in bits per pixel.102* @see #BIT_DEPTH_MULTI103*/104public int getBitDepth() {105return bitDepth;106}107108/**109* Value of the refresh rate if not known.110* @see #getRefreshRate111*/112@Native public static final int REFRESH_RATE_UNKNOWN = 0;113114/**115* Returns the refresh rate of the display, in hertz. This may be116* {@code REFRESH_RATE_UNKNOWN} if the information is not available.117*118* @return the refresh rate of the display, in hertz.119* @see #REFRESH_RATE_UNKNOWN120*/121public int getRefreshRate() {122return refreshRate;123}124125/**126* Returns whether the two display modes are equal.127*128* @param dm the display mode to compare to129* @return whether the two display modes are equal130*/131public boolean equals(DisplayMode dm) {132if (dm == null) {133return false;134}135return (getHeight() == dm.getHeight()136&& getWidth() == dm.getWidth()137&& getBitDepth() == dm.getBitDepth()138&& getRefreshRate() == dm.getRefreshRate());139}140141/**142* {@inheritDoc}143*/144@Override145public boolean equals(Object dm) {146if (dm instanceof DisplayMode) {147return equals((DisplayMode)dm);148} else {149return false;150}151}152153/**154* {@inheritDoc}155*/156@Override157public int hashCode() {158return getWidth() + getHeight() + getBitDepth() * 7159+ getRefreshRate() * 13;160}161162/**163* {@inheritDoc}164*/165@Override166public String toString() {167return getWidth() + "x" + getHeight() + "x" +168(getBitDepth() > 0 ? getBitDepth() + "bpp": "[Multi depth]")169+ "@" + (getRefreshRate() > 0 ? getRefreshRate() + "Hz" :170"[Unknown refresh rate]");171}172}173174175