Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / gnu / java / awt / ClasspathToolkit.java
blob1ec5664dc3ea2c75d4a4288c5317500eba45af1b
1 /* ClasspathToolkit.java -- Abstract superclass for Classpath toolkits.
2 Copyright (C) 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 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 gnu.java.awt;
41 import gnu.java.awt.EmbeddedWindow;
42 import gnu.java.awt.peer.ClasspathFontPeer;
43 import gnu.java.awt.peer.EmbeddedWindowPeer;
44 import gnu.java.awt.peer.ClasspathTextLayoutPeer;
45 import gnu.java.security.action.SetAccessibleAction;
47 import java.awt.AWTException;
48 import java.awt.Component;
49 import java.awt.Dimension;
50 import java.awt.DisplayMode;
51 import java.awt.Font;
52 import java.awt.FontMetrics;
53 import java.awt.GraphicsDevice;
54 import java.awt.GraphicsEnvironment;
55 import java.awt.Image;
56 import java.awt.Toolkit;
57 import java.awt.font.FontRenderContext;
58 import java.awt.image.ColorModel;
59 import java.awt.image.ImageProducer;
60 import java.awt.peer.RobotPeer;
61 import java.io.File;
62 import java.io.InputStream;
63 import java.lang.reflect.Constructor;
64 import java.lang.reflect.InvocationTargetException;
65 import java.net.MalformedURLException;
66 import java.net.URL;
67 import java.text.AttributedString;
68 import java.util.HashMap;
69 import java.util.Map;
70 import java.security.AccessController;
72 import javax.imageio.spi.IIORegistry;
74 /**
75 * An abstract superclass for Classpath toolkits.
77 * <p>There exist some parts of AWT and Java2D that are specific to
78 * the underlying platform, but for which the {@link Toolkit} class
79 * does not provide suitable abstractions. Examples include some
80 * methods of {@link Font} or {@link GraphicsEnvironment}. Those
81 * methods use ClasspathToolkit as a central place for obtaining
82 * platform-specific functionality.
84 * <p>In addition, ClasspathToolkit implements some abstract methods
85 * of {@link java.awt.Toolkit} that are not really platform-specific,
86 * such as the maintenance of a cache of loaded images.
88 * <p><b>Thread Safety:</b> The methods of this class may safely be
89 * called without external synchronization. This also hold for any
90 * inherited {@link Toolkit} methods. Subclasses are responsible for
91 * the necessary synchronization.
93 * @author Sascha Brawer (brawer@dandelis.ch)
95 public abstract class ClasspathToolkit
96 extends Toolkit
98 /**
99 * Returns a shared instance of the local, platform-specific
100 * graphics environment.
102 * <p>This method is specific to GNU Classpath. It gets called by
103 * the Classpath implementation of {@link
104 * GraphicsEnvironment.getLocalGraphcisEnvironment()}.
106 public abstract GraphicsEnvironment getLocalGraphicsEnvironment();
109 * Acquires an appropriate {@link ClasspathFontPeer}, for use in
110 * classpath's implementation of {@link java.awt.Font}.
112 * @param name The logical name of the font. This may be either a face
113 * name or a logical font name, or may even be null. A default
114 * implementation of name decoding is provided in
115 * {@link ClasspathFontPeer}, but may be overridden in other toolkits.
117 * @param attrs Any extra {@link java.awt.font.TextAttribute} attributes
118 * this font peer should have, such as size, weight, family name, or
119 * transformation.
121 public abstract ClasspathFontPeer getClasspathFontPeer (String name, Map attrs);
123 public abstract ClasspathTextLayoutPeer
124 getClasspathTextLayoutPeer (AttributedString str, FontRenderContext frc);
127 /**
128 * Creates a {@link Font}, in a platform-specific manner.
130 * The default implementation simply constructs a {@link Font}, but some
131 * toolkits may wish to override this, to return {@link Font} subclasses
132 * which implement {@link java.awt.font.OpenType} or
133 * {@link java.awt.font.MultipleMaster}.
135 public Font getFont (String name, Map attrs)
137 Font f = null;
139 // Circumvent the package-privateness of the
140 // java.awt.Font.Font(String,Map) constructor.
143 Constructor fontConstructor = Font.class.getDeclaredConstructor
144 (new Class[] { String.class, Map.class });
145 AccessController.doPrivileged
146 (new SetAccessibleAction(fontConstructor));
147 f = (Font) fontConstructor.newInstance(new Object[] { name, attrs });
149 catch (IllegalAccessException e)
151 throw new AssertionError(e);
153 catch (NoSuchMethodException e)
155 throw new AssertionError(e);
157 catch (InstantiationException e)
159 throw new AssertionError(e);
161 catch (InvocationTargetException e)
163 throw new AssertionError(e);
165 return f;
169 * Creates a font, reading the glyph definitions from a stream.
171 * <p>This method provides the platform-specific implementation for
172 * the static factory method {@link Font#createFont(int,
173 * java.io.InputStream)}.
175 * @param format the format of the font data, such as {@link
176 * Font#TRUETYPE_FONT}. An implementation may ignore this argument
177 * if it is able to automatically recognize the font format from the
178 * provided data.
180 * @param stream an input stream from where the font data is read
181 * in. The stream will be advanced to the position after the font
182 * data, but not closed.
184 * @throws IllegalArgumentException if <code>format</code> is
185 * not supported.
187 * @throws FontFormatException if <code>stream</code> does not
188 * contain data in the expected format, or if required tables are
189 * missing from a font.
191 * @throws IOException if a problem occurs while reading in the
192 * contents of <code>stream</code>.
194 public abstract Font createFont(int format, InputStream stream);
196 public abstract RobotPeer createRobot (GraphicsDevice screen)
197 throws AWTException;
200 * Creates an embedded window peer, and associates it with an
201 * EmbeddedWindow object.
203 * @param w The embedded window with which to associate a peer.
205 public abstract EmbeddedWindowPeer createEmbeddedWindow (EmbeddedWindow w);
208 * Used to register ImageIO SPIs provided by the toolkit.
210 public void registerImageIOSpis(IIORegistry reg)