1. /*
  2. * @(#)Toolkit.java 1.126 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.util.MissingResourceException;
  9. import java.util.Properties;
  10. import java.util.ResourceBundle;
  11. import java.util.StringTokenizer;
  12. import java.awt.event.*;
  13. import java.awt.peer.*;
  14. import java.awt.image.ImageObserver;
  15. import java.awt.image.ImageProducer;
  16. import java.awt.image.ColorModel;
  17. import java.awt.datatransfer.Clipboard;
  18. import java.awt.dnd.DnDConstants;
  19. import java.awt.dnd.DragSource;
  20. import java.awt.dnd.DragGestureRecognizer;
  21. import java.awt.dnd.DragGestureEvent;
  22. import java.awt.dnd.DragGestureListener;
  23. import java.awt.dnd.InvalidDnDOperationException;
  24. import java.awt.dnd.peer.DragSourceContextPeer;
  25. import java.net.URL;
  26. import java.io.BufferedInputStream;
  27. import java.io.File;
  28. import java.io.FileInputStream;
  29. import java.security.AccessController;
  30. import java.security.PrivilegedAction;
  31. import java.util.EventListener;
  32. import java.util.Map;
  33. import java.util.HashMap;
  34. import java.util.WeakHashMap;
  35. import java.beans.PropertyChangeListener;
  36. import java.beans.PropertyChangeSupport;
  37. /**
  38. * This class is the abstract superclass of all actual
  39. * implementations of the Abstract Window Toolkit. Subclasses of
  40. * <code>Toolkit</code> are used to bind the various components
  41. * to particular native toolkit implementations.
  42. * <p>
  43. * Most applications should not call any of the methods in this
  44. * class directly. The methods defined by <code>Toolkit</code> are
  45. * the "glue" that joins the platform-independent classes in the
  46. * <code>java.awt</code> package with their counterparts in
  47. * <code>java.awt.peer</code>. Some methods defined by
  48. * <code>Toolkit</code> query the native operating system directly.
  49. *
  50. * @version 1.126, 11/29/01
  51. * @author Sami Shaio
  52. * @author Arthur van Hoff
  53. * @author Fred Ecks
  54. * @since JDK1.0
  55. */
  56. public abstract class Toolkit {
  57. /**
  58. * Creates this toolkit's implementation of <code>Button</code> using
  59. * the specified peer interface.
  60. * @param target the button to be implemented.
  61. * @return this toolkit's implementation of <code>Button</code>.
  62. * @see java.awt.Button
  63. * @see java.awt.peer.ButtonPeer
  64. */
  65. protected abstract ButtonPeer createButton(Button target);
  66. /**
  67. * Creates this toolkit's implementation of <code>TextField</code> using
  68. * the specified peer interface.
  69. * @param target the text field to be implemented.
  70. * @return this toolkit's implementation of <code>TextField</code>.
  71. * @see java.awt.TextField
  72. * @see java.awt.peer.TextFieldPeer
  73. */
  74. protected abstract TextFieldPeer createTextField(TextField target);
  75. /**
  76. * Creates this toolkit's implementation of <code>Label</code> using
  77. * the specified peer interface.
  78. * @param target the label to be implemented.
  79. * @return this toolkit's implementation of <code>Label</code>.
  80. * @see java.awt.Label
  81. * @see java.awt.peer.LabelPeer
  82. */
  83. protected abstract LabelPeer createLabel(Label target);
  84. /**
  85. * Creates this toolkit's implementation of <code>List</code> using
  86. * the specified peer interface.
  87. * @param target the list to be implemented.
  88. * @return this toolkit's implementation of <code>List</code>.
  89. * @see java.awt.List
  90. * @see java.awt.peer.ListPeer
  91. */
  92. protected abstract ListPeer createList(List target);
  93. /**
  94. * Creates this toolkit's implementation of <code>Checkbox</code> using
  95. * the specified peer interface.
  96. * @param target the check box to be implemented.
  97. * @return this toolkit's implementation of <code>Checkbox</code>.
  98. * @see java.awt.Checkbox
  99. * @see java.awt.peer.CheckboxPeer
  100. */
  101. protected abstract CheckboxPeer createCheckbox(Checkbox target);
  102. /**
  103. * Creates this toolkit's implementation of <code>Scrollbar</code> using
  104. * the specified peer interface.
  105. * @param target the scroll bar to be implemented.
  106. * @return this toolkit's implementation of <code>Scrollbar</code>.
  107. * @see java.awt.Scrollbar
  108. * @see java.awt.peer.ScrollbarPeer
  109. */
  110. protected abstract ScrollbarPeer createScrollbar(Scrollbar target);
  111. /**
  112. * Creates this toolkit's implementation of <code>ScrollPane</code> using
  113. * the specified peer interface.
  114. * @param target the scroll pane to be implemented.
  115. * @return this toolkit's implementation of <code>ScrollPane</code>.
  116. * @see java.awt.ScrollPane
  117. * @see java.awt.peer.ScrollPanePeer
  118. * @since JDK1.1
  119. */
  120. protected abstract ScrollPanePeer createScrollPane(ScrollPane target);
  121. /**
  122. * Creates this toolkit's implementation of <code>TextArea</code> using
  123. * the specified peer interface.
  124. * @param target the text area to be implemented.
  125. * @return this toolkit's implementation of <code>TextArea</code>.
  126. * @see java.awt.TextArea
  127. * @see java.awt.peer.TextAreaPeer
  128. */
  129. protected abstract TextAreaPeer createTextArea(TextArea target);
  130. /**
  131. * Creates this toolkit's implementation of <code>Choice</code> using
  132. * the specified peer interface.
  133. * @param target the choice to be implemented.
  134. * @return this toolkit's implementation of <code>Choice</code>.
  135. * @see java.awt.Choice
  136. * @see java.awt.peer.ChoicePeer
  137. */
  138. protected abstract ChoicePeer createChoice(Choice target);
  139. /**
  140. * Creates this toolkit's implementation of <code>Frame</code> using
  141. * the specified peer interface.
  142. * @param target the frame to be implemented.
  143. * @return this toolkit's implementation of <code>Frame</code>.
  144. * @see java.awt.Frame
  145. * @see java.awt.peer.FramePeer
  146. */
  147. protected abstract FramePeer createFrame(Frame target);
  148. /**
  149. * Creates this toolkit's implementation of <code>Canvas</code> using
  150. * the specified peer interface.
  151. * @param target the canvas to be implemented.
  152. * @return this toolkit's implementation of <code>Canvas</code>.
  153. * @see java.awt.Canvas
  154. * @see java.awt.peer.CanvasPeer
  155. */
  156. protected abstract CanvasPeer createCanvas(Canvas target);
  157. /**
  158. * Creates this toolkit's implementation of <code>Panel</code> using
  159. * the specified peer interface.
  160. * @param target the panel to be implemented.
  161. * @return this toolkit's implementation of <code>Panel</code>.
  162. * @see java.awt.Panel
  163. * @see java.awt.peer.PanelPeer
  164. */
  165. protected abstract PanelPeer createPanel(Panel target);
  166. /**
  167. * Creates this toolkit's implementation of <code>Window</code> using
  168. * the specified peer interface.
  169. * @param target the window to be implemented.
  170. * @return this toolkit's implementation of <code>Window</code>.
  171. * @see java.awt.Window
  172. * @see java.awt.peer.WindowPeer
  173. */
  174. protected abstract WindowPeer createWindow(Window target);
  175. /**
  176. * Creates this toolkit's implementation of <code>Dialog</code> using
  177. * the specified peer interface.
  178. * @param target the dialog to be implemented.
  179. * @return this toolkit's implementation of <code>Dialog</code>.
  180. * @see java.awt.Dialog
  181. * @see java.awt.peer.DialogPeer
  182. */
  183. protected abstract DialogPeer createDialog(Dialog target);
  184. /**
  185. * Creates this toolkit's implementation of <code>MenuBar</code> using
  186. * the specified peer interface.
  187. * @param target the menu bar to be implemented.
  188. * @return this toolkit's implementation of <code>MenuBar</code>.
  189. * @see java.awt.MenuBar
  190. * @see java.awt.peer.MenuBarPeer
  191. */
  192. protected abstract MenuBarPeer createMenuBar(MenuBar target);
  193. /**
  194. * Creates this toolkit's implementation of <code>Menu</code> using
  195. * the specified peer interface.
  196. * @param target the menu to be implemented.
  197. * @return this toolkit's implementation of <code>Menu</code>.
  198. * @see java.awt.Menu
  199. * @see java.awt.peer.MenuPeer
  200. */
  201. protected abstract MenuPeer createMenu(Menu target);
  202. /**
  203. * Creates this toolkit's implementation of <code>PopupMenu</code> using
  204. * the specified peer interface.
  205. * @param target the popup menu to be implemented.
  206. * @return this toolkit's implementation of <code>PopupMenu</code>.
  207. * @see java.awt.PopupMenu
  208. * @see java.awt.peer.PopupMenuPeer
  209. * @since JDK1.1
  210. */
  211. protected abstract PopupMenuPeer createPopupMenu(PopupMenu target);
  212. /**
  213. * Creates this toolkit's implementation of <code>MenuItem</code> using
  214. * the specified peer interface.
  215. * @param target the menu item to be implemented.
  216. * @return this toolkit's implementation of <code>MenuItem</code>.
  217. * @see java.awt.MenuItem
  218. * @see java.awt.peer.MenuItemPeer
  219. */
  220. protected abstract MenuItemPeer createMenuItem(MenuItem target);
  221. /**
  222. * Creates this toolkit's implementation of <code>FileDialog</code> using
  223. * the specified peer interface.
  224. * @param target the file dialog to be implemented.
  225. * @return this toolkit's implementation of <code>FileDialog</code>.
  226. * @see java.awt.FileDialog
  227. * @see java.awt.peer.FileDialogPeer
  228. */
  229. protected abstract FileDialogPeer createFileDialog(FileDialog target);
  230. /**
  231. * Creates this toolkit's implementation of <code>CheckboxMenuItem</code> using
  232. * the specified peer interface.
  233. * @param target the checkbox menu item to be implemented.
  234. * @return this toolkit's implementation of <code>CheckboxMenuItem</code>.
  235. * @see java.awt.CheckboxMenuItem
  236. * @see java.awt.peer.CheckboxMenuItemPeer
  237. */
  238. protected abstract CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target);
  239. private static java.awt.LightweightPeer lightweightMarker;
  240. /**
  241. * Creates a peer for a component or container. This peer is windowless
  242. * and allows the Component and Container classes to be extended directly
  243. * to create windowless components that are defined entirely in java.
  244. *
  245. * @param target The Component to be created.
  246. */
  247. protected java.awt.peer.LightweightPeer createComponent(Component target) {
  248. if (lightweightMarker == null) {
  249. lightweightMarker = new java.awt.LightweightPeer(target);
  250. }
  251. return lightweightMarker;
  252. }
  253. /**
  254. * Creates this toolkit's implementation of <code>Font</code> using
  255. * the specified peer interface.
  256. * @param target the font to be implemented.
  257. * @return this toolkit's implementation of <code>Font</code>.
  258. * @see java.awt.Font
  259. * @see java.awt.peer.FontPeer
  260. * @see java.awt.GraphicsEnvironment#getAllFonts
  261. * @deprecated see java.awt.GraphicsEnvironment#getAllFonts
  262. */
  263. protected abstract FontPeer getFontPeer(String name, int style);
  264. /**
  265. * Fills in the integer array that is supplied as an argument
  266. * with the current system color values.
  267. * <p>
  268. * This method is called by the method <code>updateSystemColors</code>
  269. * in the <code>SystemColor</code> class.
  270. * @param an integer array.
  271. * @see java.awt.SystemColor#updateSystemColors
  272. * @since JDK1.1
  273. */
  274. protected void loadSystemColors(int[] systemColors) {
  275. }
  276. /**
  277. * Gets the size of the screen.
  278. * @return the size of this toolkit's screen, in pixels.
  279. */
  280. public abstract Dimension getScreenSize();
  281. /**
  282. * Returns the screen resolution in dots-per-inch.
  283. * @return this toolkit's screen resolution, in dots-per-inch.
  284. */
  285. public abstract int getScreenResolution();
  286. /**
  287. * Determines the color model of this toolkit's screen.
  288. * <p>
  289. * <code>ColorModel</code> is an abstract class that
  290. * encapsulates the ability to translate between the
  291. * pixel values of an image and its red, green, blue,
  292. * and alpha components.
  293. * <p>
  294. * This toolkit method is called by the
  295. * <code>getColorModel</code> method
  296. * of the <code>Component</code> class.
  297. * @return the color model of this toolkit's screen.
  298. * @see java.awt.image.ColorModel
  299. * @see java.awt.Component#getColorModel
  300. */
  301. public abstract ColorModel getColorModel();
  302. /**
  303. * Returns the names of the available fonts in this toolkit.<p>
  304. * For 1.1, the following font names are deprecated (the replacement
  305. * name follows):
  306. * <ul>
  307. * <li>TimesRoman (use Serif)
  308. * <li>Helvetica (use SansSerif)
  309. * <li>Courier (use Monospaced)
  310. * </ul><p>
  311. * The ZapfDingbats fontname is also deprecated in 1.1 but the characters
  312. * are defined in Unicode starting at 0x2700, and as of 1.1 Java supports
  313. * those characters.
  314. * @return the names of the available fonts in this toolkit.
  315. * @deprecated see {@link java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()}
  316. * @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()
  317. */
  318. public abstract String[] getFontList();
  319. /**
  320. * Gets the screen device metrics for rendering of the font.
  321. * @param font a font.
  322. * @return the screen metrics of the specified font in this toolkit.
  323. * @deprecated This returns integer metrics for the default screen.
  324. * @see java.awt.Font#LineMetrics
  325. * @see java.awt.Font#retreiveLineMetrics
  326. * @see java.awt.GraphicsEnvironment#getScreenDevices;
  327. */
  328. public abstract FontMetrics getFontMetrics(Font font);
  329. /**
  330. * Synchronizes this toolkit's graphics state. Some window systems
  331. * may do buffering of graphics events.
  332. * <p>
  333. * This method ensures that the display is up-to-date. It is useful
  334. * for animation.
  335. */
  336. public abstract void sync();
  337. /**
  338. * The default toolkit.
  339. */
  340. private static Toolkit toolkit;
  341. /**
  342. * Loads additional classes into the VM, using the property
  343. * 'assistive_technologies' specified in the Sun reference
  344. * implementation by a line in the 'accessibility.properties'
  345. * file. The form is "assistive_technologies=..." where
  346. * the "..." is a comma-separated list of assistive technology
  347. * classes to load. Each class is loaded in the order given
  348. * and a single instance of each is created using
  349. * Class.forName(class).newInstance(). All errors are handled
  350. * via an AWTError exception.
  351. *
  352. * <p>The assumption is made that assistive technology classes are supplied
  353. * as part of INSTALLED (as opposed to: BUNDLED) extensions or specified
  354. * on the class path
  355. * (and therefore can be loaded using the class loader returned by
  356. * a call to <code>ClassLoader.getSystemClassLoader</code>, whose
  357. * delegation parent is the extension class loader for installed
  358. * extensions).
  359. */
  360. private static void loadAssistiveTechnologies() {
  361. final String sep = File.separator;
  362. final Properties properties = new Properties();
  363. java.security.AccessController.doPrivileged(
  364. new java.security.PrivilegedAction() {
  365. public Object run() {
  366. try {
  367. File propsFile = new File(
  368. System.getProperty("java.home") + sep + "lib" +
  369. sep + "accessibility.properties");
  370. FileInputStream in =
  371. new FileInputStream(propsFile);
  372. properties.load(new BufferedInputStream(in));
  373. in.close();
  374. } catch (Exception e) {
  375. // File does not exist; no classes will be auto loaded
  376. }
  377. return null;
  378. }
  379. });
  380. String atNames = properties.getProperty("assistive_technologies",null);
  381. ClassLoader cl = ClassLoader.getSystemClassLoader();
  382. if (atNames != null) {
  383. StringTokenizer parser = new StringTokenizer(atNames," ,");
  384. String atName;
  385. while (parser.hasMoreTokens()) {
  386. atName = parser.nextToken();
  387. try {
  388. Class clazz;
  389. if (cl != null) {
  390. clazz = cl.loadClass(atName);
  391. } else {
  392. clazz = Class.forName(atName);
  393. }
  394. clazz.newInstance();
  395. } catch (ClassNotFoundException e) {
  396. throw new AWTError("Assistive Technology not found: "
  397. + atName);
  398. } catch (InstantiationException e) {
  399. throw new AWTError("Could not instantiate Assistive"
  400. + " Technology: " + atName);
  401. } catch (IllegalAccessException e) {
  402. throw new AWTError("Could not access Assistive"
  403. + " Technology: " + atName);
  404. } catch (Exception e) {
  405. throw new AWTError("Error trying to install Assistive"
  406. + " Technology: " + atName + " " + e);
  407. }
  408. }
  409. }
  410. }
  411. /**
  412. * Gets the default toolkit.
  413. * <p>
  414. * If there is a system property named <code>"awt.toolkit"</code>,
  415. * that property is treated as the name of a class that is a subclass
  416. * of <code>Toolkit</code>.
  417. * <p>
  418. * If the system property does not exist, then the default toolkit
  419. * used is the class named <code>"sun.awt.motif.MToolkit"</code>,
  420. * which is a motif implementation of the Abstract Window Toolkit.
  421. * <p>
  422. * Also loads additional classes into the VM, using the property
  423. * 'assistive_technologies' specified in the Sun reference
  424. * implementation by a line in the 'accessibility.properties'
  425. * file. The form is "assistive_technologies=..." where
  426. * the "..." is a comma-separated list of assistive technology
  427. * classes to load. Each class is loaded in the order given
  428. * and a single instance of each is created using
  429. * Class.forName(class).newInstance(). This is done just after
  430. * the AWT toolkit is created. All errors are handled via an
  431. * AWTError exception.
  432. * @return the default toolkit.
  433. * @exception AWTError if a toolkit could not be found, or
  434. * if one could not be accessed or instantiated.
  435. */
  436. public static synchronized Toolkit getDefaultToolkit() {
  437. if (toolkit == null) {
  438. try {
  439. // We disable the JIT during toolkit initialization. This
  440. // tends to touch lots of classes that aren't needed again
  441. // later and therefore JITing is counter-productiive.
  442. java.lang.Compiler.disable();
  443. java.security.AccessController.doPrivileged(
  444. new java.security.PrivilegedAction() {
  445. public Object run() {
  446. String nm = null;
  447. try {
  448. nm = System.getProperty("awt.toolkit",
  449. "sun.awt.motif.MToolkit");
  450. toolkit = (Toolkit)Class.forName(nm).newInstance();
  451. } catch (ClassNotFoundException e) {
  452. throw new AWTError("Toolkit not found: " + nm);
  453. } catch (InstantiationException e) {
  454. throw new AWTError("Could not instantiate Toolkit: " +
  455. nm);
  456. } catch (IllegalAccessException e) {
  457. throw new AWTError("Could not access Toolkit: " + nm);
  458. }
  459. return null;
  460. }
  461. });
  462. loadAssistiveTechnologies();
  463. } finally {
  464. // Make sure to always re-enable the JIT.
  465. java.lang.Compiler.enable();
  466. }
  467. }
  468. return toolkit;
  469. }
  470. /**
  471. * Returns an image which gets pixel data from the specified file.
  472. * The underlying toolkit attempts to resolve multiple requests
  473. * with the same filename to the same returned Image.
  474. * Since the mechanism required to facilitate this sharing of
  475. * Image objects may continue to hold onto images that are no
  476. * longer of use for an indefinate period of time, developers
  477. * are encouraged to implement their own caching of images by
  478. * using the createImage variant wherever available.
  479. * @param filename the name of a file containing pixel data
  480. * in a recognized file format.
  481. * @return an image which gets its pixel data from
  482. * the specified file.
  483. * @see createImage(java.lang.String)
  484. */
  485. public abstract Image getImage(String filename);
  486. /**
  487. * Returns an image which gets pixel data from the specified URL.
  488. * The underlying toolkit attempts to resolve multiple requests
  489. * with the same URL to the same returned Image.
  490. * Since the mechanism required to facilitate this sharing of
  491. * Image objects may continue to hold onto images that are no
  492. * longer of use for an indefinate period of time, developers
  493. * are encouraged to implement their own caching of images by
  494. * using the createImage variant wherever available.
  495. * @param url the URL to use in fetching the pixel data.
  496. * @return an image which gets its pixel data from
  497. * the specified URL.
  498. * @see createImage(java.net.URL)
  499. */
  500. public abstract Image getImage(URL url);
  501. /**
  502. * Returns an image which gets pixel data from the specified file.
  503. * The returned Image is a new object which will not be shared
  504. * with any other caller of this method or its getImage variant.
  505. * @param filename the name of a file containing pixel data
  506. * in a recognized file format.
  507. * @return an image which gets its pixel data from
  508. * the specified file.
  509. * @see getImage(java.lang.String)
  510. */
  511. public abstract Image createImage(String filename);
  512. /**
  513. * Returns an image which gets pixel data from the specified URL.
  514. * The returned Image is a new object which will not be shared
  515. * with any other caller of this method or its getImage variant.
  516. * @param url the URL to use in fetching the pixel data.
  517. * @return an image which gets its pixel data from
  518. * the specified URL.
  519. * @see getImage(java.net.URL)
  520. */
  521. public abstract Image createImage(URL url);
  522. /**
  523. * Prepares an image for rendering.
  524. * <p>
  525. * If the values of the width and height arguments are both
  526. * <code>-1</code>, this method prepares the image for rendering
  527. * on the default screen; otherwise, this method prepares an image
  528. * for rendering on the default screen at the specified width and height.
  529. * <p>
  530. * The image data is downloaded asynchronously in another thread,
  531. * and an appropriately scaled screen representation of the image is
  532. * generated.
  533. * <p>
  534. * This method is called by components <code>prepareImage</code>
  535. * methods.
  536. * <p>
  537. * Information on the flags returned by this method can be found
  538. * with the definition of the <code>ImageObserver</code> interface.
  539. * @param image the image for which to prepare a
  540. * screen representation.
  541. * @param width the width of the desired screen
  542. * representation, or <code>-1</code>.
  543. * @param height the height of the desired screen
  544. * representation, or <code>-1</code>.
  545. * @param observer the <code>ImageObserver</code>
  546. * object to be notified as the
  547. * image is being prepared.
  548. * @return <code>true</code> if the image has already been
  549. * fully prepared; <code>false</code> otherwise.
  550. * @see java.awt.Component#prepareImage(java.awt.Image,
  551. * java.awt.image.ImageObserver)
  552. * @see java.awt.Component#prepareImage(java.awt.Image,
  553. * int, int, java.awt.image.ImageObserver)
  554. * @see java.awt.image.ImageObserver
  555. */
  556. public abstract boolean prepareImage(Image image, int width, int height,
  557. ImageObserver observer);
  558. /**
  559. * Indicates the construction status of a specified image that is
  560. * being prepared for display.
  561. * <p>
  562. * If the values of the width and height arguments are both
  563. * <code>-1</code>, this method returns the construction status of
  564. * a screen representation of the specified image in this toolkit.
  565. * Otherwise, this method returns the construction status of a
  566. * scaled representation of the image at the specified width
  567. * and height.
  568. * <p>
  569. * This method does not cause the image to begin loading.
  570. * An application must call <code>prepareImage</code> to force
  571. * the loading of an image.
  572. * <p>
  573. * This method is called by the component's <code>checkImage</code>
  574. * methods.
  575. * <p>
  576. * Information on the flags returned by this method can be found
  577. * with the definition of the <code>ImageObserver</code> interface.
  578. * @param image the image whose status is being checked.
  579. * @param width the width of the scaled version whose status is
  580. * being checked, or <code>-1</code>.
  581. * @param height the height of the scaled version whose status
  582. * is being checked, or <code>-1</code>.
  583. * @param observer the <code>ImageObserver</code> object to be
  584. * notified as the image is being prepared.
  585. * @return the bitwise inclusive <strong>OR</strong> of the
  586. * <code>ImageObserver</code> flags for the
  587. * image data that is currently available.
  588. * @see java.awt.Toolkit#prepareImage(java.awt.Image,
  589. * int, int, java.awt.image.ImageObserver)
  590. * @see java.awt.Component#checkImage(java.awt.Image,
  591. * java.awt.image.ImageObserver)
  592. * @see java.awt.Component#checkImage(java.awt.Image,
  593. * int, int, java.awt.image.ImageObserver)
  594. * @see java.awt.image.ImageObserver
  595. */
  596. public abstract int checkImage(Image image, int width, int height,
  597. ImageObserver observer);
  598. /**
  599. * Creates an image with the specified image producer.
  600. * @param producer the image producer to be used.
  601. * @return an image with the specified image producer.
  602. * @see java.awt.Image
  603. * @see java.awt.image.ImageProducer
  604. * @see java.awt.Component#createImage(java.awt.image.ImageProducer)
  605. */
  606. public abstract Image createImage(ImageProducer producer);
  607. /**
  608. * Creates an image which decodes the image stored in the specified
  609. * byte array.
  610. * <p>
  611. * The data must be in some image format, such as GIF or JPEG,
  612. * that is supported by this toolkit.
  613. * @param imagedata an array of bytes, representing
  614. * image data in a supported image format.
  615. * @return an image.
  616. * @since JDK1.1
  617. */
  618. public Image createImage(byte[] imagedata) {
  619. return createImage(imagedata, 0, imagedata.length);
  620. }
  621. /**
  622. * Creates an image which decodes the image stored in the specified
  623. * byte array, and at the specified offset and length.
  624. * The data must be in some image format, such as GIF or JPEG,
  625. * that is supported by this toolkit.
  626. * @param imagedata an array of bytes, representing
  627. * image data in a supported image format.
  628. * @param imageoffset the offset of the beginning
  629. * of the data in the array.
  630. * @param imagelength the length of the data in the array.
  631. * @return an image.
  632. * @since JDK1.1
  633. */
  634. public abstract Image createImage(byte[] imagedata,
  635. int imageoffset,
  636. int imagelength);
  637. /**
  638. * Gets a <code>PrintJob</code> object which is the result
  639. * of initiating a print operation on the toolkit's platform.
  640. *
  641. * <p>Each actual implementation of this method should first check if there is a
  642. * security manager installed. If there is, the method should call the security
  643. * manager's <code>checkPrintJobAccess</code> method to ensure
  644. * initiation of a print operation is allowed.
  645. * If the default implementation of <code>checkPrintJobAccess</code> is used
  646. * (that is, that method is not overriden), then this results in
  647. * a call to the security manager's <code>checkPermission</code> method
  648. * with a <code>RuntimePermission("queuePrintJob")</code> permission.
  649. *
  650. * @return a <code>PrintJob</code> object, or
  651. * <code>null</code> if the user
  652. * cancelled the print job.
  653. * @see java.awt.PrintJob
  654. * @see java.lang.RuntimePermission
  655. * @since JDK1.1
  656. */
  657. public abstract PrintJob getPrintJob(Frame frame, String jobtitle, Properties props);
  658. /**
  659. * Emits an audio beep.
  660. * @since JDK1.1
  661. */
  662. public abstract void beep();
  663. /**
  664. * Gets an instance of the system clipboard which interfaces
  665. * with clipboard facilities provided by the native platform.
  666. *
  667. * <p>This clipboard enables data transfer between Java programs
  668. * and native applications which use native clipboard facilities.
  669. *
  670. * <p>Each actual implementation of this method should first check if there is a
  671. * security manager installed. If there is, the method should call the security
  672. * manager's <code>checkSystemClipboardAccess</code> method to ensure
  673. * it's ok to to access the system clipboard.
  674. * If the default implementation of <code>checkSystemClipboardAccess</code>
  675. * is used (that is, that method is not overriden), then this results in
  676. * a call to the security manager's <code>checkPermission</code> method
  677. * with an <code>AWTPermission("accessClipboard")</code> permission.
  678. *
  679. * @return an instance of the system clipboard.
  680. * @see java.awt.datatransfer.Clipboard
  681. * @see java.awt.AWTPermission
  682. * @since JDK1.1
  683. */
  684. public abstract Clipboard getSystemClipboard();
  685. /**
  686. * Determines which modifier key is the appropriate accelerator
  687. * key for menu shortcuts.
  688. * <p>
  689. * Menu shortcuts, which are embodied in the
  690. * <code>MenuShortcut</code> class, are handled by the
  691. * <code>MenuBar</code> class.
  692. * <p>
  693. * By default, this method returns <code>Event.CTRL_MASK</code>.
  694. * Toolkit implementations should override this method if the
  695. * <b>Control</b> key isn't the correct key for accelerators.
  696. * @return the modifier mask on the <code>Event</code> class
  697. * that is used for menu shortcuts on this toolkit.
  698. * @see java.awt.MenuBar
  699. * @see java.awt.MenuShortcut
  700. * @since JDK1.1
  701. */
  702. public int getMenuShortcutKeyMask() {
  703. return Event.CTRL_MASK;
  704. }
  705. /**
  706. * Give native peers the ability to query the native container
  707. * given a native component (eg the direct parent may be lightweight).
  708. */
  709. protected static Container getNativeContainer(Component c) {
  710. return c.getNativeContainer();
  711. }
  712. /**
  713. * Creates a new custom cursor object.
  714. * @param image the image to display when the cursor is active.
  715. * @param hotSpot the X and Y of the large cursor's hot spot. The
  716. * hotSpot values must be less than the Dimension returned by
  717. * getBestCursorSize().
  718. * @param name a localized description of the cursor, for Java Accessibility use.
  719. * @exception IndexOutOfBoundsException if the hotSpot values are outside
  720. * the bounds of the cursor.
  721. * @since JDK1.2
  722. */
  723. public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
  724. throws IndexOutOfBoundsException {
  725. // Override to implement custom cursor support.
  726. return new Cursor(Cursor.DEFAULT_CURSOR);
  727. }
  728. /**
  729. * Returns the supported cursor dimension which is closest to the desired
  730. * sizes. Systems which only support a single cursor size will return that
  731. * size regardless of the desired sizes. Systems which don't support custom
  732. * cursors will return a dimension of 0, 0. <p>
  733. * Note: if an image is used whose dimensions don't match a supported size
  734. * (as returned by this method), the Toolkit implementation will attempt to
  735. * resize the image to a supported size.
  736. * Since converting low-resolution images is difficult,
  737. * no guarantees are made as to the quality of a cursor image which isn't a
  738. * supported size. It is therefore recommended that this method
  739. * be called and an appropriate image used so no image conversion is made.
  740. *
  741. * @param desiredWidth the preferred cursor width the component would like
  742. * to use.
  743. * @param desiredHeight the preferred cursor height the component would like
  744. * to use.
  745. * @return the closest matching supported cursor size, or a dimension of 0,0 if
  746. * the Toolkit implementation doesn't support custom cursors.
  747. * @since JDK1.2
  748. */
  749. public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {
  750. // Override to implement custom cursor support.
  751. return new Dimension(0, 0);
  752. }
  753. /**
  754. * Returns the maximum number of colors the Toolkit supports in a custom cursor
  755. * palette.<p>
  756. * Note: if an image is used which has more colors in its palette than
  757. * the supported maximum, the Toolkit implementation will attempt to flatten the
  758. * palette to the maximum. Since converting low-resolution images is difficult,
  759. * no guarantees are made as to the quality of a cursor image which has more
  760. * colors than the system supports. It is therefore recommended that this method
  761. * be called and an appropriate image used so no image conversion is made.
  762. *
  763. * @return the maximum number of colors, or zero if custom cursors are not
  764. * supported by this Toolkit implementation.
  765. * @since JDK1.2
  766. */
  767. public int getMaximumCursorColors() {
  768. // Override to implement custom cursor support.
  769. return 0;
  770. }
  771. /**
  772. * Support for I18N: any visible strings should be stored in
  773. * java.awt.resources.awt.properties. The ResourceBundle is stored
  774. * here, so that only one copy is maintained.
  775. */
  776. private static ResourceBundle resources;
  777. /**
  778. * Initialize JNI field and method ids
  779. */
  780. private static native void initIDs();
  781. /**
  782. * WARNING: This is a temporary workaround for a problem in the
  783. * way the AWT loads native libraries. A number of classes in the
  784. * AWT package have a native method, initIDs(), which initializes
  785. * the JNI field and method ids used in the native portion of
  786. * their implementation.
  787. *
  788. * Since the use and storage of these ids is done by the
  789. * implementation libraries, the implementation of these method is
  790. * provided by the particular AWT implementations
  791. * (i.e. "Toolkit"s/Peer), such as Motif, Win32 or Tiny. The
  792. * problem is that this means that the native libraries must be
  793. * loaded by the java.* classes, which do not necessarily know the
  794. * names of the libraries to load. A better way of doing this
  795. * would be to provide a separate library which defines java.awt.*
  796. * initIDs, and exports the relevant symbols out to the
  797. * implementation libraries.
  798. *
  799. * For now, we know it's done by the implementation, and we assume
  800. * that the name of the library is "awt". -br.
  801. *
  802. * If you change loadLibraries(), please add the change to
  803. * java.awt.image.ColorModel.loadLibraries(). Unfortunately,
  804. * classes can be loaded in java.awt.image that depend on
  805. * libawt and there is no way to call Toolkit.loadLibraries()
  806. * directly. -hung
  807. */
  808. private static boolean loaded = false;
  809. static void loadLibraries() {
  810. if (!loaded) {
  811. java.security.AccessController.doPrivileged(
  812. new sun.security.action.LoadLibraryAction("awt"));
  813. loaded = true;
  814. }
  815. }
  816. static {
  817. java.security.AccessController.doPrivileged(
  818. new java.security.PrivilegedAction() {
  819. public Object run() {
  820. try {
  821. resources =
  822. ResourceBundle.getBundle("java.awt.resources.awt");
  823. } catch (MissingResourceException e) {
  824. // No resource file; defaults will be used.
  825. }
  826. return null;
  827. }
  828. });
  829. // ensure that the proper libraries are loaded
  830. loadLibraries();
  831. initIDs();
  832. }
  833. /**
  834. * Gets a property with the specified key and default.
  835. * This method returns defaultValue if the property is not found.
  836. */
  837. public static String getProperty(String key, String defaultValue) {
  838. if (resources != null) {
  839. try {
  840. return resources.getString(key);
  841. }
  842. catch (MissingResourceException e) {}
  843. }
  844. return defaultValue;
  845. }
  846. /**
  847. * Get the application's or applet's EventQueue instance.
  848. * Depending on the Toolkit implementation, different EventQueues
  849. * may be returned for different applets. Applets should
  850. * therefore not assume that the EventQueue instance returned
  851. * by this method will be shared by other applets or the system.
  852. *
  853. * <p>First, if there is a security manager, its
  854. * <code>checkAwtEventQueueAccess</code>
  855. * method is called.
  856. * If the default implementation of <code>checkAwtEventQueueAccess</code>
  857. * is used (that is, that method is not overriden), then this results in
  858. * a call to the security manager's <code>checkPermission</code> method
  859. * with an <code>AWTPermission("accessEventQueue")</code> permission.
  860. *
  861. * @return the <code>EventQueue</code> object.
  862. * @throws SecurityException
  863. * if a security manager exists and its <code>{@link
  864. * java.lang.SecurityManager#checkAwtEventQueueAccess}</code> method denies
  865. * access to the EventQueue.
  866. * @see java.awt.AWTPermission
  867. */
  868. public final EventQueue getSystemEventQueue() {
  869. SecurityManager security = System.getSecurityManager();
  870. if (security != null) {
  871. security.checkAwtEventQueueAccess();
  872. }
  873. return getSystemEventQueueImpl();
  874. }
  875. /*
  876. * Get the application's or applet's EventQueue instance, without
  877. * checking access. For security reasons, this can only be called
  878. * from a Toolkit subclass. Implementations wishing to modify
  879. * the default EventQueue support should subclass this method.
  880. */
  881. protected abstract EventQueue getSystemEventQueueImpl();
  882. /* Accessor method for use by AWT package routines. */
  883. static EventQueue getEventQueue() {
  884. return getDefaultToolkit().getSystemEventQueueImpl();
  885. }
  886. /**
  887. * create the peer for a DragSourceContext
  888. */
  889. public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException;
  890. /**
  891. * create a concrete, platform dependent, subclass of the abstract
  892. * DragGestureRecognizer class requested, and associate it with the
  893. * DragSource, Component and DragGestureListener specified
  894. *
  895. * subclasses should override this to provide their own implementation
  896. *
  897. * @param abstractRecognizerClass The abstract class of the required recognizer
  898. * @param ds The DragSource
  899. * @param c The Component target for the DragGestureRecognizer
  900. * @param srcActions The actions permitted for the gesture
  901. * @param dgl The DragGestureListener
  902. *
  903. * @Return the new object or null
  904. */
  905. public DragGestureRecognizer createDragGestureRecognizer(Class abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) {
  906. return null;
  907. }
  908. /**
  909. * obtain a value for the specified desktop property.
  910. *
  911. * A desktop property is a uniquely named value for a resource that
  912. * is Toolkit global in nature. Usually it also is an abstract representation
  913. * for an underlying platform dependent desktop setting.
  914. */
  915. public final synchronized Object getDesktopProperty(String propertyName) {
  916. if (desktopProperties.isEmpty()) {
  917. initializeDesktopProperties();
  918. }
  919. Object value = desktopProperties.get(propertyName);
  920. if (value == null) {
  921. value = lazilyLoadDesktopProperty(propertyName);
  922. if (value != null) {
  923. setDesktopProperty(propertyName, value);
  924. }
  925. }
  926. return value;
  927. }
  928. /**
  929. * set the named desktop property to the specified value and fire a
  930. * property change event to notify any listeners that the value has changed
  931. */
  932. protected final synchronized void setDesktopProperty(String name, Object newValue) {
  933. Object oldValue = desktopProperties.get(name);
  934. desktopProperties.put(name, newValue);
  935. desktopPropsSupport.firePropertyChange(name, oldValue, newValue);
  936. }
  937. /**
  938. * an opportunity to lazily evaluate desktop property values.
  939. */
  940. protected Object lazilyLoadDesktopProperty(String name) {
  941. return null;
  942. }
  943. /**
  944. * initializeDesktopProperties
  945. */
  946. protected void initializeDesktopProperties() {
  947. }
  948. /**
  949. * add the specified property change listener for the named desktop
  950. * property
  951. * If pcl is null, no exception is thrown and no action is performed.
  952. *
  953. * @param name The name of the property to listen for
  954. * @param pcl The property change listener
  955. */
  956. public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
  957. if (pcl == null) {
  958. return;
  959. }
  960. desktopPropsSupport.addPropertyChangeListener(name, pcl);
  961. }
  962. /**
  963. * remove the specified property change listener for the named
  964. * desktop property
  965. * If pcl is null, no exception is thrown and no action is performed.
  966. *
  967. */
  968. public synchronized void removePropertyChangeListener(String name, PropertyChangeListener pcl) {
  969. if (pcl == null) {
  970. return;
  971. }
  972. desktopPropsSupport.removePropertyChangeListener(name, pcl);
  973. }
  974. protected final Map desktopProperties = new HashMap();
  975. protected final PropertyChangeSupport desktopPropsSupport = new PropertyChangeSupport(this);
  976. private AWTEventListener eventListener = null;
  977. private WeakHashMap listener2SelectiveListener = new WeakHashMap();
  978. private AWTPermission listenToAllAWTEventsPermission = null;
  979. /**
  980. * Adds an AWTEventListener to receive all AWTEvents dispatched
  981. * system-wide that conform to the given <code>eventMask</code>.
  982. * <p>
  983. * First, if there is a security manager, its <code>checkPermission</code>
  984. * method is called with an
  985. * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
  986. * This may result in a SecurityException.
  987. * <p>
  988. * <code>eventMask</code> is a bitmask of event types to receive.
  989. * It is constructed by bitwise OR-ing together the event masks
  990. * defined in <code>AWTEvent</code>.
  991. * <p>
  992. * Note: event listener use is not recommended for normal
  993. * application use, but are intended solely to support special
  994. * purpose facilities including support for accessibility,
  995. * event record/playback, and diagnostic tracing.
  996. *
  997. * If listener is null, no exception is thrown and no action is performed.
  998. *
  999. * @param listener the event listener.
  1000. * @param eventMask the bitmask of event types to receive
  1001. * @throws SecurityException
  1002. * if a security manager exists and its
  1003. * <code>checkPermission</code> method doesn't allow the operation.
  1004. * @see java.awt.event.AWTEventListener
  1005. * @see java.awt.Toolkit#addEventListener
  1006. * @see java.awt.AWTEvent
  1007. * @see SecurityManager#checkPermission
  1008. * @see java.awt.AWTPermission
  1009. * @since JDK1.2
  1010. */
  1011. public void addAWTEventListener(AWTEventListener listener, long eventMask) {
  1012. if (listener == null) {
  1013. return;
  1014. }
  1015. SecurityManager security = System.getSecurityManager();
  1016. if (security != null) {
  1017. if (listenToAllAWTEventsPermission == null) {
  1018. listenToAllAWTEventsPermission =
  1019. new AWTPermission("listenToAllAWTEvents");
  1020. }
  1021. security.checkPermission(listenToAllAWTEventsPermission);
  1022. }
  1023. synchronized (this) {
  1024. SelectiveAWTEventListener selectiveListener =
  1025. new SelectiveAWTEventListener(listener, eventMask);
  1026. listener2SelectiveListener.put(listener, selectiveListener);
  1027. eventListener = ToolkitEventMulticaster.add(eventListener,
  1028. selectiveListener);
  1029. }
  1030. }
  1031. /**
  1032. * Removes an AWTEventListener from receiving dispatched AWTEvents.
  1033. * <p>
  1034. * First, if there is a security manager, its <code>checkPermission</code>
  1035. * method is called with an
  1036. * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
  1037. * This may result in a SecurityException.
  1038. * <p>
  1039. * Note: event listener use is not recommended for normal
  1040. * application use, but are intended solely to support special
  1041. * purpose facilities including support for accessibility,
  1042. * event record/playback, and diagnostic tracing.
  1043. *
  1044. * If listener is null, no exception is thrown and no action is performed.
  1045. *
  1046. * @param listener the event listener.
  1047. * @throws SecurityException
  1048. * if a security manager exists and its
  1049. * <code>checkPermission</code> method doesn't allow the operation.
  1050. * @see java.awt.event.AWTEventListener
  1051. * @see java.awt.Toolkit#addEventListener
  1052. * @see java.awt.AWTEvent
  1053. * @see SecurityManager#checkPermission
  1054. * @see java.awt.AWTPermission
  1055. * @since JDK1.2
  1056. */
  1057. public void removeAWTEventListener(AWTEventListener listener) {
  1058. if (listener == null) {
  1059. return;
  1060. }
  1061. SecurityManager security = System.getSecurityManager();
  1062. if (security != null) {
  1063. if (listenToAllAWTEventsPermission == null) {
  1064. listenToAllAWTEventsPermission =
  1065. new AWTPermission("listenToAllAWTEvents");
  1066. }
  1067. security.checkPermission(listenToAllAWTEventsPermission);
  1068. }
  1069. synchronized (this) {
  1070. SelectiveAWTEventListener selectiveListener =
  1071. (SelectiveAWTEventListener)listener2SelectiveListener
  1072. .get(listener);
  1073. if (selectiveListener != null)
  1074. listener2SelectiveListener.remove(listener);
  1075. eventListener = ToolkitEventMulticaster.remove(eventListener,
  1076. (selectiveListener == null) ? listener : selectiveListener);
  1077. }
  1078. }
  1079. /*
  1080. * This method notifies any AWTEventListeners that an event
  1081. * is about to be dispatched.
  1082. *
  1083. * @param theEvent the event which will be dispatched.
  1084. */
  1085. void notifyAWTEventListeners(AWTEvent theEvent) {
  1086. if (eventListener != null) {
  1087. synchronized (this) {
  1088. if (eventListener != null)
  1089. eventListener.eventDispatched(theEvent);
  1090. }
  1091. }
  1092. }
  1093. static private class ToolkitEventMulticaster extends AWTEventMulticaster
  1094. implements AWTEventListener {
  1095. // Implementation cloned from AWTEventMulticaster.
  1096. ToolkitEventMulticaster(AWTEventListener a, AWTEventListener b) {
  1097. super(a, b);
  1098. }
  1099. static AWTEventListener add(AWTEventListener a,
  1100. AWTEventListener b) {
  1101. if (a == null) return b;
  1102. if (b == null) return a;
  1103. return new ToolkitEventMulticaster(a, b);
  1104. }
  1105. static AWTEventListener remove(AWTEventListener l,
  1106. AWTEventListener oldl) {
  1107. return (AWTEventListener) removeInternal(l, oldl);
  1108. }
  1109. // #4178589: must overload remove(EventListener) to call our add()
  1110. // instead of the static addInternal() so we allocate a
  1111. // ToolkitEventMulticaster instead of an AWTEventMulticaster.
  1112. // Note: this method is called by AWTEventListener.removeInternal(),
  1113. // so its method signature must match AWTEventListener.remove().
  1114. protected EventListener remove(EventListener oldl) {
  1115. if (oldl == a) return b;
  1116. if (oldl == b) return a;
  1117. AWTEventListener a2 = (AWTEventListener)removeInternal(a, oldl);
  1118. AWTEventListener b2 = (AWTEventListener)removeInternal(b, oldl);
  1119. if (a2 == a && b2 == b) {
  1120. return this; // it's not here
  1121. }
  1122. return add(a2, b2);
  1123. }
  1124. public void eventDispatched(AWTEvent event) {
  1125. ((AWTEventListener)a).eventDispatched(event);
  1126. ((AWTEventListener)b).eventDispatched(event);
  1127. }
  1128. }
  1129. private class SelectiveAWTEventListener implements AWTEventListener {
  1130. AWTEventListener listener;
  1131. private long eventMask;
  1132. SelectiveAWTEventListener(AWTEventListener l, long mask) {
  1133. listener = l;
  1134. eventMask = mask;
  1135. }
  1136. public void eventDispatched(AWTEvent event) {
  1137. if (((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 &&
  1138. event.id >= ComponentEvent.COMPONENT_FIRST &&
  1139. event.id <= ComponentEvent.COMPONENT_LAST)
  1140. || ((eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 &&
  1141. event.id >= ContainerEvent.CONTAINER_FIRST &&
  1142. event.id <= ContainerEvent.CONTAINER_LAST)
  1143. || ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 &&
  1144. event.id >= FocusEvent.FOCUS_FIRST &&
  1145. event.id <= FocusEvent.FOCUS_LAST)
  1146. || ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 &&
  1147. event.id >= KeyEvent.KEY_FIRST &&
  1148. event.id <= KeyEvent.KEY_LAST)
  1149. || ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 &&
  1150. (event.id == MouseEvent.MOUSE_MOVED ||
  1151. event.id == MouseEvent.MOUSE_DRAGGED))
  1152. || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 &&
  1153. event.id != MouseEvent.MOUSE_MOVED &&
  1154. event.id != MouseEvent.MOUSE_DRAGGED &&
  1155. event.id >= MouseEvent.MOUSE_FIRST &&
  1156. event.id <= MouseEvent.MOUSE_LAST)
  1157. || ((eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 &&
  1158. event.id >= WindowEvent.WINDOW_FIRST &&
  1159. event.id <= WindowEvent.WINDOW_LAST)
  1160. || ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 &&
  1161. event.id >= ActionEvent.ACTION_FIRST &&
  1162. event.id <= ActionEvent.ACTION_LAST)
  1163. || ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 &&
  1164. event.id >= AdjustmentEvent.ADJUSTMENT_FIRST &&
  1165. event.id <= AdjustmentEvent.ADJUSTMENT_LAST)
  1166. || ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 &&
  1167. event.id >= ItemEvent.ITEM_FIRST &&
  1168. event.id <= ItemEvent.ITEM_LAST)
  1169. || ((eventMask & AWTEvent.TEXT_EVENT_MASK) != 0 &&
  1170. event.id >= TextEvent.TEXT_FIRST &&
  1171. event.id <= TextEvent.TEXT_LAST)
  1172. || ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 &&
  1173. event.id >= InputMethodEvent.INPUT_METHOD_FIRST &&
  1174. event.id <= InputMethodEvent.INPUT_METHOD_LAST)) {
  1175. listener.eventDispatched(event);
  1176. }
  1177. }
  1178. }
  1179. }
  1180. /**
  1181. * Implements the LightweightPeer interface for use in lightweight components
  1182. * that have no native window associated with them. This gets created by
  1183. * default in Component so that Component and Container can be directly
  1184. * extended to create useful components written entirely in java. These
  1185. * components must be hosted somewhere higher up in the component tree by a
  1186. * native container (such as a Frame).
  1187. *
  1188. * This implementation provides no useful semantics and serves only as a
  1189. * marker. One could provide alternative implementations in java that do
  1190. * something useful for some of the other peer interfaces to minimize the
  1191. * native code.
  1192. *
  1193. * @author Timothy Prinzing
  1194. */
  1195. class LightweightPeer implements java.awt.peer.LightweightPeer {
  1196. public LightweightPeer(Component target) {
  1197. }
  1198. public boolean isFocusTraversable() {
  1199. return false;
  1200. }
  1201. public void setVisible(boolean b) {
  1202. }
  1203. public void show() {
  1204. }
  1205. public void hide() {
  1206. }
  1207. public void setEnabled(boolean b) {
  1208. }
  1209. public void enable() {
  1210. }
  1211. public void disable() {
  1212. }
  1213. public void paint(Graphics g) {
  1214. }
  1215. public void repaint(long tm, int x, int y, int width, int height) {
  1216. }
  1217. public void print(Graphics g) {
  1218. }
  1219. public void setBounds(int x, int y, int width, int height) {
  1220. }
  1221. public void reshape(int x, int y, int width, int height) {
  1222. }
  1223. public boolean handleEvent(Event e) {
  1224. return false;
  1225. }
  1226. public void handleEvent(java.awt.AWTEvent arg0) {
  1227. }
  1228. public Dimension getPreferredSize() {
  1229. return new Dimension(1,1);
  1230. }
  1231. public Dimension getMinimumSize() {
  1232. return new Dimension(1,1);
  1233. }
  1234. public java.awt.Toolkit getToolkit() {
  1235. return null;
  1236. }
  1237. public ColorModel getColorModel() {
  1238. return null;
  1239. }
  1240. public Graphics getGraphics() {
  1241. return null;
  1242. }
  1243. public FontMetrics getFontMetrics(Font font) {
  1244. return null;
  1245. }
  1246. public void dispose() {
  1247. // no native code
  1248. }
  1249. public void setForeground(Color c) {
  1250. }
  1251. public void setBackground(Color c) {
  1252. }
  1253. public void setFont(Font f) {
  1254. }
  1255. public void setCursor(Cursor cursor) {
  1256. }
  1257. public void requestFocus() {
  1258. }
  1259. public Image createImage(ImageProducer producer) {
  1260. return null;
  1261. }
  1262. public Image createImage(int width, int height) {
  1263. return null;
  1264. }
  1265. public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
  1266. return false;
  1267. }
  1268. public int checkImage(Image img, int w, int h, ImageObserver o) {
  1269. return 0;
  1270. }
  1271. public Dimension preferredSize() {
  1272. return getPreferredSize();
  1273. }
  1274. public Dimension minimumSize() {
  1275. return getMinimumSize();
  1276. }
  1277. public Point getLocationOnScreen() {
  1278. return null;
  1279. }
  1280. }