GraphicsDevice.java 9.2 KB

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