KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > Toolkit


1 /*
2  * @(#)Toolkit.java 1.203 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt;
9
10 import java.util.MissingResourceException JavaDoc;
11 import java.util.Properties JavaDoc;
12 import java.util.ResourceBundle JavaDoc;
13 import java.util.StringTokenizer JavaDoc;
14 import java.awt.event.*;
15 import java.awt.peer.*;
16 import java.awt.*;
17 import java.awt.im.InputMethodHighlight JavaDoc;
18 import java.awt.image.ImageObserver JavaDoc;
19 import java.awt.image.ImageProducer JavaDoc;
20 import java.awt.image.ColorModel JavaDoc;
21 import java.awt.datatransfer.Clipboard JavaDoc;
22 import java.awt.dnd.DnDConstants JavaDoc;
23 import java.awt.dnd.DragSource JavaDoc;
24 import java.awt.dnd.DragGestureRecognizer JavaDoc;
25 import java.awt.dnd.DragGestureEvent JavaDoc;
26 import java.awt.dnd.DragGestureListener JavaDoc;
27 import java.awt.dnd.InvalidDnDOperationException JavaDoc;
28 import java.awt.dnd.peer.DragSourceContextPeer;
29 import java.net.URL JavaDoc;
30 import java.io.BufferedInputStream JavaDoc;
31 import java.io.File JavaDoc;
32 import java.io.FileInputStream JavaDoc;
33 import java.security.AccessController JavaDoc;
34 import java.security.PrivilegedAction JavaDoc;
35
36 import java.util.EventListener JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.HashMap JavaDoc;
39 import java.util.WeakHashMap JavaDoc;
40 import java.util.List JavaDoc;
41 import java.util.ArrayList JavaDoc;
42
43 import java.beans.PropertyChangeListener JavaDoc;
44 import java.beans.PropertyChangeSupport JavaDoc;
45
46 import sun.awt.DebugHelper;
47 import sun.awt.HeadlessToolkit;
48 import sun.awt.NullComponentPeer;
49 import sun.security.util.SecurityConstants;
50 /**
51  * This class is the abstract superclass of all actual
52  * implementations of the Abstract Window Toolkit. Subclasses of
53  * <code>Toolkit</code> are used to bind the various components
54  * to particular native toolkit implementations.
55  * <p>
56  * Many GUI operations may be performed asynchronously. This
57  * means that if you set the state of a component, and then
58  * immediately query the state, the returned value may not yet
59  * reflect the requested change. This includes, but is not
60  * limited to:
61  * <ul>
62  * <li>Scrolling to a specified position.
63  * <br>For example, calling <code>ScrollPane.setScrollPosition</code>
64  * and then <code>getScrollPosition</code> may return an incorrect
65  * value if the original request has not yet been processed.
66  * <p>
67  * <li>Moving the focus from one component to another.
68  * <br>For more information, see
69  * <a HREF="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#transferTiming">Timing
70  * Focus Transfers</a>, a section in
71  * <a HREF="http://java.sun.com/docs/books/tutorial/uiswing/">The Swing
72  * Tutorial</a>.
73  * <p>
74  * <li>Making a top-level container visible.
75  * <br>Calling <code>setVisible(true)</code> on a <code>Window</code>,
76  * <code>Frame</code> or <code>Dialog</code> may occur
77  * asynchronously.
78  * <p>
79  * <li>Setting the size or location of a top-level container.
80  * <br>Calls to <code>setSize</code>, <code>setBounds</code> or
81  * <code>setLocation</code> on a <code>Window</code>,
82  * <code>Frame</code> or <code>Dialog</code> are forwarded
83  * to the underlying window management system and may be
84  * ignored or modified. See {@link java.awt.Window} for
85  * more information.
86  * </ul>
87  * <p>
88  * Most applications should not call any of the methods in this
89  * class directly. The methods defined by <code>Toolkit</code> are
90  * the "glue" that joins the platform-independent classes in the
91  * <code>java.awt</code> package with their counterparts in
92  * <code>java.awt.peer</code>. Some methods defined by
93  * <code>Toolkit</code> query the native operating system directly.
94  *
95  * @version 1.203, 12/19/03
96  * @author Sami Shaio
97  * @author Arthur van Hoff
98  * @author Fred Ecks
99  * @since JDK1.0
100  */

