001 package com.croftsoft.core.gui; 002 003 import java.awt.*; 004 005 import com.croftsoft.core.lang.NullArgumentException; 006 007 /********************************************************************* 008 * Library of static methods for manipulating DisplayMode objects. 009 * 010 * @version 011 * 2003-07-25 012 * @since 013 * 2003-02-21 014 * @author 015 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 016 *********************************************************************/ 017 018 public final class DisplayModeLib 019 ////////////////////////////////////////////////////////////////////// 020 ////////////////////////////////////////////////////////////////////// 021 { 022 023 /********************************************************************* 024 * Template matching of a supported to a desired DisplayMode. 025 * 026 * @param desiredDisplayMode 027 * 028 * Values of zero in desiredDisplayMode are treated as wildcards. 029 *********************************************************************/ 030 public static boolean matches ( 031 DisplayMode supportedDisplayMode, 032 DisplayMode desiredDisplayMode ) 033 ////////////////////////////////////////////////////////////////////// 034 { 035 NullArgumentException.check ( supportedDisplayMode ); 036 037 NullArgumentException.check ( desiredDisplayMode ); 038 039 int desiredWidth = desiredDisplayMode.getWidth ( ); 040 041 if ( ( desiredWidth != 0 ) 042 && ( desiredWidth != supportedDisplayMode.getWidth ( ) ) ) 043 { 044 return false; 045 } 046 047 int desiredHeight = desiredDisplayMode.getHeight ( ); 048 049 if ( ( desiredHeight != 0 ) 050 && ( desiredHeight != supportedDisplayMode.getHeight ( ) ) ) 051 { 052 return false; 053 } 054 055 int desiredRefreshRate = desiredDisplayMode .getRefreshRate ( ); 056 057 int supportedRefreshRate = supportedDisplayMode.getRefreshRate ( ); 058 059 if ( ( desiredRefreshRate != 0 ) 060 && ( desiredRefreshRate != supportedRefreshRate ) ) 061 { 062 return false; 063 } 064 065 int desiredBitDepth = desiredDisplayMode .getBitDepth ( ); 066 067 int supportedBitDepth = supportedDisplayMode.getBitDepth ( ); 068 069 if ( ( desiredBitDepth != 0 ) 070 && ( desiredBitDepth != supportedBitDepth ) ) 071 { 072 return false; 073 } 074 075 return true; 076 } 077 078 public static void print ( DisplayMode displayMode ) 079 ////////////////////////////////////////////////////////////////////// 080 { 081 NullArgumentException.check ( displayMode ); 082 083 System.out.println ( "width..........: " 084 + displayMode.getWidth ( ) ); 085 086 System.out.println ( "height.........: " 087 + displayMode.getHeight ( ) ); 088 089 System.out.println ( "bit depth......: " 090 + displayMode.getBitDepth ( ) ); 091 092 System.out.println ( "refresh rate...: " 093 + displayMode.getRefreshRate ( ) ); 094 } 095 096 ////////////////////////////////////////////////////////////////////// 097 ////////////////////////////////////////////////////////////////////// 098 099 private DisplayModeLib ( ) { } 100 101 ////////////////////////////////////////////////////////////////////// 102 ////////////////////////////////////////////////////////////////////// 103 }