Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / awt / GraphicsEnvironment.java
blobb963f4bab2bc5db11d2b79ac2619be31a6506ef0
1 /* GraphicsEnvironment.java -- information about the graphics environment
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt;
41 import gnu.java.awt.ClasspathToolkit;
43 import java.awt.image.BufferedImage;
44 import java.util.Locale;
46 /**
47 * This descibes the collection of GraphicsDevice and Font objects available
48 * on a given platform. The resources might be local or remote, and specify
49 * the valid configurations for displaying graphics.
51 * @author Eric Blake (ebb9@email.byu.edu)
52 * @see GraphicsDevice
53 * @see GraphicsConfiguration
54 * @since 1.4
55 * @status updated to 1.4
57 public abstract class GraphicsEnvironment
59 /**
60 * The environment must be obtained from a factory or query method, hence
61 * this constructor is protected.
63 protected GraphicsEnvironment()
67 /**
68 * Returns the local graphics environment.
70 * XXX Not implemented in Classpath yet.
71 * @return the local environment
73 public static GraphicsEnvironment getLocalGraphicsEnvironment()
75 ClasspathToolkit tk;
76 tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit ());
77 return tk.getLocalGraphicsEnvironment ();
80 /**
81 * Check if the local environment is headless, meaning that it does not
82 * support a display, keyboard, or mouse. Many methods in the Abstract
83 * Windows Toolkit (java.awt) throw a {@link HeadlessException} if this
84 * returns true.
86 * XXX For now, Classpath assumes that it is never headless.
88 * @return true if the environment is headless, meaning that graphics are
89 * unsupported
90 * @since 1.4
92 public static boolean isHeadless()
94 // XXX Should be: getLocalGraphicsEnvironment().isHeadlessInstance();
95 return false;
98 /**
99 * Check if the given environment is headless, meaning that it does not
100 * support a display, keyboard, or mouse. Many methods in the Abstract
101 * Windows Toolkit (java.awt) throw a {@link HeadlessException} if this
102 * returns true. This default implementation returns false, so subclasses
103 * need only override it if they are headless.
105 * @return true if the environment is headless, meaning that graphics are
106 * unsupported
107 * @since 1.4
109 public boolean isHeadlessInstance()
111 return false;
115 * Get an array of all the GraphicsDevice objects.
117 * @return the available graphics devices, may be 0 length
118 * @throws HeadlessException if the environment is headless
120 public abstract GraphicsDevice[] getScreenDevices();
123 * Get the default screen GraphicsDevice object.
125 * @return the default screen device
126 * @throws HeadlessException if the environment is headless
128 public abstract GraphicsDevice getDefaultScreenDevice();
131 * Return a Graphics2D object which will render into the specified image.
133 * @param image the image to render into
134 * @return the object that renders into the image
136 public abstract Graphics2D createGraphics(BufferedImage image);
139 * Returns an array of the one-point size fonts available in this
140 * environment. From there, the user can select the font and derive the
141 * correct one of proper size and attributes, using <code>deriveFont</code>.
142 * Only one master version of each font appears in this array; if a font
143 * can be derived from another, it must be created in that way.
145 * @return the array of available fonts
146 * @see #getAvailableFontFamilyNames()
147 * @see Font#deriveFont(int, float)
148 * @since 1.2
150 public abstract Font[] getAllFonts();
153 * Returns an array of the font family names available in this environment.
154 * This allows flexibility in choosing the style of font, while still letting
155 * the Font class decide its best match.
157 * @return the array of available font families
158 * @see #getAllFonts()
159 * @see Font#getFamily()
160 * @since 1.2
162 public abstract String[] getAvailableFontFamilyNames();
165 * Returns an array of the font family names available in this environment,
166 * localized to the current Locale if l is non-null. This allows
167 * flexibility in choosing the style of font, while still letting the Font
168 * class decide its best match.
170 * @param l the locale to use
171 * @return the array of available font families, localized
172 * @see #getAllFonts()
173 * @see Font#getFamily()
174 * @since 1.2
176 public abstract String[] getAvailableFontFamilyNames(Locale l);
179 * Returns the point where a window should be centered. You should probably
180 * also check that the window fits within the screen bounds. The default
181 * simply returns the center of the maximum window bounds; subclasses should
182 * override this if native objects (like scrollbars) make that off-centered.
184 * @return the centering point
185 * @throws HeadlessException if the environment is headless
186 * @see #getMaximumWindowBounds()
187 * @since 1.4
189 public Point getCenterPoint()
191 Rectangle r = getMaximumWindowBounds();
192 return new Point(r.x + r.width / 2, r.y + r.height / 2);
196 * Returns the maximum bounds for a centered window object. The default
197 * implementation simply returns the bounds of the default configuration
198 * of the default screen; subclasses should override this to if native
199 * objects (like scrollbars) reduce what is truly available. Also,
200 * subclasses should override this if the window should be centered across
201 * a multi-screen display.
203 * @return the maximum window bounds
204 * @throws HeadlessException if the environment is headless
205 * @see #getCenterPoint()
206 * @see GraphicsConfiguration#getBounds()
207 * @see Toolkit#getScreenInsets(GraphicsConfiguration)
208 * @since 1.4
210 public Rectangle getMaximumWindowBounds()
212 return getDefaultScreenDevice().getDefaultConfiguration().getBounds();
214 } // class GraphicsEnvironment