2608 lines · 112.4 KB · Java
RawDownload
/* * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.  Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package java.awt; import java.beans.PropertyChangeEvent;import java.util.MissingResourceException;import java.util.Properties;import java.util.ResourceBundle;import java.util.StringTokenizer;import java.awt.event.*;import java.awt.peer.*;import java.awt.im.InputMethodHighlight;import java.awt.image.ImageObserver;import java.awt.image.ImageProducer;import java.awt.image.ColorModel;import java.awt.datatransfer.Clipboard;import java.awt.dnd.DragSource;import java.awt.dnd.DragGestureRecognizer;import java.awt.dnd.DragGestureEvent;import java.awt.dnd.DragGestureListener;import java.awt.dnd.InvalidDnDOperationException;import java.awt.dnd.peer.DragSourceContextPeer;import java.net.URL;import java.io.File;import java.io.FileInputStream; import java.util.*;import sun.util.logging.PlatformLogger; import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import sun.awt.AppContext; import sun.awt.HeadlessToolkit;import sun.awt.NullComponentPeer;import sun.awt.PeerEvent;import sun.awt.SunToolkit;import sun.security.util.SecurityConstants; import sun.util.CoreResourceBundleControl; /** * This class is the abstract superclass of all actual * implementations of the Abstract Window Toolkit. Subclasses of * the <code>Toolkit</code> class are used to bind the various components * to particular native toolkit implementations. * <p> * Many GUI events may be delivered to user * asynchronously, if the opposite is not specified explicitly. * As well as * many GUI operations may be performed asynchronously. * This fact means that if the state of a component is set, and then * the state immediately queried, the returned value may not yet * reflect the requested change.  This behavior includes, but is not * limited to: * <ul> * <li>Scrolling to a specified position. * <br>For example, calling <code>ScrollPane.setScrollPosition</code> *     and then <code>getScrollPosition</code> may return an incorrect *     value if the original request has not yet been processed. * <p> * <li>Moving the focus from one component to another. * <br>For more information, see * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#transferTiming">Timing * Focus Transfers</a>, a section in * <a href="http://java.sun.com/docs/books/tutorial/uiswing/">The Swing * Tutorial</a>. * <p> * <li>Making a top-level container visible. * <br>Calling <code>setVisible(true)</code> on a <code>Window</code>, *     <code>Frame</code> or <code>Dialog</code> may occur *     asynchronously. * <p> * <li>Setting the size or location of a top-level container. * <br>Calls to <code>setSize</code>, <code>setBounds</code> or *     <code>setLocation</code> on a <code>Window</code>, *     <code>Frame</code> or <code>Dialog</code> are forwarded *     to the underlying window management system and may be *     ignored or modified.  See {@link java.awt.Window} for *     more information. * </ul> * <p> * Most applications should not call any of the methods in this * class directly. The methods defined by <code>Toolkit</code> are * the "glue" that joins the platform-independent classes in the * <code>java.awt</code> package with their counterparts in * <code>java.awt.peer</code>. Some methods defined by * <code>Toolkit</code> query the native operating system directly. * * @author      Sami Shaio * @author      Arthur van Hoff * @author      Fred Ecks * @since       JDK1.0 */public abstract class Toolkit {     /**     * Creates this toolkit's implementation of the <code>Desktop</code>     * using the specified peer interface.     * @param     target the desktop to be implemented     * @return    this toolkit's implementation of the <code>Desktop</code>     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Desktop     * @see       java.awt.peer.DesktopPeer     * @since 1.6     */    protected abstract DesktopPeer createDesktopPeer(Desktop target)      throws HeadlessException;      /**     * Creates this toolkit's implementation of <code>Button</code> using     * the specified peer interface.     * @param     target the button to be implemented.     * @return    this toolkit's implementation of <code>Button</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Button     * @see       java.awt.peer.ButtonPeer     */    protected abstract ButtonPeer createButton(Button target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>TextField</code> using     * the specified peer interface.     * @param     target the text field to be implemented.     * @return    this toolkit's implementation of <code>TextField</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.TextField     * @see       java.awt.peer.TextFieldPeer     */    protected abstract TextFieldPeer createTextField(TextField target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>Label</code> using     * the specified peer interface.     * @param     target the label to be implemented.     * @return    this toolkit's implementation of <code>Label</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Label     * @see       java.awt.peer.LabelPeer     */    protected abstract LabelPeer createLabel(Label target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>List</code> using     * the specified peer interface.     * @param     target the list to be implemented.     * @return    this toolkit's implementation of <code>List</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.List     * @see       java.awt.peer.ListPeer     */    protected abstract ListPeer createList(java.awt.List target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>Checkbox</code> using     * the specified peer interface.     * @param     target the check box to be implemented.     * @return    this toolkit's implementation of <code>Checkbox</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Checkbox     * @see       java.awt.peer.CheckboxPeer     */    protected abstract CheckboxPeer createCheckbox(Checkbox target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>Scrollbar</code> using     * the specified peer interface.     * @param     target the scroll bar to be implemented.     * @return    this toolkit's implementation of <code>Scrollbar</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Scrollbar     * @see       java.awt.peer.ScrollbarPeer     */    protected abstract ScrollbarPeer createScrollbar(Scrollbar target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>ScrollPane</code> using     * the specified peer interface.     * @param     target the scroll pane to be implemented.     * @return    this toolkit's implementation of <code>ScrollPane</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.ScrollPane     * @see       java.awt.peer.ScrollPanePeer     * @since     JDK1.1     */    protected abstract ScrollPanePeer createScrollPane(ScrollPane target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>TextArea</code> using     * the specified peer interface.     * @param     target the text area to be implemented.     * @return    this toolkit's implementation of <code>TextArea</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.TextArea     * @see       java.awt.peer.TextAreaPeer     */    protected abstract TextAreaPeer createTextArea(TextArea target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>Choice</code> using     * the specified peer interface.     * @param     target the choice to be implemented.     * @return    this toolkit's implementation of <code>Choice</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Choice     * @see       java.awt.peer.ChoicePeer     */    protected abstract ChoicePeer createChoice(Choice target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>Frame</code> using     * the specified peer interface.     * @param     target the frame to be implemented.     * @return    this toolkit's implementation of <code>Frame</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Frame     * @see       java.awt.peer.FramePeer     */    protected abstract FramePeer createFrame(Frame target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>Canvas</code> using     * the specified peer interface.     * @param     target the canvas to be implemented.     * @return    this toolkit's implementation of <code>Canvas</code>.     * @see       java.awt.Canvas     * @see       java.awt.peer.CanvasPeer     */    protected abstract CanvasPeer       createCanvas(Canvas target);     /**     * Creates this toolkit's implementation of <code>Panel</code> using     * the specified peer interface.     * @param     target the panel to be implemented.     * @return    this toolkit's implementation of <code>Panel</code>.     * @see       java.awt.Panel     * @see       java.awt.peer.PanelPeer     */    protected abstract PanelPeer        createPanel(Panel target);     /**     * Creates this toolkit's implementation of <code>Window</code> using     * the specified peer interface.     * @param     target the window to be implemented.     * @return    this toolkit's implementation of <code>Window</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Window     * @see       java.awt.peer.WindowPeer     */    protected abstract WindowPeer createWindow(Window target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>Dialog</code> using     * the specified peer interface.     * @param     target the dialog to be implemented.     * @return    this toolkit's implementation of <code>Dialog</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Dialog     * @see       java.awt.peer.DialogPeer     */    protected abstract DialogPeer createDialog(Dialog target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>MenuBar</code> using     * the specified peer interface.     * @param     target the menu bar to be implemented.     * @return    this toolkit's implementation of <code>MenuBar</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.MenuBar     * @see       java.awt.peer.MenuBarPeer     */    protected abstract MenuBarPeer createMenuBar(MenuBar target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>Menu</code> using     * the specified peer interface.     * @param     target the menu to be implemented.     * @return    this toolkit's implementation of <code>Menu</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.Menu     * @see       java.awt.peer.MenuPeer     */    protected abstract MenuPeer createMenu(Menu target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>PopupMenu</code> using     * the specified peer interface.     * @param     target the popup menu to be implemented.     * @return    this toolkit's implementation of <code>PopupMenu</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.PopupMenu     * @see       java.awt.peer.PopupMenuPeer     * @since     JDK1.1     */    protected abstract PopupMenuPeer createPopupMenu(PopupMenu target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>MenuItem</code> using     * the specified peer interface.     * @param     target the menu item to be implemented.     * @return    this toolkit's implementation of <code>MenuItem</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.MenuItem     * @see       java.awt.peer.MenuItemPeer     */    protected abstract MenuItemPeer createMenuItem(MenuItem target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>FileDialog</code> using     * the specified peer interface.     * @param     target the file dialog to be implemented.     * @return    this toolkit's implementation of <code>FileDialog</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.FileDialog     * @see       java.awt.peer.FileDialogPeer     */    protected abstract FileDialogPeer createFileDialog(FileDialog target)        throws HeadlessException;     /**     * Creates this toolkit's implementation of <code>CheckboxMenuItem</code> using     * the specified peer interface.     * @param     target the checkbox menu item to be implemented.     * @return    this toolkit's implementation of <code>CheckboxMenuItem</code>.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @see       java.awt.CheckboxMenuItem     * @see       java.awt.peer.CheckboxMenuItemPeer     */    protected abstract CheckboxMenuItemPeer createCheckboxMenuItem(        CheckboxMenuItem target) throws HeadlessException;     /**     * Obtains this toolkit's implementation of helper class for     * <code>MouseInfo</code> operations.     * @return    this toolkit's implementation of  helper for <code>MouseInfo</code>     * @throws    UnsupportedOperationException if this operation is not implemented     * @see       java.awt.peer.MouseInfoPeer     * @see       java.awt.MouseInfo     * @since 1.5     */    protected MouseInfoPeer getMouseInfoPeer() {        throw new UnsupportedOperationException("Not implemented");    }     private static LightweightPeer lightweightMarker;     /**     * Creates a peer for a component or container.  This peer is windowless     * and allows the Component and Container classes to be extended directly     * to create windowless components that are defined entirely in java.     *     * @param target The Component to be created.     */    protected LightweightPeer createComponent(Component target) {        if (lightweightMarker == null) {            lightweightMarker = new NullComponentPeer();        }        return lightweightMarker;    }     /**     * Creates this toolkit's implementation of <code>Font</code> using     * the specified peer interface.     * @param     name the font to be implemented     * @param     style the style of the font, such as <code>PLAIN</code>,     *            <code>BOLD</code>, <code>ITALIC</code>, or a combination     * @return    this toolkit's implementation of <code>Font</code>     * @see       java.awt.Font     * @see       java.awt.peer.FontPeer     * @see       java.awt.GraphicsEnvironment#getAllFonts     * @deprecated  see java.awt.GraphicsEnvironment#getAllFonts     */    @Deprecated    protected abstract FontPeer getFontPeer(String name, int style);     // The following method is called by the private method    // <code>updateSystemColors</code> in <code>SystemColor</code>.     /**     * Fills in the integer array that is supplied as an argument     * with the current system color values.     *     * @param     systemColors an integer array.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     * returns true     * @see       java.awt.GraphicsEnvironment#isHeadless     * @since     JDK1.1     */    protected void loadSystemColors(int[] systemColors)        throws HeadlessException {        GraphicsEnvironment.checkHeadless();    } /**     * Controls whether the layout of Containers is validated dynamically     * during resizing, or statically, after resizing is complete.     * Use {@code isDynamicLayoutActive()} to detect if this feature enabled     * in this program and is supported by this operating system     * and/or window manager.     * Note that this feature is supported not on all platforms, and     * conversely, that this feature cannot be turned off on some platforms.     * On these platforms where dynamic layout during resizing is not supported     * (or is always supported), setting this property has no effect.     * Note that this feature can be set or unset as a property of the     * operating system or window manager on some platforms.  On such     * platforms, the dynamic resize property must be set at the operating     * system or window manager level before this method can take effect.     * This method does not change support or settings of the underlying     * operating system or     * window manager.  The OS/WM support can be     * queried using getDesktopProperty("awt.dynamicLayoutSupported") method.     *     * @param     dynamic  If true, Containers should re-layout their     *            components as the Container is being resized.  If false,     *            the layout will be validated after resizing is completed.     * @exception HeadlessException if GraphicsEnvironment.isHeadless()     *            returns true     * @see       #isDynamicLayoutSet()     * @see       #isDynamicLayoutActive()     * @see       #getDesktopProperty(String propertyName)     * @see       java.awt.GraphicsEnvironment#isHeadless     * @since     1.4

Lines 1–500 of 2608.