101 public abstract class Toolkit {
102
103     /**
104      * Creates this toolkit's implementation of <code>Button</code> using
105      * the specified peer interface.
106      * @param target the button to be implemented.
107      * @return this toolkit's implementation of <code>Button</code>.
108      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
109      * returns true
110      * @see java.awt.GraphicsEnvironment#isHeadless
111      * @see java.awt.Button
112      * @see java.awt.peer.ButtonPeer
113      */

114     protected abstract ButtonPeer createButton(Button JavaDoc target)
115         throws HeadlessException JavaDoc;
116
117     /**
118      * Creates this toolkit's implementation of <code>TextField</code> using
119      * the specified peer interface.
120      * @param target the text field to be implemented.
121      * @return this toolkit's implementation of <code>TextField</code>.
122      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
123      * returns true
124      * @see java.awt.GraphicsEnvironment#isHeadless
125      * @see java.awt.TextField
126      * @see java.awt.peer.TextFieldPeer
127      */

128     protected abstract TextFieldPeer createTextField(TextField JavaDoc target)
129         throws HeadlessException JavaDoc;
130
131     /**
132      * Creates this toolkit's implementation of <code>Label</code> using
133      * the specified peer interface.
134      * @param target the label to be implemented.
135      * @return this toolkit's implementation of <code>Label</code>.
136      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
137      * returns true
138      * @see java.awt.GraphicsEnvironment#isHeadless
139      * @see java.awt.Label
140      * @see java.awt.peer.LabelPeer
141      */

142     protected abstract LabelPeer createLabel(Label JavaDoc target)
143         throws HeadlessException JavaDoc;
144
145     /**
146      * Creates this toolkit's implementation of <code>List</code> using
147      * the specified peer interface.
148      * @param target the list to be implemented.
149      * @return this toolkit's implementation of <code>List</code>.
150      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
151      * returns true
152      * @see java.awt.GraphicsEnvironment#isHeadless
153      * @see java.awt.List
154      * @see java.awt.peer.ListPeer
155      */

156     protected abstract ListPeer createList(java.awt.List JavaDoc target)
157         throws HeadlessException JavaDoc;
158
159     /**
160      * Creates this toolkit's implementation of <code>Checkbox</code> using
161      * the specified peer interface.
162      * @param target the check box to be implemented.
163      * @return this toolkit's implementation of <code>Checkbox</code>.
164      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
165      * returns true
166      * @see java.awt.GraphicsEnvironment#isHeadless
167      * @see java.awt.Checkbox
168      * @see java.awt.peer.CheckboxPeer
169      */

170     protected abstract CheckboxPeer createCheckbox(Checkbox JavaDoc target)
171         throws HeadlessException JavaDoc;
172
173     /**
174      * Creates this toolkit's implementation of <code>Scrollbar</code> using
175      * the specified peer interface.
176      * @param target the scroll bar to be implemented.
177      * @return this toolkit's implementation of <code>Scrollbar</code>.
178      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
179      * returns true
180      * @see java.awt.GraphicsEnvironment#isHeadless
181      * @see java.awt.Scrollbar
182      * @see java.awt.peer.ScrollbarPeer
183      */

184     protected abstract ScrollbarPeer createScrollbar(Scrollbar JavaDoc target)
185         throws HeadlessException JavaDoc;
186
187     /**
188      * Creates this toolkit's implementation of <code>ScrollPane</code> using
189      * the specified peer interface.
190      * @param target the scroll pane to be implemented.
191      * @return this toolkit's implementation of <code>ScrollPane</code>.
192      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
193      * returns true
194      * @see java.awt.GraphicsEnvironment#isHeadless
195      * @see java.awt.ScrollPane
196      * @see java.awt.peer.ScrollPanePeer
197      * @since JDK1.1
198      */

199     protected abstract ScrollPanePeer createScrollPane(ScrollPane JavaDoc target)
200         throws HeadlessException JavaDoc;
201
202     /**
203      * Creates this toolkit's implementation of <code>TextArea</code> using
204      * the specified peer interface.
205      * @param target the text area to be implemented.
206      * @return this toolkit's implementation of <code>TextArea</code>.
207      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
208      * returns true
209      * @see java.awt.GraphicsEnvironment#isHeadless
210      * @see java.awt.TextArea
211      * @see java.awt.peer.TextAreaPeer
212      */

213     protected abstract TextAreaPeer createTextArea(TextArea JavaDoc target)
214         throws HeadlessException JavaDoc;
215
216     /**
217      * Creates this toolkit's implementation of <code>Choice</code> using
218      * the specified peer interface.
219      * @param target the choice to be implemented.
220      * @return this toolkit's implementation of <code>Choice</code>.
221      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
222      * returns true
223      * @see java.awt.GraphicsEnvironment#isHeadless
224      * @see java.awt.Choice
225      * @see java.awt.peer.ChoicePeer
226      */

227     protected abstract ChoicePeer createChoice(Choice JavaDoc target)
228         throws HeadlessException JavaDoc;
229
230     /**
231      * Creates this toolkit's implementation of <code>Frame</code> using
232      * the specified peer interface.
233      * @param target the frame to be implemented.
234      * @return this toolkit's implementation of <code>Frame</code>.
235      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
236      * returns true
237      * @see java.awt.GraphicsEnvironment#isHeadless
238      * @see java.awt.Frame
239      * @see java.awt.peer.FramePeer
240      */

241     protected abstract FramePeer createFrame(Frame JavaDoc target)
242         throws HeadlessException JavaDoc;
243
244     /**
245      * Creates this toolkit's implementation of <code>Canvas</code> using
246      * the specified peer interface.
247      * @param target the canvas to be implemented.
248      * @return this toolkit's implementation of <code>Canvas</code>.
249      * @see java.awt.Canvas
250      * @see java.awt.peer.CanvasPeer
251      */

252     protected abstract CanvasPeer createCanvas(Canvas JavaDoc target);
253
254     /**
255      * Creates this toolkit's implementation of <code>Panel</code> using
256      * the specified peer interface.
257      * @param target the panel to be implemented.
258      * @return this toolkit's implementation of <code>Panel</code>.
259      * @see java.awt.Panel
260      * @see java.awt.peer.PanelPeer
261      */

262     protected abstract PanelPeer createPanel(Panel JavaDoc target);
263
264     /**
265      * Creates this toolkit's implementation of <code>Window</code> using
266      * the specified peer interface.
267      * @param target the window to be implemented.
268      * @return this toolkit's implementation of <code>Window</code>.
269      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
270      * returns true
271      * @see java.awt.GraphicsEnvironment#isHeadless
272      * @see java.awt.Window
273      * @see java.awt.peer.WindowPeer
274      */

275     protected abstract WindowPeer createWindow(Window JavaDoc target)
276         throws HeadlessException JavaDoc;
277
278     /**
279      * Creates this toolkit's implementation of <code>Dialog</code> using
280      * the specified peer interface.
281      * @param target the dialog to be implemented.
282      * @return this toolkit's implementation of <code>Dialog</code>.
283      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
284      * returns true
285      * @see java.awt.GraphicsEnvironment#isHeadless
286      * @see java.awt.Dialog
287      * @see java.awt.peer.DialogPeer
288      */

289     protected abstract DialogPeer createDialog(Dialog JavaDoc target)
290         throws HeadlessException JavaDoc;
291
292     /**
293      * Creates this toolkit's implementation of <code>MenuBar</code> using
294      * the specified peer interface.
295      * @param target the menu bar to be implemented.
296      * @return this toolkit's implementation of <code>MenuBar</code>.
297      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
298      * returns true
299      * @see java.awt.GraphicsEnvironment#isHeadless
300      * @see java.awt.MenuBar
301      * @see java.awt.peer.MenuBarPeer
302      */

303     protected abstract MenuBarPeer createMenuBar(MenuBar JavaDoc target)
304         throws HeadlessException JavaDoc;
305
306     /**
307      * Creates this toolkit's implementation of <code>Menu</code> using
308      * the specified peer interface.
309      * @param target the menu to be implemented.
310      * @return this toolkit's implementation of <code>Menu</code>.
311      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
312      * returns true
313      * @see java.awt.GraphicsEnvironment#isHeadless
314      * @see java.awt.Menu
315      * @see java.awt.peer.MenuPeer
316      */

317     protected abstract MenuPeer createMenu(Menu JavaDoc target)
318         throws HeadlessException JavaDoc;
319
320     /**
321      * Creates this toolkit's implementation of <code>PopupMenu</code> using
322      * the specified peer interface.
323      * @param target the popup menu to be implemented.
324      * @return this toolkit's implementation of <code>PopupMenu</code>.
325      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
326      * returns true
327      * @see java.awt.GraphicsEnvironment#isHeadless
328      * @see java.awt.PopupMenu
329      * @see java.awt.peer.PopupMenuPeer
330      * @since JDK1.1
331      */

332     protected abstract PopupMenuPeer createPopupMenu(PopupMenu JavaDoc target)
333         throws HeadlessException JavaDoc;
334
335     /**
336      * Creates this toolkit's implementation of <code>MenuItem</code> using
337      * the specified peer interface.
338      * @param target the menu item to be implemented.
339      * @return this toolkit's implementation of <code>MenuItem</code>.
340      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
341      * returns true
342      * @see java.awt.GraphicsEnvironment#isHeadless
343      * @see java.awt.MenuItem
344      * @see java.awt.peer.MenuItemPeer
345      */

346     protected abstract MenuItemPeer createMenuItem(MenuItem JavaDoc target)
347         throws HeadlessException JavaDoc;
348
349     /**
350      * Creates this toolkit's implementation of <code>FileDialog</code> using
351      * the specified peer interface.
352      * @param target the file dialog to be implemented.
353      * @return this toolkit's implementation of <code>FileDialog</code>.
354      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
355      * returns true
356      * @see java.awt.GraphicsEnvironment#isHeadless
357      * @see java.awt.FileDialog
358      * @see java.awt.peer.FileDialogPeer
359      */

360     protected abstract FileDialogPeer createFileDialog(FileDialog JavaDoc target)
361         throws HeadlessException JavaDoc;
362
363     /**
364      * Creates this toolkit's implementation of <code>CheckboxMenuItem</code> using
365      * the specified peer interface.
366      * @param target the checkbox menu item to be implemented.
367      * @return this toolkit's implementation of <code>CheckboxMenuItem</code>.
368      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
369      * returns true
370      * @see java.awt.GraphicsEnvironment#isHeadless
371      * @see java.awt.CheckboxMenuItem
372      * @see java.awt.peer.CheckboxMenuItemPeer
373      */

374     protected abstract CheckboxMenuItemPeer createCheckboxMenuItem(
375         CheckboxMenuItem JavaDoc target) throws HeadlessException JavaDoc;
376
377     /**
378      * Obtains this toolkit's implementation of helper class for
379      * <code>MouseInfo</code> operations.
380      * @return this toolkit's implementation of helper for <code>MouseInfo</code>
381      * @throws UnsupportedOperationException if this operation is not implemented
382      * @see java.awt.peer.MouseInfoPeer
383      * @see java.awt.MouseInfo
384      */

385     protected MouseInfoPeer getMouseInfoPeer() {
386         throw new UnsupportedOperationException JavaDoc("Not implemented");
387     }
388
389     private static LightweightPeer lightweightMarker;
390
391     /**
392      * Creates a peer for a component or container. This peer is windowless
393      * and allows the Component and Container classes to be extended directly
394      * to create windowless components that are defined entirely in java.
395      *
396      * @param target The Component to be created.
397      */

398     protected LightweightPeer createComponent(Component JavaDoc target) {
399         if (lightweightMarker == null) {
400             lightweightMarker = new NullComponentPeer();
401         }
402         return lightweightMarker;
403     }
404
405     /**
406      * Creates this toolkit's implementation of <code>Font</code> using
407      * the specified peer interface.
408      * @param name the font to be implemented
409      * @param style the style of the font, such as <code>PLAIN</code>,
410      * <code>BOLD</code>, <code>ITALIC</code>, or a combination
411      * @return this toolkit's implementation of <code>Font</code>
412      * @see java.awt.Font
413      * @see java.awt.peer.FontPeer
414      * @see java.awt.GraphicsEnvironment#getAllFonts
415      * @deprecated see java.awt.GraphicsEnvironment#getAllFonts
416      */

417     @Deprecated JavaDoc
418     protected abstract FontPeer getFontPeer(String JavaDoc name, int style);
419
420     // The following method is called by the private method
421
// <code>updateSystemColors</code> in <code>SystemColor</code>.
422

423     /**
424      * Fills in the integer array that is supplied as an argument
425      * with the current system color values.
426      *
427      * @param systemColors an integer array.
428      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
429      * returns true
430      * @see java.awt.GraphicsEnvironment#isHeadless
431      * @since JDK1.1
432      */

433     protected void loadSystemColors(int[] systemColors)
434         throws HeadlessException JavaDoc {
435     }
436
437     /**
438      * Controls whether the layout of Containers is validated dynamically
439      * during resizing, or statically, after resizing is complete.
440      * Note that this feature is not supported on all platforms, and
441      * conversely, that this feature cannot be turned off on some platforms.
442      * On platforms where dynamic layout during resize is not supported
443      * (or is always supported), setting this property has no effect.
444      * Note that this feature can be set or unset as a property of the
445      * operating system or window manager on some platforms. On such
446      * platforms, the dynamic resize property must be set at the operating
447      * system or window manager level before this method can take effect.
448      * This method does not change the underlying operating system or
449      * window manager support or settings. The OS/WM support can be
450      * queried using getDesktopProperty("awt.dynamicLayoutSupported").
451      *
452      * @param dynamic If true, Containers should re-layout their
453      * components as the Container is being resized. If false,
454      * the layout will be validated after resizing is finished.
455      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
456      * returns true
457      * @see #isDynamicLayoutSet()
458      * @see #isDynamicLayoutActive()
459      * @see #getDesktopProperty(String propertyName)
460      * @see java.awt.GraphicsEnvironment#isHeadless
461      * @since 1.4
462      */

463     public void setDynamicLayout(boolean dynamic)
464         throws HeadlessException JavaDoc {
465     }
466
467     /**
468      * Returns whether the layout of Containers is validated dynamically
469      * during resizing, or statically, after resizing is complete.
470      * Note: this method returns the value that was set programmatically;
471      * it does not reflect support at the level of the operating system
472      * or window manager for dynamic layout on resizing, or the current
473      * operating system or window manager settings. The OS/WM support can
474      * be queried using getDesktopProperty("awt.dynamicLayoutSupported").
475      *
476      * @return true if validation of Containers is done dynamically,
477      * false if validation is done after resizing is finished.
478      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
479      * returns true
480      * @see #setDynamicLayout(boolean dynamic)
481      * @see #isDynamicLayoutActive()
482      * @see #getDesktopProperty(String propertyName)
483      * @see java.awt.GraphicsEnvironment#isHeadless
484      * @since 1.4
485      */

486     protected boolean isDynamicLayoutSet()
487         throws HeadlessException JavaDoc {
488         if (this != Toolkit.getDefaultToolkit()) {
489             return Toolkit.getDefaultToolkit().isDynamicLayoutSet();
490         } else {
491             return false;
492         }
493     }
494
495     /**
496      * Returns whether dynamic layout of Containers on resize is
497      * currently active (both set programmatically, and supported
498      * by the underlying operating system and/or window manager).
499      * The OS/WM support can be queried using
500      * getDesktopProperty("awt.dynamicLayoutSupported").
501      *
502      * @return true if dynamic layout of Containers on resize is
503      * currently active, false otherwise.
504      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
505      * returns true
506      * @see #setDynamicLayout(boolean dynamic)
507      * @see #isDynamicLayoutSet()
508      * @see #getDesktopProperty(String propertyName)
509      * @see java.awt.GraphicsEnvironment#isHeadless
510      * @since 1.4
511      */

512     public boolean isDynamicLayoutActive()
513         throws HeadlessException JavaDoc {
514         if (this != Toolkit.getDefaultToolkit()) {
515             return Toolkit.getDefaultToolkit().isDynamicLayoutActive();
516         } else {
517             return false;
518         }
519     }
520
521     /**
522      * Gets the size of the screen. On systems with multiple displays, the
523      * primary display is used. Multi-screen aware display dimensions are
524      * available from <code>GraphicsConfiguration</code> and
525      * <code>GraphicsDevice</code>.
526      * @return the size of this toolkit's screen, in pixels.
527      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
528      * returns true
529      * @see java.awt.GraphicsConfiguration#getBounds
530      * @see java.awt.GraphicsDevice#getDisplayMode
531      * @see java.awt.GraphicsEnvironment#isHeadless
532      */

533     public abstract Dimension JavaDoc getScreenSize()
534         throws HeadlessException JavaDoc;
535
536     /**
537      * Returns the screen resolution in dots-per-inch.
538      * @return this toolkit's screen resolution, in dots-per-inch.
539      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
540      * returns true
541      * @see java.awt.GraphicsEnvironment#isHeadless
542      */

543     public abstract int getScreenResolution()
544         throws HeadlessException JavaDoc;
545
546     /**
547      * Gets the insets of the screen.
548      * @param gc a <code>GraphicsConfiguration</code>
549      * @return the insets of this toolkit's screen, in pixels.
550      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
551      * returns true
552      * @see java.awt.GraphicsEnvironment#isHeadless
553      * @since 1.4
554      */

555     public Insets JavaDoc getScreenInsets(GraphicsConfiguration JavaDoc gc)
556         throws HeadlessException JavaDoc {
557         if (this != Toolkit.getDefaultToolkit()) {
558             return Toolkit.getDefaultToolkit().getScreenInsets(gc);
559         } else {
560             return new Insets JavaDoc(0, 0, 0, 0);
561         }
562     }
563     
564     /**
565      * Determines the color model of this toolkit's screen.
566      * <p>
567      * <code>ColorModel</code> is an abstract class that
568      * encapsulates the ability to translate between the
569      * pixel values of an image and its red, green, blue,
570      * and alpha components.
571      * <p>
572      * This toolkit method is called by the
573      * <code>getColorModel</code> method
574      * of the <code>Component</code> class.
575      * @return the color model of this toolkit's screen.
576      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
577      * returns true
578      * @see java.awt.GraphicsEnvironment#isHeadless
579      * @see java.awt.image.ColorModel
580      * @see java.awt.Component#getColorModel
581      */

582     public abstract ColorModel JavaDoc getColorModel()
583         throws HeadlessException JavaDoc;
584
585     /**
586      * Returns the names of the available fonts in this toolkit.<p>
587      * For 1.1, the following font names are deprecated (the replacement
588      * name follows):
589      * <ul>
590      * <li>TimesRoman (use Serif)
591      * <li>Helvetica (use SansSerif)
592      * <li>Courier (use Monospaced)
593      * </ul><p>
594      * The ZapfDingbats fontname is also deprecated in 1.1 but the characters
595      * are defined in Unicode starting at 0x2700, and as of 1.1 Java supports
596      * those characters.
597      * @return the names of the available fonts in this toolkit.
598      * @deprecated see {@link java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()}
599      * @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()
600      */

601     @Deprecated JavaDoc
602     public abstract String JavaDoc[] getFontList();
603
604     /**
605      * Gets the screen device metrics for rendering of the font.
606      * @param font a font
607      * @return the screen metrics of the specified font in this toolkit
608      * @deprecated As of JDK version 1.2, replaced by the <code>Font</code>
609      * method <code>getLineMetrics</code>.
610      * @see java.awt.font.LineMetrics
611      * @see java.awt.Font#getLineMetrics
612      * @see java.awt.GraphicsEnvironment#getScreenDevices
613      */

614     @Deprecated JavaDoc
615     public abstract FontMetrics JavaDoc getFontMetrics(Font JavaDoc font);
616
617     /**
618      * Synchronizes this toolkit's graphics state. Some window systems
619      * may do buffering of graphics events.
620      * <p>
621      * This method ensures that the display is up-to-date. It is useful
622      * for animation.
623      */

624     public abstract void sync();
625
626     /**
627      * The default toolkit.
628      */

629     private static Toolkit JavaDoc toolkit;
630
631     /**
632      * Used internally by the assistive technologies functions; set at
633      * init time and used at load time
634      */

635     private static String JavaDoc atNames;
636
637     /**
638      * Initializes properties related to assistive technologies.
639      * These properties are used both in the loadAssistiveProperties()
640      * function below, as well as other classes in the jdk that depend
641      * on the properties (such as the use of the screen_magnifier_present
642      * property in Java2D hardware acceleration initialization). The
643      * initialization of the properties must be done before the platform-
644      * specific Toolkit class is instantiated so that all necessary
645      * properties are set up properly before any classes dependent upon them
646      * are initialized.
647      */

648     private static void initAssistiveTechnologies() {
649
650     // Get accessibility properties
651
final String JavaDoc sep = File.separator;
652         final Properties JavaDoc properties = new Properties JavaDoc();
653
654
655     atNames = (String JavaDoc)java.security.AccessController.doPrivileged(
656         new java.security.PrivilegedAction JavaDoc() {
657         public Object JavaDoc run() {
658
659         // Try loading the per-user accessibility properties file.
660
try {
661             File JavaDoc propsFile = new File JavaDoc(
662               System.getProperty("user.home") +
663               sep + ".accessibility.properties");
664             FileInputStream JavaDoc in =
665             new FileInputStream JavaDoc(propsFile);
666
667                     // Inputstream has been buffered in Properties class
668
properties.load(in);
669             in.close();
670         } catch (Exception JavaDoc e) {
671             // Per-user accessibility properties file does not exist
672
}
673
674         // Try loading the system-wide accessibility properties
675
// file only if a per-user accessibility properties
676
// file does not exist or is empty.
677
if (properties.size() == 0) {
678             try {
679             File JavaDoc propsFile = new File JavaDoc(
680                 System.getProperty("java.home") + sep + "lib" +
681                 sep + "accessibility.properties");
682             FileInputStream JavaDoc in =
683                 new FileInputStream JavaDoc(propsFile);
684             
685             // Inputstream has been buffered in Properties class
686
properties.load(in);
687             in.close();
688             } catch (Exception JavaDoc e) {
689             // System-wide accessibility properties file does
690
// not exist;
691
}
692         }
693         
694         // Get whether a screen magnifier is present. First check
695
// the system property and then check the properties file.
696
String JavaDoc magPresent = System.getProperty("javax.accessibility.screen_magnifier_present");
697         if (magPresent == null) {
698             magPresent = properties.getProperty("screen_magnifier_present", null);
699             if (magPresent != null) {
700             System.setProperty("javax.accessibility.screen_magnifier_present", magPresent);
701             }
702         }
703
704         // Get the names of any assistive technolgies to load. First
705
// check the system property and then check the properties
706
// file.
707
String JavaDoc classNames = System.getProperty("javax.accessibility.assistive_technologies");
708         if (classNames == null) {
709             classNames = properties.getProperty("assistive_technologies", null);
710             if (classNames != null) {
711             System.setProperty("javax.accessibility.assistive_technologies", classNames);
712             }
713         }
714         return classNames;
715         }
716     });
717     }
718
719     /**
720      * Loads additional classes into the VM, using the property
721      * 'assistive_technologies' specified in the Sun reference
722      * implementation by a line in the 'accessibility.properties'
723      * file. The form is "assistive_technologies=..." where
724      * the "..." is a comma-separated list of assistive technology
725      * classes to load. Each class is loaded in the order given
726      * and a single instance of each is created using
727      * Class.forName(class).newInstance(). All errors are handled
728      * via an AWTError exception.
729      *
730      * <p>The assumption is made that assistive technology classes are supplied
731      * as part of INSTALLED (as opposed to: BUNDLED) extensions or specified
732      * on the class path
733      * (and therefore can be loaded using the class loader returned by
734      * a call to <code>ClassLoader.getSystemClassLoader</code>, whose
735      * delegation parent is the extension class loader for installed
736      * extensions).
737      */

738     private static void loadAssistiveTechnologies() {
739     // Load any assistive technologies
740
if (atNames != null) {
741         ClassLoader JavaDoc cl = ClassLoader.getSystemClassLoader();
742             StringTokenizer JavaDoc parser = new StringTokenizer JavaDoc(atNames," ,");
743         String JavaDoc atName;
744             while (parser.hasMoreTokens()) {
745         atName = parser.nextToken();
746                 try {
747             Class JavaDoc clazz;
748             if (cl != null) {
749             clazz = cl.loadClass(atName);
750             } else {
751             clazz = Class.forName(atName);
752             }
753             clazz.newInstance();
754                 } catch (ClassNotFoundException JavaDoc e) {
755                     throw new AWTError JavaDoc("Assistive Technology not found: "
756                 + atName);
757                 } catch (InstantiationException JavaDoc e) {
758                     throw new AWTError JavaDoc("Could not instantiate Assistive"
759                 + " Technology: " + atName);
760                 } catch (IllegalAccessException JavaDoc e) {
761                     throw new AWTError JavaDoc("Could not access Assistive"
762                 + " Technology: " + atName);
763                 } catch (Exception JavaDoc e) {
764                     throw new AWTError JavaDoc("Error trying to install Assistive"
765                 + " Technology: " + atName + " " + e);
766                 }
767             }
768         }
769     }
770
771     /**
772      * Gets the default toolkit.
773      * <p>
774      * If there is a system property named <code>"awt.toolkit"</code>,
775      * that property is treated as the name of a class that is a subclass
776      * of <code>Toolkit</code>.
777      * <p>
778      * If the system property does not exist, then the default toolkit
779      * used is the class named <code>"sun.awt.motif.MToolkit"</code>,
780      * which is a motif implementation of the Abstract Window Toolkit.
781      * <p>
782      * Also loads additional classes into the VM, using the property
783      * 'assistive_technologies' specified in the Sun reference
784      * implementation by a line in the 'accessibility.properties'
785      * file. The form is "assistive_technologies=..." where
786      * the "..." is a comma-separated list of assistive technology
787      * classes to load. Each class is loaded in the order given
788      * and a single instance of each is created using
789      * Class.forName(class).newInstance(). This is done just after
790      * the AWT toolkit is created. All errors are handled via an
791      * AWTError exception.
792      * @return the default toolkit.
793      * @exception AWTError if a toolkit could not be found, or
794      * if one could not be accessed or instantiated.
795      */

796     public static synchronized Toolkit JavaDoc getDefaultToolkit() {
797     if (toolkit == null) {
798         try {
799         // We disable the JIT during toolkit initialization. This
800
// tends to touch lots of classes that aren't needed again
801
// later and therefore JITing is counter-productiive.
802
java.lang.Compiler.disable();
803         
804             java.security.AccessController.doPrivileged(
805             new java.security.PrivilegedAction JavaDoc() {
806             public Object JavaDoc run() {
807                 String JavaDoc nm = null;
808             Class JavaDoc cls = null;
809                 try {
810                             String JavaDoc defaultToolkit;
811
812                             if (System.getProperty("os.name").equals("Linux")) {
813                                 defaultToolkit = "sun.awt.X11.XToolkit";
814                             }
815                             else {
816                                 defaultToolkit = "sun.awt.motif.MToolkit";
817                             }
818                 nm = System.getProperty("awt.toolkit",
819                         defaultToolkit);
820                 try {
821                     cls = Class.forName(nm);
822                     } catch (ClassNotFoundException JavaDoc e) {
823                     ClassLoader JavaDoc cl = ClassLoader.getSystemClassLoader();
824                                 if (cl != null) {
825                         try {
826                                         cls = cl.loadClass(nm);
827                             } catch (ClassNotFoundException JavaDoc ee) {
828                         throw new AWTError JavaDoc("Toolkit not found: " + nm);
829                     }
830                                 }
831                         }
832                             if (cls != null) {
833                 toolkit = (Toolkit JavaDoc)cls.newInstance();
834                                 if (GraphicsEnvironment.isHeadless()) {
835                                     toolkit = new HeadlessToolkit(toolkit);
836                                 }
837                 }
838                 } catch (InstantiationException JavaDoc e) {
839                 throw new AWTError JavaDoc("Could not instantiate Toolkit: " +
840                        nm);
841                 } catch (IllegalAccessException JavaDoc e) {
842                 throw new AWTError JavaDoc("Could not access Toolkit: " + nm);
843