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