1 /* Toolkit.java -- AWT Toolkit superclass 2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 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 java.awt.datatransfer.Clipboard; 43 import java.awt.dnd.DragGestureEvent; 44 import java.awt.dnd.DragGestureListener; 45 import java.awt.dnd.DragGestureRecognizer; 46 import java.awt.dnd.DragSource; 47 import java.awt.dnd.peer.DragSourceContextPeer; 48 import java.awt.event.AWTEventListener; 49 import java.awt.event.KeyEvent; 50 import java.awt.im.InputMethodHighlight; 51 import java.awt.image.ColorModel; 52 import java.awt.image.ImageObserver; 53 import java.awt.image.ImageProducer; 54 import java.awt.peer.ButtonPeer; 55 import java.awt.peer.CanvasPeer; 56 import java.awt.peer.CheckboxMenuItemPeer; 57 import java.awt.peer.CheckboxPeer; 58 import java.awt.peer.ChoicePeer; 59 import java.awt.peer.DialogPeer; 60 import java.awt.peer.FileDialogPeer; 61 import java.awt.peer.FontPeer; 62 import java.awt.peer.FramePeer; 63 import java.awt.peer.LabelPeer; 64 import java.awt.peer.LightweightPeer; 65 import java.awt.peer.ListPeer; 66 import java.awt.peer.MenuBarPeer; 67 import java.awt.peer.MenuItemPeer; 68 import java.awt.peer.MenuPeer; 69 import java.awt.peer.PanelPeer; 70 import java.awt.peer.PopupMenuPeer; 71 import java.awt.peer.ScrollPanePeer; 72 import java.awt.peer.ScrollbarPeer; 73 import java.awt.peer.TextAreaPeer; 74 import java.awt.peer.TextFieldPeer; 75 import java.awt.peer.WindowPeer; 76 import java.beans.PropertyChangeListener; 77 import java.beans.PropertyChangeSupport; 78 import java.net.URL; 79 import java.util.Map; 80 import java.util.Properties; 81 82 /** 83 * The AWT system uses a set of native peer objects to implement its 84 * widgets. These peers are provided by a peer toolkit, that is accessed 85 * via a subclass of this superclass. The system toolkit is retrieved 86 * by the static methods <code>getDefaultToolkit</code>. This method 87 * determines the system toolkit by examining the system property 88 * <code>awt.toolkit</code>. That property is set to the name of the 89 * <code>Toolkit</code> subclass for the specified peer set. If the 90 * <code>awt.toolkit</code> property is not set, then the default 91 * toolkit <code>gnu.java.awt.peer.gtk.GtkToolkit</code> is used. This 92 * toolkit creates its peers using the GTK+ toolkit. 93 * 94 * @author Aaron M. Renn (arenn@urbanophile.com) 95 */ 96 public abstract class Toolkit 97 { 98 /** The default toolkit name. */ 99 private static String default_toolkit_name 100 = gnu.classpath.Configuration.default_awt_peer_toolkit; 101 102 /** 103 * The toolkit in use. Once we load it, we don't ever change it 104 * if the awt.toolkit property is set. 105 */ 106 private static Toolkit toolkit; 107 108 /** The toolkit properties. */ 109 private static Properties props = new Properties(); 110 111 protected final Map desktopProperties = new Properties(); 112 113 protected final PropertyChangeSupport desktopPropsSupport 114 = new PropertyChangeSupport(this); 115 116 /** 117 * Default constructor for subclasses. 118 */ Toolkit()119 public Toolkit() 120 { 121 } 122 123 /** 124 * Creates a peer object for the specified <code>Button</code>. 125 * 126 * @param target The <code>Button</code> to create the peer for. 127 * 128 * @return The peer for the specified <code>Button</code> object. 129 * 130 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 131 */ createButton(Button target)132 protected abstract ButtonPeer createButton(Button target); 133 134 /** 135 * Creates a peer object for the specified <code>TextField</code>. 136 * 137 * @param target The <code>TextField</code> to create the peer for. 138 * 139 * @return The peer for the specified <code>TextField</code> object. 140 * 141 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 142 */ createTextField(TextField target)143 protected abstract TextFieldPeer createTextField(TextField target); 144 145 /** 146 * Creates a peer object for the specified <code>Label</code>. 147 * 148 * @param target The <code>Label</code> to create the peer for. 149 * 150 * @return The peer for the specified <code>Label</code> object. 151 * 152 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 153 */ createLabel(Label target)154 protected abstract LabelPeer createLabel(Label target); 155 156 /** 157 * Creates a peer object for the specified <code>List</code>. 158 * 159 * @param target The <code>List</code> to create the peer for. 160 * 161 * @return The peer for the specified <code>List</code> object. 162 * 163 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 164 */ createList(List target)165 protected abstract ListPeer createList(List target); 166 167 /** 168 * Creates a peer object for the specified <code>Checkbox</code>. 169 * 170 * @param target The <code>Checkbox</code> to create the peer for. 171 * 172 * @return The peer for the specified <code>Checkbox</code> object. 173 * 174 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 175 */ createCheckbox(Checkbox target)176 protected abstract CheckboxPeer createCheckbox(Checkbox target); 177 178 /** 179 * Creates a peer object for the specified <code>Scrollbar</code>. 180 * 181 * @param target The <code>Scrollbar</code> to create the peer for. 182 * 183 * @return The peer for the specified <code>Scrollbar</code> object. 184 * 185 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 186 */ createScrollbar(Scrollbar target)187 protected abstract ScrollbarPeer createScrollbar(Scrollbar target); 188 189 /** 190 * Creates a peer object for the specified <code>ScrollPane</code>. 191 * 192 * @param target The <code>ScrollPane</code> to create the peer for. 193 * 194 * @return The peer for the specified <code>ScrollPane</code> object. 195 * 196 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 197 */ createScrollPane(ScrollPane target)198 protected abstract ScrollPanePeer createScrollPane(ScrollPane target); 199 200 /** 201 * Creates a peer object for the specified <code>TextArea</code>. 202 * 203 * @param target The <code>TextArea</code> to create the peer for. 204 * 205 * @return The peer for the specified <code>TextArea</code> object. 206 * 207 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 208 */ createTextArea(TextArea target)209 protected abstract TextAreaPeer createTextArea(TextArea target); 210 211 /** 212 * Creates a peer object for the specified <code>Choice</code>. 213 * 214 * @param target The <code>Choice</code> to create the peer for. 215 * 216 * @return The peer for the specified <code>Choice</code> object. 217 * 218 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 219 */ createChoice(Choice target)220 protected abstract ChoicePeer createChoice(Choice target); 221 222 /** 223 * Creates a peer object for the specified <code>Frame</code>. 224 * 225 * @param target The <code>Frame</code> to create the peer for. 226 * 227 * @return The peer for the specified <code>Frame</code> object. 228 * 229 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 230 */ createFrame(Frame target)231 protected abstract FramePeer createFrame(Frame target); 232 233 /** 234 * Creates a peer object for the specified <code>Canvas</code>. 235 * 236 * @param target The <code>Canvas</code> to create the peer for. 237 * 238 * @return The peer for the specified <code>Canvas</code> object. 239 */ createCanvas(Canvas target)240 protected abstract CanvasPeer createCanvas(Canvas target); 241 242 /** 243 * Creates a peer object for the specified <code>Panel</code>. 244 * 245 * @param target The <code>Panel</code> to create the peer for. 246 * 247 * @return The peer for the specified <code>Panel</code> object. 248 */ createPanel(Panel target)249 protected abstract PanelPeer createPanel(Panel target); 250 251 /** 252 * Creates a peer object for the specified <code>Window</code>. 253 * 254 * @param target The <code>Window</code> to create the peer for. 255 * 256 * @return The peer for the specified <code>Window</code> object. 257 * 258 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 259 */ createWindow(Window target)260 protected abstract WindowPeer createWindow(Window target); 261 262 /** 263 * Creates a peer object for the specified <code>Dialog</code>. 264 * 265 * @param target The dialog to create the peer for 266 * 267 * @return The peer for the specified font name. 268 * 269 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 270 */ createDialog(Dialog target)271 protected abstract DialogPeer createDialog(Dialog target); 272 273 /** 274 * Creates a peer object for the specified <code>MenuBar</code>. 275 * 276 * @param target The <code>MenuBar</code> to create the peer for. 277 * 278 * @return The peer for the specified <code>MenuBar</code> object. 279 * 280 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 281 */ createMenuBar(MenuBar target)282 protected abstract MenuBarPeer createMenuBar(MenuBar target); 283 284 /** 285 * Creates a peer object for the specified <code>Menu</code>. 286 * 287 * @param target The <code>Menu</code> to create the peer for. 288 * 289 * @return The peer for the specified <code>Menu</code> object. 290 * 291 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 292 */ createMenu(Menu target)293 protected abstract MenuPeer createMenu(Menu target); 294 295 /** 296 * Creates a peer object for the specified <code>PopupMenu</code>. 297 * 298 * @param target The <code>PopupMenu</code> to create the peer for. 299 * 300 * @return The peer for the specified <code>PopupMenu</code> object. 301 * 302 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 303 */ createPopupMenu(PopupMenu target)304 protected abstract PopupMenuPeer createPopupMenu(PopupMenu target); 305 306 /** 307 * Creates a peer object for the specified <code>MenuItem</code>. 308 * 309 * @param target The <code>MenuItem</code> to create the peer for. 310 * 311 * @return The peer for the specified <code>MenuItem</code> object. 312 * 313 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 314 */ createMenuItem(MenuItem target)315 protected abstract MenuItemPeer createMenuItem(MenuItem target); 316 317 /** 318 * Creates a peer object for the specified <code>FileDialog</code>. 319 * 320 * @param target The <code>FileDialog</code> to create the peer for. 321 * 322 * @return The peer for the specified <code>FileDialog</code> object. 323 * 324 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 325 */ createFileDialog(FileDialog target)326 protected abstract FileDialogPeer createFileDialog(FileDialog target); 327 328 /** 329 * Creates a peer object for the specified <code>CheckboxMenuItem</code>. 330 * 331 * @param target The <code>CheckboxMenuItem</code> to create the peer for. 332 * 333 * @return The peer for the specified <code>CheckboxMenuItem</code> object. 334 * 335 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 336 */ 337 protected abstract CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target)338 createCheckboxMenuItem(CheckboxMenuItem target); 339 340 /** 341 * Creates a peer object for the specified <code>Component</code>. The 342 * peer returned by this method is not a native windowing system peer 343 * with its own native window. Instead, this method allows the component 344 * to draw on its parent window as a "lightweight" widget. 345 * 346 * @param target The <code>Component</code> to create the peer for. 347 * 348 * @return The peer for the specified <code>Component</code> object. 349 */ createComponent(Component target)350 protected LightweightPeer createComponent(Component target) 351 { 352 return new gnu.java.awt.peer.GLightweightPeer (target); 353 } 354 355 /** 356 * Creates a peer object for the specified font name. 357 * 358 * @param name The font to create the peer for. 359 * @param style The font style to create the peer for. 360 * 361 * @return The peer for the specified font name. 362 * 363 * @deprecated 364 */ getFontPeer(String name, int style)365 protected abstract FontPeer getFontPeer(String name, int style); 366 367 /** 368 * Copies the current system colors into the specified array. This is 369 * the interface used by the <code>SystemColor</code> class. Although 370 * this method fills in the array with some default colors a real Toolkit 371 * should override this method and provide real system colors for the 372 * native GUI platform. 373 * 374 * @param systemColors The array to copy the system colors into. 375 * It must be at least 26 elements. 376 * 377 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 378 * 379 * @see java.awt.SystemColor 380 */ loadSystemColors(int systemColors[])381 protected void loadSystemColors(int systemColors[]) 382 { 383 systemColors[SystemColor.DESKTOP] = 0xFF005C5C; 384 systemColors[SystemColor.ACTIVE_CAPTION] = 0xFF000080; 385 systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = 0xFFFFFFFF; 386 systemColors[SystemColor.ACTIVE_CAPTION_BORDER] = 0xFFC0C0C0; 387 systemColors[SystemColor.INACTIVE_CAPTION] = 0xFF808080; 388 systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = 0xFFC0C0C0; 389 systemColors[SystemColor.INACTIVE_CAPTION_BORDER] = 0xFFC0C0C0; 390 systemColors[SystemColor.WINDOW] = 0xFFFFFFFF; 391 systemColors[SystemColor.WINDOW_BORDER] = 0xFF000000; 392 systemColors[SystemColor.WINDOW_TEXT] = 0xFF000000; 393 systemColors[SystemColor.MENU] = 0xFFC0C0C0; 394 systemColors[SystemColor.MENU_TEXT] = 0xFF000000; 395 systemColors[SystemColor.TEXT] = 0xFFC0C0C0; 396 systemColors[SystemColor.TEXT_TEXT] = 0xFF000000; 397 systemColors[SystemColor.TEXT_HIGHLIGHT] = 0xFF000090; 398 systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = 0xFFFFFFFF; 399 systemColors[SystemColor.TEXT_INACTIVE_TEXT] = 0xFF808080; 400 systemColors[SystemColor.CONTROL] = 0xFFC0C0C0; 401 systemColors[SystemColor.CONTROL_TEXT] = 0xFF000000; 402 systemColors[SystemColor.CONTROL_HIGHLIGHT] = 0xFFFFFFFF; 403 systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] = 0xFFE0E0E0; 404 systemColors[SystemColor.CONTROL_SHADOW] = 0xFF808080; 405 systemColors[SystemColor.CONTROL_DK_SHADOW] = 0xFF000000; 406 systemColors[SystemColor.SCROLLBAR] = 0xFFE0E0E0; 407 systemColors[SystemColor.INFO] = 0xFFE0E000; 408 systemColors[SystemColor.INFO_TEXT] = 0xFF000000; 409 } 410 411 /** 412 * @since 1.4 413 * 414 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 415 */ setDynamicLayout(boolean dynamic)416 public void setDynamicLayout(boolean dynamic) 417 { 418 } 419 420 /** 421 * @since 1.4 422 * 423 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 424 */ isDynamicLayoutSet()425 protected boolean isDynamicLayoutSet() 426 { 427 return false; 428 } 429 430 /** 431 * @since 1.4 432 * 433 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 434 */ isDynamicLayoutActive()435 public boolean isDynamicLayoutActive() 436 { 437 return false; 438 } 439 440 /** 441 * Returns the dimensions of the screen in pixels. 442 * 443 * @return The dimensions of the screen in pixels. 444 * 445 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 446 */ getScreenSize()447 public abstract Dimension getScreenSize(); 448 449 /** 450 * Returns the screen resolution in dots per square inch. 451 * 452 * @return The screen resolution in dots per square inch. 453 * 454 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 455 */ getScreenResolution()456 public abstract int getScreenResolution(); 457 458 /** 459 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 460 * 461 * @since 1.4 462 */ getScreenInsets(GraphicsConfiguration gc)463 public Insets getScreenInsets(GraphicsConfiguration gc) 464 { 465 return null; 466 } 467 468 /** 469 * Returns the color model of the screen. 470 * 471 * @return The color model of the screen. 472 * 473 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 474 */ getColorModel()475 public abstract ColorModel getColorModel(); 476 477 /** 478 * Returns the names of the available fonts. 479 * 480 * @return The names of the available fonts. 481 * 482 * @deprecated 483 */ getFontList()484 public abstract String[] getFontList(); 485 486 /** 487 * Return the font metrics for the specified font 488 * 489 * @param name The name of the font to return metrics for. 490 * 491 * @return The requested font metrics. 492 * 493 * @deprecated 494 */ getFontMetrics(Font name)495 public abstract FontMetrics getFontMetrics(Font name); 496 497 /** 498 * Flushes any buffered data to the screen so that it is in sync with 499 * what the AWT system has drawn to it. 500 */ sync()501 public abstract void sync(); 502 503 /** 504 * Returns an instance of the default toolkit. The default toolkit is 505 * the subclass of <code>Toolkit</code> specified in the system property 506 * <code>awt.toolkit</code>, or <code>gnu.java.awt.peer.gtk.GtkToolkit</code> 507 * if the property is not set. 508 * 509 * @return An instance of the system default toolkit. 510 * 511 * @throws AWTError If the toolkit cannot be loaded. 512 */ getDefaultToolkit()513 public static Toolkit getDefaultToolkit() 514 { 515 if (toolkit != null) 516 return toolkit; 517 String toolkit_name = System.getProperty("awt.toolkit", 518 default_toolkit_name); 519 try 520 { 521 Class cls = Class.forName(toolkit_name); 522 Object obj = cls.newInstance(); 523 if (!(obj instanceof Toolkit)) 524 throw new AWTError(toolkit_name + " is not a subclass of " + 525 "java.awt.Toolkit"); 526 toolkit = (Toolkit) obj; 527 return toolkit; 528 } 529 catch (ThreadDeath death) 530 { 531 throw death; 532 } 533 catch (Throwable t) 534 { 535 AWTError e = new AWTError("Cannot load AWT toolkit: " + toolkit_name); 536 throw (AWTError) e.initCause(t); 537 } 538 } 539 540 /** 541 * Returns an image from the specified file, which must be in a 542 * recognized format. Supported formats vary from toolkit to toolkit. 543 * 544 * @return name The name of the file to read the image from. 545 */ getImage(String name)546 public abstract Image getImage(String name); 547 548 /** 549 * Returns an image from the specified URL, which must be in a 550 * recognized format. Supported formats vary from toolkit to toolkit. 551 * 552 * @return url The URl to read the image from. 553 */ getImage(URL url)554 public abstract Image getImage(URL url); 555 createImage(String filename)556 public abstract Image createImage(String filename); 557 createImage(URL url)558 public abstract Image createImage(URL url); 559 560 /** 561 * Readies an image to be rendered on the screen. The width and height 562 * values can be set to the default sizes for the image by passing -1 563 * in those parameters. 564 * 565 * @param image The image to prepare for rendering. 566 * @param width The width of the image. 567 * @param height The height of the image. 568 * @param observer The observer to receive events about the preparation 569 * process. 570 * 571 * @return <code>true</code> if the image is already prepared for rendering, 572 * <code>false</code> otherwise. 573 */ prepareImage(Image image, int width, int height, ImageObserver observer)574 public abstract boolean prepareImage(Image image, int width, int height, 575 ImageObserver observer); 576 577 /** 578 * Checks the status of specified image as it is being readied for 579 * rendering. 580 * 581 * @param image The image to prepare for rendering. 582 * @param width The width of the image. 583 * @param height The height of the image. 584 * @param observer The observer to receive events about the preparation 585 * process. 586 * 587 * @return A union of the bitmasks from 588 * <code>java.awt.image.ImageObserver</code> that indicates the current 589 * state of the imaging readying process. 590 */ checkImage(Image image, int width, int height, ImageObserver observer)591 public abstract int checkImage(Image image, int width, int height, 592 ImageObserver observer); 593 594 /** 595 * Creates an image using the specified <code>ImageProducer</code> 596 * 597 * @param producer The <code>ImageProducer</code> to create the image from. 598 * 599 * @return The created image. 600 */ createImage(ImageProducer producer)601 public abstract Image createImage(ImageProducer producer); 602 603 /** 604 * Creates an image from the specified byte array. The array must be in 605 * a recognized format. Supported formats vary from toolkit to toolkit. 606 * 607 * @param data The raw image data. 608 * 609 * @return The created image. 610 */ createImage(byte[] data)611 public Image createImage(byte[] data) 612 { 613 return createImage(data, 0, data.length); 614 } 615 616 /** 617 * Creates an image from the specified portion of the byte array passed. 618 * The array must be in a recognized format. Supported formats vary from 619 * toolkit to toolkit. 620 * 621 * @param data The raw image data. 622 * @param offset The offset into the data where the image data starts. 623 * @param len The length of the image data. 624 * 625 * @return The created image. 626 */ createImage(byte[] data, int offset, int len)627 public abstract Image createImage(byte[] data, int offset, int len); 628 629 /** 630 * Returns a instance of <code>PrintJob</code> for the specified 631 * arguments. 632 * 633 * @param frame The window initiating the print job. 634 * @param title The print job title. 635 * @param props The print job properties. 636 * 637 * @return The requested print job, or <code>null</code> if the job 638 * was cancelled. 639 * 640 * @exception NullPointerException If frame is null, 641 * or GraphicsEnvironment.isHeadless() returns true. 642 * @exception SecurityException If this thread is not allowed to initiate 643 * a print job request. 644 */ getPrintJob(Frame frame, String title, Properties props)645 public abstract PrintJob getPrintJob(Frame frame, String title, 646 Properties props); 647 648 /** 649 * Returns a instance of <code>PrintJob</code> for the specified 650 * arguments. 651 * 652 * @param frame The window initiating the print job. 653 * @param title The print job title. 654 * @param jobAttr A set of job attributes which will control the print job. 655 * @param pageAttr A set of page attributes which will control the print job. 656 * 657 * @exception NullPointerException If frame is null, and either jobAttr is null 658 * or jobAttr.getDialog() returns JobAttributes.DialogType.NATIVE. 659 * @exception IllegalArgumentException If pageAttrspecifies differing cross 660 * feed and feed resolutions, or when GraphicsEnvironment.isHeadless() returns 661 * true. 662 * @exception SecurityException If this thread is not allowed to initiate 663 * a print job request. 664 * 665 * @since 1.3 666 */ getPrintJob(Frame frame, String title, JobAttributes jobAttr, PageAttributes pageAttr)667 public PrintJob getPrintJob(Frame frame, String title, 668 JobAttributes jobAttr, PageAttributes pageAttr) 669 { 670 return null; 671 } 672 673 /** 674 * Causes a "beep" tone to be generated. 675 */ beep()676 public abstract void beep(); 677 678 /** 679 * Returns the system clipboard. 680 * 681 * @return THe system clipboard. 682 * 683 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 684 */ getSystemClipboard()685 public abstract Clipboard getSystemClipboard(); 686 687 /** 688 * Gets the singleton instance of the system selection as a Clipboard object. 689 * 690 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 691 * 692 * @since 1.4 693 */ getSystemSelection()694 public Clipboard getSystemSelection() 695 { 696 return null; 697 } 698 699 /** 700 * Returns the accelerator key mask for menu shortcuts. The default is 701 * <code>Event.CTRL_MASK</code>. A toolkit must override this method 702 * to change the default. 703 * 704 * @return The key mask for the menu accelerator key. 705 * 706 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 707 */ getMenuShortcutKeyMask()708 public int getMenuShortcutKeyMask() 709 { 710 return Event.CTRL_MASK; 711 } 712 713 /** 714 * Returns whether the given locking key on the keyboard is currently in its 715 * "on" state. 716 * 717 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 718 * @exception IllegalArgumentException If keyCode is not one of the valid keys. 719 * @exception UnsupportedOperationException If the host system doesn't allow 720 * getting the state of this key programmatically, or if the keyboard doesn't 721 * have this key. 722 */ getLockingKeyState(int keyCode)723 public boolean getLockingKeyState(int keyCode) 724 { 725 if (keyCode != KeyEvent.VK_CAPS_LOCK 726 && keyCode != KeyEvent.VK_NUM_LOCK 727 && keyCode != KeyEvent.VK_SCROLL_LOCK) 728 throw new IllegalArgumentException(); 729 730 throw new UnsupportedOperationException(); 731 } 732 733 /** 734 * Sets the state of the given locking key on the keyboard. 735 * 736 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 737 * @exception IllegalArgumentException If keyCode is not one of the valid keys. 738 * @exception UnsupportedOperationException If the host system doesn't allow 739 * getting the state of this key programmatically, or if the keyboard doesn't 740 * have this key. 741 */ setLockingKeyState(int keyCode, boolean on)742 public void setLockingKeyState(int keyCode, boolean on) 743 { 744 if (keyCode != KeyEvent.VK_CAPS_LOCK 745 && keyCode != KeyEvent.VK_NUM_LOCK 746 && keyCode != KeyEvent.VK_SCROLL_LOCK) 747 throw new IllegalArgumentException(); 748 749 throw new UnsupportedOperationException(); 750 } 751 752 /** 753 * Returns the native container object of the specified component. This 754 * method is necessary because the parent component might be a lightweight 755 * component. 756 * 757 * @param component The component to fetch the native container for. 758 * 759 * @return The native container object for this component. 760 */ getNativeContainer(Component component)761 protected static Container getNativeContainer(Component component) 762 { 763 component = component.getParent(); 764 while (true) 765 { 766 if (component == null) 767 return null; 768 if (! (component instanceof Container)) 769 { 770 component = component.getParent(); 771 continue; 772 } 773 if (component.getPeer() instanceof LightweightPeer) 774 { 775 component = component.getParent(); 776 continue; 777 } 778 return (Container) component; 779 } 780 } 781 782 /** 783 * Creates a new custom cursor object. 784 * 785 * @exception IndexOutOfBoundsException If the hotSpot values are outside 786 * the bounds of the cursor. 787 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 788 */ createCustomCursor(Image cursor, Point hotSpot, String name)789 public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) 790 { 791 // Presumably the only reason this isn't abstract is for backwards 792 // compatibility? FIXME? 793 if (GraphicsEnvironment.isHeadless()) 794 throw new HeadlessException("No custom cursor in an headless graphics " 795 + "environment."); 796 return null; 797 } 798 799 /** 800 * Returns the supported cursor dimension which is closest to the 801 * desired sizes. 802 * 803 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 804 */ getBestCursorSize(int preferredWidth, int preferredHeight)805 public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) 806 { 807 if (GraphicsEnvironment.isHeadless()) 808 throw new HeadlessException("No best cursor size in an headless " 809 + "graphics environment."); 810 return new Dimension (0,0); 811 } 812 813 /** 814 * Returns the maximum number of colors the Toolkit supports in a custom 815 * cursor palette. 816 * 817 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 818 */ getMaximumCursorColors()819 public int getMaximumCursorColors() 820 { 821 return 0; 822 } 823 824 /** 825 * Returns whether Toolkit supports this state for Frames. 826 * 827 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. 828 * 829 * @since 1.4 830 */ isFrameStateSupported(int state)831 public boolean isFrameStateSupported(int state) 832 { 833 return false; 834 } 835 836 /** 837 * Returns the value of the property with the specified name, or the 838 * default value if the property does not exist. 839 * 840 * @param key The name of the property to retrieve. 841 * @param def The default value of the property. 842 */ getProperty(String key, String def)843 public static String getProperty(String key, String def) 844 { 845 return props.getProperty(key, def); 846 } 847 848 849 /** 850 * Returns the event queue that is suitable for the calling context. 851 * 852 * <p>Despite the word “System” in the name of this 853 * method, a toolkit may provide different event queues for each 854 * applet. There is no guarantee that the same queue is shared 855 * system-wide. 856 * 857 * <p>The implementation first checks whether a 858 * SecurityManager has been installed. If so, its {@link 859 * java.lang.SecurityManager#checkAwtEventQueueAccess()} method gets 860 * called. The security manager will throw a SecurityException if it 861 * does not grant the permission to access the event queue. 862 * 863 * <p>Next, the call is delegated to {@link 864 * #getSystemEventQueueImpl()}. 865 * 866 * @return The event queue for this applet (or application). 867 * 868 * @throws SecurityException if a security manager has been 869 * installed, and it does not grant the permission to access the 870 * event queue. 871 */ getSystemEventQueue()872 public final EventQueue getSystemEventQueue() 873 { 874 SecurityManager sm; 875 876 sm = System.getSecurityManager(); 877 if (sm != null) 878 sm.checkAwtEventQueueAccess(); 879 880 return getSystemEventQueueImpl(); 881 } 882 883 884 /** 885 * Returns the event queue that is suitable for the calling context. 886 * 887 * <p>Despite the word “System” in the name of this 888 * method, a toolkit may provide different event queues for each 889 * applet. There is no guarantee that the same queue is shared 890 * system-wide. 891 * 892 * <p>No security checks are performed, which is why this method 893 * may only be called by Toolkits. 894 * 895 * @see #getSystemEventQueue() 896 */ getSystemEventQueueImpl()897 protected abstract EventQueue getSystemEventQueueImpl(); 898 899 900 /** 901 * @since 1.3 902 */ 903 public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent e)904 createDragSourceContextPeer(DragGestureEvent e); 905 906 /** 907 * @since 1.3 908 */ 909 public DragGestureRecognizer createDragGestureRecognizer(Class recognizer, DragSource ds, Component comp, int actions, DragGestureListener l)910 createDragGestureRecognizer(Class recognizer, DragSource ds, 911 Component comp, int actions, 912 DragGestureListener l) 913 { 914 return null; 915 } 916 getDesktopProperty(String propertyName)917 public final Object getDesktopProperty(String propertyName) 918 { 919 return desktopProperties.get(propertyName); 920 } 921 setDesktopProperty(String name, Object newValue)922 protected final void setDesktopProperty(String name, Object newValue) 923 { 924 Object oldValue = getDesktopProperty(name); 925 desktopProperties.put(name, newValue); 926 desktopPropsSupport.firePropertyChange(name, oldValue, newValue); 927 } 928 lazilyLoadDesktopProperty(String name)929 protected Object lazilyLoadDesktopProperty(String name) 930 { 931 // FIXME - what is this?? 932 return null; 933 } 934 initializeDesktopProperties()935 protected void initializeDesktopProperties() 936 { 937 // Overridden by toolkit implementation? 938 } 939 addPropertyChangeListener(String name, PropertyChangeListener pcl)940 public void addPropertyChangeListener(String name, 941 PropertyChangeListener pcl) 942 { 943 desktopPropsSupport.addPropertyChangeListener(name, pcl); 944 } 945 removePropertyChangeListener(String name, PropertyChangeListener pcl)946 public void removePropertyChangeListener(String name, 947 PropertyChangeListener pcl) 948 { 949 desktopPropsSupport.removePropertyChangeListener(name, pcl); 950 } 951 952 /** 953 * @since 1.4 954 */ getPropertyChangeListeners()955 public PropertyChangeListener[] getPropertyChangeListeners() 956 { 957 return desktopPropsSupport.getPropertyChangeListeners(); 958 } 959 960 /** 961 * @since 1.4 962 */ getPropertyChangeListeners(String name)963 public PropertyChangeListener[] getPropertyChangeListeners(String name) 964 { 965 return desktopPropsSupport.getPropertyChangeListeners(name); 966 } 967 addAWTEventListener(AWTEventListener listener, long eventMask)968 public void addAWTEventListener(AWTEventListener listener, long eventMask) 969 { 970 // SecurityManager s = System.getSecurityManager(); 971 // if (s != null) 972 // s.checkPermission(AWTPermission("listenToAllAWTEvents")); 973 // FIXME 974 } 975 removeAWTEventListener(AWTEventListener listener)976 public void removeAWTEventListener(AWTEventListener listener) 977 { 978 // FIXME 979 } 980 981 /** 982 * @since 1.4 983 */ getAWTEventListeners()984 public AWTEventListener[] getAWTEventListeners() 985 { 986 return null; 987 } 988 989 /** 990 * @since 1.4 991 */ getAWTEventListeners(long mask)992 public AWTEventListener[] getAWTEventListeners(long mask) 993 { 994 return null; 995 } 996 997 /** 998 * @since 1.3 999 */ mapInputMethodHighlight(InputMethodHighlight highlight)1000 public abstract Map mapInputMethodHighlight(InputMethodHighlight highlight); 1001 } // class Toolkit 1002