Frames | No Frames |
1: /* Toolkit.java -- AWT Toolkit superclass 2: Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 3: Free Software Foundation, Inc. 4: 5: This file is part of GNU Classpath. 6: 7: GNU Classpath is free software; you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation; either version 2, or (at your option) 10: any later version. 11: 12: GNU Classpath is distributed in the hope that it will be useful, but 13: WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15: General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with GNU Classpath; see the file COPYING. If not, write to the 19: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20: 02110-1301 USA. 21: 22: Linking this library statically or dynamically with other modules is 23: making a combined work based on this library. Thus, the terms and 24: conditions of the GNU General Public License cover the whole 25: combination. 26: 27: As a special exception, the copyright holders of this library give you 28: permission to link this library with independent modules to produce an 29: executable, regardless of the license terms of these independent 30: modules, and to copy and distribute the resulting executable under 31: terms of your choice, provided that you also meet, for each linked 32: independent module, the terms and conditions of the license of that 33: module. An independent module is a module which is not derived from 34: or based on this library. If you modify this library, you may extend 35: this exception to your version of the library, but you are not 36: obligated to do so. If you do not wish to do so, delete this 37: exception statement from your version. */ 38: 39: 40: package java.awt; 41: 42: import gnu.classpath.SystemProperties; 43: import gnu.java.awt.peer.GLightweightPeer; 44: 45: import java.awt.datatransfer.Clipboard; 46: import java.awt.dnd.DragGestureEvent; 47: import java.awt.dnd.DragGestureListener; 48: import java.awt.dnd.DragGestureRecognizer; 49: import java.awt.dnd.DragSource; 50: import java.awt.dnd.peer.DragSourceContextPeer; 51: import java.awt.event.AWTEventListener; 52: import java.awt.event.AWTEventListenerProxy; 53: import java.awt.event.KeyEvent; 54: import java.awt.im.InputMethodHighlight; 55: import java.awt.image.ColorModel; 56: import java.awt.image.ImageObserver; 57: import java.awt.image.ImageProducer; 58: import java.awt.peer.ButtonPeer; 59: import java.awt.peer.CanvasPeer; 60: import java.awt.peer.CheckboxMenuItemPeer; 61: import java.awt.peer.CheckboxPeer; 62: import java.awt.peer.ChoicePeer; 63: import java.awt.peer.DialogPeer; 64: import java.awt.peer.FileDialogPeer; 65: import java.awt.peer.FontPeer; 66: import java.awt.peer.FramePeer; 67: import java.awt.peer.LabelPeer; 68: import java.awt.peer.LightweightPeer; 69: import java.awt.peer.ListPeer; 70: import java.awt.peer.MenuBarPeer; 71: import java.awt.peer.MenuItemPeer; 72: import java.awt.peer.MenuPeer; 73: import java.awt.peer.MouseInfoPeer; 74: import java.awt.peer.PanelPeer; 75: import java.awt.peer.PopupMenuPeer; 76: import java.awt.peer.ScrollPanePeer; 77: import java.awt.peer.ScrollbarPeer; 78: import java.awt.peer.TextAreaPeer; 79: import java.awt.peer.TextFieldPeer; 80: import java.awt.peer.WindowPeer; 81: import java.beans.PropertyChangeListener; 82: import java.beans.PropertyChangeSupport; 83: import java.io.File; 84: import java.io.FileInputStream; 85: import java.net.URL; 86: import java.security.AccessController; 87: import java.security.PrivilegedAction; 88: import java.util.ArrayList; 89: import java.util.Map; 90: import java.util.Properties; 91: import java.util.StringTokenizer; 92: 93: /** 94: * The AWT system uses a set of native peer objects to implement its 95: * widgets. These peers are provided by a peer toolkit, that is accessed 96: * via a subclass of this superclass. The system toolkit is retrieved 97: * by the static methods <code>getDefaultToolkit</code>. This method 98: * determines the system toolkit by examining the system property 99: * <code>awt.toolkit</code>. That property is set to the name of the 100: * <code>Toolkit</code> subclass for the specified peer set. If the 101: * <code>awt.toolkit</code> property is not set, then the default 102: * toolkit <code>gnu.java.awt.peer.gtk.GtkToolkit</code> is used. This 103: * toolkit creates its peers using the GTK+ toolkit. 104: * 105: * @author Aaron M. Renn (arenn@urbanophile.com) 106: */ 107: public abstract class Toolkit 108: { 109: /** The default toolkit name. */ 110: private static String default_toolkit_name 111: = gnu.classpath.Configuration.default_awt_peer_toolkit; 112: 113: /** 114: * The toolkit in use. Once we load it, we don't ever change it 115: * if the awt.toolkit property is set. 116: */ 117: private static Toolkit toolkit; 118: 119: /** The toolkit properties. */ 120: private static Properties props = new Properties(); 121: 122: protected final Map desktopProperties = new Properties(); 123: 124: protected final PropertyChangeSupport desktopPropsSupport 125: = new PropertyChangeSupport(this); 126: 127: /** 128: * All registered AWTEventListener objects. This is package private, so the 129: * event queue can efficiently access this list. 130: */ 131: AWTEventListenerProxy[] awtEventListeners; 132: 133: /** 134: * Default constructor for subclasses. 135: */ 136: public Toolkit() 137: { 138: awtEventListeners = new AWTEventListenerProxy[0]; 139: } 140: 141: /** 142: * Creates a peer object for the specified <code>Button</code>. 143: * 144: * @param target The <code>Button</code> to create the peer for. 145: * 146: * @return The peer for the specified <code>Button</code> object. 147: * 148: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 149: */ 150: protected abstract ButtonPeer createButton(Button target); 151: 152: /** 153: * Creates a peer object for the specified <code>TextField</code>. 154: * 155: * @param target The <code>TextField</code> to create the peer for. 156: * 157: * @return The peer for the specified <code>TextField</code> object. 158: * 159: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 160: */ 161: protected abstract TextFieldPeer createTextField(TextField target); 162: 163: /** 164: * Creates a peer object for the specified <code>Label</code>. 165: * 166: * @param target The <code>Label</code> to create the peer for. 167: * 168: * @return The peer for the specified <code>Label</code> object. 169: * 170: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 171: */ 172: protected abstract LabelPeer createLabel(Label target); 173: 174: /** 175: * Creates a peer object for the specified <code>List</code>. 176: * 177: * @param target The <code>List</code> to create the peer for. 178: * 179: * @return The peer for the specified <code>List</code> object. 180: * 181: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 182: */ 183: protected abstract ListPeer createList(List target); 184: 185: /** 186: * Creates a peer object for the specified <code>Checkbox</code>. 187: * 188: * @param target The <code>Checkbox</code> to create the peer for. 189: * 190: * @return The peer for the specified <code>Checkbox</code> object. 191: * 192: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 193: */ 194: protected abstract CheckboxPeer createCheckbox(Checkbox target); 195: 196: /** 197: * Creates a peer object for the specified <code>Scrollbar</code>. 198: * 199: * @param target The <code>Scrollbar</code> to create the peer for. 200: * 201: * @return The peer for the specified <code>Scrollbar</code> object. 202: * 203: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 204: */ 205: protected abstract ScrollbarPeer createScrollbar(Scrollbar target); 206: 207: /** 208: * Creates a peer object for the specified <code>ScrollPane</code>. 209: * 210: * @param target The <code>ScrollPane</code> to create the peer for. 211: * 212: * @return The peer for the specified <code>ScrollPane</code> object. 213: * 214: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 215: */ 216: protected abstract ScrollPanePeer createScrollPane(ScrollPane target); 217: 218: /** 219: * Creates a peer object for the specified <code>TextArea</code>. 220: * 221: * @param target The <code>TextArea</code> to create the peer for. 222: * 223: * @return The peer for the specified <code>TextArea</code> object. 224: * 225: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 226: */ 227: protected abstract TextAreaPeer createTextArea(TextArea target); 228: 229: /** 230: * Creates a peer object for the specified <code>Choice</code>. 231: * 232: * @param target The <code>Choice</code> to create the peer for. 233: * 234: * @return The peer for the specified <code>Choice</code> object. 235: * 236: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 237: */ 238: protected abstract ChoicePeer createChoice(Choice target); 239: 240: /** 241: * Creates a peer object for the specified <code>Frame</code>. 242: * 243: * @param target The <code>Frame</code> to create the peer for. 244: * 245: * @return The peer for the specified <code>Frame</code> object. 246: * 247: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 248: */ 249: protected abstract FramePeer createFrame(Frame target); 250: 251: /** 252: * Creates a peer object for the specified <code>Canvas</code>. 253: * 254: * @param target The <code>Canvas</code> to create the peer for. 255: * 256: * @return The peer for the specified <code>Canvas</code> object. 257: */ 258: protected abstract CanvasPeer createCanvas(Canvas target); 259: 260: /** 261: * Creates a peer object for the specified <code>Panel</code>. 262: * 263: * @param target The <code>Panel</code> to create the peer for. 264: * 265: * @return The peer for the specified <code>Panel</code> object. 266: */ 267: protected abstract PanelPeer createPanel(Panel target); 268: 269: /** 270: * Creates a peer object for the specified <code>Window</code>. 271: * 272: * @param target The <code>Window</code> to create the peer for. 273: * 274: * @return The peer for the specified <code>Window</code> object. 275: * 276: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 277: */ 278: protected abstract WindowPeer createWindow(Window target); 279: 280: /** 281: * Creates a peer object for the specified <code>Dialog</code>. 282: * 283: * @param target The dialog to create the peer for 284: * 285: * @return The peer for the specified font name. 286: * 287: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 288: */ 289: protected abstract DialogPeer createDialog(Dialog target); 290: 291: /** 292: * Creates a peer object for the specified <code>MenuBar</code>. 293: * 294: * @param target The <code>MenuBar</code> to create the peer for. 295: * 296: * @return The peer for the specified <code>MenuBar</code> object. 297: * 298: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 299: */ 300: protected abstract MenuBarPeer createMenuBar(MenuBar target); 301: 302: /** 303: * Creates a peer object for the specified <code>Menu</code>. 304: * 305: * @param target The <code>Menu</code> to create the peer for. 306: * 307: * @return The peer for the specified <code>Menu</code> object. 308: * 309: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 310: */ 311: protected abstract MenuPeer createMenu(Menu target); 312: 313: /** 314: * Creates a peer object for the specified <code>PopupMenu</code>. 315: * 316: * @param target The <code>PopupMenu</code> to create the peer for. 317: * 318: * @return The peer for the specified <code>PopupMenu</code> object. 319: * 320: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 321: */ 322: protected abstract PopupMenuPeer createPopupMenu(PopupMenu target); 323: 324: /** 325: * Creates a peer object for the specified <code>MenuItem</code>. 326: * 327: * @param target The <code>MenuItem</code> to create the peer for. 328: * 329: * @return The peer for the specified <code>MenuItem</code> object. 330: * 331: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 332: */ 333: protected abstract MenuItemPeer createMenuItem(MenuItem target); 334: 335: /** 336: * Returns a MouseInfoPeer. 337: * The default implementation of this method throws 338: * UnsupportedOperationException. 339: * 340: * Toolkit implementations should overload this if possible, however. 341: */ 342: protected MouseInfoPeer getMouseInfoPeer() 343: { 344: throw new UnsupportedOperationException("No mouse info peer."); 345: } 346: 347: /** 348: * Creates a peer object for the specified <code>FileDialog</code>. 349: * 350: * @param target The <code>FileDialog</code> to create the peer for. 351: * 352: * @return The peer for the specified <code>FileDialog</code> object. 353: * 354: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 355: */ 356: protected abstract FileDialogPeer createFileDialog(FileDialog target); 357: 358: /** 359: * Creates a peer object for the specified <code>CheckboxMenuItem</code>. 360: * 361: * @param target The <code>CheckboxMenuItem</code> to create the peer for. 362: * 363: * @return The peer for the specified <code>CheckboxMenuItem</code> object. 364: * 365: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 366: */ 367: protected abstract CheckboxMenuItemPeer 368: createCheckboxMenuItem(CheckboxMenuItem target); 369: 370: /** 371: * Creates a peer object for the specified <code>Component</code>. The 372: * peer returned by this method is not a native windowing system peer 373: * with its own native window. Instead, this method allows the component 374: * to draw on its parent window as a "lightweight" widget. 375: * 376: * @param target The <code>Component</code> to create the peer for. 377: * 378: * @return The peer for the specified <code>Component</code> object. 379: */ 380: protected LightweightPeer createComponent(Component target) 381: { 382: return new GLightweightPeer(target); 383: } 384: 385: /** 386: * Creates a peer object for the specified font name. 387: * 388: * @param name The font to create the peer for. 389: * @param style The font style to create the peer for. 390: * 391: * @return The peer for the specified font name. 392: * 393: * @deprecated 394: */ 395: protected abstract FontPeer getFontPeer(String name, int style); 396: 397: /** 398: * Copies the current system colors into the specified array. This is 399: * the interface used by the <code>SystemColor</code> class. Although 400: * this method fills in the array with some default colors a real Toolkit 401: * should override this method and provide real system colors for the 402: * native GUI platform. 403: * 404: * @param systemColors The array to copy the system colors into. 405: * It must be at least 26 elements. 406: * 407: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 408: * 409: * @see java.awt.SystemColor 410: */ 411: protected void loadSystemColors(int systemColors[]) 412: { 413: systemColors[SystemColor.DESKTOP] = 0xFF005C5C; 414: systemColors[SystemColor.ACTIVE_CAPTION] = 0xFF000080; 415: systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = 0xFFFFFFFF; 416: systemColors[SystemColor.ACTIVE_CAPTION_BORDER] = 0xFFC0C0C0; 417: systemColors[SystemColor.INACTIVE_CAPTION] = 0xFF808080; 418: systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = 0xFFC0C0C0; 419: systemColors[SystemColor.INACTIVE_CAPTION_BORDER] = 0xFFC0C0C0; 420: systemColors[SystemColor.WINDOW] = 0xFFFFFFFF; 421: systemColors[SystemColor.WINDOW_BORDER] = 0xFF000000; 422: systemColors[SystemColor.WINDOW_TEXT] = 0xFF000000; 423: systemColors[SystemColor.MENU] = 0xFFC0C0C0; 424: systemColors[SystemColor.MENU_TEXT] = 0xFF000000; 425: systemColors[SystemColor.TEXT] = 0xFFC0C0C0; 426: systemColors[SystemColor.TEXT_TEXT] = 0xFF000000; 427: systemColors[SystemColor.TEXT_HIGHLIGHT] = 0xFF000090; 428: systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = 0xFFFFFFFF; 429: systemColors[SystemColor.TEXT_INACTIVE_TEXT] = 0xFF808080; 430: systemColors[SystemColor.CONTROL] = 0xFFC0C0C0; 431: systemColors[SystemColor.CONTROL_TEXT] = 0xFF000000; 432: systemColors[SystemColor.CONTROL_HIGHLIGHT] = 0xFFFFFFFF; 433: systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] = 0xFFE0E0E0; 434: systemColors[SystemColor.CONTROL_SHADOW] = 0xFF808080; 435: systemColors[SystemColor.CONTROL_DK_SHADOW] = 0xFF000000; 436: systemColors[SystemColor.SCROLLBAR] = 0xFFE0E0E0; 437: systemColors[SystemColor.INFO] = 0xFFE0E000; 438: systemColors[SystemColor.INFO_TEXT] = 0xFF000000; 439: } 440: 441: /** 442: * @since 1.4 443: * 444: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 445: */ 446: public void setDynamicLayout(boolean dynamic) 447: { 448: } 449: 450: /** 451: * @since 1.4 452: * 453: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 454: */ 455: protected boolean isDynamicLayoutSet() 456: { 457: return false; 458: } 459: 460: /** 461: * @since 1.4 462: * 463: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 464: */ 465: public boolean isDynamicLayoutActive() 466: { 467: return false; 468: } 469: 470: /** 471: * Returns the dimensions of the screen in pixels. 472: * 473: * @return The dimensions of the screen in pixels. 474: * 475: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 476: */ 477: public abstract Dimension getScreenSize(); 478: 479: /** 480: * Returns the screen resolution in dots per square inch. 481: * 482: * @return The screen resolution in dots per square inch. 483: * 484: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 485: */ 486: public abstract int getScreenResolution(); 487: 488: /** 489: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 490: * 491: * @since 1.4 492: */ 493: public Insets getScreenInsets(GraphicsConfiguration gc) 494: { 495: return new Insets(0, 0, 0, 0); 496: } 497: 498: /** 499: * Returns the color model of the screen. 500: * 501: * @return The color model of the screen. 502: * 503: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 504: */ 505: public abstract ColorModel getColorModel(); 506: 507: /** 508: * Returns the names of the available fonts. 509: * 510: * @return The names of the available fonts. 511: * 512: * @deprecated 513: */ 514: public abstract String[] getFontList(); 515: 516: /** 517: * Return the font metrics for the specified font 518: * 519: * @param name The name of the font to return metrics for. 520: * 521: * @return The requested font metrics. 522: * 523: * @deprecated 524: */ 525: public abstract FontMetrics getFontMetrics(Font name); 526: 527: /** 528: * Flushes any buffered data to the screen so that it is in sync with 529: * what the AWT system has drawn to it. 530: */ 531: public abstract void sync(); 532: 533: /** 534: * Returns an instance of the default toolkit. The default toolkit is 535: * the subclass of <code>Toolkit</code> specified in the system property 536: * <code>awt.toolkit</code>, or <code>gnu.java.awt.peer.gtk.GtkToolkit</code> 537: * if the property is not set. 538: * 539: * @return An instance of the system default toolkit. 540: * 541: * @throws AWTError If the toolkit cannot be loaded. 542: */ 543: public static Toolkit getDefaultToolkit() 544: { 545: if (toolkit != null) 546: return toolkit; 547: String toolkit_name = SystemProperties.getProperty("awt.toolkit", 548: default_toolkit_name); 549: try 550: { 551: ClassLoader cl; 552: cl = (ClassLoader) AccessController.doPrivileged 553: (new PrivilegedAction() 554: { 555: public Object run() 556: { 557: return ClassLoader.getSystemClassLoader(); 558: } 559: }); 560: Class cls = Class.forName(toolkit_name, true, cl); 561: Object obj = cls.newInstance(); 562: if (!(obj instanceof Toolkit)) 563: throw new AWTError(toolkit_name + " is not a subclass of " + 564: "java.awt.Toolkit"); 565: toolkit = (Toolkit) obj; 566: 567: initAccessibility(); 568: return toolkit; 569: } 570: catch (ThreadDeath death) 571: { 572: throw death; 573: } 574: catch (Throwable t) 575: { 576: AWTError e = new AWTError("Cannot load AWT toolkit: " + toolkit_name); 577: throw (AWTError) e.initCause(t); 578: } 579: } 580: 581: /** 582: * Returns an image from the specified file, which must be in a 583: * recognized format. Supported formats vary from toolkit to toolkit. 584: * 585: * @return name The name of the file to read the image from. 586: */ 587: public abstract Image getImage(String name); 588: 589: /** 590: * Returns an image from the specified URL, which must be in a 591: * recognized format. Supported formats vary from toolkit to toolkit. 592: * 593: * @return url The URl to read the image from. 594: */ 595: public abstract Image getImage(URL url); 596: 597: public abstract Image createImage(String filename); 598: 599: public abstract Image createImage(URL url); 600: 601: /** 602: * Readies an image to be rendered on the screen. The width and height 603: * values can be set to the default sizes for the image by passing -1 604: * in those parameters. 605: * 606: * @param image The image to prepare for rendering. 607: * @param width The width of the image. 608: * @param height The height of the image. 609: * @param observer The observer to receive events about the preparation 610: * process. 611: * 612: * @return <code>true</code> if the image is already prepared for rendering, 613: * <code>false</code> otherwise. 614: */ 615: public abstract boolean prepareImage(Image image, int width, int height, 616: ImageObserver observer); 617: 618: /** 619: * Checks the status of specified image as it is being readied for 620: * rendering. 621: * 622: * @param image The image to prepare for rendering. 623: * @param width The width of the image. 624: * @param height The height of the image. 625: * @param observer The observer to receive events about the preparation 626: * process. 627: * 628: * @return A union of the bitmasks from 629: * <code>java.awt.image.ImageObserver</code> that indicates the current 630: * state of the imaging readying process. 631: */ 632: public abstract int checkImage(Image image, int width, int height, 633: ImageObserver observer); 634: 635: /** 636: * Creates an image using the specified <code>ImageProducer</code> 637: * 638: * @param producer The <code>ImageProducer</code> to create the image from. 639: * 640: * @return The created image. 641: */ 642: public abstract Image createImage(ImageProducer producer); 643: 644: /** 645: * Creates an image from the specified byte array. The array must be in 646: * a recognized format. Supported formats vary from toolkit to toolkit. 647: * 648: * @param data The raw image data. 649: * 650: * @return The created image. 651: */ 652: public Image createImage(byte[] data) 653: { 654: return createImage(data, 0, data.length); 655: } 656: 657: /** 658: * Creates an image from the specified portion of the byte array passed. 659: * The array must be in a recognized format. Supported formats vary from 660: * toolkit to toolkit. 661: * 662: * @param data The raw image data. 663: * @param offset The offset into the data where the image data starts. 664: * @param len The length of the image data. 665: * 666: * @return The created image. 667: */ 668: public abstract Image createImage(byte[] data, int offset, int len); 669: 670: /** 671: * Returns a instance of <code>PrintJob</code> for the specified 672: * arguments. 673: * 674: * @param frame The window initiating the print job. 675: * @param title The print job title. 676: * @param props The print job properties. 677: * 678: * @return The requested print job, or <code>null</code> if the job 679: * was cancelled. 680: * 681: * @exception NullPointerException If frame is null, 682: * or GraphicsEnvironment.isHeadless() returns true. 683: * @exception SecurityException If this thread is not allowed to initiate 684: * a print job request. 685: */ 686: public abstract PrintJob getPrintJob(Frame frame, String title, 687: Properties props); 688: 689: /** 690: * Returns a instance of <code>PrintJob</code> for the specified 691: * arguments. 692: * 693: * @param frame The window initiating the print job. 694: * @param title The print job title. 695: * @param jobAttr A set of job attributes which will control the print job. 696: * @param pageAttr A set of page attributes which will control the print job. 697: * 698: * @exception NullPointerException If frame is null, and either jobAttr is null 699: * or jobAttr.getDialog() returns JobAttributes.DialogType.NATIVE. 700: * @exception IllegalArgumentException If pageAttrspecifies differing cross 701: * feed and feed resolutions, or when GraphicsEnvironment.isHeadless() returns 702: * true. 703: * @exception SecurityException If this thread is not allowed to initiate 704: * a print job request. 705: * 706: * @since 1.3 707: */ 708: public PrintJob getPrintJob(Frame frame, String title, 709: JobAttributes jobAttr, PageAttributes pageAttr) 710: { 711: // FIXME: it is possible this check may be removed 712: // if this method, when written, always delegates to 713: // getPrintJob(Frame, String, Properties). 714: SecurityManager sm; 715: sm = System.getSecurityManager(); 716: if (sm != null) 717: sm.checkPrintJobAccess(); 718: 719: return null; 720: } 721: 722: /** 723: * Causes a "beep" tone to be generated. 724: */ 725: public abstract void beep(); 726: 727: /** 728: * Returns the system clipboard. 729: * 730: * @return THe system clipboard. 731: * 732: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 733: */ 734: public abstract Clipboard getSystemClipboard(); 735: 736: /** 737: * Gets the singleton instance of the system selection as a 738: * Clipboard object. The system selection contains the selected text 739: * of the last component/widget that had focus and a text selection. 740: * The default implementation returns null. 741: * 742: * @return The Clipboard holding the system (text) selection or null 743: * if the Toolkit or system doesn't support a selection clipboard. 744: * 745: * @exception HeadlessException If GraphicsEnvironment.isHeadless() 746: * is true. 747: * @exception SecurityException If the current security manager 748: * checkSystemClipboardAccess() doesn't allow access. 749: * 750: * @since 1.4 751: */ 752: public Clipboard getSystemSelection() 753: { 754: return null; 755: } 756: 757: /** 758: * Returns the accelerator key mask for menu shortcuts. The default is 759: * <code>Event.CTRL_MASK</code>. A toolkit must override this method 760: * to change the default. 761: * 762: * @return The key mask for the menu accelerator key. 763: * 764: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 765: */ 766: public int getMenuShortcutKeyMask() 767: { 768: return Event.CTRL_MASK; 769: } 770: 771: /** 772: * Returns whether the given locking key on the keyboard is currently in its 773: * "on" state. 774: * 775: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 776: * @exception IllegalArgumentException If keyCode is not one of the valid keys. 777: * @exception UnsupportedOperationException If the host system doesn't allow 778: * getting the state of this key programmatically, or if the keyboard doesn't 779: * have this key. 780: */ 781: public boolean getLockingKeyState(int keyCode) 782: { 783: if (keyCode != KeyEvent.VK_CAPS_LOCK 784: && keyCode != KeyEvent.VK_NUM_LOCK 785: && keyCode != KeyEvent.VK_SCROLL_LOCK) 786: throw new IllegalArgumentException(); 787: 788: throw new UnsupportedOperationException(); 789: } 790: 791: /** 792: * Sets the state of the given locking key on the keyboard. 793: * 794: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 795: * @exception IllegalArgumentException If keyCode is not one of the valid keys. 796: * @exception UnsupportedOperationException If the host system doesn't allow 797: * getting the state of this key programmatically, or if the keyboard doesn't 798: * have this key. 799: */ 800: public void setLockingKeyState(int keyCode, boolean on) 801: { 802: if (keyCode != KeyEvent.VK_CAPS_LOCK 803: && keyCode != KeyEvent.VK_NUM_LOCK 804: && keyCode != KeyEvent.VK_SCROLL_LOCK) 805: throw new IllegalArgumentException(); 806: 807: throw new UnsupportedOperationException(); 808: } 809: 810: /** 811: * Returns the native container object of the specified component. This 812: * method is necessary because the parent component might be a lightweight 813: * component. 814: * 815: * @param component The component to fetch the native container for. 816: * 817: * @return The native container object for this component. 818: */ 819: protected static Container getNativeContainer(Component component) 820: { 821: component = component.getParent(); 822: while (true) 823: { 824: if (component == null) 825: return null; 826: if (! (component instanceof Container)) 827: { 828: component = component.getParent(); 829: continue; 830: } 831: if (component.getPeer() instanceof LightweightPeer) 832: { 833: component = component.getParent(); 834: continue; 835: } 836: return (Container) component; 837: } 838: } 839: 840: /** 841: * Creates a new custom cursor object. 842: * 843: * @exception IndexOutOfBoundsException If the hotSpot values are outside 844: * the bounds of the cursor. 845: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 846: */ 847: public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) 848: { 849: // Presumably the only reason this isn't abstract is for backwards 850: // compatibility? FIXME? 851: if (GraphicsEnvironment.isHeadless()) 852: throw new HeadlessException("No custom cursor in an headless graphics " 853: + "environment."); 854: return null; 855: } 856: 857: /** 858: * Returns the supported cursor dimension which is closest to the 859: * desired sizes. 860: * 861: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 862: */ 863: public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) 864: { 865: if (GraphicsEnvironment.isHeadless()) 866: throw new HeadlessException("No best cursor size in an headless " 867: + "graphics environment."); 868: return new Dimension (0,0); 869: } 870: 871: /** 872: * Returns the maximum number of colors the Toolkit supports in a custom 873: * cursor palette. 874: * 875: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 876: */ 877: public int getMaximumCursorColors() 878: { 879: return 0; 880: } 881: 882: /** 883: * Returns whether Toolkit supports this state for Frames. 884: * 885: * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 886: * 887: * @since 1.4 888: */ 889: public boolean isFrameStateSupported(int state) 890: { 891: return false; 892: } 893: 894: /** 895: * Returns the value of the property with the specified name, or the 896: * default value if the property does not exist. 897: * 898: * @param key The name of the property to retrieve. 899: * @param def The default value of the property. 900: */ 901: public static String getProperty(String key, String def) 902: { 903: return props.getProperty(key, def); 904: } 905: 906: 907: /** 908: * Returns the event queue that is suitable for the calling context. 909: * 910: * <p>Despite the word “System” in the name of this 911: * method, a toolkit may provide different event queues for each 912: * applet. There is no guarantee that the same queue is shared 913: * system-wide. 914: * 915: * <p>The implementation first checks whether a 916: * SecurityManager has been installed. If so, its {@link 917: * java.lang.SecurityManager#checkAwtEventQueueAccess()} method gets 918: * called. The security manager will throw a SecurityException if it 919: * does not grant the permission to access the event queue. 920: * 921: * <p>Next, the call is delegated to {@link 922: * #getSystemEventQueueImpl()}. 923: * 924: * @return The event queue for this applet (or application). 925: * 926: * @throws SecurityException if a security manager has been 927: * installed, and it does not grant the permission to access the 928: * event queue. 929: */ 930: public final EventQueue getSystemEventQueue() 931: { 932: SecurityManager sm; 933: 934: sm = System.getSecurityManager(); 935: if (sm != null) 936: sm.checkAwtEventQueueAccess(); 937: 938: return getSystemEventQueueImpl(); 939: } 940: 941: 942: /** 943: * Returns the event queue that is suitable for the calling context. 944: * 945: * <p>Despite the word “System” in the name of this 946: * method, a toolkit may provide different event queues for each 947: * applet. There is no guarantee that the same queue is shared 948: * system-wide. 949: * 950: * <p>No security checks are performed, which is why this method 951: * may only be called by Toolkits. 952: * 953: * @see #getSystemEventQueue() 954: */ 955: protected abstract EventQueue getSystemEventQueueImpl(); 956: 957: 958: /** 959: * @since 1.3 960: */ 961: public abstract DragSourceContextPeer 962: createDragSourceContextPeer(DragGestureEvent e); 963: 964: /** 965: * @since 1.3 966: */ 967: public DragGestureRecognizer 968: createDragGestureRecognizer(Class recognizer, DragSource ds, 969: Component comp, int actions, 970: DragGestureListener l) 971: { 972: return null; 973: } 974: 975: public final Object getDesktopProperty(String propertyName) 976: { 977: return desktopProperties.get(propertyName); 978: } 979: 980: protected final void setDesktopProperty(String name, Object newValue) 981: { 982: Object oldValue = getDesktopProperty(name); 983: desktopProperties.put(name, newValue); 984: desktopPropsSupport.firePropertyChange(name, oldValue, newValue); 985: } 986: 987: protected Object lazilyLoadDesktopProperty(String name) 988: { 989: // FIXME - what is this?? 990: return null; 991: } 992: 993: protected void initializeDesktopProperties() 994: { 995: // Overridden by toolkit implementation? 996: } 997: 998: public void addPropertyChangeListener(String name, 999: PropertyChangeListener pcl) 1000: { 1001: desktopPropsSupport.addPropertyChangeListener(name, pcl); 1002: } 1003: 1004: public void removePropertyChangeListener(String name, 1005: PropertyChangeListener pcl) 1006: { 1007: desktopPropsSupport.removePropertyChangeListener(name, pcl); 1008: } 1009: 1010: /** 1011: * @since 1.4 1012: */ 1013: public PropertyChangeListener[] getPropertyChangeListeners() 1014: { 1015: return desktopPropsSupport.getPropertyChangeListeners(); 1016: } 1017: 1018: /** 1019: * @since 1.4 1020: */ 1021: public PropertyChangeListener[] getPropertyChangeListeners(String name) 1022: { 1023: return desktopPropsSupport.getPropertyChangeListeners(name); 1024: } 1025: 1026: /** 1027: * Adds an AWTEventListener to this toolkit. This listener is informed about 1028: * all events that pass the eventqueue that match the specified 1029: * <code>evenMask</code>. The <code>eventMask</code> is an ORed combination 1030: * of event masks as defined in {@link AWTEvent}. 1031: * 1032: * If a security manager is installed, it is asked first if an 1033: * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. 1034: * This may result in a <code>SecurityException</code> beeing thrown. 1035: * 1036: * It is not recommended to use this kind of notification for normal 1037: * applications. It is intended solely for the purpose of debugging and to 1038: * support special facilities. 1039: * 1040: * @param listener the listener to add 1041: * @param eventMask the event mask of event types which the listener is 1042: * interested in 1043: * 1044: * @since 1.2 1045: * 1046: * @throws SecurityException if there is a <code>SecurityManager</code> that 1047: * doesn't grant 1048: * <code>AWTPermission("listenToAllAWTEvents")</code> 1049: * 1050: * @see #getAWTEventListeners() 1051: * @see #getAWTEventListeners(long) 1052: * @see #removeAWTEventListener(AWTEventListener) 1053: */ 1054: public void addAWTEventListener(AWTEventListener listener, long eventMask) 1055: { 1056: // First we must check the security permissions. 1057: SecurityManager s = System.getSecurityManager(); 1058: if (s != null) 1059: s.checkPermission(new AWTPermission("listenToAllAWTEvents")); 1060: 1061: // Go through the list and check if the requested listener is already 1062: // registered. 1063: boolean found = false; 1064: for (int i = 0; i < awtEventListeners.length; ++i) 1065: { 1066: AWTEventListenerProxy proxy = awtEventListeners[i]; 1067: if (proxy.getListener() == listener) 1068: { 1069: found = true; 1070: // Modify the proxies event mask to include the new event mask. 1071: AWTEventListenerProxy newProxy = 1072: new AWTEventListenerProxy(proxy.getEventMask() | eventMask, 1073: listener); 1074: awtEventListeners[i] = newProxy; 1075: break; 1076: } 1077: } 1078: 1079: // If that listener was not found, then add it. 1080: if (! found) 1081: { 1082: AWTEventListenerProxy proxy = 1083: new AWTEventListenerProxy(eventMask, listener); 1084: AWTEventListenerProxy[] newArray = 1085: new AWTEventListenerProxy[awtEventListeners.length + 1]; 1086: System.arraycopy(awtEventListeners, 0, newArray, 0, 1087: awtEventListeners.length); 1088: newArray[newArray.length - 1] = proxy; 1089: awtEventListeners = newArray; 1090: } 1091: } 1092: 1093: /** 1094: * Removes an AWT event listener from this toolkit. This listener is no 1095: * longer informed of any event types it was registered in. 1096: * 1097: * If a security manager is installed, it is asked first if an 1098: * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. 1099: * This may result in a <code>SecurityException</code> beeing thrown. 1100: * 1101: * It is not recommended to use this kind of notification for normal 1102: * applications. It is intended solely for the purpose of debugging and to 1103: * support special facilities. 1104: * 1105: * @param listener the listener to remove 1106: * 1107: * @throws SecurityException if there is a <code>SecurityManager</code> that 1108: * doesn't grant 1109: * <code>AWTPermission("listenToAllAWTEvents")</code> 1110: * 1111: * @since 1.2 1112: * 1113: * @see #addAWTEventListener(AWTEventListener, long) 1114: * @see #getAWTEventListeners() 1115: * @see #getAWTEventListeners(long) 1116: */ 1117: public void removeAWTEventListener(AWTEventListener listener) 1118: { 1119: // First we must check the security permissions. 1120: SecurityManager s = System.getSecurityManager(); 1121: if (s != null) 1122: s.checkPermission(new AWTPermission("listenToAllAWTEvents")); 1123: 1124: 1125: // Find the index of the listener. 1126: int index = -1; 1127: for (int i = 0; i < awtEventListeners.length; ++i) 1128: { 1129: AWTEventListenerProxy proxy = awtEventListeners[i]; 1130: if (proxy.getListener() == listener) 1131: { 1132: index = i; 1133: break; 1134: } 1135: } 1136: 1137: // Copy over the arrays and leave out the removed element. 1138: if (index != -1) 1139: { 1140: AWTEventListenerProxy[] newArray = 1141: new AWTEventListenerProxy[awtEventListeners.length - 1]; 1142: if (index > 0) 1143: System.arraycopy(awtEventListeners, 0, newArray, 0, index); 1144: if (index < awtEventListeners.length - 1) 1145: System.arraycopy(awtEventListeners, index + 1, newArray, index, 1146: awtEventListeners.length - index - 1); 1147: awtEventListeners = newArray; 1148: } 1149: } 1150: 1151: /** 1152: * Returns all registered AWT event listeners. This method returns a copy of 1153: * the listener array, so that application cannot trash the listener list. 1154: * 1155: * If a security manager is installed, it is asked first if an 1156: * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. 1157: * This may result in a <code>SecurityException</code> beeing thrown. 1158: * 1159: * It is not recommended to use this kind of notification for normal 1160: * applications. It is intended solely for the purpose of debugging and to 1161: * support special facilities. 1162: * 1163: * @return all registered AWT event listeners 1164: * 1165: * @throws SecurityException if there is a <code>SecurityManager</code> that 1166: * doesn't grant 1167: * <code>AWTPermission("listenToAllAWTEvents")</code> 1168: * 1169: * @since 1.4 1170: * 1171: * @see #addAWTEventListener(AWTEventListener, long) 1172: * @see #removeAWTEventListener(AWTEventListener) 1173: * @see #getAWTEventListeners(long) 1174: */ 1175: public AWTEventListener[] getAWTEventListeners() 1176: { 1177: // First we must check the security permissions. 1178: SecurityManager s = System.getSecurityManager(); 1179: if (s != null) 1180: s.checkPermission(new AWTPermission("listenToAllAWTEvents")); 1181: 1182: // Create a copy of the array. 1183: AWTEventListener[] copy = new AWTEventListener[awtEventListeners.length]; 1184: System.arraycopy(awtEventListeners, 0, copy, 0, awtEventListeners.length); 1185: return copy; 1186: } 1187: 1188: /** 1189: * Returns all registered AWT event listeners that listen for events with 1190: * the specified <code>eventMask</code>. This method returns a copy of 1191: * the listener array, so that application cannot trash the listener list. 1192: * 1193: * If a security manager is installed, it is asked first if an 1194: * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. 1195: * This may result in a <code>SecurityException</code> beeing thrown. 1196: * 1197: * It is not recommended to use this kind of notification for normal 1198: * applications. It is intended solely for the purpose of debugging and to 1199: * support special facilities. 1200: * 1201: * @param mask the event mask 1202: * 1203: * @throws SecurityException if there is a <code>SecurityManager</code> that 1204: * doesn't grant 1205: * <code>AWTPermission("listenToAllAWTEvents")</code> 1206: * 1207: * 1208: * @since 1.4 1209: * 1210: * @see #addAWTEventListener(AWTEventListener, long) 1211: * @see #removeAWTEventListener(AWTEventListener) 1212: * @see #getAWTEventListeners() 1213: */ 1214: public AWTEventListener[] getAWTEventListeners(long mask) 1215: { 1216: // First we must check the security permissions. 1217: SecurityManager s = System.getSecurityManager(); 1218: if (s != null) 1219: s.checkPermission(new AWTPermission("listenToAllAWTEvents")); 1220: 1221: // Create a copy of the array with only the requested listeners in it. 1222: ArrayList l = new ArrayList(awtEventListeners.length); 1223: for (int i = 0; i < awtEventListeners.length; ++i) 1224: { 1225: if ((awtEventListeners[i].getEventMask() & mask) != 0) 1226: l.add(awtEventListeners[i]); 1227: } 1228: 1229: return (AWTEventListener[] ) l.toArray(new AWTEventListener[l.size()]); 1230: } 1231: 1232: 1233: /** 1234: * Dispatches events to listeners registered to this Toolkit. This is called 1235: * by {@link Component#dispatchEventImpl(AWTEvent)} in order to dispatch 1236: * events globally. 1237: * 1238: * @param ev the event to dispatch 1239: */ 1240: void globalDispatchEvent(AWTEvent ev) 1241: { 1242: // We do not use the accessor methods here because they create new 1243: // arrays each time. We must be very efficient, so we access this directly. 1244: for (int i = 0; i < awtEventListeners.length; ++i) 1245: { 1246: AWTEventListenerProxy proxy = awtEventListeners[i]; 1247: if ((proxy.getEventMask() & AWTEvent.eventIdToMask(ev.getID())) != 0) 1248: proxy.eventDispatched(ev); 1249: } 1250: } 1251: 1252: /** 1253: * @since 1.3 1254: */ 1255: public abstract Map mapInputMethodHighlight(InputMethodHighlight highlight); 1256: 1257: /** 1258: * Initializes the accessibility framework. In particular, this loads the 1259: * properties javax.accessibility.screen_magnifier_present and 1260: * javax.accessibility.screen_reader_present and loads 1261: * the classes specified in javax.accessibility.assistive_technologies. 1262: */ 1263: private static void initAccessibility() 1264: { 1265: AccessController.doPrivileged 1266: (new PrivilegedAction() 1267: { 1268: public Object run() 1269: { 1270: Properties props = new Properties(); 1271: String sep = File.separator; 1272: 1273: // Try the user configuration. 1274: try 1275: { 1276: File propsFile = new File(System.getProperty("user.home") + sep 1277: + ".accessibility.properties"); 1278: FileInputStream in = new FileInputStream(propsFile); 1279: props.load(in); 1280: in.close(); 1281: } 1282: catch (Exception ex) 1283: { 1284: // User configuration not present, ignore. 1285: } 1286: 1287: // Try the system configuration if there was no user configuration. 1288: if (props.size() == 0) 1289: { 1290: try 1291: { 1292: File propsFile = 1293: new File(System.getProperty("gnu.classpath.home.url") 1294: + sep + "accessibility.properties"); 1295: FileInputStream in = new FileInputStream(propsFile); 1296: props.load(in); 1297: in.close(); 1298: } 1299: catch (Exception ex) 1300: { 1301: // System configuration not present, ignore. 1302: } 1303: } 1304: 1305: // Fetch the screen_magnifier_present property. Check systen properties 1306: // first, then fallback to the configuration file. 1307: String magPresent = SystemProperties.getProperty 1308: ("javax.accessibility.screen_magnifier_present"); 1309: if (magPresent == null) 1310: { 1311: magPresent = props.getProperty("screen_magnifier_present"); 1312: if (magPresent != null) 1313: { 1314: SystemProperties.setProperty 1315: ("javax.accessibility.screen_magnifier_present", magPresent); 1316: } 1317: } 1318: 1319: // Fetch the screen_reader_present property. Check systen properties 1320: // first, then fallback to the configuration file. 1321: String readerPresent = SystemProperties.getProperty 1322: ("javax.accessibility.screen_reader_present"); 1323: if (readerPresent == null) 1324: { 1325: readerPresent = props.getProperty("screen_reader_present"); 1326: if (readerPresent != null) 1327: { 1328: SystemProperties.setProperty 1329: ("javax.accessibility.screen_reader_present", readerPresent); 1330: } 1331: } 1332: 1333: // Fetch the list of classes to be loaded. 1334: String classes = SystemProperties.getProperty 1335: ("javax.accessibility.assistive_technologies"); 1336: if (classes == null) 1337: { 1338: classes = props.getProperty("assistive_technologies"); 1339: if (classes != null) 1340: { 1341: SystemProperties.setProperty 1342: ("javax.accessibility.assistive_technologies", classes); 1343: } 1344: } 1345: 1346: // Try to load the assisitive_technologies classes. 1347: if (classes != null) 1348: { 1349: ClassLoader cl = ClassLoader.getSystemClassLoader(); 1350: StringTokenizer tokenizer = new StringTokenizer(classes, ","); 1351: while (tokenizer.hasMoreTokens()) 1352: { 1353: String className = tokenizer.nextToken(); 1354: try 1355: { 1356: Class atClass = cl.loadClass(className); 1357: atClass.newInstance(); 1358: } 1359: catch (ClassNotFoundException ex) 1360: { 1361: AWTError err = new AWTError("Assistive Technology class not" 1362: + " found: " + className); 1363: err.initCause(ex); 1364: throw err; 1365: } 1366: catch (InstantiationException ex) 1367: { 1368: AWTError err = 1369: new AWTError("Assistive Technology class cannot be " 1370: + "instantiated: " + className); 1371: err.initCause(ex); 1372: throw err; 1373: } 1374: catch (IllegalAccessException ex) 1375: { 1376: AWTError err = 1377: new AWTError("Assistive Technology class cannot be " 1378: + "accessed: " + className); 1379: err.initCause(err); 1380: throw err; 1381: } 1382: } 1383: } 1384: return null; 1385: } 1386: }); 1387: 1388: } 1389: 1390: } // class Toolkit