1. /*
  2. * @(#)GraphicsEnvironment.java 1.37 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.awt.image.BufferedImage;
  9. import java.util.Hashtable;
  10. import java.util.Locale;
  11. import java.util.Map;
  12. import java.io.InputStream;
  13. /**
  14. *
  15. * The <code>GraphicsEnvironment</code> class describes the collection
  16. * of {@link GraphicsDevice} objects and {@link java.awt.Font} objects
  17. * available to a Java(tm) application on a particular platform.
  18. * The resources in this <code>GraphicsEnvironment</code> might be local
  19. * or on a remote machine. <code>GraphicsDevice</code> objects can be
  20. * screens, printers or image buffers and are the destination of
  21. * {@link Graphics2D} drawing methods. Each <code>GraphicsDevice</code>
  22. * has a number of {@link GraphicsConfiguration} objects associated with
  23. * it. These objects specify the different configurations in which the
  24. * <code>GraphicsDevice</code> can be used.
  25. * @see GraphicsDevice
  26. * @see GraphicsConfiguration
  27. * @version 10 Feb 1997
  28. */
  29. public abstract class GraphicsEnvironment {
  30. private static GraphicsEnvironment localEnv;
  31. /**
  32. * This is an abstract class and cannot be instantiated directly.
  33. * Instances must be obtained from a suitable factory or query method.
  34. */
  35. protected GraphicsEnvironment() {
  36. }
  37. /**
  38. * Returns the local <code>GraphicsEnvironment</code>.
  39. * @return this <code>GraphicsEnvironment</code>.
  40. */
  41. public static GraphicsEnvironment getLocalGraphicsEnvironment() {
  42. if (localEnv == null) {
  43. String nm = (String) java.security.AccessController.doPrivileged
  44. (new sun.security.action.GetPropertyAction
  45. ("java.awt.graphicsenv", null));
  46. try {
  47. localEnv =
  48. (GraphicsEnvironment) Class.forName(nm).newInstance();
  49. } catch (ClassNotFoundException e) {
  50. throw new Error("Could not find class: "+nm);
  51. } catch (InstantiationException e) {
  52. throw new Error("Could not instantiate Graphics Environment: "
  53. + nm);
  54. } catch (IllegalAccessException e) {
  55. throw new Error ("Could not access Graphics Environment: "
  56. + nm);
  57. }
  58. }
  59. return localEnv;
  60. }
  61. /**
  62. * Returns an array of all of the screen <code>GraphicsDevice</code>
  63. * objects.
  64. * @return an array containing all the <code>GraphicsDevice</code>
  65. * objects that represent screen devices.
  66. */
  67. public abstract GraphicsDevice[] getScreenDevices();
  68. /**
  69. * Returns the default screen <code>GraphicsDevice</code>.
  70. * @return the <code>GraphicsDevice</code> that represents the
  71. * default screen device.
  72. */
  73. public abstract GraphicsDevice getDefaultScreenDevice();
  74. /**
  75. * Returns a <code>Graphics2D</code> object for rendering into the
  76. * specified {@link BufferedImage}.
  77. * @param img the specified <code>BufferedImage</code>
  78. * @return a <code>Graphics2D</code> to be used for rendering into
  79. * the specified <code>BufferedImage</code>.
  80. */
  81. public abstract Graphics2D createGraphics(BufferedImage img);
  82. /**
  83. * Returns an array containing a one-point size instance of all fonts
  84. * available in this <code>GraphicsEnvironment</code>. Typical usage
  85. * would be to allow a user to select a particular font. Then, the
  86. * application can size the font and set various font attributes by
  87. * calling the <code>deriveFont</code> method on the choosen instance.
  88. * <p>
  89. * This method provides for the application the most precise control
  90. * over which <code>Font</code> instance is used to render text.
  91. * If a font in this <code>GraphicsEnvironment</code> has multiple
  92. * programmable variations, only one
  93. * instance of that <code>Font</code> is returned in the array, and
  94. * other variations must be derived by the application.
  95. * <p>
  96. * If a font in this environment has multiple programmable variations,
  97. * such as Multiple-Master fonts, only one instance of that font is
  98. * returned in the <code>Font</code> array. The other variations
  99. * must be derived by the application.
  100. * @return an array of <code>Font</code> objects.
  101. * @see #getAvailableFontFamilyNames
  102. * @see java.awt.Font
  103. * @see java.awt.Font#deriveFont
  104. * @see java.awt.Font#getFontName
  105. * @since JDK 1.2
  106. */
  107. public abstract Font[] getAllFonts();
  108. /**
  109. * Returns an array containing the names of all font families available
  110. * in this <code>GraphicsEnvironment</code>.
  111. * Typical usage would be to allow a user to select a particular family
  112. * name and allow the application to choose related variants of the
  113. * same family when the user specifies style attributes such
  114. * as Bold or Italic.
  115. * <p>
  116. * This method provides for the application some control over which
  117. * <code>Font</code> instance is used to render text, but allows the
  118. * <code>Font</code> object more flexibility in choosing its own best
  119. * match among multiple fonts in the same font family.
  120. * @return an array of <code>String</code> containing names of font
  121. * families.
  122. * @see #getAllFonts
  123. * @see java.awt.Font
  124. * @see java.awt.Font#getFamily
  125. * @since JDK 1.2
  126. */
  127. public abstract String[] getAvailableFontFamilyNames();
  128. /**
  129. * Returns an array containing the localized names of all font families
  130. * available in this <code>GraphicsEnvironment</code>.
  131. * Typical usage would be to allow a user to select a particular family
  132. * name and allow the application to choose related variants of the
  133. * same family when the user specifies style attributes such
  134. * as Bold or Italic.
  135. * <p>
  136. * This method provides for the application some control over which
  137. * <code>Font</code> instance used to render text, but allows the
  138. * <code>Font</code> object more flexibility in choosing its own best
  139. * match among multiple fonts in the same font family.
  140. * If <code>l</code> is <code>null</code>, this method returns an
  141. * array containing all font family names available in this
  142. * <code>GraphicsEnvironment</code>.
  143. * @param l a {@link Locale} object that represents a
  144. * particular geographical, political, or cultural region
  145. * @return an array of <code>String</code> objects containing names of
  146. * font families specific to the specified <code>Locale</code>.
  147. * @see #getAllFonts
  148. * @see java.awt.Font
  149. * @see java.awt.Font#getFamily
  150. * @since JDK 1.2
  151. */
  152. public abstract String[] getAvailableFontFamilyNames(Locale l);
  153. }