1. /*
  2. * @(#)GraphicsConfiguration.java 1.28 01/02/09
  3. *
  4. * Copyright 1997-2001 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.awt;
  11. import java.awt.geom.AffineTransform;
  12. import java.awt.image.BufferedImage;
  13. import java.awt.image.ColorModel;
  14. /**
  15. * The <code>GraphicsConfiguration</code> class describes the
  16. * characteristics of a graphics destination such as a printer or monitor.
  17. * There can be many <code>GraphicsConfiguration</code> objects associated
  18. * with a single graphics device, representing different drawing modes or
  19. * capabilities. The corresponding native structure will vary from platform
  20. * to platform. For example, on X11 windowing systems,
  21. * each visual is a different <code>GraphicsConfiguration</code>.
  22. * On win32, <code>GraphicsConfiguration</code>s represent PixelFormats
  23. * available in the current resolution and color depth.
  24. * <p>
  25. * In a virtual device multi-screen environment in which the desktop
  26. * area could span multiple physical screen devices, the bounds of the
  27. * <code>GraphicsConfiguration</code> objects are relative to the
  28. * virtual coordinate system. When setting the location of a
  29. * component, use {@link #getBounds() getBounds} to get the bounds of
  30. * the desired <code>GraphicsConfiguration</code> and offset the location
  31. * with the coordinates of the <code>GraphicsConfiguration</code>,
  32. * as the following code sample illustrates:
  33. * <pre>
  34. * Frame f = new Frame(GraphicsConfiguration gc);
  35. * Rectangle bounds = gc.getBounds();
  36. * f.setLocation(10 + bounds.x, 10 + bounds.y);
  37. * </pre>
  38. * To determine if your environment is a virtual device
  39. * environment, call <code>getBounds</code> on all of the
  40. * <code>GraphicsConfiguration</code> objects in your system. If
  41. * any of the origins of the returned bounds are not (0, 0),
  42. * your environment is a virtual device environment.
  43. * <p>
  44. * You can also use <code>getBounds</code> to determine the bounds
  45. * of the virtual device. Call <code>getBounds</code> on all
  46. * of the <code>GraphicsConfiguration</code> objects in your
  47. * system. Then, calculate the union of all of the bounds returned
  48. * from the calls to <code>getBounds</code>. The union is the
  49. * bounds of the virtual device. The following code sample
  50. * calculates the bounds of the virtual device.
  51. * <pre>
  52. * Rectangle virtualBounds = new Rectangle();
  53. * GraphicsEnvironment ge = GraphicsEnvironment.
  54. * getLocalGraphicsEnvironment();
  55. * GraphicsDevice[] gs =
  56. * ge.getScreenDevices();
  57. * for (int j = 0; j < gs.length; j++) {
  58. * GraphicsDevice gd = gs[j];
  59. * GraphicsConfiguration[] gc =
  60. * gd.getConfigurations();
  61. * for (int i=0; i < gc.length; i++) {
  62. * virtualBounds =
  63. * virtualBounds.union(gc[i].getBounds());
  64. * }
  65. * }
  66. * </pre>
  67. * @see Window
  68. * @see Frame
  69. * @see GraphicsEnvironment
  70. * @see GraphicsDevice
  71. */
  72. /*
  73. * REMIND: What to do about capabilities?
  74. * The
  75. * capabilities of the device can be determined by enumerating the possible
  76. * capabilities and checking if the GraphicsConfiguration
  77. * implements the interface for that capability.
  78. *
  79. * @version 1.28, 02/09/01
  80. */
  81. public abstract class GraphicsConfiguration {
  82. /**
  83. * This is an abstract class that cannot be instantiated directly.
  84. * Instances must be obtained from a suitable factory or query method.
  85. *
  86. * @see GraphicsDevice#getConfigurations
  87. * @see GraphicsDevice#getDefaultConfiguration
  88. * @see GraphicsDevice#getBestConfiguration
  89. * @see Graphics2D#getDeviceConfiguration
  90. */
  91. protected GraphicsConfiguration() {
  92. }
  93. /**
  94. * Returns the {@link GraphicsDevice} associated with this
  95. * <code>GraphicsConfiguration</code>.
  96. * @return a <code>GraphicsDevice</code> object that is
  97. * associated with this <code>GraphicsConfiguration</code>.
  98. */
  99. public abstract GraphicsDevice getDevice();
  100. /**
  101. * Returns a {@link BufferedImage} with a data layout and color model
  102. * compatible with this <code>GraphicsConfiguration</code>. This
  103. * method has nothing to do with memory-mapping
  104. * a device. The returned <code>BufferedImage</code> has
  105. * a layout and color model that is closest to this native device
  106. * configuration and can therefore be optimally blitted to this
  107. * device.
  108. * @param width the width of the returned <code>BufferedImage</code>
  109. * @param height the height of the returned <code>BufferedImage</code>
  110. * @return a <code>BufferedImage</code> whose data layout and color
  111. * model is compatible with this <code>GraphicsConfiguration</code>.
  112. */
  113. public abstract BufferedImage createCompatibleImage(int width, int height);
  114. /**
  115. * Returns a <code>BufferedImage</code> that supports the specified
  116. * transparency and has a data layout and color model
  117. * compatible with this <code>GraphicsConfiguration</code>. This
  118. * method has nothing to do with memory-mapping
  119. * a device. The returned <code>BufferedImage</code> has a layout and
  120. * color model that can be optimally blitted to a device
  121. * with this <code>GraphicsConfiguration</code>.
  122. * @param width the width of the returned <code>BufferedImage</code>
  123. * @param height the height of the returned <code>BufferedImage</code>
  124. * @param transparency the specified transparency mode
  125. * @return a <code>BufferedImage</code> whose data layout and color
  126. * model is compatible with this <code>GraphicsConfiguration</code>
  127. * and also supports the specified transparency.
  128. * @see Transparency#OPAQUE
  129. * @see Transparency#BITMASK
  130. * @see Transparency#TRANSLUCENT
  131. */
  132. public abstract BufferedImage createCompatibleImage(int width, int height,
  133. int transparency);
  134. /**
  135. * Returns the {@link ColorModel} associated with this
  136. * <code>GraphicsConfiguration</code>.
  137. * @return a <code>ColorModel</code> object that is associated with
  138. * this <code>GraphicsConfiguration</code>.
  139. */
  140. public abstract ColorModel getColorModel();
  141. /**
  142. * Returns the <code>ColorModel</code> associated with this
  143. * <code>GraphicsConfiguration</code> that supports the specified
  144. * transparency.
  145. * @param transparency the specified transparency mode
  146. * @return a <code>ColorModel</code> object that is associated with
  147. * this <code>GraphicsConfiguration</code> and supports the
  148. * specified transparency.
  149. */
  150. public abstract ColorModel getColorModel(int transparency);
  151. /**
  152. * Returns the default {@link AffineTransform} for this
  153. * <code>GraphicsConfiguration</code>. This
  154. * <code>AffineTransform</code> is typically the Identity transform
  155. * for most normal screens. The default <code>AffineTransform</code>
  156. * maps coordinates onto the device such that 72 user space
  157. * coordinate units measure approximately 1 inch in device
  158. * space. The normalizing transform can be used to make
  159. * this mapping more exact. Coordinates in the coordinate space
  160. * defined by the default <code>AffineTransform</code> for screen and
  161. * printer devices have the origin in the upper left-hand corner of
  162. * the target region of the device, with X coordinates
  163. * increasing to the right and Y coordinates increasing downwards.
  164. * For image buffers not associated with a device, such as those not
  165. * created by <code>createCompatibleImage</code>,
  166. * this <code>AffineTransform</code> is the Identity transform.
  167. * @return the default <code>AffineTransform</code> for this
  168. * <code>GraphicsConfiguration</code>.
  169. */
  170. public abstract AffineTransform getDefaultTransform();
  171. /**
  172. *
  173. * Returns a <code>AffineTransform</code> that can be concatenated
  174. * with the default <code>AffineTransform</code>
  175. * of a <code>GraphicsConfiguration</code> so that 72 units in user
  176. * space equals 1 inch in device space.
  177. * <p>
  178. * For a particular {@link Graphics2D}, g, one
  179. * can reset the transformation to create
  180. * such a mapping by using the following pseudocode:
  181. * <pre>
  182. * GraphicsConfiguration gc = g.getGraphicsConfiguration();
  183. *
  184. * g.setTransform(gc.getDefaultTransform());
  185. * g.transform(gc.getNormalizingTransform());
  186. * </pre>
  187. * Note that sometimes this <code>AffineTransform</code> is identity,
  188. * such as for printers or metafile output, and that this
  189. * <code>AffineTransform</code> is only as accurate as the information
  190. * supplied by the underlying system. For image buffers not
  191. * associated with a device, such as those not created by
  192. * <code>createCompatibleImage</code>, this
  193. * <code>AffineTransform</code> is the Identity transform
  194. * since there is no valid distance measurement.
  195. * @return an <code>AffineTransform</code> to concatenate to the
  196. * default <code>AffineTransform</code> so that 72 units in user
  197. * space is mapped to 1 inch in device space.
  198. */
  199. public abstract AffineTransform getNormalizingTransform();
  200. /**
  201. * Returns the bounds of the <code>GraphicsConfiguration</code>
  202. * in the device coordinates. In a multi-screen environment
  203. * with a virtual device, the bounds can have negative X
  204. * or Y origins.
  205. * @return the bounds of the area covered by this
  206. * <code>GraphicsConfiguration</code>.
  207. * @since 1.3
  208. */
  209. public abstract Rectangle getBounds();
  210. }