0001: /*
0002: * Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved.
0003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004: *
0005: * This code is free software; you can redistribute it and/or modify it
0006: * under the terms of the GNU General Public License version 2 only, as
0007: * published by the Free Software Foundation. Sun designates this
0008: * particular file as subject to the "Classpath" exception as provided
0009: * by Sun in the LICENSE file that accompanied this code.
0010: *
0011: * This code is distributed in the hope that it will be useful, but WITHOUT
0012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0014: * version 2 for more details (a copy is included in the LICENSE file that
0015: * accompanied this code).
0016: *
0017: * You should have received a copy of the GNU General Public License version
0018: * 2 along with this work; if not, write to the Free Software Foundation,
0019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020: *
0021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022: * CA 95054 USA or visit www.sun.com if you need additional information or
0023: * have any questions.
0024: */
0025:
0026: package java.awt;
0027:
0028: import java.beans.PropertyChangeEvent;
0029: import java.util.MissingResourceException;
0030: import java.util.Properties;
0031: import java.util.ResourceBundle;
0032: import java.util.StringTokenizer;
0033: import java.awt.event.*;
0034: import java.awt.peer.*;
0035: import java.awt.im.InputMethodHighlight;
0036: import java.awt.image.ImageObserver;
0037: import java.awt.image.ImageProducer;
0038: import java.awt.image.ColorModel;
0039: import java.awt.datatransfer.Clipboard;
0040: import java.awt.dnd.DragSource;
0041: import java.awt.dnd.DragGestureRecognizer;
0042: import java.awt.dnd.DragGestureEvent;
0043: import java.awt.dnd.DragGestureListener;
0044: import java.awt.dnd.InvalidDnDOperationException;
0045: import java.awt.dnd.peer.DragSourceContextPeer;
0046: import java.net.URL;
0047: import java.io.File;
0048: import java.io.FileInputStream;
0049:
0050: import java.util.EventListener;
0051: import java.util.Map;
0052: import java.util.HashMap;
0053: import java.util.WeakHashMap;
0054: import java.util.ArrayList;
0055:
0056: import java.beans.PropertyChangeListener;
0057: import java.beans.PropertyChangeSupport;
0058: import sun.awt.AppContext;
0059:
0060: import sun.awt.DebugHelper;
0061: import sun.awt.HeadlessToolkit;
0062: import sun.awt.NullComponentPeer;
0063: import sun.awt.PeerEvent;
0064: import sun.awt.SunToolkit;
0065: import sun.security.util.SecurityConstants;
0066:
0067: import sun.util.CoreResourceBundleControl;
0068:
0069: /**
0070: * This class is the abstract superclass of all actual
0071: * implementations of the Abstract Window Toolkit. Subclasses of
0072: * <code>Toolkit</code> are used to bind the various components
0073: * to particular native toolkit implementations.
0074: * <p>
0075: * Many GUI operations may be performed asynchronously. This
0076: * means that if you set the state of a component, and then
0077: * immediately query the state, the returned value may not yet
0078: * reflect the requested change. This includes, but is not
0079: * limited to:
0080: * <ul>
0081: * <li>Scrolling to a specified position.
0082: * <br>For example, calling <code>ScrollPane.setScrollPosition</code>
0083: * and then <code>getScrollPosition</code> may return an incorrect
0084: * value if the original request has not yet been processed.
0085: * <p>
0086: * <li>Moving the focus from one component to another.
0087: * <br>For more information, see
0088: * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#transferTiming">Timing
0089: * Focus Transfers</a>, a section in
0090: * <a href="http://java.sun.com/docs/books/tutorial/uiswing/">The Swing
0091: * Tutorial</a>.
0092: * <p>
0093: * <li>Making a top-level container visible.
0094: * <br>Calling <code>setVisible(true)</code> on a <code>Window</code>,
0095: * <code>Frame</code> or <code>Dialog</code> may occur
0096: * asynchronously.
0097: * <p>
0098: * <li>Setting the size or location of a top-level container.
0099: * <br>Calls to <code>setSize</code>, <code>setBounds</code> or
0100: * <code>setLocation</code> on a <code>Window</code>,
0101: * <code>Frame</code> or <code>Dialog</code> are forwarded
0102: * to the underlying window management system and may be
0103: * ignored or modified. See {@link java.awt.Window} for
0104: * more information.
0105: * </ul>
0106: * <p>
0107: * Most applications should not call any of the methods in this
0108: * class directly. The methods defined by <code>Toolkit</code> are
0109: * the "glue" that joins the platform-independent classes in the
0110: * <code>java.awt</code> package with their counterparts in
0111: * <code>java.awt.peer</code>. Some methods defined by
0112: * <code>Toolkit</code> query the native operating system directly.
0113: *
0114: * @version 1.203, 12/19/03
0115: * @author Sami Shaio
0116: * @author Arthur van Hoff
0117: * @author Fred Ecks
0118: * @since JDK1.0
0119: */
0120: public abstract class Toolkit {
0121:
0122: /**
0123: * Creates this toolkit's implementation of the <code>Desktop</code>
0124: * using the specified peer interface.
0125: * @param target the desktop to be implemented
0126: * @return this toolkit's implementation of the <code>Desktop</code>
0127: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0128: * returns true
0129: * @see java.awt.GraphicsEnvironment#isHeadless
0130: * @see java.awt.Desktop
0131: * @see java.awt.peer.DesktopPeer
0132: * @since 1.6
0133: */
0134: protected abstract DesktopPeer createDesktopPeer(Desktop target)
0135: throws HeadlessException;
0136:
0137: /**
0138: * Creates this toolkit's implementation of <code>Button</code> using
0139: * the specified peer interface.
0140: * @param target the button to be implemented.
0141: * @return this toolkit's implementation of <code>Button</code>.
0142: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0143: * returns true
0144: * @see java.awt.GraphicsEnvironment#isHeadless
0145: * @see java.awt.Button
0146: * @see java.awt.peer.ButtonPeer
0147: */
0148: protected abstract ButtonPeer createButton(Button target)
0149: throws HeadlessException;
0150:
0151: /**
0152: * Creates this toolkit's implementation of <code>TextField</code> using
0153: * the specified peer interface.
0154: * @param target the text field to be implemented.
0155: * @return this toolkit's implementation of <code>TextField</code>.
0156: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0157: * returns true
0158: * @see java.awt.GraphicsEnvironment#isHeadless
0159: * @see java.awt.TextField
0160: * @see java.awt.peer.TextFieldPeer
0161: */
0162: protected abstract TextFieldPeer createTextField(TextField target)
0163: throws HeadlessException;
0164:
0165: /**
0166: * Creates this toolkit's implementation of <code>Label</code> using
0167: * the specified peer interface.
0168: * @param target the label to be implemented.
0169: * @return this toolkit's implementation of <code>Label</code>.
0170: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0171: * returns true
0172: * @see java.awt.GraphicsEnvironment#isHeadless
0173: * @see java.awt.Label
0174: * @see java.awt.peer.LabelPeer
0175: */
0176: protected abstract LabelPeer createLabel(Label target)
0177: throws HeadlessException;
0178:
0179: /**
0180: * Creates this toolkit's implementation of <code>List</code> using
0181: * the specified peer interface.
0182: * @param target the list to be implemented.
0183: * @return this toolkit's implementation of <code>List</code>.
0184: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0185: * returns true
0186: * @see java.awt.GraphicsEnvironment#isHeadless
0187: * @see java.awt.List
0188: * @see java.awt.peer.ListPeer
0189: */
0190: protected abstract ListPeer createList(java.awt.List target)
0191: throws HeadlessException;
0192:
0193: /**
0194: * Creates this toolkit's implementation of <code>Checkbox</code> using
0195: * the specified peer interface.
0196: * @param target the check box to be implemented.
0197: * @return this toolkit's implementation of <code>Checkbox</code>.
0198: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0199: * returns true
0200: * @see java.awt.GraphicsEnvironment#isHeadless
0201: * @see java.awt.Checkbox
0202: * @see java.awt.peer.CheckboxPeer
0203: */
0204: protected abstract CheckboxPeer createCheckbox(Checkbox target)
0205: throws HeadlessException;
0206:
0207: /**
0208: * Creates this toolkit's implementation of <code>Scrollbar</code> using
0209: * the specified peer interface.
0210: * @param target the scroll bar to be implemented.
0211: * @return this toolkit's implementation of <code>Scrollbar</code>.
0212: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0213: * returns true
0214: * @see java.awt.GraphicsEnvironment#isHeadless
0215: * @see java.awt.Scrollbar
0216: * @see java.awt.peer.ScrollbarPeer
0217: */
0218: protected abstract ScrollbarPeer createScrollbar(Scrollbar target)
0219: throws HeadlessException;
0220:
0221: /**
0222: * Creates this toolkit's implementation of <code>ScrollPane</code> using
0223: * the specified peer interface.
0224: * @param target the scroll pane to be implemented.
0225: * @return this toolkit's implementation of <code>ScrollPane</code>.
0226: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0227: * returns true
0228: * @see java.awt.GraphicsEnvironment#isHeadless
0229: * @see java.awt.ScrollPane
0230: * @see java.awt.peer.ScrollPanePeer
0231: * @since JDK1.1
0232: */
0233: protected abstract ScrollPanePeer createScrollPane(ScrollPane target)
0234: throws HeadlessException;
0235:
0236: /**
0237: * Creates this toolkit's implementation of <code>TextArea</code> using
0238: * the specified peer interface.
0239: * @param target the text area to be implemented.
0240: * @return this toolkit's implementation of <code>TextArea</code>.
0241: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0242: * returns true
0243: * @see java.awt.GraphicsEnvironment#isHeadless
0244: * @see java.awt.TextArea
0245: * @see java.awt.peer.TextAreaPeer
0246: */
0247: protected abstract TextAreaPeer createTextArea(TextArea target)
0248: throws HeadlessException;
0249:
0250: /**
0251: * Creates this toolkit's implementation of <code>Choice</code> using
0252: * the specified peer interface.
0253: * @param target the choice to be implemented.
0254: * @return this toolkit's implementation of <code>Choice</code>.
0255: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0256: * returns true
0257: * @see java.awt.GraphicsEnvironment#isHeadless
0258: * @see java.awt.Choice
0259: * @see java.awt.peer.ChoicePeer
0260: */
0261: protected abstract ChoicePeer createChoice(Choice target)
0262: throws HeadlessException;
0263:
0264: /**
0265: * Creates this toolkit's implementation of <code>Frame</code> using
0266: * the specified peer interface.
0267: * @param target the frame to be implemented.
0268: * @return this toolkit's implementation of <code>Frame</code>.
0269: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0270: * returns true
0271: * @see java.awt.GraphicsEnvironment#isHeadless
0272: * @see java.awt.Frame
0273: * @see java.awt.peer.FramePeer
0274: */
0275: protected abstract FramePeer createFrame(Frame target)
0276: throws HeadlessException;
0277:
0278: /**
0279: * Creates this toolkit's implementation of <code>Canvas</code> using
0280: * the specified peer interface.
0281: * @param target the canvas to be implemented.
0282: * @return this toolkit's implementation of <code>Canvas</code>.
0283: * @see java.awt.Canvas
0284: * @see java.awt.peer.CanvasPeer
0285: */
0286: protected abstract CanvasPeer createCanvas(Canvas target);
0287:
0288: /**
0289: * Creates this toolkit's implementation of <code>Panel</code> using
0290: * the specified peer interface.
0291: * @param target the panel to be implemented.
0292: * @return this toolkit's implementation of <code>Panel</code>.
0293: * @see java.awt.Panel
0294: * @see java.awt.peer.PanelPeer
0295: */
0296: protected abstract PanelPeer createPanel(Panel target);
0297:
0298: /**
0299: * Creates this toolkit's implementation of <code>Window</code> using
0300: * the specified peer interface.
0301: * @param target the window to be implemented.
0302: * @return this toolkit's implementation of <code>Window</code>.
0303: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0304: * returns true
0305: * @see java.awt.GraphicsEnvironment#isHeadless
0306: * @see java.awt.Window
0307: * @see java.awt.peer.WindowPeer
0308: */
0309: protected abstract WindowPeer createWindow(Window target)
0310: throws HeadlessException;
0311:
0312: /**
0313: * Creates this toolkit's implementation of <code>Dialog</code> using
0314: * the specified peer interface.
0315: * @param target the dialog to be implemented.
0316: * @return this toolkit's implementation of <code>Dialog</code>.
0317: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0318: * returns true
0319: * @see java.awt.GraphicsEnvironment#isHeadless
0320: * @see java.awt.Dialog
0321: * @see java.awt.peer.DialogPeer
0322: */
0323: protected abstract DialogPeer createDialog(Dialog target)
0324: throws HeadlessException;
0325:
0326: /**
0327: * Creates this toolkit's implementation of <code>MenuBar</code> using
0328: * the specified peer interface.
0329: * @param target the menu bar to be implemented.
0330: * @return this toolkit's implementation of <code>MenuBar</code>.
0331: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0332: * returns true
0333: * @see java.awt.GraphicsEnvironment#isHeadless
0334: * @see java.awt.MenuBar
0335: * @see java.awt.peer.MenuBarPeer
0336: */
0337: protected abstract MenuBarPeer createMenuBar(MenuBar target)
0338: throws HeadlessException;
0339:
0340: /**
0341: * Creates this toolkit's implementation of <code>Menu</code> using
0342: * the specified peer interface.
0343: * @param target the menu to be implemented.
0344: * @return this toolkit's implementation of <code>Menu</code>.
0345: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0346: * returns true
0347: * @see java.awt.GraphicsEnvironment#isHeadless
0348: * @see java.awt.Menu
0349: * @see java.awt.peer.MenuPeer
0350: */
0351: protected abstract MenuPeer createMenu(Menu target)
0352: throws HeadlessException;
0353:
0354: /**
0355: * Creates this toolkit's implementation of <code>PopupMenu</code> using
0356: * the specified peer interface.
0357: * @param target the popup menu to be implemented.
0358: * @return this toolkit's implementation of <code>PopupMenu</code>.
0359: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0360: * returns true
0361: * @see java.awt.GraphicsEnvironment#isHeadless
0362: * @see java.awt.PopupMenu
0363: * @see java.awt.peer.PopupMenuPeer
0364: * @since JDK1.1
0365: */
0366: protected abstract PopupMenuPeer createPopupMenu(PopupMenu target)
0367: throws HeadlessException;
0368:
0369: /**
0370: * Creates this toolkit's implementation of <code>MenuItem</code> using
0371: * the specified peer interface.
0372: * @param target the menu item to be implemented.
0373: * @return this toolkit's implementation of <code>MenuItem</code>.
0374: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0375: * returns true
0376: * @see java.awt.GraphicsEnvironment#isHeadless
0377: * @see java.awt.MenuItem
0378: * @see java.awt.peer.MenuItemPeer
0379: */
0380: protected abstract MenuItemPeer createMenuItem(MenuItem target)
0381: throws HeadlessException;
0382:
0383: /**
0384: * Creates this toolkit's implementation of <code>FileDialog</code> using
0385: * the specified peer interface.
0386: * @param target the file dialog to be implemented.
0387: * @return this toolkit's implementation of <code>FileDialog</code>.
0388: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0389: * returns true
0390: * @see java.awt.GraphicsEnvironment#isHeadless
0391: * @see java.awt.FileDialog
0392: * @see java.awt.peer.FileDialogPeer
0393: */
0394: protected abstract FileDialogPeer createFileDialog(FileDialog target)
0395: throws HeadlessException;
0396:
0397: /**
0398: * Creates this toolkit's implementation of <code>CheckboxMenuItem</code> using
0399: * the specified peer interface.
0400: * @param target the checkbox menu item to be implemented.
0401: * @return this toolkit's implementation of <code>CheckboxMenuItem</code>.
0402: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0403: * returns true
0404: * @see java.awt.GraphicsEnvironment#isHeadless
0405: * @see java.awt.CheckboxMenuItem
0406: * @see java.awt.peer.CheckboxMenuItemPeer
0407: */
0408: protected abstract CheckboxMenuItemPeer createCheckboxMenuItem(
0409: CheckboxMenuItem target) throws HeadlessException;
0410:
0411: /**
0412: * Obtains this toolkit's implementation of helper class for
0413: * <code>MouseInfo</code> operations.
0414: * @return this toolkit's implementation of helper for <code>MouseInfo</code>
0415: * @throws UnsupportedOperationException if this operation is not implemented
0416: * @see java.awt.peer.MouseInfoPeer
0417: * @see java.awt.MouseInfo
0418: * @since 1.5
0419: */
0420: protected MouseInfoPeer getMouseInfoPeer() {
0421: throw new UnsupportedOperationException("Not implemented");
0422: }
0423:
0424: private static LightweightPeer lightweightMarker;
0425:
0426: /**
0427: * Creates a peer for a component or container. This peer is windowless
0428: * and allows the Component and Container classes to be extended directly
0429: * to create windowless components that are defined entirely in java.
0430: *
0431: * @param target The Component to be created.
0432: */
0433: protected LightweightPeer createComponent(Component target) {
0434: if (lightweightMarker == null) {
0435: lightweightMarker = new NullComponentPeer();
0436: }
0437: return lightweightMarker;
0438: }
0439:
0440: /**
0441: * Creates this toolkit's implementation of <code>Font</code> using
0442: * the specified peer interface.
0443: * @param name the font to be implemented
0444: * @param style the style of the font, such as <code>PLAIN</code>,
0445: * <code>BOLD</code>, <code>ITALIC</code>, or a combination
0446: * @return this toolkit's implementation of <code>Font</code>
0447: * @see java.awt.Font
0448: * @see java.awt.peer.FontPeer
0449: * @see java.awt.GraphicsEnvironment#getAllFonts
0450: * @deprecated see java.awt.GraphicsEnvironment#getAllFonts
0451: */
0452: @Deprecated
0453: protected abstract FontPeer getFontPeer(String name, int style);
0454:
0455: // The following method is called by the private method
0456: // <code>updateSystemColors</code> in <code>SystemColor</code>.
0457:
0458: /**
0459: * Fills in the integer array that is supplied as an argument
0460: * with the current system color values.
0461: *
0462: * @param systemColors an integer array.
0463: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0464: * returns true
0465: * @see java.awt.GraphicsEnvironment#isHeadless
0466: * @since JDK1.1
0467: */
0468: protected void loadSystemColors(int[] systemColors)
0469: throws HeadlessException {
0470: }
0471:
0472: /**
0473: * Controls whether the layout of Containers is validated dynamically
0474: * during resizing, or statically, after resizing is complete.
0475: * Use {@code isDynamicLayoutActive()} to detect if this feature enabled
0476: * in this program and is supported by this operating system
0477: * and/or window manager.
0478: * Note that this feature is supported not on all platforms, and
0479: * conversely, that this feature cannot be turned off on some platforms.
0480: * On these platforms where dynamic layout during resizing is not supported
0481: * (or is always supported), setting this property has no effect.
0482: * Note that this feature can be set or unset as a property of the
0483: * operating system or window manager on some platforms. On such
0484: * platforms, the dynamic resize property must be set at the operating
0485: * system or window manager level before this method can take effect.
0486: * This method does not change support or settings of the underlying
0487: * operating system or
0488: * window manager. The OS/WM support can be
0489: * queried using getDesktopProperty("awt.dynamicLayoutSupported") method.
0490: *
0491: * @param dynamic If true, Containers should re-layout their
0492: * components as the Container is being resized. If false,
0493: * the layout will be validated after resizing is completed.
0494: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0495: * returns true
0496: * @see #isDynamicLayoutSet()
0497: * @see #isDynamicLayoutActive()
0498: * @see #getDesktopProperty(String propertyName)
0499: * @see java.awt.GraphicsEnvironment#isHeadless
0500: * @since 1.4
0501: */
0502: public void setDynamicLayout(boolean dynamic)
0503: throws HeadlessException {
0504: }
0505:
0506: /**
0507: * Returns whether the layout of Containers is validated dynamically
0508: * during resizing, or statically, after resizing is complete.
0509: * Note: this method returns the value that was set programmatically;
0510: * it does not reflect support at the level of the operating system
0511: * or window manager for dynamic layout on resizing, or the current
0512: * operating system or window manager settings. The OS/WM support can
0513: * be queried using getDesktopProperty("awt.dynamicLayoutSupported").
0514: *
0515: * @return true if validation of Containers is done dynamically,
0516: * false if validation is done after resizing is finished.
0517: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0518: * returns true
0519: * @see #setDynamicLayout(boolean dynamic)
0520: * @see #isDynamicLayoutActive()
0521: * @see #getDesktopProperty(String propertyName)
0522: * @see java.awt.GraphicsEnvironment#isHeadless
0523: * @since 1.4
0524: */
0525: protected boolean isDynamicLayoutSet() throws HeadlessException {
0526: if (this != Toolkit.getDefaultToolkit()) {
0527: return Toolkit.getDefaultToolkit().isDynamicLayoutSet();
0528: } else {
0529: return false;
0530: }
0531: }
0532:
0533: /**
0534: * Returns whether dynamic layout of Containers on resize is
0535: * currently active (both set in program
0536: *( {@code isDynamicLayoutSet()} )
0537: *, and supported
0538: * by the underlying operating system and/or window manager).
0539: * If dynamic layout is currently inactive then Containers
0540: * re-layout their components when resizing is completed. As a result
0541: * the {@code Component.validate()} method will be invoked only
0542: * once per resize.
0543: * If dynamic layout is currently active then Containers
0544: * re-layout their components on every native resize event and
0545: * the {@code validate()} method will be invoked each time.
0546: * The OS/WM support can be queried using
0547: * the getDesktopProperty("awt.dynamicLayoutSupported") method.
0548: *
0549: * @return true if dynamic layout of Containers on resize is
0550: * currently active, false otherwise.
0551: * @exception HeadlessException if the GraphicsEnvironment.isHeadless()
0552: * method returns true
0553: * @see #setDynamicLayout(boolean dynamic)
0554: * @see #isDynamicLayoutSet()
0555: * @see #getDesktopProperty(String propertyName)
0556: * @see java.awt.GraphicsEnvironment#isHeadless
0557: * @since 1.4
0558: */
0559: public boolean isDynamicLayoutActive() throws HeadlessException {
0560: if (this != Toolkit.getDefaultToolkit()) {
0561: return Toolkit.getDefaultToolkit().isDynamicLayoutActive();
0562: } else {
0563: return false;
0564: }
0565: }
0566:
0567: /**
0568: * Gets the size of the screen. On systems with multiple displays, the
0569: * primary display is used. Multi-screen aware display dimensions are
0570: * available from <code>GraphicsConfiguration</code> and
0571: * <code>GraphicsDevice</code>.
0572: * @return the size of this toolkit's screen, in pixels.
0573: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0574: * returns true
0575: * @see java.awt.GraphicsConfiguration#getBounds
0576: * @see java.awt.GraphicsDevice#getDisplayMode
0577: * @see java.awt.GraphicsEnvironment#isHeadless
0578: */
0579: public abstract Dimension getScreenSize() throws HeadlessException;
0580:
0581: /**
0582: * Returns the screen resolution in dots-per-inch.
0583: * @return this toolkit's screen resolution, in dots-per-inch.
0584: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0585: * returns true
0586: * @see java.awt.GraphicsEnvironment#isHeadless
0587: */
0588: public abstract int getScreenResolution() throws HeadlessException;
0589:
0590: /**
0591: * Gets the insets of the screen.
0592: * @param gc a <code>GraphicsConfiguration</code>
0593: * @return the insets of this toolkit's screen, in pixels.
0594: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0595: * returns true
0596: * @see java.awt.GraphicsEnvironment#isHeadless
0597: * @since 1.4
0598: */
0599: public Insets getScreenInsets(GraphicsConfiguration gc)
0600: throws HeadlessException {
0601: if (this != Toolkit.getDefaultToolkit()) {
0602: return Toolkit.getDefaultToolkit().getScreenInsets(gc);
0603: } else {
0604: return new Insets(0, 0, 0, 0);
0605: }
0606: }
0607:
0608: /**
0609: * Determines the color model of this toolkit's screen.
0610: * <p>
0611: * <code>ColorModel</code> is an abstract class that
0612: * encapsulates the ability to translate between the
0613: * pixel values of an image and its red, green, blue,
0614: * and alpha components.
0615: * <p>
0616: * This toolkit method is called by the
0617: * <code>getColorModel</code> method
0618: * of the <code>Component</code> class.
0619: * @return the color model of this toolkit's screen.
0620: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0621: * returns true
0622: * @see java.awt.GraphicsEnvironment#isHeadless
0623: * @see java.awt.image.ColorModel
0624: * @see java.awt.Component#getColorModel
0625: */
0626: public abstract ColorModel getColorModel() throws HeadlessException;
0627:
0628: /**
0629: * Returns the names of the available fonts in this toolkit.<p>
0630: * For 1.1, the following font names are deprecated (the replacement
0631: * name follows):
0632: * <ul>
0633: * <li>TimesRoman (use Serif)
0634: * <li>Helvetica (use SansSerif)
0635: * <li>Courier (use Monospaced)
0636: * </ul><p>
0637: * The ZapfDingbats fontname is also deprecated in 1.1 but the characters
0638: * are defined in Unicode starting at 0x2700, and as of 1.1 Java supports
0639: * those characters.
0640: * @return the names of the available fonts in this toolkit.
0641: * @deprecated see {@link java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()}
0642: * @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()
0643: */
0644: @Deprecated
0645: public abstract String[] getFontList();
0646:
0647: /**
0648: * Gets the screen device metrics for rendering of the font.
0649: * @param font a font
0650: * @return the screen metrics of the specified font in this toolkit
0651: * @deprecated As of JDK version 1.2, replaced by the <code>Font</code>
0652: * method <code>getLineMetrics</code>.
0653: * @see java.awt.font.LineMetrics
0654: * @see java.awt.Font#getLineMetrics
0655: * @see java.awt.GraphicsEnvironment#getScreenDevices
0656: */
0657: @Deprecated
0658: public abstract FontMetrics getFontMetrics(Font font);
0659:
0660: /**
0661: * Synchronizes this toolkit's graphics state. Some window systems
0662: * may do buffering of graphics events.
0663: * <p>
0664: * This method ensures that the display is up-to-date. It is useful
0665: * for animation.
0666: */
0667: public abstract void sync();
0668:
0669: /**
0670: * The default toolkit.
0671: */
0672: private static Toolkit toolkit;
0673:
0674: /**
0675: * Used internally by the assistive technologies functions; set at
0676: * init time and used at load time
0677: */
0678: private static String atNames;
0679:
0680: /**
0681: * Initializes properties related to assistive technologies.
0682: * These properties are used both in the loadAssistiveProperties()
0683: * function below, as well as other classes in the jdk that depend
0684: * on the properties (such as the use of the screen_magnifier_present
0685: * property in Java2D hardware acceleration initialization). The
0686: * initialization of the properties must be done before the platform-
0687: * specific Toolkit class is instantiated so that all necessary
0688: * properties are set up properly before any classes dependent upon them
0689: * are initialized.
0690: */
0691: private static void initAssistiveTechnologies() {
0692:
0693: // Get accessibility properties
0694: final String sep = File.separator;
0695: final Properties properties = new Properties();
0696:
0697: atNames = (String) java.security.AccessController
0698: .doPrivileged(new java.security.PrivilegedAction() {
0699: public Object run() {
0700:
0701: // Try loading the per-user accessibility properties file.
0702: try {
0703: File propsFile = new File(System
0704: .getProperty("user.home")
0705: + sep + ".accessibility.properties");
0706: FileInputStream in = new FileInputStream(
0707: propsFile);
0708:
0709: // Inputstream has been buffered in Properties class
0710: properties.load(in);
0711: in.close();
0712: } catch (Exception e) {
0713: // Per-user accessibility properties file does not exist
0714: }
0715:
0716: // Try loading the system-wide accessibility properties
0717: // file only if a per-user accessibility properties
0718: // file does not exist or is empty.
0719: if (properties.size() == 0) {
0720: try {
0721: File propsFile = new File(System
0722: .getProperty("java.home")
0723: + sep
0724: + "lib"
0725: + sep
0726: + "accessibility.properties");
0727: FileInputStream in = new FileInputStream(
0728: propsFile);
0729:
0730: // Inputstream has been buffered in Properties class
0731: properties.load(in);
0732: in.close();
0733: } catch (Exception e) {
0734: // System-wide accessibility properties file does
0735: // not exist;
0736: }
0737: }
0738:
0739: // Get whether a screen magnifier is present. First check
0740: // the system property and then check the properties file.
0741: String magPresent = System
0742: .getProperty("javax.accessibility.screen_magnifier_present");
0743: if (magPresent == null) {
0744: magPresent = properties.getProperty(
0745: "screen_magnifier_present", null);
0746: if (magPresent != null) {
0747: System
0748: .setProperty(
0749: "javax.accessibility.screen_magnifier_present",
0750: magPresent);
0751: }
0752: }
0753:
0754: // Get the names of any assistive technolgies to load. First
0755: // check the system property and then check the properties
0756: // file.
0757: String classNames = System
0758: .getProperty("javax.accessibility.assistive_technologies");
0759: if (classNames == null) {
0760: classNames = properties.getProperty(
0761: "assistive_technologies", null);
0762: if (classNames != null) {
0763: System
0764: .setProperty(
0765: "javax.accessibility.assistive_technologies",
0766: classNames);
0767: }
0768: }
0769: return classNames;
0770: }
0771: });
0772: }
0773:
0774: /**
0775: * Loads additional classes into the VM, using the property
0776: * 'assistive_technologies' specified in the Sun reference
0777: * implementation by a line in the 'accessibility.properties'
0778: * file. The form is "assistive_technologies=..." where
0779: * the "..." is a comma-separated list of assistive technology
0780: * classes to load. Each class is loaded in the order given
0781: * and a single instance of each is created using
0782: * Class.forName(class).newInstance(). All errors are handled
0783: * via an AWTError exception.
0784: *
0785: * <p>The assumption is made that assistive technology classes are supplied
0786: * as part of INSTALLED (as opposed to: BUNDLED) extensions or specified
0787: * on the class path
0788: * (and therefore can be loaded using the class loader returned by
0789: * a call to <code>ClassLoader.getSystemClassLoader</code>, whose
0790: * delegation parent is the extension class loader for installed
0791: * extensions).
0792: */
0793: private static void loadAssistiveTechnologies() {
0794: // Load any assistive technologies
0795: if (atNames != null) {
0796: ClassLoader cl = ClassLoader.getSystemClassLoader();
0797: StringTokenizer parser = new StringTokenizer(atNames, " ,");
0798: String atName;
0799: while (parser.hasMoreTokens()) {
0800: atName = parser.nextToken();
0801: try {
0802: Class clazz;
0803: if (cl != null) {
0804: clazz = cl.loadClass(atName);
0805: } else {
0806: clazz = Class.forName(atName);
0807: }
0808: clazz.newInstance();
0809: } catch (ClassNotFoundException e) {
0810: throw new AWTError(
0811: "Assistive Technology not found: " + atName);
0812: } catch (InstantiationException e) {
0813: throw new AWTError(
0814: "Could not instantiate Assistive"
0815: + " Technology: " + atName);
0816: } catch (IllegalAccessException e) {
0817: throw new AWTError("Could not access Assistive"
0818: + " Technology: " + atName);
0819: } catch (Exception e) {
0820: throw new AWTError(
0821: "Error trying to install Assistive"
0822: + " Technology: " + atName + " "
0823: + e);
0824: }
0825: }
0826: }
0827: }
0828:
0829: /**
0830: * Gets the default toolkit.
0831: * <p>
0832: * If a system property named <code>"java.awt.headless"</code> is set
0833: * to <code>true</code> then the headless implementation
0834: * of <code>Toolkit</code> is used.
0835: * <p>
0836: * If there is no <code>"java.awt.headless"</code> or it is set to
0837: * <code>false</code> and there is a system property named
0838: * <code>"awt.toolkit"</code>,
0839: * that property is treated as the name of a class that is a subclass
0840: * of <code>Toolkit</code>;
0841: * otherwise the default platform-specific implementation of
0842: * <code>Toolkit</code> is used.
0843: * <p>
0844: * Also loads additional classes into the VM, using the property
0845: * 'assistive_technologies' specified in the Sun reference
0846: * implementation by a line in the 'accessibility.properties'
0847: * file. The form is "assistive_technologies=..." where
0848: * the "..." is a comma-separated list of assistive technology
0849: * classes to load. Each class is loaded in the order given
0850: * and a single instance of each is created using
0851: * Class.forName(class).newInstance(). This is done just after
0852: * the AWT toolkit is created. All errors are handled via an
0853: * AWTError exception.
0854: * @return the default toolkit.
0855: * @exception AWTError if a toolkit could not be found, or
0856: * if one could not be accessed or instantiated.
0857: */
0858: public static synchronized Toolkit getDefaultToolkit() {
0859: if (toolkit == null) {
0860: try {
0861: // We disable the JIT during toolkit initialization. This
0862: // tends to touch lots of classes that aren't needed again
0863: // later and therefore JITing is counter-productiive.
0864: java.lang.Compiler.disable();
0865:
0866: java.security.AccessController
0867: .doPrivileged(new java.security.PrivilegedAction() {
0868: public Object run() {
0869: String nm = null;
0870: Class cls = null;
0871: try {
0872: nm = System.getProperty(
0873: "awt.toolkit",
0874: "sun.awt.X11.XToolkit");
0875: try {
0876: cls = Class.forName(nm);
0877: } catch (ClassNotFoundException e) {
0878: ClassLoader cl = ClassLoader
0879: .getSystemClassLoader();
0880: if (cl != null) {
0881: try {
0882: cls = cl.loadClass(nm);
0883: } catch (ClassNotFoundException ee) {
0884: throw new AWTError(
0885: "Toolkit not found: "
0886: + nm);
0887: }
0888: }
0889: }
0890: if (cls != null) {
0891: toolkit = (Toolkit) cls
0892: .newInstance();
0893: if (GraphicsEnvironment
0894: .isHeadless()) {
0895: toolkit = new HeadlessToolkit(
0896: toolkit);
0897: }
0898: }
0899: } catch (InstantiationException e) {
0900: throw new AWTError(
0901: "Could not instantiate Toolkit: "
0902: + nm);
0903: } catch (IllegalAccessException e) {
0904: throw new AWTError(
0905: "Could not access Toolkit: "
0906: + nm);
0907: }
0908: return null;
0909: }
0910: });
0911: loadAssistiveTechnologies();
0912: } finally {
0913: // Make sure to always re-enable the JIT.
0914: java.lang.Compiler.enable();
0915: }
0916: }
0917: return toolkit;
0918: }
0919:
0920: /**
0921: * Returns an image which gets pixel data from the specified file,
0922: * whose format can be either GIF, JPEG or PNG.
0923: * The underlying toolkit attempts to resolve multiple requests
0924: * with the same filename to the same returned Image.
0925: * <p>
0926: * Since the mechanism required to facilitate this sharing of
0927: * <code>Image</code> objects may continue to hold onto images
0928: * that are no longer in use for an indefinite period of time,
0929: * developers are encouraged to implement their own caching of
0930: * images by using the {@link #createImage(java.lang.String) createImage}
0931: * variant wherever available.
0932: * If the image data contained in the specified file changes,
0933: * the <code>Image</code> object returned from this method may
0934: * still contain stale information which was loaded from the
0935: * file after a prior call.
0936: * Previously loaded image data can be manually discarded by
0937: * calling the {@link Image#flush flush} method on the
0938: * returned <code>Image</code>.
0939: * <p>
0940: * This method first checks if there is a security manager installed.
0941: * If so, the method calls the security manager's
0942: * <code>checkRead</code> method with the file specified to ensure
0943: * that the access to the image is allowed.
0944: * @param filename the name of a file containing pixel data
0945: * in a recognized file format.
0946: * @return an image which gets its pixel data from
0947: * the specified file.
0948: * @throws SecurityException if a security manager exists and its
0949: * checkRead method doesn't allow the operation.
0950: * @see #createImage(java.lang.String)
0951: */
0952: public abstract Image getImage(String filename);
0953:
0954: /**
0955: * Returns an image which gets pixel data from the specified URL.
0956: * The pixel data referenced by the specified URL must be in one
0957: * of the following formats: GIF, JPEG or PNG.
0958: * The underlying toolkit attempts to resolve multiple requests
0959: * with the same URL to the same returned Image.
0960: * <p>
0961: * Since the mechanism required to facilitate this sharing of
0962: * <code>Image</code> objects may continue to hold onto images
0963: * that are no longer in use for an indefinite period of time,
0964: * developers are encouraged to implement their own caching of
0965: * images by using the {@link #createImage(java.net.URL) createImage}
0966: * variant wherever available.
0967: * If the image data stored at the specified URL changes,
0968: * the <code>Image</code> object returned from this method may
0969: * still contain stale information which was fetched from the
0970: * URL after a prior call.
0971: * Previously loaded image data can be manually discarded by
0972: * calling the {@link Image#flush flush} method on the
0973: * returned <code>Image</code>.
0974: * <p>
0975: * This method first checks if there is a security manager installed.
0976: * If so, the method calls the security manager's
0977: * <code>checkPermission</code> method with the
0978: * url.openConnection().getPermission() permission to ensure
0979: * that the access to the image is allowed. For compatibility
0980: * with pre-1.2 security managers, if the access is denied with
0981: * <code>FilePermission</code> or <code>SocketPermission</code>,
0982: * the method throws the <code>SecurityException</code>
0983: * if the corresponding 1.1-style SecurityManager.checkXXX method
0984: * also denies permission.
0985: * @param url the URL to use in fetching the pixel data.
0986: * @return an image which gets its pixel data from
0987: * the specified URL.
0988: * @throws SecurityException if a security manager exists and its
0989: * checkPermission method doesn't allow
0990: * the operation.
0991: * @see #createImage(java.net.URL)
0992: */
0993: public abstract Image getImage(URL url);
0994:
0995: /**
0996: * Returns an image which gets pixel data from the specified file.
0997: * The returned Image is a new object which will not be shared
0998: * with any other caller of this method or its getImage variant.
0999: * <p>
1000: * This method first checks if there is a security manager installed.
1001: * If so, the method calls the security manager's
1002: * <code>checkRead</code> method with the specified file to ensure
1003: * that the image creation is allowed.
1004: * @param filename the name of a file containing pixel data
1005: * in a recognized file format.
1006: * @return an image which gets its pixel data from
1007: * the specified file.
1008: * @throws SecurityException if a security manager exists and its
1009: * checkRead method doesn't allow the operation.
1010: * @see #getImage(java.lang.String)
1011: */
1012: public abstract Image createImage(String filename);
1013:
1014: /**
1015: * Returns an image which gets pixel data from the specified URL.
1016: * The returned Image is a new object which will not be shared
1017: * with any other caller of this method or its getImage variant.
1018: * <p>
1019: * This method first checks if there is a security manager installed.
1020: * If so, the method calls the security manager's
1021: * <code>checkPermission</code> method with the
1022: * url.openConnection().getPermission() permission to ensure
1023: * that the image creation is allowed. For compatibility
1024: * with pre-1.2 security managers, if the access is denied with
1025: * <code>FilePermission</code> or <code>SocketPermission</code>,
1026: * the method throws <code>SecurityException</code>
1027: * if the corresponding 1.1-style SecurityManager.checkXXX method
1028: * also denies permission.
1029: * @param url the URL to use in fetching the pixel data.
1030: * @return an image which gets its pixel data from
1031: * the specified URL.
1032: * @throws SecurityException if a security manager exists and its
1033: * checkPermission method doesn't allow
1034: * the operation.
1035: * @see #getImage(java.net.URL)
1036: */
1037: public abstract Image createImage(URL url);
1038:
1039: /**
1040: * Prepares an image for rendering.
1041: * <p>
1042: * If the values of the width and height arguments are both
1043: * <code>-1</code>, this method prepares the image for rendering
1044: * on the default screen; otherwise, this method prepares an image
1045: * for rendering on the default screen at the specified width and height.
1046: * <p>
1047: * The image data is downloaded asynchronously in another thread,
1048: * and an appropriately scaled screen representation of the image is
1049: * generated.
1050: * <p>
1051: * This method is called by components <code>prepareImage</code>
1052: * methods.
1053: * <p>
1054: * Information on the flags returned by this method can be found
1055: * with the definition of the <code>ImageObserver</code> interface.
1056:
1057: * @param image the image for which to prepare a
1058: * screen representation.
1059: * @param width the width of the desired screen
1060: * representation, or <code>-1</code>.
1061: * @param height the height of the desired screen
1062: * representation, or <code>-1</code>.
1063: * @param observer the <code>ImageObserver</code>
1064: * object to be notified as the
1065: * image is being prepared.
1066: * @return <code>true</code> if the image has already been
1067: * fully prepared; <code>false</code> otherwise.
1068: * @see java.awt.Component#prepareImage(java.awt.Image,
1069: * java.awt.image.ImageObserver)
1070: * @see java.awt.Component#prepareImage(java.awt.Image,
1071: * int, int, java.awt.image.ImageObserver)
1072: * @see java.awt.image.ImageObserver
1073: */
1074: public abstract boolean prepareImage(Image image, int width,
1075: int height, ImageObserver observer);
1076:
1077: /**
1078: * Indicates the construction status of a specified image that is
1079: * being prepared for display.
1080: * <p>
1081: * If the values of the width and height arguments are both
1082: * <code>-1</code>, this method returns the construction status of
1083: * a screen representation of the specified image in this toolkit.
1084: * Otherwise, this method returns the construction status of a
1085: * scaled representation of the image at the specified width
1086: * and height.
1087: * <p>
1088: * This method does not cause the image to begin loading.
1089: * An application must call <code>prepareImage</code> to force
1090: * the loading of an image.
1091: * <p>
1092: * This method is called by the component's <code>checkImage</code>
1093: * methods.
1094: * <p>
1095: * Information on the flags returned by this method can be found
1096: * with the definition of the <code>ImageObserver</code> interface.
1097: * @param image the image whose status is being checked.
1098: * @param width the width of the scaled version whose status is
1099: * being checked, or <code>-1</code>.
1100: * @param height the height of the scaled version whose status
1101: * is being checked, or <code>-1</code>.
1102: * @param observer the <code>ImageObserver</code> object to be
1103: * notified as the image is being prepared.
1104: * @return the bitwise inclusive <strong>OR</strong> of the
1105: * <code>ImageObserver</code> flags for the
1106: * image data that is currently available.
1107: * @see java.awt.Toolkit#prepareImage(java.awt.Image,
1108: * int, int, java.awt.image.ImageObserver)
1109: * @see java.awt.Component#checkImage(java.awt.Image,
1110: * java.awt.image.ImageObserver)
1111: * @see java.awt.Component#checkImage(java.awt.Image,
1112: * int, int, java.awt.image.ImageObserver)
1113: * @see java.awt.image.ImageObserver
1114: */
1115: public abstract int checkImage(Image image, int width, int height,
1116: ImageObserver observer);
1117:
1118: /**
1119: * Creates an image with the specified image producer.
1120: * @param producer the image producer to be used.
1121: * @return an image with the specified image producer.
1122: * @see java.awt.Image
1123: * @see java.awt.image.ImageProducer
1124: * @see java.awt.Component#createImage(java.awt.image.ImageProducer)
1125: */
1126: public abstract Image createImage(ImageProducer producer);
1127:
1128: /**
1129: * Creates an image which decodes the image stored in the specified
1130: * byte array.
1131: * <p>
1132: * The data must be in some image format, such as GIF or JPEG,
1133: * that is supported by this toolkit.
1134: * @param imagedata an array of bytes, representing
1135: * image data in a supported image format.
1136: * @return an image.
1137: * @since JDK1.1
1138: */
1139: public Image createImage(byte[] imagedata) {
1140: return createImage(imagedata, 0, imagedata.length);
1141: }
1142:
1143: /**
1144: * Creates an image which decodes the image stored in the specified
1145: * byte array, and at the specified offset and length.
1146: * The data must be in some image format, such as GIF or JPEG,
1147: * that is supported by this toolkit.
1148: * @param imagedata an array of bytes, representing
1149: * image data in a supported image format.
1150: * @param imageoffset the offset of the beginning
1151: * of the data in the array.
1152: * @param imagelength the length of the data in the array.
1153: * @return an image.
1154: * @since JDK1.1
1155: */
1156: public abstract Image createImage(byte[] imagedata,
1157: int imageoffset, int imagelength);
1158:
1159: /**
1160: * Gets a <code>PrintJob</code> object which is the result of initiating
1161: * a print operation on the toolkit's platform.
1162: * <p>
1163: * Each actual implementation of this method should first check if there
1164: * is a security manager installed. If there is, the method should call
1165: * the security manager's <code>checkPrintJobAccess</code> method to
1166: * ensure initiation of a print operation is allowed. If the default
1167: * implementation of <code>checkPrintJobAccess</code> is used (that is,
1168: * that method is not overriden), then this results in a call to the
1169: * security manager's <code>checkPermission</code> method with a <code>
1170: * RuntimePermission("queuePrintJob")</code> permission.
1171: *
1172: * @param frame the parent of the print dialog. May not be null.
1173: * @param jobtitle the title of the PrintJob. A null title is equivalent
1174: * to "".
1175: * @param props a Properties object containing zero or more properties.
1176: * Properties are not standardized and are not consistent across
1177: * implementations. Because of this, PrintJobs which require job
1178: * and page control should use the version of this function which
1179: * takes JobAttributes and PageAttributes objects. This object
1180: * may be updated to reflect the user's job choices on exit. May
1181: * be null.
1182: *
1183: * @return a <code>PrintJob</code> object, or <code>null</code> if the
1184: * user cancelled the print job.
1185: * @throws NullPointerException if frame is null. This exception is
1186: * always thrown when GraphicsEnvironment.isHeadless() returns
1187: * true.
1188: * @throws SecurityException if this thread is not allowed to initiate a
1189: * print job request
1190: * @see java.awt.GraphicsEnvironment#isHeadless
1191: * @see java.awt.PrintJob
1192: * @see java.lang.RuntimePermission
1193: * @since JDK1.1
1194: */
1195: public abstract PrintJob getPrintJob(Frame frame, String jobtitle,
1196: Properties props);
1197:
1198: /**
1199: * Gets a <code>PrintJob</code> object which is the result of initiating
1200: * a print operation on the toolkit's platform.
1201: * <p>
1202: * Each actual implementation of this method should first check if there
1203: * is a security manager installed. If there is, the method should call
1204: * the security manager's <code>checkPrintJobAccess</code> method to
1205: * ensure initiation of a print operation is allowed. If the default
1206: * implementation of <code>checkPrintJobAccess</code> is used (that is,
1207: * that method is not overriden), then this results in a call to the
1208: * security manager's <code>checkPermission</code> method with a <code>
1209: * RuntimePermission("queuePrintJob")</code> permission.
1210: *
1211: * @param frame the parent of the print dialog. May be null if and only
1212: * if jobAttributes is not null and jobAttributes.getDialog()
1213: * returns JobAttributes.DialogType.NONE or
1214: * JobAttributes.DialogType.COMMON.
1215: * @param jobtitle the title of the PrintJob. A null title is equivalent
1216: * to "".
1217: * @param jobAttributes a set of job attributes which will control the
1218: * PrintJob. The attributes will be updated to reflect the user's
1219: * choices as outlined in the JobAttributes documentation. May be
1220: * null.
1221: * @param pageAttributes a set of page attributes which will control the
1222: * PrintJob. The attributes will be applied to every page in the
1223: * job. The attributes will be updated to reflect the user's
1224: * choices as outlined in the PageAttributes documentation. May be
1225: * null.
1226: *
1227: * @return a <code>PrintJob</code> object, or <code>null</code> if the
1228: * user cancelled the print job.
1229: * @throws NullPointerException if frame is null and either jobAttributes
1230: * is null or jobAttributes.getDialog() returns
1231: * JobAttributes.DialogType.NATIVE.
1232: * @throws IllegalArgumentException if pageAttributes specifies differing
1233: * cross feed and feed resolutions. Also if this thread has
1234: * access to the file system and jobAttributes specifies
1235: * print to file, and the specified destination file exists but
1236: * is a directory rather than a regular file, does not exist but
1237: * cannot be created, or cannot be opened for any other reason.
1238: * However in the case of print to file, if a dialog is also
1239: * requested to be displayed then the user will be given an
1240: * opportunity to select a file and proceed with printing.
1241: * The dialog will ensure that the selected output file
1242: * is valid before returning from this method.
1243: * <p>
1244: * This exception is always thrown when GraphicsEnvironment.isHeadless()
1245: * returns true.
1246: * @throws SecurityException if this thread is not allowed to initiate a
1247: * print job request, or if jobAttributes specifies print to file,
1248: * and this thread is not allowed to access the file system
1249: * @see java.awt.PrintJob
1250: * @see java.awt.GraphicsEnvironment#isHeadless
1251: * @see java.lang.RuntimePermission
1252: * @see java.awt.JobAttributes
1253: * @see java.awt.PageAttributes
1254: * @since 1.3
1255: */
1256: public PrintJob getPrintJob(Frame frame, String jobtitle,
1257: JobAttributes jobAttributes, PageAttributes pageAttributes) {
1258: // Override to add printing support with new job/page control classes
1259:
1260: if (GraphicsEnvironment.isHeadless()) {
1261: throw new IllegalArgumentException();
1262: }
1263:
1264: if (this != Toolkit.getDefaultToolkit()) {
1265: return Toolkit.getDefaultToolkit().getPrintJob(frame,
1266: jobtitle, jobAttributes, pageAttributes);
1267: } else {
1268: return getPrintJob(frame, jobtitle, null);
1269: }
1270: }
1271:
1272: /**
1273: * Emits an audio beep.
1274: * @since JDK1.1
1275: */
1276: public abstract void beep();
1277:
1278: /**
1279: * Gets the singleton instance of the system Clipboard which interfaces
1280: * with clipboard facilities provided by the native platform. This
1281: * clipboard enables data transfer between Java programs and native
1282: * applications which use native clipboard facilities.
1283: * <p>
1284: * In addition to any and all formats specified in the flavormap.properties
1285: * file, or other file specified by the <code>AWT.DnD.flavorMapFileURL
1286: * </code> Toolkit property, text returned by the system Clipboard's <code>
1287: * getTransferData()</code> method is available in the following flavors:
1288: * <ul>
1289: * <li>DataFlavor.stringFlavor</li>
1290: * <li>DataFlavor.plainTextFlavor (<b>deprecated</b>)</li>
1291: * </ul>
1292: * As with <code>java.awt.datatransfer.StringSelection</code>, if the
1293: * requested flavor is <code>DataFlavor.plainTextFlavor</code>, or an
1294: * equivalent flavor, a Reader is returned. <b>Note:</b> The behavior of
1295: * the system Clipboard's <code>getTransferData()</code> method for <code>
1296: * DataFlavor.plainTextFlavor</code>, and equivalent DataFlavors, is
1297: * inconsistent with the definition of <code>DataFlavor.plainTextFlavor
1298: * </code>. Because of this, support for <code>
1299: * DataFlavor.plainTextFlavor</code>, and equivalent flavors, is
1300: * <b>deprecated</b>.
1301: * <p>
1302: * Each actual implementation of this method should first check if there
1303: * is a security manager installed. If there is, the method should call
1304: * the security manager's <code>checkSystemClipboardAccess</code> method
1305: * to ensure it's ok to to access the system clipboard. If the default
1306: * implementation of <code>checkSystemClipboardAccess</code> is used (that
1307: * is, that method is not overriden), then this results in a call to the
1308: * security manager's <code>checkPermission</code> method with an <code>
1309: * AWTPermission("accessClipboard")</code> permission.
1310: *
1311: * @return the system Clipboard
1312: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1313: * returns true
1314: * @see java.awt.GraphicsEnvironment#isHeadless
1315: * @see java.awt.datatransfer.Clipboard
1316: * @see java.awt.datatransfer.StringSelection
1317: * @see java.awt.datatransfer.DataFlavor#stringFlavor
1318: * @see java.awt.datatransfer.DataFlavor#plainTextFlavor
1319: * @see java.io.Reader
1320: * @see java.awt.AWTPermission
1321: * @since JDK1.1
1322: */
1323: public abstract Clipboard getSystemClipboard()
1324: throws HeadlessException;
1325:
1326: /**
1327: * Gets the singleton instance of the system selection as a
1328: * <code>Clipboard</code> object. This allows an application to read and
1329: * modify the current, system-wide selection.
1330: * <p>
1331: * An application is responsible for updating the system selection whenever
1332: * the user selects text, using either the mouse or the keyboard.
1333: * Typically, this is implemented by installing a
1334: * <code>FocusListener</code> on all <code>Component</code>s which support
1335: * text selection, and, between <code>FOCUS_GAINED</code> and
1336: * <code>FOCUS_LOST</code> events delivered to that <code>Component</code>,
1337: * updating the system selection <code>Clipboard</code> when the selection
1338: * changes inside the <code>Component</code>. Properly updating the system
1339: * selection ensures that a Java application will interact correctly with
1340: * native applications and other Java applications running simultaneously
1341: * on the system. Note that <code>java.awt.TextComponent</code> and
1342: * <code>javax.swing.text.JTextComponent</code> already adhere to this
1343: * policy. When using these classes, and their subclasses, developers need
1344: * not write any additional code.
1345: * <p>
1346: * Some platforms do not support a system selection <code>Clipboard</code>.
1347: * On those platforms, this method will return <code>null</code>. In such a
1348: * case, an application is absolved from its responsibility to update the
1349: * system selection <code>Clipboard</code> as described above.
1350: * <p>
1351: * Each actual implementation of this method should first check if there
1352: * is a <code>SecurityManager</code> installed. If there is, the method
1353: * should call the <code>SecurityManager</code>'s
1354: * <code>checkSystemClipboardAccess</code> method to ensure that client
1355: * code has access the system selection. If the default implementation of
1356: * <code>checkSystemClipboardAccess</code> is used (that is, if the method
1357: * is not overridden), then this results in a call to the
1358: * <code>SecurityManager</code>'s <code>checkPermission</code> method with
1359: * an <code>AWTPermission("accessClipboard")</code> permission.
1360: *
1361: * @return the system selection as a <code>Clipboard</code>, or
1362: * <code>null</code> if the native platform does not support a
1363: * system selection <code>Clipboard</code>
1364: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1365: * returns true
1366: *
1367: * @see java.awt.datatransfer.Clipboard
1368: * @see java.awt.event.FocusListener
1369: * @see java.awt.event.FocusEvent#FOCUS_GAINED
1370: * @see java.awt.event.FocusEvent#FOCUS_LOST
1371: * @see TextComponent
1372: * @see javax.swing.text.JTextComponent
1373: * @see AWTPermission
1374: * @see GraphicsEnvironment#isHeadless
1375: * @since 1.4
1376: */
1377: public Clipboard getSystemSelection() throws HeadlessException {
1378: if (this != Toolkit.getDefaultToolkit()) {
1379: return Toolkit.getDefaultToolkit().getSystemSelection();
1380: } else {
1381: GraphicsEnvironment.checkHeadless();
1382: return null;
1383: }
1384: }
1385:
1386: /**
1387: * Determines which modifier key is the appropriate accelerator
1388: * key for menu shortcuts.
1389: * <p>
1390: * Menu shortcuts, which are embodied in the
1391: * <code>MenuShortcut</code> class, are handled by the
1392: * <code>MenuBar</code> class.
1393: * <p>
1394: * By default, this method returns <code>Event.CTRL_MASK</code>.
1395: * Toolkit implementations should override this method if the
1396: * <b>Control</b> key isn't the correct key for accelerators.
1397: * @return the modifier mask on the <code>Event</code> class
1398: * that is used for menu shortcuts on this toolkit.
1399: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1400: * returns true
1401: * @see java.awt.GraphicsEnvironment#isHeadless
1402: * @see java.awt.MenuBar
1403: * @see java.awt.MenuShortcut
1404: * @since JDK1.1
1405: */
1406: public int getMenuShortcutKeyMask() throws HeadlessException {
1407: return Event.CTRL_MASK;
1408: }
1409:
1410: /**
1411: * Returns whether the given locking key on the keyboard is currently in
1412: * its "on" state.
1413: * Valid key codes are
1414: * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK},
1415: * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK},
1416: * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and
1417: * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}.
1418: *
1419: * @exception java.lang.IllegalArgumentException if <code>keyCode</code>
1420: * is not one of the valid key codes
1421: * @exception java.lang.UnsupportedOperationException if the host system doesn't
1422: * allow getting the state of this key programmatically, or if the keyboard
1423: * doesn't have this key
1424: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1425: * returns true
1426: * @see java.awt.GraphicsEnvironment#isHeadless
1427: * @since 1.3
1428: */
1429: public boolean getLockingKeyState(int keyCode)
1430: throws UnsupportedOperationException {
1431: if (!(keyCode == KeyEvent.VK_CAPS_LOCK
1432: || keyCode == KeyEvent.VK_NUM_LOCK
1433: || keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
1434: throw new IllegalArgumentException(
1435: "invalid key for Toolkit.getLockingKeyState");
1436: }
1437: throw new UnsupportedOperationException(
1438: "Toolkit.getLockingKeyState");
1439: }
1440:
1441: /**
1442: * Sets the state of the given locking key on the keyboard.
1443: * Valid key codes are
1444: * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK},
1445: * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK},
1446: * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and
1447: * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}.
1448: * <p>
1449: * Depending on the platform, setting the state of a locking key may
1450: * involve event processing and therefore may not be immediately
1451: * observable through getLockingKeyState.
1452: *
1453: * @exception java.lang.IllegalArgumentException if <code>keyCode</code>
1454: * is not one of the valid key codes
1455: * @exception java.lang.UnsupportedOperationException if the host system doesn't
1456: * allow setting the state of this key programmatically, or if the keyboard
1457: * doesn't have this key
1458: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1459: * returns true
1460: * @see java.awt.GraphicsEnvironment#isHeadless
1461: * @since 1.3
1462: */
1463: public void setLockingKeyState(int keyCode, boolean on)
1464: throws UnsupportedOperationException {
1465: if (!(keyCode == KeyEvent.VK_CAPS_LOCK
1466: || keyCode == KeyEvent.VK_NUM_LOCK
1467: || keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
1468: throw new IllegalArgumentException(
1469: "invalid key for Toolkit.setLockingKeyState");
1470: }
1471: throw new UnsupportedOperationException(
1472: "Toolkit.setLockingKeyState");
1473: }
1474:
1475: /**
1476: * Give native peers the ability to query the native container
1477: * given a native component (eg the direct parent may be lightweight).
1478: */
1479: protected static Container getNativeContainer(Component c) {
1480: return c.getNativeContainer();
1481: }
1482:
1483: /**
1484: * Creates a new custom cursor object.
1485: * If the image to display is invalid, the cursor will be hidden (made
1486: * completely transparent), and the hotspot will be set to (0, 0).
1487: *
1488: * <p>Note that multi-frame images are invalid and may cause this
1489: * method to hang.
1490: *
1491: * @param cursor the image to display when the cursor is actived
1492: * @param hotSpot the X and Y of the large cursor's hot spot; the
1493: * hotSpot values must be less than the Dimension returned by
1494: * <code>getBestCursorSize</code>
1495: * @param name a localized description of the cursor, for Java Accessibility use
1496: * @exception IndexOutOfBoundsException if the hotSpot values are outside
1497: * the bounds of the cursor
1498: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1499: * returns true
1500: * @see java.awt.GraphicsEnvironment#isHeadless
1501: * @since 1.2
1502: */
1503: public Cursor createCustomCursor(Image cursor, Point hotSpot,
1504: String name) throws IndexOutOfBoundsException,
1505: HeadlessException {
1506: // Override to implement custom cursor support.
1507: if (this != Toolkit.getDefaultToolkit()) {
1508: return Toolkit.getDefaultToolkit().createCustomCursor(
1509: cursor, hotSpot, name);
1510: } else {
1511: return new Cursor(Cursor.DEFAULT_CURSOR);
1512: }
1513: }
1514:
1515: /**
1516: * Returns the supported cursor dimension which is closest to the desired
1517: * sizes. Systems which only support a single cursor size will return that
1518: * size regardless of the desired sizes. Systems which don't support custom
1519: * cursors will return a dimension of 0, 0. <p>
1520: * Note: if an image is used whose dimensions don't match a supported size
1521: * (as returned by this method), the Toolkit implementation will attempt to
1522: * resize the image to a supported size.
1523: * Since converting low-resolution images is difficult,
1524: * no guarantees are made as to the quality of a cursor image which isn't a
1525: * supported size. It is therefore recommended that this method
1526: * be called and an appropriate image used so no image conversion is made.
1527: *
1528: * @param preferredWidth the preferred cursor width the component would like
1529: * to use.
1530: * @param preferredHeight the preferred cursor height the component would like
1531: * to use.
1532: * @return the closest matching supported cursor size, or a dimension of 0,0 if
1533: * the Toolkit implementation doesn't support custom cursors.
1534: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1535: * returns true
1536: * @see java.awt.GraphicsEnvironment#isHeadless
1537: * @since 1.2
1538: */
1539: public Dimension getBestCursorSize(int preferredWidth,
1540: int preferredHeight) throws HeadlessException {
1541: // Override to implement custom cursor support.
1542: if (this != Toolkit.getDefaultToolkit()) {
1543: return Toolkit.getDefaultToolkit().getBestCursorSize(
1544: preferredWidth, preferredHeight);
1545: } else {
1546: return new Dimension(0, 0);
1547: }
1548: }
1549:
1550: /**
1551: * Returns the maximum number of colors the Toolkit supports in a custom cursor
1552: * palette.<p>
1553: * Note: if an image is used which has more colors in its palette than
1554: * the supported maximum, the Toolkit implementation will attempt to flatten the
1555: * palette to the maximum. Since converting low-resolution images is difficult,
1556: * no guarantees are made as to the quality of a cursor image which has more
1557: * colors than the system supports. It is therefore recommended that this method
1558: * be called and an appropriate image used so no image conversion is made.
1559: *
1560: * @return the maximum number of colors, or zero if custom cursors are not
1561: * supported by this Toolkit implementation.
1562: * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1563: * returns true
1564: * @see java.awt.GraphicsEnvironment#isHeadless
1565: * @since 1.2
1566: */
1567: public int getMaximumCursorColors() throws HeadlessException {
1568: // Override to implement custom cursor support.
1569: if (this != Toolkit.getDefaultToolkit()) {
1570: return Toolkit.getDefaultToolkit().getMaximumCursorColors();
1571: } else {
1572: return 0;
1573: }
1574: }
1575:
1576: /**
1577: * Returns whether Toolkit supports this state for
1578: * <code>Frame</code>s. This method tells whether the <em>UI
1579: * concept</em> of, say, maximization or iconification is
1580: * supported. It will always return false for "compound" states
1581: * like <code>Frame.ICONIFIED|Frame.MAXIMIZED_VERT</code>.
1582: * In other words, the rule of thumb is that only queries with a
1583: * single frame state constant as an argument are meaningful.
1584: *
1585: * @param state one of named frame state constants.
1586: * @return <code>true</code> is this frame state is supported by
1587: * this Toolkit implementation, <code>false</code> otherwise.
1588: * @exception HeadlessException
1589: * if <code>GraphicsEnvironment.isHeadless()</code>
1590: * returns <code>true</code>.
1591: * @see java.awt.Frame#setExtendedState
1592: * @since 1.4
1593: */
1594: public boolean isFrameStateSupported(int state)
1595: throws HeadlessException {
1596: if (GraphicsEnvironment.isHeadless()) {
1597: throw new HeadlessException();
1598: }
1599: if (this != Toolkit.getDefaultToolkit()) {
1600: return Toolkit.getDefaultToolkit().isFrameStateSupported(
1601: state);
1602: } else {
1603: return (state == Frame.NORMAL); // others are not guaranteed
1604: }
1605: }
1606:
1607: /**
1608: * Support for I18N: any visible strings should be stored in
1609: * sun.awt.resources.awt.properties. The ResourceBundle is stored
1610: * here, so that only one copy is maintained.
1611: */
1612: private static ResourceBundle resources;
1613:
1614: /**
1615: * Initialize JNI field and method ids
1616: */
1617: private static native void initIDs();
1618:
1619: /**
1620: * WARNING: This is a temporary workaround for a problem in the
1621: * way the AWT loads native libraries. A number of classes in the
1622: * AWT package have a native method, initIDs(), which initializes
1623: * the JNI field and method ids used in the native portion of
1624: * their implementation.
1625: *
1626: * Since the use and storage of these ids is done by the
1627: * implementation libraries, the implementation of these method is
1628: * provided by the particular AWT implementations (for example,
1629: * "Toolkit"s/Peer), such as Motif, Microsoft Windows, or Tiny. The
1630: * problem is that this means that the native libraries must be
1631: * loaded by the java.* classes, which do not necessarily know the
1632: * names of the libraries to load. A better way of doing this
1633: * would be to provide a separate library which defines java.awt.*
1634: * initIDs, and exports the relevant symbols out to the
1635: * implementation libraries.
1636: *
1637: * For now, we know it's done by the implementation, and we assume
1638: * that the name of the library is "awt". -br.
1639: *
1640: * If you change loadLibraries(), please add the change to
1641: * java.awt.image.ColorModel.loadLibraries(). Unfortunately,
1642: * classes can be loaded in java.awt.image that depend on
1643: * libawt and there is no way to call Toolkit.loadLibraries()
1644: * directly. -hung
1645: */
1646: private static boolean loaded = false;
1647:
1648: static void loadLibraries() {
1649: if (!loaded) {
1650: java.security.AccessController
1651: .doPrivileged(new sun.security.action.LoadLibraryAction(
1652: "awt"));
1653: loaded = true;
1654: }
1655: }
1656:
1657: static {
1658: java.security.AccessController
1659: .doPrivileged(new java.security.PrivilegedAction() {
1660: public Object run() {
1661: try {
1662: resources = ResourceBundle.getBundle(
1663: "sun.awt.resources.awt",
1664: CoreResourceBundleControl
1665: .getRBControlInstance());
1666: } catch (MissingResourceException e) {
1667: // No resource file; defaults will be used.
1668: }
1669: return null;
1670: }
1671: });
1672:
1673: // ensure that the proper libraries are loaded
1674: loadLibraries();
1675: initAssistiveTechnologies();
1676: if (!GraphicsEnvironment.isHeadless()) {
1677: initIDs();
1678: }
1679: }
1680:
1681: /**
1682: * Gets a property with the specified key and default.
1683: * This method returns defaultValue if the property is not found.
1684: */
1685: public static String getProperty(String key, String defaultValue) {
1686: if (resources != null) {
1687: try {
1688: return resources.getString(key);
1689: } catch (MissingResourceException e) {
1690: }
1691: }
1692:
1693: return defaultValue;
1694: }
1695:
1696: /**
1697: * Get the application's or applet's EventQueue instance.
1698: * Depending on the Toolkit implementation, different EventQueues
1699: * may be returned for different applets. Applets should
1700: * therefore not assume that the EventQueue instance returned
1701: * by this method will be shared by other applets or the system.
1702: *
1703: * <p>First, if there is a security manager, its
1704: * <code>checkAwtEventQueueAccess</code>
1705: * method is called.
1706: * If the default implementation of <code>checkAwtEventQueueAccess</code>
1707: * is used (that is, that method is not overriden), then this results in
1708: * a call to the security manager's <code>checkPermission</code> method
1709: * with an <code>AWTPermission("accessEventQueue")</code> permission.
1710: *
1711: * @return the <code>EventQueue</code> object
1712: * @throws SecurityException
1713: * if a security manager exists and its <code>{@link
1714: * java.lang.SecurityManager#checkAwtEventQueueAccess}</code>
1715: * method denies access to the <code>EventQueue</code>
1716: * @see java.awt.AWTPermission
1717: */
1718: public final EventQueue getSystemEventQueue() {
1719: SecurityManager security = System.getSecurityManager();
1720: if (security != null) {
1721: security.checkAwtEventQueueAccess();
1722: }
1723: return getSystemEventQueueImpl();
1724: }
1725:
1726: /**
1727: * Gets the application's or applet's <code>EventQueue</code>
1728: * instance, without checking access. For security reasons,
1729: * this can only be called from a <code>Toolkit</code> subclass.
1730: * @return the <code>EventQueue</code> object
1731: */
1732: protected abstract EventQueue getSystemEventQueueImpl();
1733:
1734: /* Accessor method for use by AWT package routines. */
1735: static EventQueue getEventQueue() {
1736: return getDefaultToolkit().getSystemEventQueueImpl();
1737: }
1738:
1739: /**
1740: * Creates the peer for a DragSourceContext.
1741: * Always throws InvalidDndOperationException if
1742: * GraphicsEnvironment.isHeadless() returns true.
1743: * @see java.awt.GraphicsEnvironment#isHeadless
1744: */
1745: public abstract DragSourceContextPeer createDragSourceContextPeer(
1746: DragGestureEvent dge) throws InvalidDnDOperationException;
1747:
1748: /**
1749: * Creates a concrete, platform dependent, subclass of the abstract
1750: * DragGestureRecognizer class requested, and associates it with the
1751: * DragSource, Component and DragGestureListener specified.
1752: *
1753: * subclasses should override this to provide their own implementation
1754: *
1755: * @param abstractRecognizerClass The abstract class of the required recognizer
1756: * @param ds The DragSource
1757: * @param c The Component target for the DragGestureRecognizer
1758: * @param srcActions The actions permitted for the gesture
1759: * @param dgl The DragGestureListener
1760: *
1761: * @return the new object or null. Always returns null if
1762: * GraphicsEnvironment.isHeadless() returns true.
1763: * @see java.awt.GraphicsEnvironment#isHeadless
1764: */
1765: public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
1766: Class<T> abstractRecognizerClass, DragSource ds,
1767: Component c, int srcActions, DragGestureListener dgl) {
1768: return null;
1769: }
1770:
1771: /**
1772: * Obtains a value for the specified desktop property.
1773: *
1774: * A desktop property is a uniquely named value for a resource that
1775: * is Toolkit global in nature. Usually it also is an abstract
1776: * representation for an underlying platform dependent desktop setting.
1777: * For more information on desktop properties supported by the AWT see
1778: * <a href="doc-files/DesktopProperties.html">AWT Desktop Properties</a>.
1779: */
1780: public final synchronized Object getDesktopProperty(
1781: String propertyName) {
1782: // This is a workaround for headless toolkits. It would be
1783: // better to override this method but it is declared final.
1784: // "this instanceof" syntax defeats polymorphism.
1785: // --mm, 03/03/00
1786: if (this instanceof HeadlessToolkit) {
1787: return ((HeadlessToolkit) this ).getUnderlyingToolkit()
1788: .getDesktopProperty(propertyName);
1789: }
1790:
1791: if (desktopProperties.isEmpty()) {
1792: initializeDesktopProperties();
1793: }
1794:
1795: Object value;
1796:
1797: // This property should never be cached
1798: if (propertyName.equals("awt.dynamicLayoutSupported")) {
1799: value = lazilyLoadDesktopProperty(propertyName);
1800: return value;
1801: }
1802:
1803: value = desktopProperties.get(propertyName);
1804:
1805: if (value == null) {
1806: value = lazilyLoadDesktopProperty(propertyName);
1807:
1808: if (value != null) {
1809: setDesktopProperty(propertyName, value);
1810: }
1811: }
1812:
1813: /* for property "awt.font.desktophints" */
1814: if (value instanceof RenderingHints) {
1815: value = ((RenderingHints) value).clone();
1816: }
1817:
1818: return value;
1819: }
1820:
1821: /**
1822: * Sets the named desktop property to the specified value and fires a
1823: * property change event to notify any listeners that the value has changed.
1824: */
1825: protected final void setDesktopProperty(String name, Object newValue) {
1826: // This is a workaround for headless toolkits. It would be
1827: // better to override this method but it is declared final.
1828: // "this instanceof" syntax defeats polymorphism.
1829: // --mm, 03/03/00
1830: if (this instanceof HeadlessToolkit) {
1831: ((HeadlessToolkit) this ).getUnderlyingToolkit()
1832: .setDesktopProperty(name, newValue);
1833: return;
1834: }
1835: Object oldValue;
1836:
1837: synchronized (this ) {
1838: oldValue = desktopProperties.get(name);
1839: desktopProperties.put(name, newValue);
1840: }
1841:
1842: desktopPropsSupport
1843: .firePropertyChange(name, oldValue, newValue);
1844: }
1845:
1846: /**
1847: * an opportunity to lazily evaluate desktop property values.
1848: */
1849: protected Object lazilyLoadDesktopProperty(String name) {
1850: return null;
1851: }
1852:
1853: /**
1854: * initializeDesktopProperties
1855: */
1856: protected void initializeDesktopProperties() {
1857: }
1858:
1859: /**
1860: * Adds the specified property change listener for the named desktop
1861: * property.
1862: * If pcl is null, no exception is thrown and no action is performed.
1863: *
1864: * @param name The name of the property to listen for
1865: * @param pcl The property change listener
1866: * @since 1.2
1867: */
1868: public void addPropertyChangeListener(String name,
1869: PropertyChangeListener pcl) {
1870: desktopPropsSupport.addPropertyChangeListener(name, pcl);
1871: }
1872:
1873: /**
1874: * Removes the specified property change listener for the named
1875: * desktop property.
1876: * If pcl is null, no exception is thrown and no action is performed.
1877: *
1878: * @param name The name of the property to remove
1879: * @param pcl The property change listener
1880: * @since 1.2
1881: */
1882: public void removePropertyChangeListener(String name,
1883: PropertyChangeListener pcl) {
1884: desktopPropsSupport.removePropertyChangeListener(name, pcl);
1885: }
1886:
1887: /**
1888: * Returns an array of all the property change listeners
1889: * registered on this toolkit.
1890: *
1891: * @return all of this toolkit's <code>PropertyChangeListener</code>s
1892: * or an empty array if no property change
1893: * listeners are currently registered
1894: *
1895: * @since 1.4
1896: */
1897: public PropertyChangeListener[] getPropertyChangeListeners() {
1898: return desktopPropsSupport.getPropertyChangeListeners();
1899: }
1900:
1901: /**
1902: * Returns an array of all the <code>PropertyChangeListener</code>s
1903: * associated with the named property.
1904: *
1905: * @param propertyName the named property
1906: * @return all of the <code>PropertyChangeListener</code>s associated with
1907: * the named property or an empty array if no such listeners have
1908: * been added
1909: * @since 1.4
1910: */
1911: public PropertyChangeListener[] getPropertyChangeListeners(
1912: String propertyName) {
1913: return desktopPropsSupport
1914: .getPropertyChangeListeners(propertyName);
1915: }
1916:
1917: protected final Map<String, Object> desktopProperties = new HashMap<String, Object>();
1918: protected final PropertyChangeSupport desktopPropsSupport = Toolkit
1919: .createPropertyChangeSupport(this );
1920:
1921: /**
1922: * Returns whether the always-on-top mode is supported by this toolkit.
1923: * To detect whether the always-on-top mode is supported for a
1924: * particular Window, use {@link Window#isAlwaysOnTopSupported}.
1925: * @return <code>true</code>, if current toolkit supports the always-on-top mode,
1926: * otherwise returns <code>false</code>
1927: * @see Window#isAlwaysOnTopSupported
1928: * @see Window#setAlwaysOnTop(boolean)
1929: * @since 1.6
1930: */
1931: public boolean isAlwaysOnTopSupported() {
1932: return true;
1933: }
1934:
1935: /**
1936: * Returns whether the given modality type is supported by this toolkit. If
1937: * a dialog with unsupported modality type is created, then
1938: * <code>Dialog.ModalityType.MODELESS</code> is used instead.
1939: *
1940: * @param modalityType modality type to be checked for support by this toolkit
1941: *
1942: * @return <code>true</code>, if current toolkit supports given modality
1943: * type, <code>false</code> otherwise
1944: *
1945: * @see java.awt.Dialog.ModalityType
1946: * @see java.awt.Dialog#getModalityType
1947: * @see java.awt.Dialog#setModalityType
1948: *
1949: * @since 1.6
1950: */
1951: public abstract boolean isModalityTypeSupported(
1952: Dialog.ModalityType modalityType);
1953:
1954: /**
1955: * Returns whether the given modal exclusion type is supported by this
1956: * toolkit. If an unsupported modal exclusion type property is set on a window,
1957: * then <code>Dialog.ModalExclusionType.NO_EXCLUDE</code> is used instead.
1958: *
1959: * @param modalExclusionType modal exclusion type to be checked for support by this toolkit
1960: *
1961: * @return <code>true</code>, if current toolkit supports given modal exclusion
1962: * type, <code>false</code> otherwise
1963: *
1964: * @see java.awt.Dialog.ModalExclusionType
1965: * @see java.awt.Window#getModalExclusionType
1966: * @see java.awt.Window#setModalExclusionType
1967: *
1968: * @since 1.6
1969: */
1970: public abstract boolean isModalExclusionTypeSupported(
1971: Dialog.ModalExclusionType modalExclusionType);
1972:
1973: private static final DebugHelper dbg = DebugHelper
1974: .create(Toolkit.class);
1975: private static final int LONG_BITS = 64;
1976: private int[] calls = new int[LONG_BITS];
1977: private static volatile long enabledOnToolkitMask;
1978: private AWTEventListener eventListener = null;
1979: private WeakHashMap listener2SelectiveListener = new WeakHashMap();
1980:
1981: /*
1982: * Extracts a "pure" AWTEventListener from a AWTEventListenerProxy,
1983: * if the listener is proxied.
1984: */
1985: static private AWTEventListener deProxyAWTEventListener(
1986: AWTEventListener l) {
1987: AWTEventListener localL = l;
1988:
1989: if (localL == null) {
1990: return null;
1991: }
1992: // if user passed in a AWTEventListenerProxy object, extract
1993: // the listener
1994: if (l instanceof AWTEventListenerProxy) {
1995: localL = (AWTEventListener) ((AWTEventListenerProxy) l)
1996: .getListener();
1997: }
1998: return localL;
1999: }
2000:
2001: /**
2002: * Adds an AWTEventListener to receive all AWTEvents dispatched
2003: * system-wide that conform to the given <code>eventMask</code>.
2004: * <p>
2005: * First, if there is a security manager, its <code>checkPermission</code>
2006: * method is called with an
2007: * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
2008: * This may result in a SecurityException.
2009: * <p>
2010: * <code>eventMask</code> is a bitmask of event types to receive.
2011: * It is constructed by bitwise OR-ing together the event masks
2012: * defined in <code>AWTEvent</code>.
2013: * <p>
2014: * Note: event listener use is not recommended for normal
2015: * application use, but are intended solely to support special
2016: * purpose facilities including support for accessibility,
2017: * event record/playback, and diagnostic tracing.
2018: *
2019: * If listener is null, no exception is thrown and no action is performed.
2020: *
2021: * @param listener the event listener.
2022: * @param eventMask the bitmask of event types to receive
2023: * @throws SecurityException
2024: * if a security manager exists and its
2025: * <code>checkPermission</code> method doesn't allow the operation.
2026: * @see #removeAWTEventListener
2027: * @see #getAWTEventListeners
2028: * @see SecurityManager#checkPermission
2029: * @see java.awt.AWTEvent
2030: * @see java.awt.AWTPermission
2031: * @see java.awt.event.AWTEventListener
2032: * @see java.awt.event.AWTEventListenerProxy
2033: * @since 1.2
2034: */
2035: public void addAWTEventListener(AWTEventListener listener,
2036: long eventMask) {
2037: AWTEventListener localL = deProxyAWTEventListener(listener);
2038:
2039: if (localL == null) {
2040: return;
2041: }
2042: SecurityManager security = System.getSecurityManager();
2043: if (security != null) {
2044: security
2045: .checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
2046: }
2047: synchronized (this ) {
2048: SelectiveAWTEventListener selectiveListener = (SelectiveAWTEventListener) listener2SelectiveListener
2049: .get(localL);
2050:
2051: if (selectiveListener == null) {
2052: // Create a new selectiveListener.
2053: selectiveListener = new SelectiveAWTEventListener(
2054: localL, eventMask);
2055: listener2SelectiveListener.put(localL,
2056: selectiveListener);
2057: eventListener = ToolkitEventMulticaster.add(
2058: eventListener, selectiveListener);
2059: }
2060: // OR the eventMask into the selectiveListener's event mask.
2061: selectiveListener.orEventMasks(eventMask);
2062:
2063: enabledOnToolkitMask |= eventMask;
2064:
2065: long mask = eventMask;
2066: for (int i = 0; i < LONG_BITS; i++) {
2067: // If no bits are set, break out of loop.
2068: if (mask == 0) {
2069: break;
2070: }
2071: if ((mask & 1L) != 0) { // Always test bit 0.
2072: calls[i]++;
2073: }
2074: mask >>>= 1; // Right shift, fill with zeros on left.
2075: }
2076: }
2077: }
2078:
2079: /**
2080: * Removes an AWTEventListener from receiving dispatched AWTEvents.
2081: * <p>
2082: * First, if there is a security manager, its <code>checkPermission</code>
2083: * method is called with an
2084: * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
2085: * This may result in a SecurityException.
2086: * <p>
2087: * Note: event listener use is not recommended for normal
2088: * application use, but are intended solely to support special
2089: * purpose facilities including support for accessibility,
2090: * event record/playback, and diagnostic tracing.
2091: *
2092: * If listener is null, no exception is thrown and no action is performed.
2093: *
2094: * @param listener the event listener.
2095: * @throws SecurityException
2096: * if a security manager exists and its
2097: * <code>checkPermission</code> method doesn't allow the operation.
2098: * @see #addAWTEventListener
2099: * @see #getAWTEventListeners
2100: * @see SecurityManager#checkPermission
2101: * @see java.awt.AWTEvent
2102: * @see java.awt.AWTPermission
2103: * @see java.awt.event.AWTEventListener
2104: * @see java.awt.event.AWTEventListenerProxy
2105: * @since 1.2
2106: */
2107: public void removeAWTEventListener(AWTEventListener listener) {
2108: AWTEventListener localL = deProxyAWTEventListener(listener);
2109:
2110: if (listener == null) {
2111: return;
2112: }
2113: SecurityManager security = System.getSecurityManager();
2114: if (security != null) {
2115: security
2116: .checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
2117: }
2118:
2119: synchronized (this ) {
2120: SelectiveAWTEventListener selectiveListener = (SelectiveAWTEventListener) listener2SelectiveListener
2121: .get(localL);
2122:
2123: if (selectiveListener != null) {
2124: listener2SelectiveListener.remove(localL);
2125: int[] listenerCalls = selectiveListener.getCalls();
2126: for (int i = 0; i < LONG_BITS; i++) {
2127: calls[i] -= listenerCalls[i];
2128: assert calls[i] >= 0 : "Negative Listeners count";
2129:
2130: if (calls[i] == 0) {
2131: enabledOnToolkitMask &= ~(1L << i);
2132: }
2133: }
2134: }
2135: eventListener = ToolkitEventMulticaster.remove(
2136: eventListener, (selectiveListener == null) ? localL
2137: : selectiveListener);
2138: }
2139: }
2140:
2141: static boolean enabledOnToolkit(long eventMask) {
2142: return (enabledOnToolkitMask & eventMask) != 0;
2143: }
2144:
2145: synchronized int countAWTEventListeners(long eventMask) {
2146: if (dbg.on) {
2147: dbg.assertion(eventMask != 0);
2148: }
2149:
2150: int ci = 0;
2151: for (; eventMask != 0; eventMask >>>= 1, ci++) {
2152: }
2153: ci--;
2154: return calls[ci];
2155: }
2156:
2157: /**
2158: * Returns an array of all the <code>AWTEventListener</code>s
2159: * registered on this toolkit.
2160: * If there is a security manager, its {@code checkPermission}
2161: * method is called with an
2162: * {@code AWTPermission("listenToAllAWTEvents")} permission.
2163: * This may result in a SecurityException.
2164: * Listeners can be returned
2165: * within <code>AWTEventListenerProxy</code> objects, which also contain
2166: * the event mask for the given listener.
2167: * Note that listener objects
2168: * added multiple times appear only once in the returned array.
2169: *
2170: * @return all of the <code>AWTEventListener</code>s or an empty
2171: * array if no listeners are currently registered
2172: * @throws SecurityException
2173: * if a security manager exists and its
2174: * <code>checkPermission</code> method doesn't allow the operation.
2175: * @see #addAWTEventListener
2176: * @see #removeAWTEventListener
2177: * @see SecurityManager#checkPermission
2178: * @see java.awt.AWTEvent
2179: * @see java.awt.AWTPermission
2180: * @see java.awt.event.AWTEventListener
2181: * @see java.awt.event.AWTEventListenerProxy
2182: * @since 1.4
2183: */
2184: public AWTEventListener[] getAWTEventListeners() {
2185: SecurityManager security = System.getSecurityManager();
2186: if (security != null) {
2187: security
2188: .checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
2189: }
2190: synchronized (this ) {
2191: EventListener[] la = ToolkitEventMulticaster.getListeners(
2192: eventListener, AWTEventListener.class);
2193:
2194: AWTEventListener[] ret = new AWTEventListener[la.length];
2195: for (int i = 0; i < la.length; i++) {
2196: SelectiveAWTEventListener sael = (SelectiveAWTEventListener) la[i];
2197: AWTEventListener tempL = sael.getListener();
2198: //assert tempL is not an AWTEventListenerProxy - we should
2199: // have weeded them all out
2200: // don't want to wrap a proxy inside a proxy
2201: ret[i] = new AWTEventListenerProxy(sael.getEventMask(),
2202: tempL);
2203: }
2204: return ret;
2205: }
2206: }
2207:
2208: /**
2209: * Returns an array of all the <code>AWTEventListener</code>s
2210: * registered on this toolkit which listen to all of the event
2211: * types specified in the {@code eventMask} argument.
2212: * If there is a security manager, its {@code checkPermission}
2213: * method is called with an
2214: * {@code AWTPermission("listenToAllAWTEvents")} permission.
2215: * This may result in a SecurityException.
2216: * Listeners can be returned
2217: * within <code>AWTEventListenerProxy</code> objects, which also contain
2218: * the event mask for the given listener.
2219: * Note that listener objects
2220: * added multiple times appear only once in the returned array.
2221: *
2222: * @param eventMask the bitmask of event types to listen for
2223: * @return all of the <code>AWTEventListener</code>s registered
2224: * on this toolkit for the specified
2225: * event types, or an empty array if no such listeners
2226: * are currently registered
2227: * @throws SecurityException
2228: * if a security manager exists and its
2229: * <code>checkPermission</code> method doesn't allow the operation.
2230: * @see #addAWTEventListener
2231: * @see #removeAWTEventListener
2232: * @see SecurityManager#checkPermission
2233: * @see java.awt.AWTEvent
2234: * @see java.awt.AWTPermission
2235: * @see java.awt.event.AWTEventListener
2236: * @see java.awt.event.AWTEventListenerProxy
2237: * @since 1.4
2238: */
2239: public AWTEventListener[] getAWTEventListeners(long eventMask) {
2240: SecurityManager security = System.getSecurityManager();
2241: if (security != null) {
2242: security
2243: .checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
2244: }
2245: synchronized (this ) {
2246: EventListener[] la = ToolkitEventMulticaster.getListeners(
2247: eventListener, AWTEventListener.class);
2248:
2249: java.util.List list = new ArrayList(la.length);
2250:
2251: for (int i = 0; i < la.length; i++) {
2252: SelectiveAWTEventListener sael = (SelectiveAWTEventListener) la[i];
2253: if ((sael.getEventMask() & eventMask) == eventMask) {
2254: //AWTEventListener tempL = sael.getListener();
2255: list.add(new AWTEventListenerProxy(sael
2256: .getEventMask(), sael.getListener()));
2257: }
2258: }
2259: return (AWTEventListener[]) list
2260: .toArray(new AWTEventListener[0]);
2261: }
2262: }
2263:
2264: /*
2265: * This method notifies any AWTEventListeners that an event
2266: * is about to be dispatched.
2267: *
2268: * @param theEvent the event which will be dispatched.
2269: */
2270: void notifyAWTEventListeners(AWTEvent theEvent) {
2271: // This is a workaround for headless toolkits. It would be
2272: // better to override this method but it is declared package private.
2273: // "this instanceof" syntax defeats polymorphism.
2274: // --mm, 03/03/00
2275: if (this instanceof HeadlessToolkit) {
2276: ((HeadlessToolkit) this ).getUnderlyingToolkit()
2277: .notifyAWTEventListeners(theEvent);
2278: return;
2279: }
2280:
2281: AWTEventListener eventListener = this .eventListener;
2282: if (eventListener != null) {
2283: eventListener.eventDispatched(theEvent);
2284: }
2285: }
2286:
2287: static private class ToolkitEventMulticaster extends
2288: AWTEventMulticaster implements AWTEventListener {
2289: // Implementation cloned from AWTEventMulticaster.
2290:
2291: ToolkitEventMulticaster(AWTEventListener a, AWTEventListener b) {
2292: super (a, b);
2293: }
2294:
2295: static AWTEventListener add(AWTEventListener a,
2296: AWTEventListener b) {
2297: if (a == null)
2298: return b;
2299: if (b == null)
2300: return a;
2301: return new ToolkitEventMulticaster(a, b);
2302: }
2303:
2304: static AWTEventListener remove(AWTEventListener l,
2305: AWTEventListener oldl) {
2306: return (AWTEventListener) removeInternal(l, oldl);
2307: }
2308:
2309: // #4178589: must overload remove(EventListener) to call our add()
2310: // instead of the static addInternal() so we allocate a
2311: // ToolkitEventMulticaster instead of an AWTEventMulticaster.
2312: // Note: this method is called by AWTEventListener.removeInternal(),
2313: // so its method signature must match AWTEventListener.remove().
2314: protected EventListener remove(EventListener oldl) {
2315: if (oldl == a)
2316: return b;
2317: if (oldl == b)
2318: return a;
2319: AWTEventListener a2 = (AWTEventListener) removeInternal(a,
2320: oldl);
2321: AWTEventListener b2 = (AWTEventListener) removeInternal(b,
2322: oldl);
2323: if (a2 == a && b2 == b) {
2324: return this ; // it's not here
2325: }
2326: return add(a2, b2);
2327: }
2328:
2329: public void eventDispatched(AWTEvent event) {
2330: ((AWTEventListener) a).eventDispatched(event);
2331: ((AWTEventListener) b).eventDispatched(event);
2332: }
2333: }
2334:
2335: private class SelectiveAWTEventListener implements AWTEventListener {
2336: AWTEventListener listener;
2337: private long eventMask;
2338: // This array contains the number of times to call the eventlistener
2339: // for each event type.
2340: int[] calls = new int[Toolkit.LONG_BITS];
2341:
2342: public AWTEventListener getListener() {
2343: return listener;
2344: }
2345:
2346: public long getEventMask() {
2347: return eventMask;
2348: }
2349:
2350: public int[] getCalls() {
2351: return calls;
2352: }
2353:
2354: public void orEventMasks(long mask) {
2355: eventMask |= mask;
2356: // For each event bit set in mask, increment its call count.
2357: for (int i = 0; i < Toolkit.LONG_BITS; i++) {
2358: // If no bits are set, break out of loop.
2359: if (mask == 0) {
2360: break;
2361: }
2362: if ((mask & 1L) != 0) { // Always test bit 0.
2363: calls[i]++;
2364: }
2365: mask >>>= 1; // Right shift, fill with zeros on left.
2366: }
2367: }
2368:
2369: SelectiveAWTEventListener(AWTEventListener l, long mask) {
2370: listener = l;
2371: eventMask = mask;
2372: }
2373:
2374: public void eventDispatched(AWTEvent event) {
2375: long eventBit = 0; // Used to save the bit of the event type.
2376: if (((eventBit = eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0
2377: && event.id >= ComponentEvent.COMPONENT_FIRST && event.id <= ComponentEvent.COMPONENT_LAST)
2378: || ((eventBit = eventMask
2379: & AWTEvent.CONTAINER_EVENT_MASK) != 0
2380: && event.id >= ContainerEvent.CONTAINER_FIRST && event.id <= ContainerEvent.CONTAINER_LAST)
2381: || ((eventBit = eventMask
2382: & AWTEvent.FOCUS_EVENT_MASK) != 0
2383: && event.id >= FocusEvent.FOCUS_FIRST && event.id <= FocusEvent.FOCUS_LAST)
2384: || ((eventBit = eventMask & AWTEvent.KEY_EVENT_MASK) != 0
2385: && event.id >= KeyEvent.KEY_FIRST && event.id <= KeyEvent.KEY_LAST)
2386: || ((eventBit = eventMask
2387: & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 && event.id == MouseEvent.MOUSE_WHEEL)
2388: || ((eventBit = eventMask
2389: & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 && (event.id == MouseEvent.MOUSE_MOVED || event.id == MouseEvent.MOUSE_DRAGGED))
2390: || ((eventBit = eventMask
2391: & AWTEvent.MOUSE_EVENT_MASK) != 0
2392: && event.id != MouseEvent.MOUSE_MOVED
2393: && event.id != MouseEvent.MOUSE_DRAGGED
2394: && event.id != MouseEvent.MOUSE_WHEEL
2395: && event.id >= MouseEvent.MOUSE_FIRST && event.id <= MouseEvent.MOUSE_LAST)
2396: || ((eventBit = eventMask
2397: & AWTEvent.WINDOW_EVENT_MASK) != 0 && (event.id >= WindowEvent.WINDOW_FIRST && event.id <= WindowEvent.WINDOW_LAST))
2398: || ((eventBit = eventMask
2399: & AWTEvent.ACTION_EVENT_MASK) != 0
2400: && event.id >= ActionEvent.ACTION_FIRST && event.id <= ActionEvent.ACTION_LAST)
2401: || ((eventBit = eventMask
2402: & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0
2403: && event.id >= AdjustmentEvent.ADJUSTMENT_FIRST && event.id <= AdjustmentEvent.ADJUSTMENT_LAST)
2404: || ((eventBit = eventMask
2405: & AWTEvent.ITEM_EVENT_MASK) != 0
2406: && event.id >= ItemEvent.ITEM_FIRST && event.id <= ItemEvent.ITEM_LAST)
2407: || ((eventBit = eventMask
2408: & AWTEvent.TEXT_EVENT_MASK) != 0
2409: && event.id >= TextEvent.TEXT_FIRST && event.id <= TextEvent.TEXT_LAST)
2410: || ((eventBit = eventMask
2411: & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0
2412: && event.id >= InputMethodEvent.INPUT_METHOD_FIRST && event.id <= InputMethodEvent.INPUT_METHOD_LAST)
2413: || ((eventBit = eventMask
2414: & AWTEvent.PAINT_EVENT_MASK) != 0
2415: && event.id >= PaintEvent.PAINT_FIRST && event.id <= PaintEvent.PAINT_LAST)
2416: || ((eventBit = eventMask
2417: & AWTEvent.INVOCATION_EVENT_MASK) != 0
2418: && event.id >= InvocationEvent.INVOCATION_FIRST && event.id <= InvocationEvent.INVOCATION_LAST)
2419: || ((eventBit = eventMask
2420: & AWTEvent.HIERARCHY_EVENT_MASK) != 0 && event.id == HierarchyEvent.HIERARCHY_CHANGED)
2421: || ((eventBit = eventMask
2422: & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 && (event.id == HierarchyEvent.ANCESTOR_MOVED || event.id == HierarchyEvent.ANCESTOR_RESIZED))
2423: || ((eventBit = eventMask
2424: & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 && event.id == WindowEvent.WINDOW_STATE_CHANGED)
2425: || ((eventBit = eventMask
2426: & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 && (event.id == WindowEvent.WINDOW_GAINED_FOCUS || event.id == WindowEvent.WINDOW_LOST_FOCUS))
2427: || ((eventBit = eventMask
2428: & sun.awt.SunToolkit.GRAB_EVENT_MASK) != 0 && (event instanceof sun.awt.UngrabEvent))) {
2429: // Get the index of the call count for this event type.
2430: // Instead of using Math.log(...) we will calculate it with
2431: // bit shifts. That's what previous implementation looked like:
2432: //
2433: // int ci = (int) (Math.log(eventBit)/Math.log(2));
2434: int ci = 0;
2435: for (long eMask = eventBit; eMask != 0; eMask >>>= 1, ci++) {
2436: }
2437: ci--;
2438: // Call the listener as many times as it was added for this
2439: // event type.
2440: for (int i = 0; i < calls[ci]; i++) {
2441: listener.eventDispatched(event);
2442: }
2443: }
2444: }
2445: }
2446:
2447: /**
2448: * Returns a map of visual attributes for the abstract level description
2449: * of the given input method highlight, or null if no mapping is found.
2450: * The style field of the input method highlight is ignored. The map
2451: * returned is unmodifiable.
2452: * @param highlight input method highlight
2453: * @return style attribute map, or <code>null</code>
2454: * @exception HeadlessException if
2455: * <code>GraphicsEnvironment.isHeadless</code> returns true
2456: * @see java.awt.GraphicsEnvironment#isHeadless
2457: * @since 1.3
2458: */
2459: public abstract Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(
2460: InputMethodHighlight highlight) throws HeadlessException;
2461:
2462: private static PropertyChangeSupport createPropertyChangeSupport(
2463: Toolkit toolkit) {
2464: if (toolkit instanceof SunToolkit
2465: || toolkit instanceof HeadlessToolkit) {
2466: return new DesktopPropertyChangeSupport(toolkit);
2467: } else {
2468: return new PropertyChangeSupport(toolkit);
2469: }
2470: }
2471:
2472: private static class DesktopPropertyChangeSupport extends
2473: PropertyChangeSupport {
2474: private static final StringBuilder PROP_CHANGE_SUPPORT_KEY = new StringBuilder(
2475: "desktop property change support key");
2476: private final Object source;
2477:
2478: public DesktopPropertyChangeSupport(Object sourceBean) {
2479: super (sourceBean);
2480: source = sourceBean;
2481: }
2482:
2483: @Override
2484: public synchronized void addPropertyChangeListener(
2485: String propertyName, PropertyChangeListener listener) {
2486: PropertyChangeSupport pcs = (PropertyChangeSupport) AppContext
2487: .getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
2488: if (null == pcs) {
2489: pcs = new PropertyChangeSupport(source);
2490: AppContext.getAppContext().put(PROP_CHANGE_SUPPORT_KEY,
2491: pcs);
2492: }
2493: pcs.addPropertyChangeListener(propertyName, listener);
2494: }
2495:
2496: @Override
2497: public synchronized void removePropertyChangeListener(
2498: String propertyName, PropertyChangeListener listener) {
2499: PropertyChangeSupport pcs = (PropertyChangeSupport) AppContext
2500: .getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
2501: if (null != pcs) {
2502: pcs
2503: .removePropertyChangeListener(propertyName,
2504: listener);
2505: }
2506: }
2507:
2508: @Override
2509: public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
2510: PropertyChangeSupport pcs = (PropertyChangeSupport) AppContext
2511: .getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
2512: if (null != pcs) {
2513: return pcs.getPropertyChangeListeners();
2514: } else {
2515: return new PropertyChangeListener[0];
2516: }
2517: }
2518:
2519: @Override
2520: public synchronized PropertyChangeListener[] getPropertyChangeListeners(
2521: String propertyName) {
2522: PropertyChangeSupport pcs = (PropertyChangeSupport) AppContext
2523: .getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
2524: if (null != pcs) {
2525: return pcs.getPropertyChangeListeners(propertyName);
2526: } else {
2527: return new PropertyChangeListener[0];
2528: }
2529: }
2530:
2531: @Override
2532: public synchronized void addPropertyChangeListener(
2533: PropertyChangeListener listener) {
2534: PropertyChangeSupport pcs = (PropertyChangeSupport) AppContext
2535: .getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
2536: if (null == pcs) {
2537: pcs = new PropertyChangeSupport(source);
2538: AppContext.getAppContext().put(PROP_CHANGE_SUPPORT_KEY,
2539: pcs);
2540: }
2541: pcs.addPropertyChangeListener(listener);
2542: }
2543:
2544: @Override
2545: public synchronized void removePropertyChangeListener(
2546: PropertyChangeListener listener) {
2547: PropertyChangeSupport pcs = (PropertyChangeSupport) AppContext
2548: .getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
2549: if (null != pcs) {
2550: pcs.removePropertyChangeListener(listener);
2551: }
2552: }
2553:
2554: /*
2555: * we do expect that all other fireXXX() methods of java.beans.PropertyChangeSupport
2556: * use this method. If this will be changed we will need to change this class.
2557: */
2558: @Override
2559: public void firePropertyChange(final PropertyChangeEvent evt) {
2560: Object oldValue = evt.getOldValue();
2561: Object newValue = evt.getNewValue();
2562: String propertyName = evt.getPropertyName();
2563: if (oldValue != null && newValue != null
2564: && oldValue.equals(newValue)) {
2565: return;
2566: }
2567: Runnable updater = new Runnable() {
2568: public void run() {
2569: PropertyChangeSupport pcs = (PropertyChangeSupport) AppContext
2570: .getAppContext().get(
2571: PROP_CHANGE_SUPPORT_KEY);
2572: if (null != pcs) {
2573: pcs.firePropertyChange(evt);
2574: }
2575: }
2576: };
2577: final AppContext currentAppContext = AppContext
2578: .getAppContext();
2579: for (AppContext appContext : AppContext.getAppContexts()) {
2580: if (null == appContext || appContext.isDisposed()) {
2581: continue;
2582: }
2583: if (currentAppContext == appContext) {
2584: updater.run();
2585: } else {
2586: final PeerEvent e = new PeerEvent(source, updater,
2587: PeerEvent.ULTIMATE_PRIORITY_EVENT);
2588: SunToolkit.postEvent(appContext, e);
2589: }
2590: }
2591: }
2592: }
2593: }
|