| 1 | /* GraphicsEnvironment.java -- information about the graphics environment
|
|---|
| 2 | Copyright (C) 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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.
|
|---|
| 20 |
|
|---|
| 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.
|
|---|
| 25 |
|
|---|
| 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. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.awt;
|
|---|
| 40 |
|
|---|
| 41 | import java.awt.image.BufferedImage;
|
|---|
| 42 | import java.util.Locale;
|
|---|
| 43 |
|
|---|
| 44 | /**
|
|---|
| 45 | * This descibes the collection of GraphicsDevice and Font objects available
|
|---|
| 46 | * on a given platform. The resources might be local or remote, and specify
|
|---|
| 47 | * the valid configurations for displaying graphics.
|
|---|
| 48 | *
|
|---|
| 49 | * @author Eric Blake <[email protected]>
|
|---|
| 50 | * @see GraphicsDevice
|
|---|
| 51 | * @see GraphicsConfiguration
|
|---|
| 52 | * @since 1.4
|
|---|
| 53 | * @status updated to 1.4
|
|---|
| 54 | */
|
|---|
| 55 | public abstract class GraphicsEnvironment
|
|---|
| 56 | {
|
|---|
| 57 | /**
|
|---|
| 58 | * The environment must be obtained from a factory or query method, hence
|
|---|
| 59 | * this constructor is protected.
|
|---|
| 60 | */
|
|---|
| 61 | protected GraphicsEnvironment()
|
|---|
| 62 | {
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | /**
|
|---|
| 66 | * Returns the local graphics environment.
|
|---|
| 67 | *
|
|---|
| 68 | * XXX Not implemented in Classpath yet.
|
|---|
| 69 | * @return the local environment
|
|---|
| 70 | */
|
|---|
| 71 | public static GraphicsEnvironment getLocalGraphicsEnvironment()
|
|---|
| 72 | {
|
|---|
| 73 | throw new Error("not implemented");
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /**
|
|---|
| 77 | * Check if the local environment is headless, meaning that it does not
|
|---|
| 78 | * support a display, keyboard, or mouse. Many methods in the Abstract
|
|---|
| 79 | * Windows Toolkit (java.awt) throw a {@link HeadlessException} if this
|
|---|
| 80 | * returns true.
|
|---|
| 81 | *
|
|---|
| 82 | * XXX For now, Classpath assumes that it is never headless.
|
|---|
| 83 | *
|
|---|
| 84 | * @return true if the environment is headless, meaning that graphics are
|
|---|
| 85 | * unsupported
|
|---|
| 86 | * @since 1.4
|
|---|
| 87 | */
|
|---|
| 88 | public static boolean isHeadless()
|
|---|
| 89 | {
|
|---|
| 90 | // XXX Should be: getLocalGraphicsEnvironment().isHeadlessInstance();
|
|---|
| 91 | return false;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | /**
|
|---|
| 95 | * Check if the given environment is headless, meaning that it does not
|
|---|
| 96 | * support a display, keyboard, or mouse. Many methods in the Abstract
|
|---|
| 97 | * Windows Toolkit (java.awt) throw a {@link HeadlessException} if this
|
|---|
| 98 | * returns true. This default implementation returns false, so subclasses
|
|---|
| 99 | * need only override it if they are headless.
|
|---|
| 100 | *
|
|---|
| 101 | * @return true if the environment is headless, meaning that graphics are
|
|---|
| 102 | * unsupported
|
|---|
| 103 | * @since 1.4
|
|---|
| 104 | */
|
|---|
| 105 | public boolean isHeadlessInstance()
|
|---|
| 106 | {
|
|---|
| 107 | return false;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | /**
|
|---|
| 111 | * Get an array of all the GraphicsDevice objects.
|
|---|
| 112 | *
|
|---|
| 113 | * @return the available graphics devices, may be 0 length
|
|---|
| 114 | * @throws HeadlessException if the environment is headless
|
|---|
| 115 | */
|
|---|
| 116 | public abstract GraphicsDevice[] getScreenDevices();
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * Get the default screen GraphicsDevice object.
|
|---|
| 120 | *
|
|---|
| 121 | * @return the default screen device
|
|---|
| 122 | * @throws HeadlessException if the environment is headless
|
|---|
| 123 | */
|
|---|
| 124 | public abstract GraphicsDevice getDefaultScreenDevice();
|
|---|
| 125 |
|
|---|
| 126 | /**
|
|---|
| 127 | * Return a Graphics2D object which will render into the specified image.
|
|---|
| 128 | *
|
|---|
| 129 | * @param image the image to render into
|
|---|
| 130 | * @return the object that renders into the image
|
|---|
| 131 | */
|
|---|
| 132 | public abstract Graphics2D createGraphics(BufferedImage image);
|
|---|
| 133 |
|
|---|
| 134 | /**
|
|---|
| 135 | * Returns an array of the one-point size fonts available in this
|
|---|
| 136 | * environment. From there, the user can select the font and derive the
|
|---|
| 137 | * correct one of proper size and attributes, using <code>deriveFont</code>.
|
|---|
| 138 | * Only one master version of each font appears in this array; if a font
|
|---|
| 139 | * can be derived from another, it must be created in that way.
|
|---|
| 140 | *
|
|---|
| 141 | * @return the array of available fonts
|
|---|
| 142 | * @see #getAvailableFontFamilyNames()
|
|---|
| 143 | * @see Font#deriveFont(int, float)
|
|---|
| 144 | * @since 1.2
|
|---|
| 145 | */
|
|---|
| 146 | public abstract Font[] getAllFonts();
|
|---|
| 147 |
|
|---|
| 148 | /**
|
|---|
| 149 | * Returns an array of the font family names available in this environment.
|
|---|
| 150 | * This allows flexibility in choosing the style of font, while still letting
|
|---|
| 151 | * the Font class decide its best match.
|
|---|
| 152 | *
|
|---|
| 153 | * @return the array of available font families
|
|---|
| 154 | * @see #getAllFonts()
|
|---|
| 155 | * @see Font#getFamily()
|
|---|
| 156 | * @since 1.2
|
|---|
| 157 | */
|
|---|
| 158 | public abstract String[] getAvailableFontFamilyNames();
|
|---|
| 159 |
|
|---|
| 160 | /**
|
|---|
| 161 | * Returns an array of the font family names available in this environment,
|
|---|
| 162 | * localized to the current Locale if l is non-null. This allows
|
|---|
| 163 | * flexibility in choosing the style of font, while still letting the Font
|
|---|
| 164 | * class decide its best match.
|
|---|
| 165 | *
|
|---|
| 166 | * @param l the locale to use
|
|---|
| 167 | * @return the array of available font families, localized
|
|---|
| 168 | * @see #getAllFonts()
|
|---|
| 169 | * @see Font#getFamily()
|
|---|
| 170 | * @since 1.2
|
|---|
| 171 | */
|
|---|
| 172 | public abstract String[] getAvailableFontFamilyNames(Locale l);
|
|---|
| 173 |
|
|---|
| 174 | /**
|
|---|
| 175 | * Returns the point where a window should be centered. You should probably
|
|---|
| 176 | * also check that the window fits within the screen bounds. The default
|
|---|
| 177 | * simply returns the center of the maximum window bounds; subclasses should
|
|---|
| 178 | * override this if native objects (like scrollbars) make that off-centered.
|
|---|
| 179 | *
|
|---|
| 180 | * @return the centering point
|
|---|
| 181 | * @throws HeadlessException if the environment is headless
|
|---|
| 182 | * @see #getMaximumWindowBounds()
|
|---|
| 183 | * @since 1.4
|
|---|
| 184 | */
|
|---|
| 185 | public Point getCenterPoint()
|
|---|
| 186 | {
|
|---|
| 187 | Rectangle r = getMaximumWindowBounds();
|
|---|
| 188 | return new Point(r.x + r.width / 2, r.y + r.height / 2);
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | /**
|
|---|
| 192 | * Returns the maximum bounds for a centered window object. The default
|
|---|
| 193 | * implementation simply returns the bounds of the default configuration
|
|---|
| 194 | * of the default screen; subclasses should override this to if native
|
|---|
| 195 | * objects (like scrollbars) reduce what is truly available. Also,
|
|---|
| 196 | * subclasses should override this if the window should be centered across
|
|---|
| 197 | * a multi-screen display.
|
|---|
| 198 | *
|
|---|
| 199 | * @return the maximum window bounds
|
|---|
| 200 | * @throws HeadlessException if the environment is headless
|
|---|
| 201 | * @see #getCenterPoint()
|
|---|
| 202 | * @see GraphicsConfiguration#getBounds()
|
|---|
| 203 | * @see Toolkit#getScreenInsets(GraphicsConfiguration)
|
|---|
| 204 | * @since 1.4
|
|---|
| 205 | */
|
|---|
| 206 | public Rectangle getMaximumWindowBounds()
|
|---|
| 207 | {
|
|---|
| 208 | return getDefaultScreenDevice().getDefaultConfiguration().getBounds();
|
|---|
| 209 | }
|
|---|
| 210 | } // class GraphicsEnvironment
|
|---|