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