001/* GraphicsDevice.java -- information about a graphics device 002 Copyright (C) 2002, 2005 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package java.awt; 040 041import java.awt.image.VolatileImage; 042 043/** 044 * This describes a graphics device available to the given environment. This 045 * includes screen and printer devices, and the different configurations for 046 * each device. Also, this allows you to create virtual devices which operate 047 * over a multi-screen environment. 048 * 049 * @author Eric Blake (ebb9@email.byu.edu) 050 * @see GraphicsEnvironment 051 * @see GraphicsConfiguration 052 * @since 1.3 053 * @status updated to 1.4 054 */ 055public abstract class GraphicsDevice 056{ 057 /** Device is a raster screen. */ 058 public static final int TYPE_RASTER_SCREEN = 0; 059 060 /** Device is a printer. */ 061 public static final int TYPE_PRINTER = 1; 062 063 /** Device is an image buffer not visible to the user. */ 064 public static final int TYPE_IMAGE_BUFFER = 2; 065 066 /** The current full-screen window, or null if there is none. */ 067 private Window full_screen; 068 069 /** 070 * The bounds of the fullscreen window before it has been switched to full 071 * screen. 072 */ 073 private Rectangle fullScreenOldBounds; 074 075 /** The current display mode, or null if unknown. */ 076 private DisplayMode mode; 077 078 /** 079 * The default constructor. 080 * 081 * @see GraphicsEnvironment#getScreenDevices() 082 * @see GraphicsEnvironment#getDefaultScreenDevice() 083 * @see GraphicsConfiguration#getDevice() 084 */ 085 protected GraphicsDevice() 086 { 087 } 088 089 /** 090 * Returns the type of the device. 091 * 092 * @return the device type 093 * @see #TYPE_RASTER_SCREEN 094 * @see #TYPE_PRINTER 095 * @see #TYPE_IMAGE_BUFFER 096 */ 097 public abstract int getType(); 098 099 /** 100 * Returns an identification string for the device. This can be 101 * vendor-specific, and may be useful for debugging. 102 * 103 * @return the identification 104 */ 105 public abstract String getIDstring(); 106 107 /** 108 * Return all configurations valid for this device. 109 * 110 * @return an array of configurations 111 */ 112 public abstract GraphicsConfiguration[] getConfigurations(); 113 114 /** 115 * Return the default configuration for this device. 116 * 117 * @return the default configuration 118 */ 119 public abstract GraphicsConfiguration getDefaultConfiguration(); 120 121 /** 122 * Return the best configuration, according to the criteria in the given 123 * template. 124 * 125 * @param template the template to adjust by 126 * @return the best configuration 127 * @throws NullPointerException if template is null 128 */ 129 public GraphicsConfiguration getBestConfiguration 130 (GraphicsConfigTemplate template) 131 { 132 return template.getBestConfiguration(getConfigurations()); 133 } 134 135 /** 136 * Returns true if the device supports full-screen exclusive mode. The 137 * default implementation returns true; subclass it if this is not the case. 138 * 139 * @return true if full screen support is available 140 * @since 1.4 141 */ 142 public boolean isFullScreenSupported() 143 { 144 return true; 145 } 146 147 /** 148 * Toggle the given window between full screen and normal mode. The previous 149 * full-screen window, if different, is restored; if the given window is 150 * null, no window will be full screen. If 151 * <code>isFullScreenSupported()</code> returns true, full screen mode is 152 * considered to be exclusive, which implies:<ul> 153 * <li>Windows cannot overlap the full-screen window. All other application 154 * windows will always appear beneath the full-screen window in the 155 * Z-order.</li> 156 * <li>Input method windows are disabled. It is advisable to call 157 * <code>Component.enableInputMethods(false)</code> to make a component 158 * a non-client of the input method framework.</li> 159 * </ul><br> 160 * If <code>isFullScreenSupported()</code> returns false, full-screen 161 * exclusive mode is simulated by resizing the window to the size of the 162 * screen and positioning it at (0,0). This is also what this method does. 163 * If a device supports real fullscreen mode then it should override this 164 * method as well as #isFullScreenSupported and #getFullScreenWindow. 165 * 166 * @param w the window to toggle 167 * @see #isFullScreenSupported() 168 * @see #getFullScreenWindow() 169 * @see #setDisplayMode(DisplayMode) 170 * @see Component#enableInputMethods(boolean) 171 * @since 1.4 172 */ 173 public synchronized void setFullScreenWindow(Window w) 174 { 175 // Restore the previous window to normal mode and release the reference. 176 if (full_screen != null) 177 { 178 full_screen.setBounds(fullScreenOldBounds); 179 } 180 181 full_screen = null; 182 183 // If w != null, make it full-screen. 184 if (w != null) 185 { 186 fullScreenOldBounds = w.getBounds(); 187 full_screen = w; 188 DisplayMode dMode = getDisplayMode(); 189 full_screen.setBounds(0, 0, dMode.getWidth(), dMode.getHeight()); 190 full_screen.requestFocus(); 191 full_screen.setLocationRelativeTo(null); 192 } 193 } 194 195 /** 196 * Returns the current full-screen window of the device, or null if no 197 * window is full-screen. 198 * 199 * @return the full-screen window 200 * @see #setFullScreenWindow(Window) 201 * @since 1.4 202 */ 203 public Window getFullScreenWindow() 204 { 205 return full_screen; 206 } 207 208 /** 209 * Returns whether this device supports low-level display changes. This may 210 * depend on whether full-screen exclusive mode is available. 211 * 212 * XXX The default implementation returns false for now. 213 * 214 * @return true if display changes are supported 215 * @see #setDisplayMode(DisplayMode) 216 * @since 1.4 217 */ 218 public boolean isDisplayChangeSupported() 219 { 220 return false; 221 } 222 223 /** 224 * Sets the display mode. This may be dependent on the availability of 225 * full-screen exclusive mode. 226 * 227 * @param mode the new mode 228 * @throws IllegalArgumentException if the new mode is not in getDisplayModes 229 * @throws UnsupportedOperationException if ! isDisplayChangeSupported() 230 * @see #getDisplayMode() 231 * @see #getDisplayModes() 232 * @see #isDisplayChangeSupported() 233 * @since 1.4 234 */ 235 public void setDisplayMode(DisplayMode mode) 236 { 237 DisplayMode[] array = getDisplayModes(); 238 if (! isDisplayChangeSupported()) 239 throw new UnsupportedOperationException(); 240 int i = array == null ? 0 : array.length; 241 while (--i >= 0) 242 if (array[i].equals(mode)) 243 break; 244 if (i < 0) 245 throw new IllegalArgumentException(); 246 this.mode = mode; 247 } 248 249 /** 250 * Returns the current display mode of this device, or null if unknown. 251 * 252 * @return the current display mode 253 * @see #setDisplayMode(DisplayMode) 254 * @see #getDisplayModes() 255 * @since 1.4 256 */ 257 public DisplayMode getDisplayMode() 258 { 259 return mode; 260 } 261 262 /** 263 * Return an array of all available display modes. This implementation 264 * returns a 0-length array, so subclasses must override this. 265 * 266 * @return the array of available modes 267 * @since 1.4 268 */ 269 public DisplayMode[] getDisplayModes() 270 { 271 return new DisplayMode[0]; 272 } 273 274 /** 275 * Return the number of bytes available in accelerated memory on this 276 * device. The device may support creation or caching on a first-come, 277 * first-served basis, depending on the operating system and driver. 278 * Memory may be a finite resource, and because of multi-threading, you 279 * are not guaranteed that the result of this method ensures your image 280 * will successfully be put in accelerated memory. A negative result means 281 * the memory is unlimited. The default implementation assumes no special 282 * memory is available, and returns 0. 283 * 284 * @return the size of accelerated memory available 285 * @see VolatileImage#flush() 286 * @see ImageCapabilities#isAccelerated() 287 */ 288 public int getAvailableAcceleratedMemory() 289 { 290 return 0; 291 } 292} // class GraphicsDevice