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. package java.awt;
  8. /**
  9. * The <code>DisplayMode</code> class encapsulates the bit depth, height,
  10. * width, and refresh rate of a <code>GraphicsDevice</code>. Display modes
  11. * are hardware-dependent and may not always be available.
  12. * @see GraphicsDevice
  13. * @author Michael Martak
  14. * @since 1.4
  15. */
  16. public final class DisplayMode {
  17. private Dimension size;
  18. private int bitDepth;
  19. private int refreshRate;
  20. /**
  21. * Create a new display mode object with the supplied parameters.
  22. * @param width the width of the display, in pixels
  23. * @param height the height of the display, in pixels
  24. * @param bitDepth the bit depth of the display, in bits per
  25. * pixel. This can be <code>BIT_DEPTH_MULTI</code> if multiple
  26. * bit depths are available.
  27. * @param refreshRate the refresh rate of the display, in hertz.
  28. * This can be <code>REFRESH_RATE_UNKNOWN</code> if the
  29. * information is not available.
  30. * @see #BIT_DEPTH_MULTI
  31. * @see #REFRESH_RATE_UNKNOWN
  32. */
  33. public DisplayMode(int width, int height, int bitDepth, int refreshRate) {
  34. this.size = new Dimension(width, height);
  35. this.bitDepth = bitDepth;
  36. this.refreshRate = refreshRate;
  37. }
  38. /**
  39. * @return the height of the display, in pixels
  40. */
  41. public int getHeight() {
  42. return size.height;
  43. }
  44. /**
  45. * @return the width of the display, in pixels
  46. */
  47. public int getWidth() {
  48. return size.width;
  49. }
  50. /**
  51. * Value of the bit depth if multiple bit depths are supported in this
  52. * dislay mode.
  53. * @see #getBitDepth
  54. */
  55. public final static int BIT_DEPTH_MULTI = -1;
  56. /**
  57. * @return the bit depth of the display, in bits per pixel. This may be
  58. * <code>BIT_DEPTH_MULTI</code> if multiple bit depths are supported in
  59. * this display mode.
  60. * @see #BIT_DEPTH_MULTI
  61. */
  62. public int getBitDepth() {
  63. return bitDepth;
  64. }
  65. /**
  66. * Value of the refresh rate if not known
  67. * @see #getRefreshRate
  68. */
  69. public final static int REFRESH_RATE_UNKNOWN = 0;
  70. /**
  71. * @return the refresh rate of the display, in hertz. This may be
  72. * <code>REFRESH_RATE_UNKNOWN</code> if the information is not available.
  73. * @see #REFRESH_RATE_UNKNOWN
  74. */
  75. public int getRefreshRate() {
  76. return refreshRate;
  77. }
  78. /**
  79. * @return whether the two display modes are equal
  80. */
  81. public boolean equals(DisplayMode dm) {
  82. if (dm == null) {
  83. return false;
  84. }
  85. return (getHeight() == dm.getHeight()
  86. && getWidth() == dm.getWidth()
  87. && getBitDepth() == dm.getBitDepth()
  88. && getRefreshRate() == dm.getRefreshRate());
  89. }
  90. /**
  91. * @return whether the two display modes are equal
  92. */
  93. public boolean equals(Object dm) {
  94. if (dm instanceof DisplayMode) {
  95. return equals((DisplayMode)dm);
  96. } else {
  97. return false;
  98. }
  99. }
  100. /**
  101. * @return a hash code value for this object
  102. */
  103. public int hashCode() {
  104. return getWidth() + getHeight() + getBitDepth() * 7
  105. + getRefreshRate() * 13;
  106. }
  107. }