1 /* GraphicsDevice.java -- information about a graphics device 2 Copyright (C) 2002 Free Software Foundation, Inc. 3 4 This file is part of GNU Classpath. 5 6 GNU Classpath is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Classpath is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Classpath; see the file COPYING. If not, write to the 18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 02111-1307 USA. 20 21 Linking this library statically or dynamically with other modules is 22 making a combined work based on this library. Thus, the terms and 23 conditions of the GNU General Public License cover the whole 24 combination. 25 26 As a special exception, the copyright holders of this library give you 27 permission to link this library with independent modules to produce an 28 executable, regardless of the license terms of these independent 29 modules, and to copy and distribute the resulting executable under 30 terms of your choice, provided that you also meet, for each linked 31 independent module, the terms and conditions of the license of that 32 module. An independent module is a module which is not derived from 33 or based on this library. If you modify this library, you may extend 34 this exception to your version of the library, but you are not 35 obligated to do so. If you do not wish to do so, delete this 36 exception statement from your version. */ 37 38 39 package java.awt; 40 41 /** 42 * This describes a graphics device available to the given environment. This 43 * includes screen and printer devices, and the different configurations for 44 * each device. Also, this allows you to create virtual devices which operate 45 * over a multi-screen environment. 46 * 47 * @author Eric Blake <ebb9@email.byu.edu> 48 * @see GraphicsEnvironment 49 * @see GraphicsConfiguration 50 * @since 1.3 51 * @status updated to 1.4 52 */ 53 public abstract class GraphicsDevice 54 { 55 /** Device is a raster screen. */ 56 public static final int TYPE_RASTER_SCREEN = 0; 57 58 /** Device is a printer. */ 59 public static final int TYPE_PRINTER = 1; 60 61 /** Device is an image buffer not visible to the user. */ 62 public static final int TYPE_IMAGE_BUFFER = 2; 63 64 /** The current full-screen window, or null if there is none. */ 65 private Window full_screen; 66 67 /** The current display mode, or null if unknown. */ 68 private DisplayMode mode; 69 70 /** 71 * The default constructor. 72 * 73 * @see GraphicsEnvironment#getScreenDevices() 74 * @see GraphicsEnvironment#getDefaultScreenDevice() 75 * @see GraphicsConfiguration#getDevice() 76 */ GraphicsDevice()77 protected GraphicsDevice() 78 { 79 } 80 81 /** 82 * Returns the type of the device. 83 * 84 * @return the device type 85 * @see #TYPE_RASTER_SCREEN 86 * @see #TYPE_PRINTER 87 * @see #TYPE_IMAGE_BUFFER 88 */ getType()89 public abstract int getType(); 90 91 /** 92 * Returns an identification string for the device. This can be 93 * vendor-specific, and may be useful for debugging. 94 * 95 * @return the identification 96 */ getIDstring()97 public abstract String getIDstring(); 98 99 /** 100 * Return all configurations valid for this device. 101 * 102 * @return an array of configurations 103 */ getConfigurations()104 public abstract GraphicsConfiguration[] getConfigurations(); 105 106 /** 107 * Return the default configuration for this device. 108 * 109 * @return the default configuration 110 */ getDefaultConfiguration()111 public abstract GraphicsConfiguration getDefaultConfiguration(); 112 113 /** 114 * Return the best configuration, according to the criteria in the given 115 * template. 116 * 117 * @param template the template to adjust by 118 * @return the best configuration 119 * @throws NullPointerException if template is null 120 */ getBestConfiguration(GraphicsConfigTemplate template)121 public GraphicsConfiguration getBestConfiguration 122 (GraphicsConfigTemplate template) 123 { 124 return template.getBestConfiguration(getConfigurations()); 125 } 126 127 /** 128 * Returns true if the device supports full-screen exclusive mode. The 129 * default implementation returns true; subclass it if this is not the case. 130 * 131 * @return true if full screen support is available 132 * @since 1.4 133 */ isFullScreenSupported()134 public boolean isFullScreenSupported() 135 { 136 return true; 137 } 138 139 /** 140 * Toggle the given window between full screen and normal mode. The previous 141 * full-screen window, if different, is restored; if the given window is 142 * null, no window will be full screen. If 143 * <code>isFullScreenSupported()</code> returns true, full screen mode is 144 * considered to be exclusive, which implies:<ul> 145 * <li>Windows cannot overlap the full-screen window. All other application 146 * windows will always appear beneath the full-screen window in the 147 * Z-order.</li> 148 * <li>Input method windows are disabled. It is advisable to call 149 * <code>Component.enableInputMethods(false)</code> to make a component 150 * a non-client of the input method framework.</li> 151 * </ul><br> 152 * If <code>isFullScreenSupported()</code> returns false, full-screen 153 * exclusive mode is simulated by resizing the window to the size of the 154 * screen and positioning it at (0,0). 155 * 156 * XXX Not yet implemented in Classpath. 157 * 158 * @param w the window to toggle 159 * @see #isFullScreenSupported() 160 * @see getFullScreenWindow() 161 * @see setDisplayMode(DisplayMode) 162 * @see Component#enableInputMethods(boolean) 163 * @since 1.4 164 */ setFullScreenWindow(Window w)165 public synchronized void setFullScreenWindow(Window w) 166 { 167 if (full_screen != null) 168 ; // XXX Restore the previous window to normal mode. 169 full_screen = w; 170 // XXX If w != null, make it full-screen. 171 throw new Error("not implemented"); 172 } 173 174 /** 175 * Returns the current full-screen window of the device, or null if no 176 * window is full-screen. 177 * 178 * @return the full-screen window 179 * @see #setFullScreenWindow(Window) 180 * @since 1.4 181 */ getFullScreenWindow()182 public Window getFullScreenWindow() 183 { 184 return full_screen; 185 } 186 187 /** 188 * Returns whether this device supports low-level display changes. This may 189 * depend on whether full-screen exclusive mode is available. 190 * 191 * XXX The default implementation returns false for now. 192 * 193 * @return true if display changes are supported 194 * @see #setDisplayMode(DisplayMode) 195 * @since 1.4 196 */ isDisplayChangeSupported()197 public boolean isDisplayChangeSupported() 198 { 199 return false; 200 } 201 202 /** 203 * Sets the display mode. This may be dependent on the availability of 204 * full-screen exclusive mode. 205 * 206 * @param mode the new mode 207 * @throws IllegalArgumentException if the new mode is not in getDisplayModes 208 * @throws UnsupportedOperationException if ! isDisplayChangeSupported() 209 * @see #getDisplayMode() 210 * @see #getDisplayModes() 211 * @see #isDisplayChangeSupported() 212 * @since 1.4 213 */ setDisplayMode(DisplayMode mode)214 public void setDisplayMode(DisplayMode mode) 215 { 216 DisplayMode[] array = getDisplayModes(); 217 if (! isDisplayChangeSupported()) 218 throw new UnsupportedOperationException(); 219 int i = array == null ? 0 : array.length; 220 while (--i >= 0) 221 if (array[i].equals(mode)) 222 break; 223 if (i < 0) 224 throw new IllegalArgumentException(); 225 this.mode = mode; 226 } 227 228 /** 229 * Returns the current display mode of this device, or null if unknown. 230 * 231 * @return the current display mode 232 * @see #setDisplayMode(DisplayMode) 233 * @see #getDisplayModes() 234 * @since 1.4 235 */ getDisplayMode()236 public DisplayMode getDisplayMode() 237 { 238 return mode; 239 } 240 241 /** 242 * Return an array of all available display modes. This implementation 243 * returns a 0-length array, so subclasses must override this. 244 * 245 * @return the array of available modes 246 * @since 1.4 247 */ getDisplayModes()248 public DisplayMode[] getDisplayModes() 249 { 250 return new DisplayMode[0]; 251 } 252 253 /** 254 * Return the number of bytes available in accelerated memory on this 255 * device. The device may support creation or caching on a first-come, 256 * first-served basis, depending on the operating system and driver. 257 * Memory may be a finite resource, and because of multi-threading, you 258 * are not guaranteed that the result of this method ensures your image 259 * will successfully be put in accelerated memory. A negative result means 260 * the memory is unlimited. The default implementation assumes no special 261 * memory is available, and returns 0. 262 * 263 * @return the size of accelerated memory available 264 * @see VolatileImage#flush() 265 * @see ImageCapabilities#isAccelerated() 266 */ getAvailableAcceleratedMemory()267 public int getAvailableAcceleratedMemory() 268 { 269 return 0; 270 } 271 } // class GraphicsDevice 272