1. /*
  2. * @(#)GraphicsDevice.java 1.21 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. /**
  12. * The <code>GraphicsDevice</code> class describes the graphics devices
  13. * that might be available in a particular graphics environment. These
  14. * include screen and printer devices. Note that there can be many screens
  15. * and many printers in an instance of {@link GraphicsEnvironment}. Each
  16. * graphics device has one or more {@link GraphicsConfiguration} objects
  17. * associated with it. These objects specify the different configurations
  18. * in which the <code>GraphicsDevice</code> can be used.
  19. * <p>
  20. * In a multi-screen environment, the <code>GraphicsConfiguration</code>
  21. * objects can be used to render components on multiple screens. The
  22. * following code sample demonstrates how to create a <code>JFrame</code>
  23. * object for each <code>GraphicsConfiguration</code> on each screen
  24. * device in the <code>GraphicsEnvironment</code>:
  25. * <pre>
  26. * GraphicsEnvironment ge = GraphicsEnvironment.
  27. * getLocalGraphicsEnvironment();
  28. * GraphicsDevice[] gs = ge.getScreenDevices();
  29. * for (int j = 0; j < gs.length; j++) {
  30. * GraphicsDevice gd = gs[j];
  31. * GraphicsConfiguration[] gc =
  32. * gd.getConfigurations();
  33. * for (int i=0; i < gc.length; i++) {
  34. * JFrame f = new
  35. * JFrame(gs[j].getDefaultConfiguration());
  36. * Canvas c = new Canvas(gc[i]);
  37. * Rectangle gcBounds = gc[i].getBounds();
  38. * int xoffs = gcBounds.x;
  39. * int yoffs = gcBounds.y;
  40. * f.getContentPane().add(c);
  41. * f.setLocation((i*50)+xoffs, (i*60)+yoffs);
  42. * f.show();
  43. * }
  44. * }
  45. * </pre>
  46. * @see GraphicsEnvironment
  47. * @see GraphicsConfiguration
  48. * @version 1.21, 02/09/01
  49. */
  50. public abstract class GraphicsDevice {
  51. /**
  52. * This is an abstract class that cannot be instantiated directly.
  53. * Instances must be obtained from a suitable factory or query method.
  54. * @see GraphicsEnvironment#getScreenDevices
  55. * @see GraphicsEnvironment#getDefaultScreenDevice
  56. * @see GraphicsConfiguration#getDevice
  57. */
  58. protected GraphicsDevice() {
  59. }
  60. /**
  61. * Device is a raster screen.
  62. */
  63. public final static int TYPE_RASTER_SCREEN = 0;
  64. /**
  65. * Device is a printer.
  66. */
  67. public final static int TYPE_PRINTER = 1;
  68. /**
  69. * Device is an image buffer. This buffer can reside in device
  70. * or system memory but it is not physically viewable by the user.
  71. */
  72. public final static int TYPE_IMAGE_BUFFER = 2;
  73. /**
  74. * Returns the type of this <code>GraphicsDevice</code>.
  75. * @return the type of this <code>GraphicsDevice</code>, which can
  76. * either be TYPE_RASTER_SCREEN, TYPE_PRINTER or TYPE_IMAGE_BUFFER.
  77. * @see #TYPE_RASTER_SCREEN
  78. * @see #TYPE_PRINTER
  79. * @see #TYPE_IMAGE_BUFFER
  80. */
  81. public abstract int getType();
  82. /**
  83. * Returns the identification string associated with this
  84. * <code>GraphicsDevice</code>.
  85. * <p>
  86. * A particular program might use more than one
  87. * <code>GraphicsDevice</code> in a <code>GraphicsEnvironment</code>.
  88. * This method returns a <code>String</code> identifying a
  89. * particular <code>GraphicsDevice</code> in the local
  90. * <code>GraphicsEnvironment</code>. Although there is
  91. * no public method to set this <code>String</code>, a programmer can
  92. * use the <code>String</code> for debugging purposes. Vendors of
  93. * the Java<sup><font size=-2>TM</font></sup> Runtime Environment can
  94. * format the return value of the <code>String</code>. To determine
  95. * how to interpret the value of the <code>String</code>, contact the
  96. * vendor of your Java Runtime. To find out who the vendor is, from
  97. * your program, call the
  98. * {@link System#getProperty(String) getProperty} method of the
  99. * System class with "java.vendor".
  100. * @return a <code>String</code> that is the identification
  101. * of this <code>GraphicsDevice</code>.
  102. */
  103. public abstract String getIDstring();
  104. /**
  105. * Returns all of the <code>GraphicsConfiguration</code>
  106. * objects associated with this <code>GraphicsDevice</code>.
  107. * @return an array of <code>GraphicsConfiguration</code>
  108. * objects that are associated with this
  109. * <code>GraphicsDevice</code>.
  110. */
  111. public abstract GraphicsConfiguration[] getConfigurations();
  112. /**
  113. * Returns the default <code>GraphicsConfiguration</code>
  114. * associated with this <code>GraphicsDevice</code>.
  115. * @return the default <code>GraphicsConfiguration</code>
  116. * of this <code>GraphicsDevice</code>.
  117. */
  118. public abstract GraphicsConfiguration getDefaultConfiguration();
  119. /**
  120. * Returns the "best" configuration possible that passes the
  121. * criteria defined in the {@link GraphicsConfigTemplate}.
  122. * @param gct the <code>GraphicsConfigTemplate</code> object
  123. * used to obtain a valid <code>GraphicsConfiguration</code>
  124. * @return a <code>GraphicsConfiguration</code> that passes
  125. * the criteria defined in the specified
  126. * <code>GraphicsConfigTemplate</code>.
  127. * @see GraphicsConfigTemplate
  128. */
  129. public GraphicsConfiguration
  130. getBestConfiguration(GraphicsConfigTemplate gct) {
  131. GraphicsConfiguration[] configs = getConfigurations();
  132. return gct.getBestConfiguration(configs);
  133. }
  134. }