GraphicsDevice.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* GraphicsDevice.java -- information about a graphics device
  2. Copyright (C) 2002 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., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 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. /**
  33. * This describes a graphics device available to the given environment. This
  34. * includes screen and printer devices, and the different configurations for
  35. * each device. Also, this allows you to create virtual devices which operate
  36. * over a multi-screen environment.
  37. *
  38. * @author Eric Blake <ebb9@email.byu.edu>
  39. * @see GraphicsEnvironment
  40. * @see GraphicsConfiguration
  41. * @since 1.3
  42. * @status updated to 1.4
  43. */
  44. public abstract class GraphicsDevice
  45. {
  46. /** Device is a raster screen. */
  47. public static final int TYPE_RASTER_SCREEN = 0;
  48. /** Device is a printer. */
  49. public static final int TYPE_PRINTER = 1;
  50. /** Device is an image buffer not visible to the user. */
  51. public static final int TYPE_IMAGE_BUFFER = 2;
  52. /** The current full-screen window, or null if there is none. */
  53. private Window full_screen;
  54. /** The current display mode, or null if unknown. */
  55. private DisplayMode mode;
  56. /**
  57. * The default constructor.
  58. *
  59. * @see GraphicsEnvironment#getScreenDevices()
  60. * @see GraphicsEnvironment#getDefaultScreenDevice()
  61. * @see GraphicsConfiguration#getDevice()
  62. */
  63. protected GraphicsDevice()
  64. {
  65. }
  66. /**
  67. * Returns the type of the device.
  68. *
  69. * @return the device type
  70. * @see #TYPE_RASTER_SCREEN
  71. * @see #TYPE_PRINTER
  72. * @see #TYPE_IMAGE_BUFFER
  73. */
  74. public abstract int getType();
  75. /**
  76. * Returns an identification string for the device. This can be
  77. * vendor-specific, and may be useful for debugging.
  78. *
  79. * @return the identification
  80. */
  81. public abstract String getIDstring();
  82. /**
  83. * Return all configurations valid for this device.
  84. *
  85. * @return an array of configurations
  86. */
  87. public abstract GraphicsConfiguration[] getConfigurations();
  88. /**
  89. * Return the default configuration for this device.
  90. *
  91. * @return the default configuration
  92. */
  93. public abstract GraphicsConfiguration getDefaultConfiguration();
  94. /**
  95. * Return the best configuration, according to the criteria in the given
  96. * template.
  97. *
  98. * @param template the template to adjust by
  99. * @return the best configuration
  100. * @throws NullPointerException if template is null
  101. */
  102. public GraphicsConfiguration getBestConfiguration
  103. (GraphicsConfigTemplate template)
  104. {
  105. return template.getBestConfiguration(getConfigurations());
  106. }
  107. /**
  108. * Returns true if the device supports full-screen exclusive mode. The
  109. * default implementation returns true; subclass it if this is not the case.
  110. *
  111. * @return true if full screen support is available
  112. * @since 1.4
  113. */
  114. public boolean isFullScreenSupported()
  115. {
  116. return true;
  117. }
  118. /**
  119. * Toggle the given window between full screen and normal mode. The previous
  120. * full-screen window, if different, is restored; if the given window is
  121. * null, no window will be full screen. If
  122. * <code>isFullScreenSupported()</code> returns true, full screen mode is
  123. * considered to be exclusive, which implies:<ul>
  124. * <li>Windows cannot overlap the full-screen window. All other application
  125. * windows will always appear beneath the full-screen window in the
  126. * Z-order.</li>
  127. * <li>Input method windows are disabled. It is advisable to call
  128. * <code>Component.enableInputMethods(false)</code> to make a component
  129. * a non-client of the input method framework.</li>
  130. * </ul><br>
  131. * If <code>isFullScreenSupported()</code> returns false, full-screen
  132. * exclusive mode is simulated by resizing the window to the size of the
  133. * screen and positioning it at (0,0).
  134. *
  135. * XXX Not yet implemented in Classpath.
  136. *
  137. * @param w the window to toggle
  138. * @see #isFullScreenSupported()
  139. * @see getFullScreenWindow()
  140. * @see setDisplayMode(DisplayMode)
  141. * @see Component#enableInputMethods(boolean)
  142. * @since 1.4
  143. */
  144. public synchronized void setFullScreenWindow(Window w)
  145. {
  146. if (full_screen != null)
  147. ; // XXX Restore the previous window to normal mode.
  148. full_screen = w;
  149. // XXX If w != null, make it full-screen.
  150. throw new Error("not implemented");
  151. }
  152. /**
  153. * Returns the current full-screen window of the device, or null if no
  154. * window is full-screen.
  155. *
  156. * @return the full-screen window
  157. * @see #setFullScreenWindow(Window)
  158. * @since 1.4
  159. */
  160. public Window getFullScreenWindow()
  161. {
  162. return full_screen;
  163. }
  164. /**
  165. * Returns whether this device supports low-level display changes. This may
  166. * depend on whether full-screen exclusive mode is available.
  167. *
  168. * XXX The default implementation returns false for now.
  169. *
  170. * @return true if display changes are supported
  171. * @see #setDisplayMode(DisplayMode)
  172. * @since 1.4
  173. */
  174. public boolean isDisplayChangeSupported()
  175. {
  176. return false;
  177. }
  178. /**
  179. * Sets the display mode. This may be dependent on the availability of
  180. * full-screen exclusive mode.
  181. *
  182. * @param mode the new mode
  183. * @throws IllegalArgumentException if the new mode is not in getDisplayModes
  184. * @throws UnsupportedOperationException if ! isDisplayChangeSupported()
  185. * @see #getDisplayMode()
  186. * @see #getDisplayModes()
  187. * @see #isDisplayChangeSupported()
  188. * @since 1.4
  189. */
  190. public void setDisplayMode(DisplayMode mode)
  191. {
  192. DisplayMode[] array = getDisplayModes();
  193. if (! isDisplayChangeSupported())
  194. throw new UnsupportedOperationException();
  195. int i = array == null ? 0 : array.length;
  196. while (--i >= 0)
  197. if (array[i].equals(mode))
  198. break;
  199. if (i < 0)
  200. throw new IllegalArgumentException();
  201. this.mode = mode;
  202. }
  203. /**
  204. * Returns the current display mode of this device, or null if unknown.
  205. *
  206. * @return the current display mode
  207. * @see #setDisplayMode(DisplayMode)
  208. * @see #getDisplayModes()
  209. * @since 1.4
  210. */
  211. public DisplayMode getDisplayMode()
  212. {
  213. return mode;
  214. }
  215. /**
  216. * Return an array of all available display modes. This implementation
  217. * returns a 0-length array, so subclasses must override this.
  218. *
  219. * @return the array of available modes
  220. * @since 1.4
  221. */
  222. public DisplayMode[] getDisplayModes()
  223. {
  224. return new DisplayMode[0];
  225. }
  226. /**
  227. * Return the number of bytes available in accelerated memory on this
  228. * device. The device may support creation or caching on a first-come,
  229. * first-served basis, depending on the operating system and driver.
  230. * Memory may be a finite resource, and because of multi-threading, you
  231. * are not guaranteed that the result of this method ensures your image
  232. * will successfully be put in accelerated memory. A negative result means
  233. * the memory is unlimited. The default implementation assumes no special
  234. * memory is available, and returns 0.
  235. *
  236. * @return the size of accelerated memory available
  237. * @see VolatileImage#flush()
  238. * @see ImageCapabilities#isAccelerated()
  239. */
  240. public int getAvailableAcceleratedMemory()
  241. {
  242. return 0;
  243. }
  244. } // class GraphicsDevice