Toolkit.java revision 4193
0N/A/*
3876N/A * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt;
0N/A
0N/Aimport java.beans.PropertyChangeEvent;
0N/Aimport java.util.MissingResourceException;
0N/Aimport java.util.Properties;
0N/Aimport java.util.ResourceBundle;
0N/Aimport java.util.StringTokenizer;
0N/Aimport java.awt.event.*;
0N/Aimport java.awt.peer.*;
0N/Aimport java.awt.im.InputMethodHighlight;
0N/Aimport java.awt.image.ImageObserver;
0N/Aimport java.awt.image.ImageProducer;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.datatransfer.Clipboard;
0N/Aimport java.awt.dnd.DragSource;
0N/Aimport java.awt.dnd.DragGestureRecognizer;
0N/Aimport java.awt.dnd.DragGestureEvent;
0N/Aimport java.awt.dnd.DragGestureListener;
0N/Aimport java.awt.dnd.InvalidDnDOperationException;
0N/Aimport java.awt.dnd.peer.DragSourceContextPeer;
0N/Aimport java.net.URL;
0N/Aimport java.io.File;
0N/Aimport java.io.FileInputStream;
0N/A
0N/Aimport java.util.*;
1696N/Aimport sun.util.logging.PlatformLogger;
0N/A
0N/Aimport java.beans.PropertyChangeListener;
0N/Aimport java.beans.PropertyChangeSupport;
0N/Aimport sun.awt.AppContext;
0N/A
0N/Aimport sun.awt.HeadlessToolkit;
0N/Aimport sun.awt.NullComponentPeer;
0N/Aimport sun.awt.PeerEvent;
0N/Aimport sun.awt.SunToolkit;
0N/Aimport sun.security.util.SecurityConstants;
0N/A
0N/Aimport sun.util.CoreResourceBundleControl;
0N/A
0N/A/**
0N/A * This class is the abstract superclass of all actual
0N/A * implementations of the Abstract Window Toolkit. Subclasses of
0N/A * the <code>Toolkit</code> class are used to bind the various components
0N/A * to particular native toolkit implementations.
0N/A * <p>
0N/A * Many GUI events may be delivered to user
0N/A * asynchronously, if the opposite is not specified explicitly.
0N/A * As well as
0N/A * many GUI operations may be performed asynchronously.
0N/A * This fact means that if the state of a component is set, and then
0N/A * the state immediately queried, the returned value may not yet
0N/A * reflect the requested change. This behavior includes, but is not
0N/A * limited to:
0N/A * <ul>
0N/A * <li>Scrolling to a specified position.
0N/A * <br>For example, calling <code>ScrollPane.setScrollPosition</code>
0N/A * and then <code>getScrollPosition</code> may return an incorrect
0N/A * value if the original request has not yet been processed.
0N/A * <p>
0N/A * <li>Moving the focus from one component to another.
0N/A * <br>For more information, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#transferTiming">Timing
0N/A * Focus Transfers</a>, a section in
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/">The Swing
0N/A * Tutorial</a>.
0N/A * <p>
0N/A * <li>Making a top-level container visible.
0N/A * <br>Calling <code>setVisible(true)</code> on a <code>Window</code>,
0N/A * <code>Frame</code> or <code>Dialog</code> may occur
0N/A * asynchronously.
0N/A * <p>
0N/A * <li>Setting the size or location of a top-level container.
0N/A * <br>Calls to <code>setSize</code>, <code>setBounds</code> or
0N/A * <code>setLocation</code> on a <code>Window</code>,
0N/A * <code>Frame</code> or <code>Dialog</code> are forwarded
0N/A * to the underlying window management system and may be
0N/A * ignored or modified. See {@link java.awt.Window} for
0N/A * more information.
0N/A * </ul>
0N/A * <p>
0N/A * Most applications should not call any of the methods in this
0N/A * class directly. The methods defined by <code>Toolkit</code> are
0N/A * the "glue" that joins the platform-independent classes in the
0N/A * <code>java.awt</code> package with their counterparts in
0N/A * <code>java.awt.peer</code>. Some methods defined by
0N/A * <code>Toolkit</code> query the native operating system directly.
0N/A *
0N/A * @author Sami Shaio
0N/A * @author Arthur van Hoff
0N/A * @author Fred Ecks
0N/A * @since JDK1.0
0N/A */
0N/Apublic abstract class Toolkit {
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of the <code>Desktop</code>
0N/A * using the specified peer interface.
0N/A * @param target the desktop to be implemented
0N/A * @return this toolkit's implementation of the <code>Desktop</code>
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Desktop
0N/A * @see java.awt.peer.DesktopPeer
0N/A * @since 1.6
0N/A */
0N/A protected abstract DesktopPeer createDesktopPeer(Desktop target)
0N/A throws HeadlessException;
0N/A
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Button</code> using
0N/A * the specified peer interface.
0N/A * @param target the button to be implemented.
0N/A * @return this toolkit's implementation of <code>Button</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Button
0N/A * @see java.awt.peer.ButtonPeer
0N/A */
0N/A protected abstract ButtonPeer createButton(Button target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>TextField</code> using
0N/A * the specified peer interface.
0N/A * @param target the text field to be implemented.
0N/A * @return this toolkit's implementation of <code>TextField</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.TextField
0N/A * @see java.awt.peer.TextFieldPeer
0N/A */
0N/A protected abstract TextFieldPeer createTextField(TextField target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Label</code> using
0N/A * the specified peer interface.
0N/A * @param target the label to be implemented.
0N/A * @return this toolkit's implementation of <code>Label</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Label
0N/A * @see java.awt.peer.LabelPeer
0N/A */
0N/A protected abstract LabelPeer createLabel(Label target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>List</code> using
0N/A * the specified peer interface.
0N/A * @param target the list to be implemented.
0N/A * @return this toolkit's implementation of <code>List</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.List
0N/A * @see java.awt.peer.ListPeer
0N/A */
0N/A protected abstract ListPeer createList(java.awt.List target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Checkbox</code> using
0N/A * the specified peer interface.
0N/A * @param target the check box to be implemented.
0N/A * @return this toolkit's implementation of <code>Checkbox</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Checkbox
0N/A * @see java.awt.peer.CheckboxPeer
0N/A */
0N/A protected abstract CheckboxPeer createCheckbox(Checkbox target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Scrollbar</code> using
0N/A * the specified peer interface.
0N/A * @param target the scroll bar to be implemented.
0N/A * @return this toolkit's implementation of <code>Scrollbar</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Scrollbar
0N/A * @see java.awt.peer.ScrollbarPeer
0N/A */
0N/A protected abstract ScrollbarPeer createScrollbar(Scrollbar target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>ScrollPane</code> using
0N/A * the specified peer interface.
0N/A * @param target the scroll pane to be implemented.
0N/A * @return this toolkit's implementation of <code>ScrollPane</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.ScrollPane
0N/A * @see java.awt.peer.ScrollPanePeer
0N/A * @since JDK1.1
0N/A */
0N/A protected abstract ScrollPanePeer createScrollPane(ScrollPane target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>TextArea</code> using
0N/A * the specified peer interface.
0N/A * @param target the text area to be implemented.
0N/A * @return this toolkit's implementation of <code>TextArea</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.TextArea
0N/A * @see java.awt.peer.TextAreaPeer
0N/A */
0N/A protected abstract TextAreaPeer createTextArea(TextArea target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Choice</code> using
0N/A * the specified peer interface.
0N/A * @param target the choice to be implemented.
0N/A * @return this toolkit's implementation of <code>Choice</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Choice
0N/A * @see java.awt.peer.ChoicePeer
0N/A */
0N/A protected abstract ChoicePeer createChoice(Choice target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Frame</code> using
0N/A * the specified peer interface.
0N/A * @param target the frame to be implemented.
0N/A * @return this toolkit's implementation of <code>Frame</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Frame
0N/A * @see java.awt.peer.FramePeer
0N/A */
0N/A protected abstract FramePeer createFrame(Frame target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Canvas</code> using
0N/A * the specified peer interface.
0N/A * @param target the canvas to be implemented.
0N/A * @return this toolkit's implementation of <code>Canvas</code>.
0N/A * @see java.awt.Canvas
0N/A * @see java.awt.peer.CanvasPeer
0N/A */
0N/A protected abstract CanvasPeer createCanvas(Canvas target);
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Panel</code> using
0N/A * the specified peer interface.
0N/A * @param target the panel to be implemented.
0N/A * @return this toolkit's implementation of <code>Panel</code>.
0N/A * @see java.awt.Panel
0N/A * @see java.awt.peer.PanelPeer
0N/A */
0N/A protected abstract PanelPeer createPanel(Panel target);
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Window</code> using
0N/A * the specified peer interface.
0N/A * @param target the window to be implemented.
0N/A * @return this toolkit's implementation of <code>Window</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Window
0N/A * @see java.awt.peer.WindowPeer
0N/A */
0N/A protected abstract WindowPeer createWindow(Window target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Dialog</code> using
0N/A * the specified peer interface.
0N/A * @param target the dialog to be implemented.
0N/A * @return this toolkit's implementation of <code>Dialog</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Dialog
0N/A * @see java.awt.peer.DialogPeer
0N/A */
0N/A protected abstract DialogPeer createDialog(Dialog target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>MenuBar</code> using
0N/A * the specified peer interface.
0N/A * @param target the menu bar to be implemented.
0N/A * @return this toolkit's implementation of <code>MenuBar</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.MenuBar
0N/A * @see java.awt.peer.MenuBarPeer
0N/A */
0N/A protected abstract MenuBarPeer createMenuBar(MenuBar target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Menu</code> using
0N/A * the specified peer interface.
0N/A * @param target the menu to be implemented.
0N/A * @return this toolkit's implementation of <code>Menu</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Menu
0N/A * @see java.awt.peer.MenuPeer
0N/A */
0N/A protected abstract MenuPeer createMenu(Menu target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>PopupMenu</code> using
0N/A * the specified peer interface.
0N/A * @param target the popup menu to be implemented.
0N/A * @return this toolkit's implementation of <code>PopupMenu</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.PopupMenu
0N/A * @see java.awt.peer.PopupMenuPeer
0N/A * @since JDK1.1
0N/A */
0N/A protected abstract PopupMenuPeer createPopupMenu(PopupMenu target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>MenuItem</code> using
0N/A * the specified peer interface.
0N/A * @param target the menu item to be implemented.
0N/A * @return this toolkit's implementation of <code>MenuItem</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.MenuItem
0N/A * @see java.awt.peer.MenuItemPeer
0N/A */
0N/A protected abstract MenuItemPeer createMenuItem(MenuItem target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>FileDialog</code> using
0N/A * the specified peer interface.
0N/A * @param target the file dialog to be implemented.
0N/A * @return this toolkit's implementation of <code>FileDialog</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.FileDialog
0N/A * @see java.awt.peer.FileDialogPeer
0N/A */
0N/A protected abstract FileDialogPeer createFileDialog(FileDialog target)
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>CheckboxMenuItem</code> using
0N/A * the specified peer interface.
0N/A * @param target the checkbox menu item to be implemented.
0N/A * @return this toolkit's implementation of <code>CheckboxMenuItem</code>.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.CheckboxMenuItem
0N/A * @see java.awt.peer.CheckboxMenuItemPeer
0N/A */
0N/A protected abstract CheckboxMenuItemPeer createCheckboxMenuItem(
0N/A CheckboxMenuItem target) throws HeadlessException;
0N/A
0N/A /**
0N/A * Obtains this toolkit's implementation of helper class for
0N/A * <code>MouseInfo</code> operations.
0N/A * @return this toolkit's implementation of helper for <code>MouseInfo</code>
0N/A * @throws UnsupportedOperationException if this operation is not implemented
0N/A * @see java.awt.peer.MouseInfoPeer
0N/A * @see java.awt.MouseInfo
0N/A * @since 1.5
0N/A */
0N/A protected MouseInfoPeer getMouseInfoPeer() {
0N/A throw new UnsupportedOperationException("Not implemented");
0N/A }
0N/A
0N/A private static LightweightPeer lightweightMarker;
0N/A
0N/A /**
0N/A * Creates a peer for a component or container. This peer is windowless
0N/A * and allows the Component and Container classes to be extended directly
0N/A * to create windowless components that are defined entirely in java.
0N/A *
0N/A * @param target The Component to be created.
0N/A */
0N/A protected LightweightPeer createComponent(Component target) {
0N/A if (lightweightMarker == null) {
0N/A lightweightMarker = new NullComponentPeer();
0N/A }
0N/A return lightweightMarker;
0N/A }
0N/A
0N/A /**
0N/A * Creates this toolkit's implementation of <code>Font</code> using
0N/A * the specified peer interface.
0N/A * @param name the font to be implemented
0N/A * @param style the style of the font, such as <code>PLAIN</code>,
0N/A * <code>BOLD</code>, <code>ITALIC</code>, or a combination
0N/A * @return this toolkit's implementation of <code>Font</code>
0N/A * @see java.awt.Font
0N/A * @see java.awt.peer.FontPeer
0N/A * @see java.awt.GraphicsEnvironment#getAllFonts
0N/A * @deprecated see java.awt.GraphicsEnvironment#getAllFonts
0N/A */
0N/A @Deprecated
0N/A protected abstract FontPeer getFontPeer(String name, int style);
0N/A
0N/A // The following method is called by the private method
0N/A // <code>updateSystemColors</code> in <code>SystemColor</code>.
0N/A
0N/A /**
0N/A * Fills in the integer array that is supplied as an argument
0N/A * with the current system color values.
0N/A *
0N/A * @param systemColors an integer array.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since JDK1.1
0N/A */
0N/A protected void loadSystemColors(int[] systemColors)
0N/A throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
0N/A }
0N/A
0N/A/**
0N/A * Controls whether the layout of Containers is validated dynamically
0N/A * during resizing, or statically, after resizing is complete.
0N/A * Use {@code isDynamicLayoutActive()} to detect if this feature enabled
0N/A * in this program and is supported by this operating system
0N/A * and/or window manager.
0N/A * Note that this feature is supported not on all platforms, and
0N/A * conversely, that this feature cannot be turned off on some platforms.
0N/A * On these platforms where dynamic layout during resizing is not supported
0N/A * (or is always supported), setting this property has no effect.
0N/A * Note that this feature can be set or unset as a property of the
0N/A * operating system or window manager on some platforms. On such
0N/A * platforms, the dynamic resize property must be set at the operating
0N/A * system or window manager level before this method can take effect.
0N/A * This method does not change support or settings of the underlying
0N/A * operating system or
0N/A * window manager. The OS/WM support can be
0N/A * queried using getDesktopProperty("awt.dynamicLayoutSupported") method.
0N/A *
0N/A * @param dynamic If true, Containers should re-layout their
0N/A * components as the Container is being resized. If false,
0N/A * the layout will be validated after resizing is completed.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see #isDynamicLayoutSet()
0N/A * @see #isDynamicLayoutActive()
0N/A * @see #getDesktopProperty(String propertyName)
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.4
0N/A */
0N/A public void setDynamicLayout(boolean dynamic)
0N/A throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the layout of Containers is validated dynamically
0N/A * during resizing, or statically, after resizing is complete.
0N/A * Note: this method returns the value that was set programmatically;
0N/A * it does not reflect support at the level of the operating system
0N/A * or window manager for dynamic layout on resizing, or the current
0N/A * operating system or window manager settings. The OS/WM support can
0N/A * be queried using getDesktopProperty("awt.dynamicLayoutSupported").
0N/A *
0N/A * @return true if validation of Containers is done dynamically,
0N/A * false if validation is done after resizing is finished.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see #setDynamicLayout(boolean dynamic)
0N/A * @see #isDynamicLayoutActive()
0N/A * @see #getDesktopProperty(String propertyName)
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.4
0N/A */
0N/A protected boolean isDynamicLayoutSet()
0N/A throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
4193N/A
0N/A if (this != Toolkit.getDefaultToolkit()) {
0N/A return Toolkit.getDefaultToolkit().isDynamicLayoutSet();
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns whether dynamic layout of Containers on resize is
0N/A * currently active (both set in program
0N/A *( {@code isDynamicLayoutSet()} )
0N/A *, and supported
0N/A * by the underlying operating system and/or window manager).
0N/A * If dynamic layout is currently inactive then Containers
0N/A * re-layout their components when resizing is completed. As a result
0N/A * the {@code Component.validate()} method will be invoked only
0N/A * once per resize.
0N/A * If dynamic layout is currently active then Containers
0N/A * re-layout their components on every native resize event and
0N/A * the {@code validate()} method will be invoked each time.
0N/A * The OS/WM support can be queried using
0N/A * the getDesktopProperty("awt.dynamicLayoutSupported") method.
0N/A *
0N/A * @return true if dynamic layout of Containers on resize is
0N/A * currently active, false otherwise.
0N/A * @exception HeadlessException if the GraphicsEnvironment.isHeadless()
0N/A * method returns true
0N/A * @see #setDynamicLayout(boolean dynamic)
0N/A * @see #isDynamicLayoutSet()
0N/A * @see #getDesktopProperty(String propertyName)
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.4
0N/A */
0N/A public boolean isDynamicLayoutActive()
0N/A throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
4193N/A
0N/A if (this != Toolkit.getDefaultToolkit()) {
0N/A return Toolkit.getDefaultToolkit().isDynamicLayoutActive();
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the size of the screen. On systems with multiple displays, the
0N/A * primary display is used. Multi-screen aware display dimensions are
0N/A * available from <code>GraphicsConfiguration</code> and
0N/A * <code>GraphicsDevice</code>.
0N/A * @return the size of this toolkit's screen, in pixels.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsConfiguration#getBounds
0N/A * @see java.awt.GraphicsDevice#getDisplayMode
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public abstract Dimension getScreenSize()
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Returns the screen resolution in dots-per-inch.
0N/A * @return this toolkit's screen resolution, in dots-per-inch.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public abstract int getScreenResolution()
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Gets the insets of the screen.
0N/A * @param gc a <code>GraphicsConfiguration</code>
0N/A * @return the insets of this toolkit's screen, in pixels.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.4
0N/A */
0N/A public Insets getScreenInsets(GraphicsConfiguration gc)
0N/A throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
0N/A if (this != Toolkit.getDefaultToolkit()) {
0N/A return Toolkit.getDefaultToolkit().getScreenInsets(gc);
0N/A } else {
0N/A return new Insets(0, 0, 0, 0);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determines the color model of this toolkit's screen.
0N/A * <p>
0N/A * <code>ColorModel</code> is an abstract class that
0N/A * encapsulates the ability to translate between the
0N/A * pixel values of an image and its red, green, blue,
0N/A * and alpha components.
0N/A * <p>
0N/A * This toolkit method is called by the
0N/A * <code>getColorModel</code> method
0N/A * of the <code>Component</code> class.
0N/A * @return the color model of this toolkit's screen.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.image.ColorModel
0N/A * @see java.awt.Component#getColorModel
0N/A */
0N/A public abstract ColorModel getColorModel()
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Returns the names of the available fonts in this toolkit.<p>
0N/A * For 1.1, the following font names are deprecated (the replacement
0N/A * name follows):
0N/A * <ul>
0N/A * <li>TimesRoman (use Serif)
0N/A * <li>Helvetica (use SansSerif)
0N/A * <li>Courier (use Monospaced)
0N/A * </ul><p>
0N/A * The ZapfDingbats fontname is also deprecated in 1.1 but the characters
0N/A * are defined in Unicode starting at 0x2700, and as of 1.1 Java supports
0N/A * those characters.
0N/A * @return the names of the available fonts in this toolkit.
0N/A * @deprecated see {@link java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()}
0N/A * @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()
0N/A */
0N/A @Deprecated
0N/A public abstract String[] getFontList();
0N/A
0N/A /**
0N/A * Gets the screen device metrics for rendering of the font.
0N/A * @param font a font
0N/A * @return the screen metrics of the specified font in this toolkit
0N/A * @deprecated As of JDK version 1.2, replaced by the <code>Font</code>
0N/A * method <code>getLineMetrics</code>.
0N/A * @see java.awt.font.LineMetrics
0N/A * @see java.awt.Font#getLineMetrics
0N/A * @see java.awt.GraphicsEnvironment#getScreenDevices
0N/A */
0N/A @Deprecated
0N/A public abstract FontMetrics getFontMetrics(Font font);
0N/A
0N/A /**
0N/A * Synchronizes this toolkit's graphics state. Some window systems
0N/A * may do buffering of graphics events.
0N/A * <p>
0N/A * This method ensures that the display is up-to-date. It is useful
0N/A * for animation.
0N/A */
0N/A public abstract void sync();
0N/A
0N/A /**
0N/A * The default toolkit.
0N/A */
0N/A private static Toolkit toolkit;
0N/A
0N/A /**
0N/A * Used internally by the assistive technologies functions; set at
0N/A * init time and used at load time
0N/A */
0N/A private static String atNames;
0N/A
0N/A /**
0N/A * Initializes properties related to assistive technologies.
0N/A * These properties are used both in the loadAssistiveProperties()
0N/A * function below, as well as other classes in the jdk that depend
0N/A * on the properties (such as the use of the screen_magnifier_present
0N/A * property in Java2D hardware acceleration initialization). The
0N/A * initialization of the properties must be done before the platform-
0N/A * specific Toolkit class is instantiated so that all necessary
0N/A * properties are set up properly before any classes dependent upon them
0N/A * are initialized.
0N/A */
0N/A private static void initAssistiveTechnologies() {
0N/A
0N/A // Get accessibility properties
0N/A final String sep = File.separator;
0N/A final Properties properties = new Properties();
0N/A
0N/A
0N/A atNames = (String)java.security.AccessController.doPrivileged(
0N/A new java.security.PrivilegedAction() {
0N/A public Object run() {
0N/A
0N/A // Try loading the per-user accessibility properties file.
0N/A try {
0N/A File propsFile = new File(
0N/A System.getProperty("user.home") +
0N/A sep + ".accessibility.properties");
0N/A FileInputStream in =
0N/A new FileInputStream(propsFile);
0N/A
0N/A // Inputstream has been buffered in Properties class
0N/A properties.load(in);
0N/A in.close();
0N/A } catch (Exception e) {
0N/A // Per-user accessibility properties file does not exist
0N/A }
0N/A
0N/A // Try loading the system-wide accessibility properties
0N/A // file only if a per-user accessibility properties
0N/A // file does not exist or is empty.
0N/A if (properties.size() == 0) {
0N/A try {
0N/A File propsFile = new File(
0N/A System.getProperty("java.home") + sep + "lib" +
0N/A sep + "accessibility.properties");
0N/A FileInputStream in =
0N/A new FileInputStream(propsFile);
0N/A
0N/A // Inputstream has been buffered in Properties class
0N/A properties.load(in);
0N/A in.close();
0N/A } catch (Exception e) {
0N/A // System-wide accessibility properties file does
0N/A // not exist;
0N/A }
0N/A }
0N/A
0N/A // Get whether a screen magnifier is present. First check
0N/A // the system property and then check the properties file.
0N/A String magPresent = System.getProperty("javax.accessibility.screen_magnifier_present");
0N/A if (magPresent == null) {
0N/A magPresent = properties.getProperty("screen_magnifier_present", null);
0N/A if (magPresent != null) {
0N/A System.setProperty("javax.accessibility.screen_magnifier_present", magPresent);
0N/A }
0N/A }
0N/A
0N/A // Get the names of any assistive technolgies to load. First
0N/A // check the system property and then check the properties
0N/A // file.
0N/A String classNames = System.getProperty("javax.accessibility.assistive_technologies");
0N/A if (classNames == null) {
0N/A classNames = properties.getProperty("assistive_technologies", null);
0N/A if (classNames != null) {
0N/A System.setProperty("javax.accessibility.assistive_technologies", classNames);
0N/A }
0N/A }
0N/A return classNames;
0N/A }
0N/A });
0N/A }
0N/A
0N/A /**
0N/A * Loads additional classes into the VM, using the property
0N/A * 'assistive_technologies' specified in the Sun reference
0N/A * implementation by a line in the 'accessibility.properties'
0N/A * file. The form is "assistive_technologies=..." where
0N/A * the "..." is a comma-separated list of assistive technology
0N/A * classes to load. Each class is loaded in the order given
0N/A * and a single instance of each is created using
0N/A * Class.forName(class).newInstance(). All errors are handled
0N/A * via an AWTError exception.
0N/A *
0N/A * <p>The assumption is made that assistive technology classes are supplied
0N/A * as part of INSTALLED (as opposed to: BUNDLED) extensions or specified
0N/A * on the class path
0N/A * (and therefore can be loaded using the class loader returned by
0N/A * a call to <code>ClassLoader.getSystemClassLoader</code>, whose
0N/A * delegation parent is the extension class loader for installed
0N/A * extensions).
0N/A */
0N/A private static void loadAssistiveTechnologies() {
0N/A // Load any assistive technologies
0N/A if (atNames != null) {
0N/A ClassLoader cl = ClassLoader.getSystemClassLoader();
0N/A StringTokenizer parser = new StringTokenizer(atNames," ,");
0N/A String atName;
0N/A while (parser.hasMoreTokens()) {
0N/A atName = parser.nextToken();
0N/A try {
0N/A Class clazz;
0N/A if (cl != null) {
0N/A clazz = cl.loadClass(atName);
0N/A } else {
0N/A clazz = Class.forName(atName);
0N/A }
0N/A clazz.newInstance();
0N/A } catch (ClassNotFoundException e) {
0N/A throw new AWTError("Assistive Technology not found: "
0N/A + atName);
0N/A } catch (InstantiationException e) {
0N/A throw new AWTError("Could not instantiate Assistive"
0N/A + " Technology: " + atName);
0N/A } catch (IllegalAccessException e) {
0N/A throw new AWTError("Could not access Assistive"
0N/A + " Technology: " + atName);
0N/A } catch (Exception e) {
0N/A throw new AWTError("Error trying to install Assistive"
0N/A + " Technology: " + atName + " " + e);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the default toolkit.
0N/A * <p>
0N/A * If a system property named <code>"java.awt.headless"</code> is set
0N/A * to <code>true</code> then the headless implementation
0N/A * of <code>Toolkit</code> is used.
0N/A * <p>
0N/A * If there is no <code>"java.awt.headless"</code> or it is set to
0N/A * <code>false</code> and there is a system property named
0N/A * <code>"awt.toolkit"</code>,
0N/A * that property is treated as the name of a class that is a subclass
0N/A * of <code>Toolkit</code>;
0N/A * otherwise the default platform-specific implementation of
0N/A * <code>Toolkit</code> is used.
0N/A * <p>
0N/A * Also loads additional classes into the VM, using the property
0N/A * 'assistive_technologies' specified in the Sun reference
0N/A * implementation by a line in the 'accessibility.properties'
0N/A * file. The form is "assistive_technologies=..." where
0N/A * the "..." is a comma-separated list of assistive technology
0N/A * classes to load. Each class is loaded in the order given
0N/A * and a single instance of each is created using
0N/A * Class.forName(class).newInstance(). This is done just after
0N/A * the AWT toolkit is created. All errors are handled via an
0N/A * AWTError exception.
0N/A * @return the default toolkit.
0N/A * @exception AWTError if a toolkit could not be found, or
0N/A * if one could not be accessed or instantiated.
0N/A */
0N/A public static synchronized Toolkit getDefaultToolkit() {
0N/A if (toolkit == null) {
0N/A try {
0N/A // We disable the JIT during toolkit initialization. This
0N/A // tends to touch lots of classes that aren't needed again
0N/A // later and therefore JITing is counter-productiive.
0N/A java.lang.Compiler.disable();
0N/A
0N/A java.security.AccessController.doPrivileged(
0N/A new java.security.PrivilegedAction() {
0N/A public Object run() {
0N/A String nm = null;
0N/A Class cls = null;
0N/A try {
3876N/A nm = System.getProperty("awt.toolkit");
0N/A try {
0N/A cls = Class.forName(nm);
0N/A } catch (ClassNotFoundException e) {
0N/A ClassLoader cl = ClassLoader.getSystemClassLoader();
0N/A if (cl != null) {
0N/A try {
0N/A cls = cl.loadClass(nm);
0N/A } catch (ClassNotFoundException ee) {
0N/A throw new AWTError("Toolkit not found: " + nm);
0N/A }
0N/A }
0N/A }
0N/A if (cls != null) {
0N/A toolkit = (Toolkit)cls.newInstance();
0N/A if (GraphicsEnvironment.isHeadless()) {
0N/A toolkit = new HeadlessToolkit(toolkit);
0N/A }
0N/A }
0N/A } catch (InstantiationException e) {
0N/A throw new AWTError("Could not instantiate Toolkit: " + nm);
0N/A } catch (IllegalAccessException e) {
0N/A throw new AWTError("Could not access Toolkit: " + nm);
0N/A }
0N/A return null;
0N/A }
0N/A });
0N/A loadAssistiveTechnologies();
0N/A } finally {
0N/A // Make sure to always re-enable the JIT.
0N/A java.lang.Compiler.enable();
0N/A }
0N/A }
0N/A return toolkit;
0N/A }
0N/A
0N/A /**
0N/A * Returns an image which gets pixel data from the specified file,
0N/A * whose format can be either GIF, JPEG or PNG.
0N/A * The underlying toolkit attempts to resolve multiple requests
0N/A * with the same filename to the same returned Image.
0N/A * <p>
0N/A * Since the mechanism required to facilitate this sharing of
0N/A * <code>Image</code> objects may continue to hold onto images
0N/A * that are no longer in use for an indefinite period of time,
0N/A * developers are encouraged to implement their own caching of
0N/A * images by using the {@link #createImage(java.lang.String) createImage}
0N/A * variant wherever available.
0N/A * If the image data contained in the specified file changes,
0N/A * the <code>Image</code> object returned from this method may
0N/A * still contain stale information which was loaded from the
0N/A * file after a prior call.
0N/A * Previously loaded image data can be manually discarded by
0N/A * calling the {@link Image#flush flush} method on the
0N/A * returned <code>Image</code>.
0N/A * <p>
0N/A * This method first checks if there is a security manager installed.
0N/A * If so, the method calls the security manager's
0N/A * <code>checkRead</code> method with the file specified to ensure
0N/A * that the access to the image is allowed.
0N/A * @param filename the name of a file containing pixel data
0N/A * in a recognized file format.
0N/A * @return an image which gets its pixel data from
0N/A * the specified file.
0N/A * @throws SecurityException if a security manager exists and its
0N/A * checkRead method doesn't allow the operation.
0N/A * @see #createImage(java.lang.String)
0N/A */
0N/A public abstract Image getImage(String filename);
0N/A
0N/A /**
0N/A * Returns an image which gets pixel data from the specified URL.
0N/A * The pixel data referenced by the specified URL must be in one
0N/A * of the following formats: GIF, JPEG or PNG.
0N/A * The underlying toolkit attempts to resolve multiple requests
0N/A * with the same URL to the same returned Image.
0N/A * <p>
0N/A * Since the mechanism required to facilitate this sharing of
0N/A * <code>Image</code> objects may continue to hold onto images
0N/A * that are no longer in use for an indefinite period of time,
0N/A * developers are encouraged to implement their own caching of
0N/A * images by using the {@link #createImage(java.net.URL) createImage}
0N/A * variant wherever available.
0N/A * If the image data stored at the specified URL changes,
0N/A * the <code>Image</code> object returned from this method may
0N/A * still contain stale information which was fetched from the
0N/A * URL after a prior call.
0N/A * Previously loaded image data can be manually discarded by
0N/A * calling the {@link Image#flush flush} method on the
0N/A * returned <code>Image</code>.
0N/A * <p>
0N/A * This method first checks if there is a security manager installed.
0N/A * If so, the method calls the security manager's
0N/A * <code>checkPermission</code> method with the
0N/A * url.openConnection().getPermission() permission to ensure
0N/A * that the access to the image is allowed. For compatibility
0N/A * with pre-1.2 security managers, if the access is denied with
0N/A * <code>FilePermission</code> or <code>SocketPermission</code>,
0N/A * the method throws the <code>SecurityException</code>
0N/A * if the corresponding 1.1-style SecurityManager.checkXXX method
0N/A * also denies permission.
0N/A * @param url the URL to use in fetching the pixel data.
0N/A * @return an image which gets its pixel data from
0N/A * the specified URL.
0N/A * @throws SecurityException if a security manager exists and its
0N/A * checkPermission method doesn't allow
0N/A * the operation.
0N/A * @see #createImage(java.net.URL)
0N/A */
0N/A public abstract Image getImage(URL url);
0N/A
0N/A /**
0N/A * Returns an image which gets pixel data from the specified file.
0N/A * The returned Image is a new object which will not be shared
0N/A * with any other caller of this method or its getImage variant.
0N/A * <p>
0N/A * This method first checks if there is a security manager installed.
0N/A * If so, the method calls the security manager's
0N/A * <code>checkRead</code> method with the specified file to ensure
0N/A * that the image creation is allowed.
0N/A * @param filename the name of a file containing pixel data
0N/A * in a recognized file format.
0N/A * @return an image which gets its pixel data from
0N/A * the specified file.
0N/A * @throws SecurityException if a security manager exists and its
0N/A * checkRead method doesn't allow the operation.
0N/A * @see #getImage(java.lang.String)
0N/A */
0N/A public abstract Image createImage(String filename);
0N/A
0N/A /**
0N/A * Returns an image which gets pixel data from the specified URL.
0N/A * The returned Image is a new object which will not be shared
0N/A * with any other caller of this method or its getImage variant.
0N/A * <p>
0N/A * This method first checks if there is a security manager installed.
0N/A * If so, the method calls the security manager's
0N/A * <code>checkPermission</code> method with the
0N/A * url.openConnection().getPermission() permission to ensure
0N/A * that the image creation is allowed. For compatibility
0N/A * with pre-1.2 security managers, if the access is denied with
0N/A * <code>FilePermission</code> or <code>SocketPermission</code>,
0N/A * the method throws <code>SecurityException</code>
0N/A * if the corresponding 1.1-style SecurityManager.checkXXX method
0N/A * also denies permission.
0N/A * @param url the URL to use in fetching the pixel data.
0N/A * @return an image which gets its pixel data from
0N/A * the specified URL.
0N/A * @throws SecurityException if a security manager exists and its
0N/A * checkPermission method doesn't allow
0N/A * the operation.
0N/A * @see #getImage(java.net.URL)
0N/A */
0N/A public abstract Image createImage(URL url);
0N/A
0N/A /**
0N/A * Prepares an image for rendering.
0N/A * <p>
0N/A * If the values of the width and height arguments are both
0N/A * <code>-1</code>, this method prepares the image for rendering
0N/A * on the default screen; otherwise, this method prepares an image
0N/A * for rendering on the default screen at the specified width and height.
0N/A * <p>
0N/A * The image data is downloaded asynchronously in another thread,
0N/A * and an appropriately scaled screen representation of the image is
0N/A * generated.
0N/A * <p>
0N/A * This method is called by components <code>prepareImage</code>
0N/A * methods.
0N/A * <p>
0N/A * Information on the flags returned by this method can be found
0N/A * with the definition of the <code>ImageObserver</code> interface.
0N/A
0N/A * @param image the image for which to prepare a
0N/A * screen representation.
0N/A * @param width the width of the desired screen
0N/A * representation, or <code>-1</code>.
0N/A * @param height the height of the desired screen
0N/A * representation, or <code>-1</code>.
0N/A * @param observer the <code>ImageObserver</code>
0N/A * object to be notified as the
0N/A * image is being prepared.
0N/A * @return <code>true</code> if the image has already been
0N/A * fully prepared; <code>false</code> otherwise.
0N/A * @see java.awt.Component#prepareImage(java.awt.Image,
0N/A * java.awt.image.ImageObserver)
0N/A * @see java.awt.Component#prepareImage(java.awt.Image,
0N/A * int, int, java.awt.image.ImageObserver)
0N/A * @see java.awt.image.ImageObserver
0N/A */
0N/A public abstract boolean prepareImage(Image image, int width, int height,
0N/A ImageObserver observer);
0N/A
0N/A /**
0N/A * Indicates the construction status of a specified image that is
0N/A * being prepared for display.
0N/A * <p>
0N/A * If the values of the width and height arguments are both
0N/A * <code>-1</code>, this method returns the construction status of
0N/A * a screen representation of the specified image in this toolkit.
0N/A * Otherwise, this method returns the construction status of a
0N/A * scaled representation of the image at the specified width
0N/A * and height.
0N/A * <p>
0N/A * This method does not cause the image to begin loading.
0N/A * An application must call <code>prepareImage</code> to force
0N/A * the loading of an image.
0N/A * <p>
0N/A * This method is called by the component's <code>checkImage</code>
0N/A * methods.
0N/A * <p>
0N/A * Information on the flags returned by this method can be found
0N/A * with the definition of the <code>ImageObserver</code> interface.
0N/A * @param image the image whose status is being checked.
0N/A * @param width the width of the scaled version whose status is
0N/A * being checked, or <code>-1</code>.
0N/A * @param height the height of the scaled version whose status
0N/A * is being checked, or <code>-1</code>.
0N/A * @param observer the <code>ImageObserver</code> object to be
0N/A * notified as the image is being prepared.
0N/A * @return the bitwise inclusive <strong>OR</strong> of the
0N/A * <code>ImageObserver</code> flags for the
0N/A * image data that is currently available.
0N/A * @see java.awt.Toolkit#prepareImage(java.awt.Image,
0N/A * int, int, java.awt.image.ImageObserver)
0N/A * @see java.awt.Component#checkImage(java.awt.Image,
0N/A * java.awt.image.ImageObserver)
0N/A * @see java.awt.Component#checkImage(java.awt.Image,
0N/A * int, int, java.awt.image.ImageObserver)
0N/A * @see java.awt.image.ImageObserver
0N/A */
0N/A public abstract int checkImage(Image image, int width, int height,
0N/A ImageObserver observer);
0N/A
0N/A /**
0N/A * Creates an image with the specified image producer.
0N/A * @param producer the image producer to be used.
0N/A * @return an image with the specified image producer.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageProducer
0N/A * @see java.awt.Component#createImage(java.awt.image.ImageProducer)
0N/A */
0N/A public abstract Image createImage(ImageProducer producer);
0N/A
0N/A /**
0N/A * Creates an image which decodes the image stored in the specified
0N/A * byte array.
0N/A * <p>
0N/A * The data must be in some image format, such as GIF or JPEG,
0N/A * that is supported by this toolkit.
0N/A * @param imagedata an array of bytes, representing
0N/A * image data in a supported image format.
0N/A * @return an image.
0N/A * @since JDK1.1
0N/A */
0N/A public Image createImage(byte[] imagedata) {
0N/A return createImage(imagedata, 0, imagedata.length);
0N/A }
0N/A
0N/A /**
0N/A * Creates an image which decodes the image stored in the specified
0N/A * byte array, and at the specified offset and length.
0N/A * The data must be in some image format, such as GIF or JPEG,
0N/A * that is supported by this toolkit.
0N/A * @param imagedata an array of bytes, representing
0N/A * image data in a supported image format.
0N/A * @param imageoffset the offset of the beginning
0N/A * of the data in the array.
0N/A * @param imagelength the length of the data in the array.
0N/A * @return an image.
0N/A * @since JDK1.1
0N/A */
0N/A public abstract Image createImage(byte[] imagedata,
0N/A int imageoffset,
0N/A int imagelength);
0N/A
0N/A /**
0N/A * Gets a <code>PrintJob</code> object which is the result of initiating
0N/A * a print operation on the toolkit's platform.
0N/A * <p>
0N/A * Each actual implementation of this method should first check if there
0N/A * is a security manager installed. If there is, the method should call
0N/A * the security manager's <code>checkPrintJobAccess</code> method to
0N/A * ensure initiation of a print operation is allowed. If the default
0N/A * implementation of <code>checkPrintJobAccess</code> is used (that is,
0N/A * that method is not overriden), then this results in a call to the
0N/A * security manager's <code>checkPermission</code> method with a <code>
0N/A * RuntimePermission("queuePrintJob")</code> permission.
0N/A *
0N/A * @param frame the parent of the print dialog. May not be null.
0N/A * @param jobtitle the title of the PrintJob. A null title is equivalent
0N/A * to "".
0N/A * @param props a Properties object containing zero or more properties.
0N/A * Properties are not standardized and are not consistent across
0N/A * implementations. Because of this, PrintJobs which require job
0N/A * and page control should use the version of this function which
0N/A * takes JobAttributes and PageAttributes objects. This object
0N/A * may be updated to reflect the user's job choices on exit. May
0N/A * be null.
0N/A * @return a <code>PrintJob</code> object, or <code>null</code> if the
0N/A * user cancelled the print job.
3821N/A * @throws NullPointerException if frame is null
0N/A * @throws SecurityException if this thread is not allowed to initiate a
0N/A * print job request
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.PrintJob
0N/A * @see java.lang.RuntimePermission
0N/A * @since JDK1.1
0N/A */
0N/A public abstract PrintJob getPrintJob(Frame frame, String jobtitle,
0N/A Properties props);
0N/A
0N/A /**
0N/A * Gets a <code>PrintJob</code> object which is the result of initiating
0N/A * a print operation on the toolkit's platform.
0N/A * <p>
0N/A * Each actual implementation of this method should first check if there
0N/A * is a security manager installed. If there is, the method should call
0N/A * the security manager's <code>checkPrintJobAccess</code> method to
0N/A * ensure initiation of a print operation is allowed. If the default
0N/A * implementation of <code>checkPrintJobAccess</code> is used (that is,
0N/A * that method is not overriden), then this results in a call to the
0N/A * security manager's <code>checkPermission</code> method with a <code>
0N/A * RuntimePermission("queuePrintJob")</code> permission.
0N/A *
0N/A * @param frame the parent of the print dialog. May be null if and only
0N/A * if jobAttributes is not null and jobAttributes.getDialog()
0N/A * returns JobAttributes.DialogType.NONE or
0N/A * JobAttributes.DialogType.COMMON.
0N/A * @param jobtitle the title of the PrintJob. A null title is equivalent
0N/A * to "".
0N/A * @param jobAttributes a set of job attributes which will control the
0N/A * PrintJob. The attributes will be updated to reflect the user's
0N/A * choices as outlined in the JobAttributes documentation. May be
0N/A * null.
0N/A * @param pageAttributes a set of page attributes which will control the
0N/A * PrintJob. The attributes will be applied to every page in the
0N/A * job. The attributes will be updated to reflect the user's
0N/A * choices as outlined in the PageAttributes documentation. May be
0N/A * null.
0N/A * @return a <code>PrintJob</code> object, or <code>null</code> if the
0N/A * user cancelled the print job.
3821N/A * @throws NullPointerException if frame is null
0N/A * @throws IllegalArgumentException if pageAttributes specifies differing
0N/A * cross feed and feed resolutions. Also if this thread has
0N/A * access to the file system and jobAttributes specifies
0N/A * print to file, and the specified destination file exists but
0N/A * is a directory rather than a regular file, does not exist but
0N/A * cannot be created, or cannot be opened for any other reason.
0N/A * However in the case of print to file, if a dialog is also
0N/A * requested to be displayed then the user will be given an
0N/A * opportunity to select a file and proceed with printing.
0N/A * The dialog will ensure that the selected output file
0N/A * is valid before returning from this method.
0N/A * @throws SecurityException if this thread is not allowed to initiate a
0N/A * print job request, or if jobAttributes specifies print to file,
0N/A * and this thread is not allowed to access the file system
0N/A * @see java.awt.PrintJob
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.lang.RuntimePermission
0N/A * @see java.awt.JobAttributes
0N/A * @see java.awt.PageAttributes
0N/A * @since 1.3
0N/A */
0N/A public PrintJob getPrintJob(Frame frame, String jobtitle,
0N/A JobAttributes jobAttributes,
0N/A PageAttributes pageAttributes) {
0N/A // Override to add printing support with new job/page control classes
0N/A
0N/A if (this != Toolkit.getDefaultToolkit()) {
0N/A return Toolkit.getDefaultToolkit().getPrintJob(frame, jobtitle,
0N/A jobAttributes,
0N/A pageAttributes);
0N/A } else {
0N/A return getPrintJob(frame, jobtitle, null);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Emits an audio beep.
0N/A * @since JDK1.1
0N/A */
0N/A public abstract void beep();
0N/A
0N/A /**
0N/A * Gets the singleton instance of the system Clipboard which interfaces
0N/A * with clipboard facilities provided by the native platform. This
0N/A * clipboard enables data transfer between Java programs and native
0N/A * applications which use native clipboard facilities.
0N/A * <p>
0N/A * In addition to any and all formats specified in the flavormap.properties
0N/A * file, or other file specified by the <code>AWT.DnD.flavorMapFileURL
0N/A * </code> Toolkit property, text returned by the system Clipboard's <code>
0N/A * getTransferData()</code> method is available in the following flavors:
0N/A * <ul>
0N/A * <li>DataFlavor.stringFlavor</li>
0N/A * <li>DataFlavor.plainTextFlavor (<b>deprecated</b>)</li>
0N/A * </ul>
0N/A * As with <code>java.awt.datatransfer.StringSelection</code>, if the
0N/A * requested flavor is <code>DataFlavor.plainTextFlavor</code>, or an
0N/A * equivalent flavor, a Reader is returned. <b>Note:</b> The behavior of
0N/A * the system Clipboard's <code>getTransferData()</code> method for <code>
0N/A * DataFlavor.plainTextFlavor</code>, and equivalent DataFlavors, is
0N/A * inconsistent with the definition of <code>DataFlavor.plainTextFlavor
0N/A * </code>. Because of this, support for <code>
0N/A * DataFlavor.plainTextFlavor</code>, and equivalent flavors, is
0N/A * <b>deprecated</b>.
0N/A * <p>
0N/A * Each actual implementation of this method should first check if there
0N/A * is a security manager installed. If there is, the method should call
0N/A * the security manager's <code>checkSystemClipboardAccess</code> method
0N/A * to ensure it's ok to to access the system clipboard. If the default
0N/A * implementation of <code>checkSystemClipboardAccess</code> is used (that
0N/A * is, that method is not overriden), then this results in a call to the
0N/A * security manager's <code>checkPermission</code> method with an <code>
0N/A * AWTPermission("accessClipboard")</code> permission.
0N/A *
0N/A * @return the system Clipboard
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.datatransfer.Clipboard
0N/A * @see java.awt.datatransfer.StringSelection
0N/A * @see java.awt.datatransfer.DataFlavor#stringFlavor
0N/A * @see java.awt.datatransfer.DataFlavor#plainTextFlavor
0N/A * @see java.io.Reader
0N/A * @see java.awt.AWTPermission
0N/A * @since JDK1.1
0N/A */
0N/A public abstract Clipboard getSystemClipboard()
0N/A throws HeadlessException;
0N/A
0N/A /**
0N/A * Gets the singleton instance of the system selection as a
0N/A * <code>Clipboard</code> object. This allows an application to read and
0N/A * modify the current, system-wide selection.
0N/A * <p>
0N/A * An application is responsible for updating the system selection whenever
0N/A * the user selects text, using either the mouse or the keyboard.
0N/A * Typically, this is implemented by installing a
0N/A * <code>FocusListener</code> on all <code>Component</code>s which support
0N/A * text selection, and, between <code>FOCUS_GAINED</code> and
0N/A * <code>FOCUS_LOST</code> events delivered to that <code>Component</code>,
0N/A * updating the system selection <code>Clipboard</code> when the selection
0N/A * changes inside the <code>Component</code>. Properly updating the system
0N/A * selection ensures that a Java application will interact correctly with
0N/A * native applications and other Java applications running simultaneously
0N/A * on the system. Note that <code>java.awt.TextComponent</code> and
0N/A * <code>javax.swing.text.JTextComponent</code> already adhere to this
0N/A * policy. When using these classes, and their subclasses, developers need
0N/A * not write any additional code.
0N/A * <p>
0N/A * Some platforms do not support a system selection <code>Clipboard</code>.
0N/A * On those platforms, this method will return <code>null</code>. In such a
0N/A * case, an application is absolved from its responsibility to update the
0N/A * system selection <code>Clipboard</code> as described above.
0N/A * <p>
0N/A * Each actual implementation of this method should first check if there
0N/A * is a <code>SecurityManager</code> installed. If there is, the method
0N/A * should call the <code>SecurityManager</code>'s
0N/A * <code>checkSystemClipboardAccess</code> method to ensure that client
0N/A * code has access the system selection. If the default implementation of
0N/A * <code>checkSystemClipboardAccess</code> is used (that is, if the method
0N/A * is not overridden), then this results in a call to the
0N/A * <code>SecurityManager</code>'s <code>checkPermission</code> method with
0N/A * an <code>AWTPermission("accessClipboard")</code> permission.
0N/A *
0N/A * @return the system selection as a <code>Clipboard</code>, or
0N/A * <code>null</code> if the native platform does not support a
0N/A * system selection <code>Clipboard</code>
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A *
0N/A * @see java.awt.datatransfer.Clipboard
0N/A * @see java.awt.event.FocusListener
0N/A * @see java.awt.event.FocusEvent#FOCUS_GAINED
0N/A * @see java.awt.event.FocusEvent#FOCUS_LOST
0N/A * @see TextComponent
0N/A * @see javax.swing.text.JTextComponent
0N/A * @see AWTPermission
0N/A * @see GraphicsEnvironment#isHeadless
0N/A * @since 1.4
0N/A */
0N/A public Clipboard getSystemSelection() throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
4193N/A
0N/A if (this != Toolkit.getDefaultToolkit()) {
0N/A return Toolkit.getDefaultToolkit().getSystemSelection();
0N/A } else {
0N/A GraphicsEnvironment.checkHeadless();
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determines which modifier key is the appropriate accelerator
0N/A * key for menu shortcuts.
0N/A * <p>
0N/A * Menu shortcuts, which are embodied in the
0N/A * <code>MenuShortcut</code> class, are handled by the
0N/A * <code>MenuBar</code> class.
0N/A * <p>
0N/A * By default, this method returns <code>Event.CTRL_MASK</code>.
0N/A * Toolkit implementations should override this method if the
0N/A * <b>Control</b> key isn't the correct key for accelerators.
0N/A * @return the modifier mask on the <code>Event</code> class
0N/A * that is used for menu shortcuts on this toolkit.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.MenuBar
0N/A * @see java.awt.MenuShortcut
0N/A * @since JDK1.1
0N/A */
0N/A public int getMenuShortcutKeyMask() throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
3949N/A
0N/A return Event.CTRL_MASK;
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the given locking key on the keyboard is currently in
0N/A * its "on" state.
0N/A * Valid key codes are
0N/A * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK},
0N/A * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK},
0N/A * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and
0N/A * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}.
0N/A *
0N/A * @exception java.lang.IllegalArgumentException if <code>keyCode</code>
0N/A * is not one of the valid key codes
0N/A * @exception java.lang.UnsupportedOperationException if the host system doesn't
0N/A * allow getting the state of this key programmatically, or if the keyboard
0N/A * doesn't have this key
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.3
0N/A */
0N/A public boolean getLockingKeyState(int keyCode)
4193N/A throws UnsupportedOperationException
4193N/A {
4193N/A GraphicsEnvironment.checkHeadless();
4193N/A
0N/A if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK ||
0N/A keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
0N/A throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
0N/A }
0N/A throw new UnsupportedOperationException("Toolkit.getLockingKeyState");
0N/A }
0N/A
0N/A /**
0N/A * Sets the state of the given locking key on the keyboard.
0N/A * Valid key codes are
0N/A * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK},
0N/A * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK},
0N/A * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and
0N/A * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}.
0N/A * <p>
0N/A * Depending on the platform, setting the state of a locking key may
0N/A * involve event processing and therefore may not be immediately
0N/A * observable through getLockingKeyState.
0N/A *
0N/A * @exception java.lang.IllegalArgumentException if <code>keyCode</code>
0N/A * is not one of the valid key codes
0N/A * @exception java.lang.UnsupportedOperationException if the host system doesn't
0N/A * allow setting the state of this key programmatically, or if the keyboard
0N/A * doesn't have this key
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.3
0N/A */
0N/A public void setLockingKeyState(int keyCode, boolean on)
4193N/A throws UnsupportedOperationException
4193N/A {
4193N/A GraphicsEnvironment.checkHeadless();
4193N/A
0N/A if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK ||
0N/A keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
0N/A throw new IllegalArgumentException("invalid key for Toolkit.setLockingKeyState");
0N/A }
0N/A throw new UnsupportedOperationException("Toolkit.setLockingKeyState");
0N/A }
0N/A
0N/A /**
0N/A * Give native peers the ability to query the native container
0N/A * given a native component (eg the direct parent may be lightweight).
0N/A */
0N/A protected static Container getNativeContainer(Component c) {
0N/A return c.getNativeContainer();
0N/A }
0N/A
0N/A /**
0N/A * Creates a new custom cursor object.
0N/A * If the image to display is invalid, the cursor will be hidden (made
0N/A * completely transparent), and the hotspot will be set to (0, 0).
0N/A *
0N/A * <p>Note that multi-frame images are invalid and may cause this
0N/A * method to hang.
0N/A *
0N/A * @param cursor the image to display when the cursor is actived
0N/A * @param hotSpot the X and Y of the large cursor's hot spot; the
0N/A * hotSpot values must be less than the Dimension returned by
0N/A * <code>getBestCursorSize</code>
0N/A * @param name a localized description of the cursor, for Java Accessibility use
0N/A * @exception IndexOutOfBoundsException if the hotSpot values are outside
0N/A * the bounds of the cursor
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.2
0N/A */
0N/A public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
0N/A throws IndexOutOfBoundsException, HeadlessException
0N/A {
0N/A // Override to implement custom cursor support.
0N/A if (this != Toolkit.getDefaultToolkit()) {
0N/A return Toolkit.getDefaultToolkit().
0N/A createCustomCursor(cursor, hotSpot, name);
0N/A } else {
0N/A return new Cursor(Cursor.DEFAULT_CURSOR);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the supported cursor dimension which is closest to the desired
0N/A * sizes. Systems which only support a single cursor size will return that
0N/A * size regardless of the desired sizes. Systems which don't support custom
0N/A * cursors will return a dimension of 0, 0. <p>
0N/A * Note: if an image is used whose dimensions don't match a supported size
0N/A * (as returned by this method), the Toolkit implementation will attempt to
0N/A * resize the image to a supported size.
0N/A * Since converting low-resolution images is difficult,
0N/A * no guarantees are made as to the quality of a cursor image which isn't a
0N/A * supported size. It is therefore recommended that this method
0N/A * be called and an appropriate image used so no image conversion is made.
0N/A *
0N/A * @param preferredWidth the preferred cursor width the component would like
0N/A * to use.
0N/A * @param preferredHeight the preferred cursor height the component would like
0N/A * to use.
0N/A * @return the closest matching supported cursor size, or a dimension of 0,0 if
0N/A * the Toolkit implementation doesn't support custom cursors.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.2
0N/A */
0N/A public Dimension getBestCursorSize(int preferredWidth,
0N/A int preferredHeight) throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
4193N/A
0N/A // Override to implement custom cursor support.
0N/A if (this != Toolkit.getDefaultToolkit()) {
0N/A return Toolkit.getDefaultToolkit().
0N/A getBestCursorSize(preferredWidth, preferredHeight);
0N/A } else {
0N/A return new Dimension(0, 0);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the maximum number of colors the Toolkit supports in a custom cursor
0N/A * palette.<p>
0N/A * Note: if an image is used which has more colors in its palette than
0N/A * the supported maximum, the Toolkit implementation will attempt to flatten the
0N/A * palette to the maximum. Since converting low-resolution images is difficult,
0N/A * no guarantees are made as to the quality of a cursor image which has more
0N/A * colors than the system supports. It is therefore recommended that this method
0N/A * be called and an appropriate image used so no image conversion is made.
0N/A *
0N/A * @return the maximum number of colors, or zero if custom cursors are not
0N/A * supported by this Toolkit implementation.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.2
0N/A */
0N/A public int getMaximumCursorColors() throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
4193N/A
0N/A // Override to implement custom cursor support.
0N/A if (this != Toolkit.getDefaultToolkit()) {
0N/A return Toolkit.getDefaultToolkit().getMaximumCursorColors();
0N/A } else {
0N/A return 0;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns whether Toolkit supports this state for
0N/A * <code>Frame</code>s. This method tells whether the <em>UI
0N/A * concept</em> of, say, maximization or iconification is
0N/A * supported. It will always return false for "compound" states
0N/A * like <code>Frame.ICONIFIED|Frame.MAXIMIZED_VERT</code>.
0N/A * In other words, the rule of thumb is that only queries with a
0N/A * single frame state constant as an argument are meaningful.
0N/A * <p>Note that supporting a given concept is a platform-
0N/A * dependent feature. Due to native limitations the Toolkit
0N/A * object may report a particular state as supported, however at
0N/A * the same time the Toolkit object will be unable to apply the
0N/A * state to a given frame. This circumstance has two following
0N/A * consequences:
0N/A * <ul>
0N/A * <li>Only the return value of {@code false} for the present
0N/A * method actually indicates that the given state is not
0N/A * supported. If the method returns {@code true} the given state
0N/A * may still be unsupported and/or unavailable for a particular
0N/A * frame.
0N/A * <li>The developer should consider examining the value of the
0N/A * {@link java.awt.event.WindowEvent#getNewState} method of the
0N/A * {@code WindowEvent} received through the {@link
0N/A * java.awt.event.WindowStateListener}, rather than assuming
0N/A * that the state given to the {@code setExtendedState()} method
0N/A * will be definitely applied. For more information see the
0N/A * documentation for the {@link Frame#setExtendedState} method.
0N/A * </ul>
0N/A *
0N/A * @param state one of named frame state constants.
0N/A * @return <code>true</code> is this frame state is supported by
0N/A * this Toolkit implementation, <code>false</code> otherwise.
0N/A * @exception HeadlessException
0N/A * if <code>GraphicsEnvironment.isHeadless()</code>
0N/A * returns <code>true</code>.
0N/A * @see java.awt.Window#addWindowStateListener
0N/A * @since 1.4
0N/A */
0N/A public boolean isFrameStateSupported(int state)
0N/A throws HeadlessException
0N/A {
4193N/A GraphicsEnvironment.checkHeadless();
4193N/A
0N/A if (this != Toolkit.getDefaultToolkit()) {
0N/A return Toolkit.getDefaultToolkit().
0N/A isFrameStateSupported(state);
0N/A } else {
0N/A return (state == Frame.NORMAL); // others are not guaranteed
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Support for I18N: any visible strings should be stored in
0N/A * sun.awt.resources.awt.properties. The ResourceBundle is stored
0N/A * here, so that only one copy is maintained.
0N/A */
0N/A private static ResourceBundle resources;
0N/A
0N/A /**
0N/A * Initialize JNI field and method ids
0N/A */
0N/A private static native void initIDs();
0N/A
0N/A /**
0N/A * WARNING: This is a temporary workaround for a problem in the
0N/A * way the AWT loads native libraries. A number of classes in the
0N/A * AWT package have a native method, initIDs(), which initializes
0N/A * the JNI field and method ids used in the native portion of
0N/A * their implementation.
0N/A *
0N/A * Since the use and storage of these ids is done by the
0N/A * implementation libraries, the implementation of these method is
0N/A * provided by the particular AWT implementations (for example,
0N/A * "Toolkit"s/Peer), such as Motif, Microsoft Windows, or Tiny. The
0N/A * problem is that this means that the native libraries must be
0N/A * loaded by the java.* classes, which do not necessarily know the
0N/A * names of the libraries to load. A better way of doing this
0N/A * would be to provide a separate library which defines java.awt.*
0N/A * initIDs, and exports the relevant symbols out to the
0N/A * implementation libraries.
0N/A *
0N/A * For now, we know it's done by the implementation, and we assume
0N/A * that the name of the library is "awt". -br.
0N/A *
0N/A * If you change loadLibraries(), please add the change to
0N/A * java.awt.image.ColorModel.loadLibraries(). Unfortunately,
0N/A * classes can be loaded in java.awt.image that depend on
0N/A * libawt and there is no way to call Toolkit.loadLibraries()
0N/A * directly. -hung
0N/A */
0N/A private static boolean loaded = false;
0N/A static void loadLibraries() {
0N/A if (!loaded) {
0N/A java.security.AccessController.doPrivileged(
0N/A new sun.security.action.LoadLibraryAction("awt"));
0N/A loaded = true;
0N/A }
0N/A }
0N/A
0N/A static {
0N/A java.security.AccessController.doPrivileged(
0N/A new java.security.PrivilegedAction() {
0N/A public Object run() {
0N/A try {
0N/A resources =
0N/A ResourceBundle.getBundle("sun.awt.resources.awt",
0N/A CoreResourceBundleControl.getRBControlInstance());
0N/A } catch (MissingResourceException e) {
0N/A // No resource file; defaults will be used.
0N/A }
0N/A return null;
0N/A }
0N/A });
0N/A
0N/A // ensure that the proper libraries are loaded
0N/A loadLibraries();
0N/A initAssistiveTechnologies();
0N/A if (!GraphicsEnvironment.isHeadless()) {
0N/A initIDs();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets a property with the specified key and default.
0N/A * This method returns defaultValue if the property is not found.
0N/A */
0N/A public static String getProperty(String key, String defaultValue) {
0N/A if (resources != null) {
0N/A try {
0N/A return resources.getString(key);
0N/A }
0N/A catch (MissingResourceException e) {}
0N/A }
0N/A
0N/A return defaultValue;
0N/A }
0N/A
0N/A /**
0N/A * Get the application's or applet's EventQueue instance.
0N/A * Depending on the Toolkit implementation, different EventQueues
0N/A * may be returned for different applets. Applets should
0N/A * therefore not assume that the EventQueue instance returned
0N/A * by this method will be shared by other applets or the system.
0N/A *
0N/A * <p>First, if there is a security manager, its
0N/A * <code>checkAwtEventQueueAccess</code>
0N/A * method is called.
0N/A * If the default implementation of <code>checkAwtEventQueueAccess</code>
0N/A * is used (that is, that method is not overriden), then this results in
0N/A * a call to the security manager's <code>checkPermission</code> method
0N/A * with an <code>AWTPermission("accessEventQueue")</code> permission.
0N/A *
0N/A * @return the <code>EventQueue</code> object
0N/A * @throws SecurityException
0N/A * if a security manager exists and its <code>{@link
0N/A * java.lang.SecurityManager#checkAwtEventQueueAccess}</code>
0N/A * method denies access to the <code>EventQueue</code>
0N/A * @see java.awt.AWTPermission
0N/A */
0N/A public final EventQueue getSystemEventQueue() {
0N/A SecurityManager security = System.getSecurityManager();
0N/A if (security != null) {
0N/A security.checkAwtEventQueueAccess();
0N/A }
0N/A return getSystemEventQueueImpl();
0N/A }
0N/A
0N/A /**
0N/A * Gets the application's or applet's <code>EventQueue</code>
0N/A * instance, without checking access. For security reasons,
0N/A * this can only be called from a <code>Toolkit</code> subclass.
0N/A * @return the <code>EventQueue</code> object
0N/A */
0N/A protected abstract EventQueue getSystemEventQueueImpl();
0N/A
0N/A /* Accessor method for use by AWT package routines. */
0N/A static EventQueue getEventQueue() {
0N/A return getDefaultToolkit().getSystemEventQueueImpl();
0N/A }
0N/A
0N/A /**
0N/A * Creates the peer for a DragSourceContext.
0N/A * Always throws InvalidDndOperationException if
0N/A * GraphicsEnvironment.isHeadless() returns true.
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException;
0N/A
0N/A /**
0N/A * Creates a concrete, platform dependent, subclass of the abstract
0N/A * DragGestureRecognizer class requested, and associates it with the
0N/A * DragSource, Component and DragGestureListener specified.
0N/A *
0N/A * subclasses should override this to provide their own implementation
0N/A *
0N/A * @param abstractRecognizerClass The abstract class of the required recognizer
0N/A * @param ds The DragSource
0N/A * @param c The Component target for the DragGestureRecognizer
0N/A * @param srcActions The actions permitted for the gesture
0N/A * @param dgl The DragGestureListener
0N/A *
0N/A * @return the new object or null. Always returns null if
0N/A * GraphicsEnvironment.isHeadless() returns true.
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public <T extends DragGestureRecognizer> T
0N/A createDragGestureRecognizer(Class<T> abstractRecognizerClass,
0N/A DragSource ds, Component c, int srcActions,
0N/A DragGestureListener dgl)
0N/A {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Obtains a value for the specified desktop property.
0N/A *
0N/A * A desktop property is a uniquely named value for a resource that
0N/A * is Toolkit global in nature. Usually it also is an abstract
0N/A * representation for an underlying platform dependent desktop setting.
0N/A * For more information on desktop properties supported by the AWT see
0N/A * <a href="doc-files/DesktopProperties.html">AWT Desktop Properties</a>.
0N/A */
0N/A public final synchronized Object getDesktopProperty(String propertyName) {
0N/A // This is a workaround for headless toolkits. It would be
0N/A // better to override this method but it is declared final.
0N/A // "this instanceof" syntax defeats polymorphism.
0N/A // --mm, 03/03/00
0N/A if (this instanceof HeadlessToolkit) {
0N/A return ((HeadlessToolkit)this).getUnderlyingToolkit()
0N/A .getDesktopProperty(propertyName);
0N/A }
0N/A
0N/A if (desktopProperties.isEmpty()) {
0N/A initializeDesktopProperties();
0N/A }
0N/A
0N/A Object value;
0N/A
0N/A // This property should never be cached
0N/A if (propertyName.equals("awt.dynamicLayoutSupported")) {
0N/A value = lazilyLoadDesktopProperty(propertyName);
0N/A return value;
0N/A }
0N/A
0N/A value = desktopProperties.get(propertyName);
0N/A
0N/A if (value == null) {
0N/A value = lazilyLoadDesktopProperty(propertyName);
0N/A
0N/A if (value != null) {
0N/A setDesktopProperty(propertyName, value);
0N/A }
0N/A }
0N/A
0N/A /* for property "awt.font.desktophints" */
0N/A if (value instanceof RenderingHints) {
0N/A value = ((RenderingHints)value).clone();
0N/A }
0N/A
0N/A return value;
0N/A }
0N/A
0N/A /**
0N/A * Sets the named desktop property to the specified value and fires a
0N/A * property change event to notify any listeners that the value has changed.
0N/A */
0N/A protected final void setDesktopProperty(String name, Object newValue) {
0N/A // This is a workaround for headless toolkits. It would be
0N/A // better to override this method but it is declared final.
0N/A // "this instanceof" syntax defeats polymorphism.
0N/A // --mm, 03/03/00
0N/A if (this instanceof HeadlessToolkit) {
0N/A ((HeadlessToolkit)this).getUnderlyingToolkit()
0N/A .setDesktopProperty(name, newValue);
0N/A return;
0N/A }
0N/A Object oldValue;
0N/A
0N/A synchronized (this) {
0N/A oldValue = desktopProperties.get(name);
0N/A desktopProperties.put(name, newValue);
0N/A }
0N/A
2968N/A // Don't fire change event if old and new values are null.
2968N/A // It helps to avoid recursive resending of WM_THEMECHANGED
2968N/A if (oldValue != null || newValue != null) {
2968N/A desktopPropsSupport.firePropertyChange(name, oldValue, newValue);
2968N/A }
0N/A }
0N/A
0N/A /**
0N/A * an opportunity to lazily evaluate desktop property values.
0N/A */
0N/A protected Object lazilyLoadDesktopProperty(String name) {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * initializeDesktopProperties
0N/A */
0N/A protected void initializeDesktopProperties() {
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified property change listener for the named desktop
4078N/A * property. When a {@link PropertyChangeListenerProxy} object is added,
4078N/A * its property name is ignored, and the wrapped listener is added.
4078N/A * If {@code name} is {@code null} or {@code pcl} is {@code null},
4078N/A * no exception is thrown and no action is performed.
0N/A *
0N/A * @param name The name of the property to listen for
0N/A * @param pcl The property change listener
4078N/A * @see PropertyChangeSupport#addPropertyChangeListener(String,
4078N/A PropertyChangeListener)
0N/A * @since 1.2
0N/A */
0N/A public void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
0N/A desktopPropsSupport.addPropertyChangeListener(name, pcl);
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified property change listener for the named
4078N/A * desktop property. When a {@link PropertyChangeListenerProxy} object
4078N/A * is removed, its property name is ignored, and
4078N/A * the wrapped listener is removed.
4078N/A * If {@code name} is {@code null} or {@code pcl} is {@code null},
4078N/A * no exception is thrown and no action is performed.
0N/A *
0N/A * @param name The name of the property to remove
0N/A * @param pcl The property change listener
4078N/A * @see PropertyChangeSupport#removePropertyChangeListener(String,
4078N/A PropertyChangeListener)
0N/A * @since 1.2
0N/A */
0N/A public void removePropertyChangeListener(String name, PropertyChangeListener pcl) {
0N/A desktopPropsSupport.removePropertyChangeListener(name, pcl);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the property change listeners
4078N/A * registered on this toolkit. The returned array
4078N/A * contains {@code PropertyChangeListenerProxy} objects
4078N/A * that associate listeners with the names of desktop properties.
0N/A *
4078N/A * @return all of this toolkit's {@ code PropertyChangeListener}
4078N/A * objects wrapped in {@code PropertyChangeListenerProxy} objects
4078N/A * or an empty array if no listeners are added
0N/A *
4078N/A * @see PropertyChangeSupport#getPropertyChangeListeners()
0N/A * @since 1.4
0N/A */
0N/A public PropertyChangeListener[] getPropertyChangeListeners() {
0N/A return desktopPropsSupport.getPropertyChangeListeners();
0N/A }
0N/A
0N/A /**
4078N/A * Returns an array of all property change listeners
4078N/A * associated with the specified name of a desktop property.
0N/A *
0N/A * @param propertyName the named property
4078N/A * @return all of the {@code PropertyChangeListener} objects
4078N/A * associated with the specified name of a desktop property
4078N/A * or an empty array if no such listeners are added
4078N/A *
4078N/A * @see PropertyChangeSupport#getPropertyChangeListeners(String)
0N/A * @since 1.4
0N/A */
0N/A public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
0N/A return desktopPropsSupport.getPropertyChangeListeners(propertyName);
0N/A }
0N/A
0N/A protected final Map<String,Object> desktopProperties =
0N/A new HashMap<String,Object>();
0N/A protected final PropertyChangeSupport desktopPropsSupport =
0N/A Toolkit.createPropertyChangeSupport(this);
0N/A
0N/A /**
0N/A * Returns whether the always-on-top mode is supported by this toolkit.
0N/A * To detect whether the always-on-top mode is supported for a
0N/A * particular Window, use {@link Window#isAlwaysOnTopSupported}.
0N/A * @return <code>true</code>, if current toolkit supports the always-on-top mode,
0N/A * otherwise returns <code>false</code>
0N/A * @see Window#isAlwaysOnTopSupported
0N/A * @see Window#setAlwaysOnTop(boolean)
0N/A * @since 1.6
0N/A */
0N/A public boolean isAlwaysOnTopSupported() {
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the given modality type is supported by this toolkit. If
0N/A * a dialog with unsupported modality type is created, then
0N/A * <code>Dialog.ModalityType.MODELESS</code> is used instead.
0N/A *
0N/A * @param modalityType modality type to be checked for support by this toolkit
0N/A *
0N/A * @return <code>true</code>, if current toolkit supports given modality
0N/A * type, <code>false</code> otherwise
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog#getModalityType
0N/A * @see java.awt.Dialog#setModalityType
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public abstract boolean isModalityTypeSupported(Dialog.ModalityType modalityType);
0N/A
0N/A /**
0N/A * Returns whether the given modal exclusion type is supported by this
0N/A * toolkit. If an unsupported modal exclusion type property is set on a window,
0N/A * then <code>Dialog.ModalExclusionType.NO_EXCLUDE</code> is used instead.
0N/A *
0N/A * @param modalExclusionType modal exclusion type to be checked for support by this toolkit
0N/A *
0N/A * @return <code>true</code>, if current toolkit supports given modal exclusion
0N/A * type, <code>false</code> otherwise
0N/A *
0N/A * @see java.awt.Dialog.ModalExclusionType
0N/A * @see java.awt.Window#getModalExclusionType
0N/A * @see java.awt.Window#setModalExclusionType
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public abstract boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType modalExclusionType);
0N/A
1696N/A private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Toolkit");
0N/A
0N/A private static final int LONG_BITS = 64;
0N/A private int[] calls = new int[LONG_BITS];
0N/A private static volatile long enabledOnToolkitMask;
0N/A private AWTEventListener eventListener = null;
0N/A private WeakHashMap listener2SelectiveListener = new WeakHashMap();
0N/A
0N/A /*
0N/A * Extracts a "pure" AWTEventListener from a AWTEventListenerProxy,
0N/A * if the listener is proxied.
0N/A */
0N/A static private AWTEventListener deProxyAWTEventListener(AWTEventListener l)
0N/A {
0N/A AWTEventListener localL = l;
0N/A
0N/A if (localL == null) {
0N/A return null;
0N/A }
0N/A // if user passed in a AWTEventListenerProxy object, extract
0N/A // the listener
0N/A if (l instanceof AWTEventListenerProxy) {
0N/A localL = ((AWTEventListenerProxy)l).getListener();
0N/A }
0N/A return localL;
0N/A }
0N/A
0N/A /**
0N/A * Adds an AWTEventListener to receive all AWTEvents dispatched
0N/A * system-wide that conform to the given <code>eventMask</code>.
0N/A * <p>
0N/A * First, if there is a security manager, its <code>checkPermission</code>
0N/A * method is called with an
0N/A * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
0N/A * This may result in a SecurityException.
0N/A * <p>
0N/A * <code>eventMask</code> is a bitmask of event types to receive.
0N/A * It is constructed by bitwise OR-ing together the event masks
0N/A * defined in <code>AWTEvent</code>.
0N/A * <p>
0N/A * Note: event listener use is not recommended for normal
0N/A * application use, but are intended solely to support special
0N/A * purpose facilities including support for accessibility,
0N/A * event record/playback, and diagnostic tracing.
0N/A *
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param listener the event listener.
0N/A * @param eventMask the bitmask of event types to receive
0N/A * @throws SecurityException
0N/A * if a security manager exists and its
0N/A * <code>checkPermission</code> method doesn't allow the operation.
0N/A * @see #removeAWTEventListener
0N/A * @see #getAWTEventListeners
0N/A * @see SecurityManager#checkPermission
0N/A * @see java.awt.AWTEvent
0N/A * @see java.awt.AWTPermission
0N/A * @see java.awt.event.AWTEventListener
0N/A * @see java.awt.event.AWTEventListenerProxy
0N/A * @since 1.2
0N/A */
0N/A public void addAWTEventListener(AWTEventListener listener, long eventMask) {
0N/A AWTEventListener localL = deProxyAWTEventListener(listener);
0N/A
0N/A if (localL == null) {
0N/A return;
0N/A }
0N/A SecurityManager security = System.getSecurityManager();
0N/A if (security != null) {
1714N/A security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
0N/A }
0N/A synchronized (this) {
0N/A SelectiveAWTEventListener selectiveListener =
0N/A (SelectiveAWTEventListener)listener2SelectiveListener.get(localL);
0N/A
0N/A if (selectiveListener == null) {
0N/A // Create a new selectiveListener.
0N/A selectiveListener = new SelectiveAWTEventListener(localL,
0N/A eventMask);
0N/A listener2SelectiveListener.put(localL, selectiveListener);
0N/A eventListener = ToolkitEventMulticaster.add(eventListener,
0N/A selectiveListener);
0N/A }
0N/A // OR the eventMask into the selectiveListener's event mask.
0N/A selectiveListener.orEventMasks(eventMask);
0N/A
0N/A enabledOnToolkitMask |= eventMask;
0N/A
0N/A long mask = eventMask;
0N/A for (int i=0; i<LONG_BITS; i++) {
0N/A // If no bits are set, break out of loop.
0N/A if (mask == 0) {
0N/A break;
0N/A }
0N/A if ((mask & 1L) != 0) { // Always test bit 0.
0N/A calls[i]++;
0N/A }
0N/A mask >>>= 1; // Right shift, fill with zeros on left.
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes an AWTEventListener from receiving dispatched AWTEvents.
0N/A * <p>
0N/A * First, if there is a security manager, its <code>checkPermission</code>
0N/A * method is called with an
0N/A * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
0N/A * This may result in a SecurityException.
0N/A * <p>
0N/A * Note: event listener use is not recommended for normal
0N/A * application use, but are intended solely to support special
0N/A * purpose facilities including support for accessibility,
0N/A * event record/playback, and diagnostic tracing.
0N/A *
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param listener the event listener.
0N/A * @throws SecurityException
0N/A * if a security manager exists and its
0N/A * <code>checkPermission</code> method doesn't allow the operation.
0N/A * @see #addAWTEventListener
0N/A * @see #getAWTEventListeners
0N/A * @see SecurityManager#checkPermission
0N/A * @see java.awt.AWTEvent
0N/A * @see java.awt.AWTPermission
0N/A * @see java.awt.event.AWTEventListener
0N/A * @see java.awt.event.AWTEventListenerProxy
0N/A * @since 1.2
0N/A */
0N/A public void removeAWTEventListener(AWTEventListener listener) {
0N/A AWTEventListener localL = deProxyAWTEventListener(listener);
0N/A
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A SecurityManager security = System.getSecurityManager();
0N/A if (security != null) {
1714N/A security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
0N/A }
0N/A
0N/A synchronized (this) {
0N/A SelectiveAWTEventListener selectiveListener =
0N/A (SelectiveAWTEventListener)listener2SelectiveListener.get(localL);
0N/A
0N/A if (selectiveListener != null) {
0N/A listener2SelectiveListener.remove(localL);
0N/A int[] listenerCalls = selectiveListener.getCalls();
0N/A for (int i=0; i<LONG_BITS; i++) {
0N/A calls[i] -= listenerCalls[i];
0N/A assert calls[i] >= 0: "Negative Listeners count";
0N/A
0N/A if (calls[i] == 0) {
0N/A enabledOnToolkitMask &= ~(1L<<i);
0N/A }
0N/A }
0N/A }
0N/A eventListener = ToolkitEventMulticaster.remove(eventListener,
0N/A (selectiveListener == null) ? localL : selectiveListener);
0N/A }
0N/A }
0N/A
0N/A static boolean enabledOnToolkit(long eventMask) {
0N/A return (enabledOnToolkitMask & eventMask) != 0;
0N/A }
0N/A
0N/A synchronized int countAWTEventListeners(long eventMask) {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) {
0N/A if (eventMask == 0) {
1696N/A log.fine("Assertion (eventMask != 0) failed");
0N/A }
0N/A }
0N/A
0N/A int ci = 0;
0N/A for (; eventMask != 0; eventMask >>>= 1, ci++) {
0N/A }
0N/A ci--;
0N/A return calls[ci];
0N/A }
0N/A /**
0N/A * Returns an array of all the <code>AWTEventListener</code>s
0N/A * registered on this toolkit.
0N/A * If there is a security manager, its {@code checkPermission}
0N/A * method is called with an
0N/A * {@code AWTPermission("listenToAllAWTEvents")} permission.
0N/A * This may result in a SecurityException.
0N/A * Listeners can be returned
0N/A * within <code>AWTEventListenerProxy</code> objects, which also contain
0N/A * the event mask for the given listener.
0N/A * Note that listener objects
0N/A * added multiple times appear only once in the returned array.
0N/A *
0N/A * @return all of the <code>AWTEventListener</code>s or an empty
0N/A * array if no listeners are currently registered
0N/A * @throws SecurityException
0N/A * if a security manager exists and its
0N/A * <code>checkPermission</code> method doesn't allow the operation.
0N/A * @see #addAWTEventListener
0N/A * @see #removeAWTEventListener
0N/A * @see SecurityManager#checkPermission
0N/A * @see java.awt.AWTEvent
0N/A * @see java.awt.AWTPermission
0N/A * @see java.awt.event.AWTEventListener
0N/A * @see java.awt.event.AWTEventListenerProxy
0N/A * @since 1.4
0N/A */
0N/A public AWTEventListener[] getAWTEventListeners() {
0N/A SecurityManager security = System.getSecurityManager();
0N/A if (security != null) {
1714N/A security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
0N/A }
0N/A synchronized (this) {
0N/A EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
0N/A
0N/A AWTEventListener[] ret = new AWTEventListener[la.length];
0N/A for (int i = 0; i < la.length; i++) {
0N/A SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i];
0N/A AWTEventListener tempL = sael.getListener();
0N/A //assert tempL is not an AWTEventListenerProxy - we should
0N/A // have weeded them all out
0N/A // don't want to wrap a proxy inside a proxy
0N/A ret[i] = new AWTEventListenerProxy(sael.getEventMask(), tempL);
0N/A }
0N/A return ret;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the <code>AWTEventListener</code>s
0N/A * registered on this toolkit which listen to all of the event
0N/A * types specified in the {@code eventMask} argument.
0N/A * If there is a security manager, its {@code checkPermission}
0N/A * method is called with an
0N/A * {@code AWTPermission("listenToAllAWTEvents")} permission.
0N/A * This may result in a SecurityException.
0N/A * Listeners can be returned
0N/A * within <code>AWTEventListenerProxy</code> objects, which also contain
0N/A * the event mask for the given listener.
0N/A * Note that listener objects
0N/A * added multiple times appear only once in the returned array.
0N/A *
0N/A * @param eventMask the bitmask of event types to listen for
0N/A * @return all of the <code>AWTEventListener</code>s registered
0N/A * on this toolkit for the specified
0N/A * event types, or an empty array if no such listeners
0N/A * are currently registered
0N/A * @throws SecurityException
0N/A * if a security manager exists and its
0N/A * <code>checkPermission</code> method doesn't allow the operation.
0N/A * @see #addAWTEventListener
0N/A * @see #removeAWTEventListener
0N/A * @see SecurityManager#checkPermission
0N/A * @see java.awt.AWTEvent
0N/A * @see java.awt.AWTPermission
0N/A * @see java.awt.event.AWTEventListener
0N/A * @see java.awt.event.AWTEventListenerProxy
0N/A * @since 1.4
0N/A */
0N/A public AWTEventListener[] getAWTEventListeners(long eventMask) {
0N/A SecurityManager security = System.getSecurityManager();
0N/A if (security != null) {
1714N/A security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
0N/A }
0N/A synchronized (this) {
0N/A EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
0N/A
0N/A java.util.List list = new ArrayList(la.length);
0N/A
0N/A for (int i = 0; i < la.length; i++) {
0N/A SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i];
0N/A if ((sael.getEventMask() & eventMask) == eventMask) {
0N/A //AWTEventListener tempL = sael.getListener();
0N/A list.add(new AWTEventListenerProxy(sael.getEventMask(),
0N/A sael.getListener()));
0N/A }
0N/A }
0N/A return (AWTEventListener[])list.toArray(new AWTEventListener[0]);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * This method notifies any AWTEventListeners that an event
0N/A * is about to be dispatched.
0N/A *
0N/A * @param theEvent the event which will be dispatched.
0N/A */
0N/A void notifyAWTEventListeners(AWTEvent theEvent) {
0N/A // This is a workaround for headless toolkits. It would be
0N/A // better to override this method but it is declared package private.
0N/A // "this instanceof" syntax defeats polymorphism.
0N/A // --mm, 03/03/00
0N/A if (this instanceof HeadlessToolkit) {
0N/A ((HeadlessToolkit)this).getUnderlyingToolkit()
0N/A .notifyAWTEventListeners(theEvent);
0N/A return;
0N/A }
0N/A
0N/A AWTEventListener eventListener = this.eventListener;
0N/A if (eventListener != null) {
0N/A eventListener.eventDispatched(theEvent);
0N/A }
0N/A }
0N/A
0N/A static private class ToolkitEventMulticaster extends AWTEventMulticaster
0N/A implements AWTEventListener {
0N/A // Implementation cloned from AWTEventMulticaster.
0N/A
0N/A ToolkitEventMulticaster(AWTEventListener a, AWTEventListener b) {
0N/A super(a, b);
0N/A }
0N/A
0N/A static AWTEventListener add(AWTEventListener a,
0N/A AWTEventListener b) {
0N/A if (a == null) return b;
0N/A if (b == null) return a;
0N/A return new ToolkitEventMulticaster(a, b);
0N/A }
0N/A
0N/A static AWTEventListener remove(AWTEventListener l,
0N/A AWTEventListener oldl) {
0N/A return (AWTEventListener) removeInternal(l, oldl);
0N/A }
0N/A
0N/A // #4178589: must overload remove(EventListener) to call our add()
0N/A // instead of the static addInternal() so we allocate a
0N/A // ToolkitEventMulticaster instead of an AWTEventMulticaster.
0N/A // Note: this method is called by AWTEventListener.removeInternal(),
0N/A // so its method signature must match AWTEventListener.remove().
0N/A protected EventListener remove(EventListener oldl) {
0N/A if (oldl == a) return b;
0N/A if (oldl == b) return a;
0N/A AWTEventListener a2 = (AWTEventListener)removeInternal(a, oldl);
0N/A AWTEventListener b2 = (AWTEventListener)removeInternal(b, oldl);
0N/A if (a2 == a && b2 == b) {
0N/A return this; // it's not here
0N/A }
0N/A return add(a2, b2);
0N/A }
0N/A
0N/A public void eventDispatched(AWTEvent event) {
0N/A ((AWTEventListener)a).eventDispatched(event);
0N/A ((AWTEventListener)b).eventDispatched(event);
0N/A }
0N/A }
0N/A
0N/A private class SelectiveAWTEventListener implements AWTEventListener {
0N/A AWTEventListener listener;
0N/A private long eventMask;
0N/A // This array contains the number of times to call the eventlistener
0N/A // for each event type.
0N/A int[] calls = new int[Toolkit.LONG_BITS];
0N/A
0N/A public AWTEventListener getListener() {return listener;}
0N/A public long getEventMask() {return eventMask;}
0N/A public int[] getCalls() {return calls;}
0N/A
0N/A public void orEventMasks(long mask) {
0N/A eventMask |= mask;
0N/A // For each event bit set in mask, increment its call count.
0N/A for (int i=0; i<Toolkit.LONG_BITS; i++) {
0N/A // If no bits are set, break out of loop.
0N/A if (mask == 0) {
0N/A break;
0N/A }
0N/A if ((mask & 1L) != 0) { // Always test bit 0.
0N/A calls[i]++;
0N/A }
0N/A mask >>>= 1; // Right shift, fill with zeros on left.
0N/A }
0N/A }
0N/A
0N/A SelectiveAWTEventListener(AWTEventListener l, long mask) {
0N/A listener = l;
0N/A eventMask = mask;
0N/A }
0N/A
0N/A public void eventDispatched(AWTEvent event) {
0N/A long eventBit = 0; // Used to save the bit of the event type.
0N/A if (((eventBit = eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 &&
0N/A event.id >= ComponentEvent.COMPONENT_FIRST &&
0N/A event.id <= ComponentEvent.COMPONENT_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 &&
0N/A event.id >= ContainerEvent.CONTAINER_FIRST &&
0N/A event.id <= ContainerEvent.CONTAINER_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 &&
0N/A event.id >= FocusEvent.FOCUS_FIRST &&
0N/A event.id <= FocusEvent.FOCUS_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.KEY_EVENT_MASK) != 0 &&
0N/A event.id >= KeyEvent.KEY_FIRST &&
0N/A event.id <= KeyEvent.KEY_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 &&
0N/A event.id == MouseEvent.MOUSE_WHEEL)
0N/A || ((eventBit = eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 &&
0N/A (event.id == MouseEvent.MOUSE_MOVED ||
0N/A event.id == MouseEvent.MOUSE_DRAGGED))
0N/A || ((eventBit = eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 &&
0N/A event.id != MouseEvent.MOUSE_MOVED &&
0N/A event.id != MouseEvent.MOUSE_DRAGGED &&
0N/A event.id != MouseEvent.MOUSE_WHEEL &&
0N/A event.id >= MouseEvent.MOUSE_FIRST &&
0N/A event.id <= MouseEvent.MOUSE_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 &&
0N/A (event.id >= WindowEvent.WINDOW_FIRST &&
0N/A event.id <= WindowEvent.WINDOW_LAST))
0N/A || ((eventBit = eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 &&
0N/A event.id >= ActionEvent.ACTION_FIRST &&
0N/A event.id <= ActionEvent.ACTION_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 &&
0N/A event.id >= AdjustmentEvent.ADJUSTMENT_FIRST &&
0N/A event.id <= AdjustmentEvent.ADJUSTMENT_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 &&
0N/A event.id >= ItemEvent.ITEM_FIRST &&
0N/A event.id <= ItemEvent.ITEM_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.TEXT_EVENT_MASK) != 0 &&
0N/A event.id >= TextEvent.TEXT_FIRST &&
0N/A event.id <= TextEvent.TEXT_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 &&
0N/A event.id >= InputMethodEvent.INPUT_METHOD_FIRST &&
0N/A event.id <= InputMethodEvent.INPUT_METHOD_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.PAINT_EVENT_MASK) != 0 &&
0N/A event.id >= PaintEvent.PAINT_FIRST &&
0N/A event.id <= PaintEvent.PAINT_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.INVOCATION_EVENT_MASK) != 0 &&
0N/A event.id >= InvocationEvent.INVOCATION_FIRST &&
0N/A event.id <= InvocationEvent.INVOCATION_LAST)
0N/A || ((eventBit = eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
0N/A event.id == HierarchyEvent.HIERARCHY_CHANGED)
0N/A || ((eventBit = eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 &&
0N/A (event.id == HierarchyEvent.ANCESTOR_MOVED ||
0N/A event.id == HierarchyEvent.ANCESTOR_RESIZED))
0N/A || ((eventBit = eventMask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 &&
0N/A event.id == WindowEvent.WINDOW_STATE_CHANGED)
0N/A || ((eventBit = eventMask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 &&
0N/A (event.id == WindowEvent.WINDOW_GAINED_FOCUS ||
0N/A event.id == WindowEvent.WINDOW_LOST_FOCUS))
0N/A || ((eventBit = eventMask & sun.awt.SunToolkit.GRAB_EVENT_MASK) != 0 &&
0N/A (event instanceof sun.awt.UngrabEvent))) {
0N/A // Get the index of the call count for this event type.
0N/A // Instead of using Math.log(...) we will calculate it with
0N/A // bit shifts. That's what previous implementation looked like:
0N/A //
0N/A // int ci = (int) (Math.log(eventBit)/Math.log(2));
0N/A int ci = 0;
0N/A for (long eMask = eventBit; eMask != 0; eMask >>>= 1, ci++) {
0N/A }
0N/A ci--;
0N/A // Call the listener as many times as it was added for this
0N/A // event type.
0N/A for (int i=0; i<calls[ci]; i++) {
0N/A listener.eventDispatched(event);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a map of visual attributes for the abstract level description
0N/A * of the given input method highlight, or null if no mapping is found.
0N/A * The style field of the input method highlight is ignored. The map
0N/A * returned is unmodifiable.
0N/A * @param highlight input method highlight
0N/A * @return style attribute map, or <code>null</code>
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.3
0N/A */
0N/A public abstract Map<java.awt.font.TextAttribute,?>
0N/A mapInputMethodHighlight(InputMethodHighlight highlight)
0N/A throws HeadlessException;
0N/A
0N/A private static PropertyChangeSupport createPropertyChangeSupport(Toolkit toolkit) {
0N/A if (toolkit instanceof SunToolkit || toolkit instanceof HeadlessToolkit) {
0N/A return new DesktopPropertyChangeSupport(toolkit);
0N/A } else {
0N/A return new PropertyChangeSupport(toolkit);
0N/A }
0N/A }
0N/A
0N/A private static class DesktopPropertyChangeSupport extends PropertyChangeSupport {
0N/A private static final StringBuilder PROP_CHANGE_SUPPORT_KEY =
0N/A new StringBuilder("desktop property change support key");
0N/A private final Object source;
0N/A
0N/A public DesktopPropertyChangeSupport(Object sourceBean) {
0N/A super(sourceBean);
0N/A source = sourceBean;
0N/A }
0N/A
0N/A @Override
0N/A public synchronized void addPropertyChangeListener(
0N/A String propertyName,
0N/A PropertyChangeListener listener)
0N/A {
0N/A PropertyChangeSupport pcs = (PropertyChangeSupport)
0N/A AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
0N/A if (null == pcs) {
0N/A pcs = new PropertyChangeSupport(source);
0N/A AppContext.getAppContext().put(PROP_CHANGE_SUPPORT_KEY, pcs);
0N/A }
0N/A pcs.addPropertyChangeListener(propertyName, listener);
0N/A }
0N/A
0N/A @Override
0N/A public synchronized void removePropertyChangeListener(
0N/A String propertyName,
0N/A PropertyChangeListener listener)
0N/A {
0N/A PropertyChangeSupport pcs = (PropertyChangeSupport)
0N/A AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
0N/A if (null != pcs) {
0N/A pcs.removePropertyChangeListener(propertyName, listener);
0N/A }
0N/A }
0N/A
0N/A @Override
0N/A public synchronized PropertyChangeListener[] getPropertyChangeListeners()
0N/A {
0N/A PropertyChangeSupport pcs = (PropertyChangeSupport)
0N/A AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
0N/A if (null != pcs) {
0N/A return pcs.getPropertyChangeListeners();
0N/A } else {
0N/A return new PropertyChangeListener[0];
0N/A }
0N/A }
0N/A
0N/A @Override
0N/A public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
0N/A {
0N/A PropertyChangeSupport pcs = (PropertyChangeSupport)
0N/A AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
0N/A if (null != pcs) {
0N/A return pcs.getPropertyChangeListeners(propertyName);
0N/A } else {
0N/A return new PropertyChangeListener[0];
0N/A }
0N/A }
0N/A
0N/A @Override
0N/A public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
0N/A PropertyChangeSupport pcs = (PropertyChangeSupport)
0N/A AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
0N/A if (null == pcs) {
0N/A pcs = new PropertyChangeSupport(source);
0N/A AppContext.getAppContext().put(PROP_CHANGE_SUPPORT_KEY, pcs);
0N/A }
0N/A pcs.addPropertyChangeListener(listener);
0N/A }
0N/A
0N/A @Override
0N/A public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
0N/A PropertyChangeSupport pcs = (PropertyChangeSupport)
0N/A AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
0N/A if (null != pcs) {
0N/A pcs.removePropertyChangeListener(listener);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * we do expect that all other fireXXX() methods of java.beans.PropertyChangeSupport
0N/A * use this method. If this will be changed we will need to change this class.
0N/A */
0N/A @Override
0N/A public void firePropertyChange(final PropertyChangeEvent evt) {
0N/A Object oldValue = evt.getOldValue();
0N/A Object newValue = evt.getNewValue();
0N/A String propertyName = evt.getPropertyName();
0N/A if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
0N/A return;
0N/A }
0N/A Runnable updater = new Runnable() {
0N/A public void run() {
0N/A PropertyChangeSupport pcs = (PropertyChangeSupport)
0N/A AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
0N/A if (null != pcs) {
0N/A pcs.firePropertyChange(evt);
0N/A }
0N/A }
0N/A };
0N/A final AppContext currentAppContext = AppContext.getAppContext();
0N/A for (AppContext appContext : AppContext.getAppContexts()) {
0N/A if (null == appContext || appContext.isDisposed()) {
0N/A continue;
0N/A }
0N/A if (currentAppContext == appContext) {
0N/A updater.run();
0N/A } else {
0N/A final PeerEvent e = new PeerEvent(source, updater, PeerEvent.ULTIMATE_PRIORITY_EVENT);
0N/A SunToolkit.postEvent(appContext, e);
0N/A }
0N/A }
0N/A }
0N/A }
870N/A
870N/A /**
870N/A * Reports whether events from extra mouse buttons are allowed to be processed and posted into
870N/A * {@code EventQueue}.
870N/A * <br>
870N/A * To change the returned value it is necessary to set the {@code sun.awt.enableExtraMouseButtons}
870N/A * property before the {@code Toolkit} class initialization. This setting could be done on the application
870N/A * startup by the following command:
870N/A * <pre>
870N/A * java -Dsun.awt.enableExtraMouseButtons=false Application
870N/A * </pre>
870N/A * Alternatively, the property could be set in the application by using the following code:
870N/A * <pre>
870N/A * System.setProperty("sun.awt.enableExtraMouseButtons", "true");
870N/A * </pre>
870N/A * before the {@code Toolkit} class initialization.
870N/A * If not set by the time of the {@code Toolkit} class initialization, this property will be
870N/A * initialized with {@code true}.
870N/A * Changing this value after the {@code Toolkit} class initialization will have no effect.
870N/A * <p>
870N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
870N/A * @return {@code true} if events from extra mouse buttons are allowed to be processed and posted;
870N/A * {@code false} otherwise
870N/A * @see System#getProperty(String propertyName)
870N/A * @see System#setProperty(String propertyName, String value)
870N/A * @see java.awt.EventQueue
870N/A * @since 1.7
870N/A */
870N/A public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
4193N/A GraphicsEnvironment.checkHeadless();
4193N/A
870N/A return Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled();
870N/A }
0N/A}