001: /*
002: * @(#)GraphicsEnvironment.java 1.11 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.awt;
029:
030: import java.awt.image.BufferedImage;
031: import java.util.Hashtable;
032: import java.util.Locale;
033: import java.util.Map;
034: import java.io.InputStream;
035:
036: /**
037: *
038: * The <code>GraphicsEnvironment</code> class describes the collection
039: * of {@link GraphicsDevice} objects and {@link java.awt.Font} objects
040: * available to a Java(tm) application on a particular platform.
041: * The resources in this <code>GraphicsEnvironment</code> might be local
042: * or on a remote machine. <code>GraphicsDevice</code> objects can be
043: * screens, printers or image buffers and are the destination of
044: * {@link Graphics2D} drawing methods. Each <code>GraphicsDevice</code>
045: * has a number of {@link GraphicsConfiguration} objects associated with
046: * it. These objects specify the different configurations in which the
047: * <code>GraphicsDevice</code> can be used.
048: * @see GraphicsDevice
049: * @see GraphicsConfiguration
050: * @version 1.42, 02/02/00
051: */
052:
053: public abstract class GraphicsEnvironment {
054:
055: private static GraphicsEnvironment localEnv;
056:
057: /**
058: * This is an abstract class and cannot be instantiated directly.
059: * Instances must be obtained from a suitable factory or query method.
060: */
061: protected GraphicsEnvironment() {
062: }
063:
064: /**
065: * Returns the local <code>GraphicsEnvironment</code>.
066: * @return this <code>GraphicsEnvironment</code>.
067: */
068:
069: /**
070: * Returns the local <code>GraphicsEnvironment</code>.
071: * @return this <code>GraphicsEnvironment</code>.
072: */
073: public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment() {
074: if (localEnv == null) {
075: String nm = (String) java.security.AccessController
076: .doPrivileged(new sun.security.action.GetPropertyAction(
077: "java.awt.graphicsenv", null));
078: try {
079: localEnv = (GraphicsEnvironment) Class.forName(nm)
080: .newInstance();
081: } catch (ClassNotFoundException e) {
082: throw new Error("Could not find class: " + nm);
083: } catch (InstantiationException e) {
084: throw new Error(
085: "Could not instantiate Graphics Environment: "
086: + nm);
087: } catch (IllegalAccessException e) {
088: throw new Error(
089: "Could not access Graphics Environment: " + nm);
090: }
091: }
092: return localEnv;
093: }
094:
095: /**
096: * Tests whether or not a display, keyboard, and mouse can be
097: * supported in this environment. If this method returns true,
098: * a HeadlessException is thrown from areas of the Toolkit
099: * and GraphicsEnvironment that are dependent on a display,
100: * keyboard, or mouse.
101: * @return <code>true</code> if this environment cannot support
102: * a display, keyboard, and mouse; <code>false</code>
103: * otherwise
104: * @see java.awt.HeadlessException
105: * @since 1.4
106: */
107: public static boolean isHeadless() {
108: // fix for 5086794, matching the impl to that of basis.
109: return false;
110: }
111:
112: public abstract Graphics2D createGraphics(BufferedImage img);
113:
114: /**
115: * Returns an array of all of the screen <code>GraphicsDevice</code>
116: * objects.
117: * @return an array containing all the <code>GraphicsDevice</code>
118: * objects that represent screen devices.
119: */
120: public abstract GraphicsDevice[] getScreenDevices();
121:
122: /**
123: * Returns the default screen <code>GraphicsDevice</code>.
124: * @return the <code>GraphicsDevice</code> that represents the
125: * default screen device.
126: */
127: public abstract GraphicsDevice getDefaultScreenDevice();
128:
129: /**
130: * Returns a <code>Graphics2D</code> object for rendering into the
131: * specified {@link BufferedImage}.
132: * @param img the specified <code>BufferedImage</code>
133: * @return a <code>Graphics2D</code> to be used for rendering into
134: * the specified <code>BufferedImage</code>.
135: */
136: // public abstract Graphics2D createGraphics(BufferedImage img);
137: /**
138: * Returns an array containing a one-point size instance of all fonts
139: * available in this <code>GraphicsEnvironment</code>. Typical usage
140: * would be to allow a user to select a particular font. Then, the
141: * application can size the font and set various font attributes by
142: * calling the <code>deriveFont</code> method on the choosen instance.
143: * <p>
144: * This method provides for the application the most precise control
145: * over which <code>Font</code> instance is used to render text.
146: * If a font in this <code>GraphicsEnvironment</code> has multiple
147: * programmable variations, only one
148: * instance of that <code>Font</code> is returned in the array, and
149: * other variations must be derived by the application.
150: * <p>
151: * If a font in this environment has multiple programmable variations,
152: * such as Multiple-Master fonts, only one instance of that font is
153: * returned in the <code>Font</code> array. The other variations
154: * must be derived by the application.
155: * @return an array of <code>Font</code> objects.
156: * @see #getAvailableFontFamilyNames
157: * @see java.awt.Font
158: * @see java.awt.Font#deriveFont
159: * @see java.awt.Font#getFontName
160: * @since 1.2
161: */
162: // public abstract Font[] getAllFonts();
163: /**
164: * Returns an array containing the names of all font families available
165: * in this <code>GraphicsEnvironment</code>.
166: * Typical usage would be to allow a user to select a particular family
167: * name and allow the application to choose related variants of the
168: * same family when the user specifies style attributes such
169: * as Bold or Italic.
170: * <p>
171: * This method provides for the application some control over which
172: * <code>Font</code> instance is used to render text, but allows the
173: * <code>Font</code> object more flexibility in choosing its own best
174: * match among multiple fonts in the same font family.
175: * @return an array of <code>String</code> containing names of font
176: * families.
177: * @see #getAllFonts
178: * @see java.awt.Font
179: * @see java.awt.Font#getFamily
180: * @since 1.2
181: */
182: public abstract String[] getAvailableFontFamilyNames();
183:
184: /**
185: * Returns an array containing the localized names of all font families
186: * available in this <code>GraphicsEnvironment</code>.
187: * Typical usage would be to allow a user to select a particular family
188: * name and allow the application to choose related variants of the
189: * same family when the user specifies style attributes such
190: * as Bold or Italic.
191: * <p>
192: * This method provides for the application some control over which
193: * <code>Font</code> instance used to render text, but allows the
194: * <code>Font</code> object more flexibility in choosing its own best
195: * match among multiple fonts in the same font family.
196: * If <code>l</code> is <code>null</code>, this method returns an
197: * array containing all font family names available in this
198: * <code>GraphicsEnvironment</code>.
199: * @param l a {@link Locale} object that represents a
200: * particular geographical, political, or cultural region
201: * @return an array of <code>String</code> objects containing names of
202: * font families specific to the specified <code>Locale</code>.
203: * @see #getAllFonts
204: * @see java.awt.Font
205: * @see java.awt.Font#getFamily
206: * @since 1.2
207: */
208: public abstract String[] getAvailableFontFamilyNames(Locale l);
209: }
|