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