1 /*
   2  * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt;
  27 
  28 import jdk.internal.misc.Unsafe;
  29 
  30 import javax.accessibility.AccessibleContext;
  31 import java.awt.*;
  32 import java.awt.event.FocusEvent.Cause;
  33 import java.awt.dnd.DragSourceContext;
  34 import java.awt.dnd.DropTargetContext;
  35 import java.awt.dnd.peer.DragSourceContextPeer;
  36 import java.awt.dnd.peer.DropTargetContextPeer;
  37 import java.awt.event.AWTEventListener;
  38 import java.awt.event.InputEvent;
  39 import java.awt.event.InvocationEvent;
  40 import java.awt.event.KeyEvent;
  41 import java.awt.geom.Point2D;
  42 import java.awt.image.BufferStrategy;
  43 import java.awt.peer.ComponentPeer;
  44 
  45 import java.awt.peer.MenuComponentPeer;
  46 import java.lang.reflect.InvocationTargetException;
  47 import java.security.AccessControlContext;
  48 
  49 import java.io.File;
  50 import java.util.ResourceBundle;
  51 import java.util.Vector;
  52 import javax.accessibility.AccessibleBundle;
  53 
  54 /**
  55  * The AWTAccessor utility class.
  56  * The main purpose of this class is to enable accessing
  57  * private and package-private fields of classes from
  58  * different classes/packages. See sun.misc.SharedSecretes
  59  * for another example.
  60  */
  61 public final class AWTAccessor {
  62 
  63     private static final Unsafe unsafe = Unsafe.getUnsafe();
  64 
  65     /*
  66      * We don't need any objects of this class.
  67      * It's rather a collection of static methods
  68      * and interfaces.
  69      */
  70     private AWTAccessor() {
  71     }
  72 
  73     /*
  74      * An interface of accessor for the java.awt.Component class.
  75      */
  76     public interface ComponentAccessor {
  77         /*
  78          * Sets whether the native background erase for a component
  79          * has been disabled via SunToolkit.disableBackgroundErase().
  80          */
  81         void setBackgroundEraseDisabled(Component comp, boolean disabled);
  82         /*
  83          * Indicates whether the native background erase for a
  84          * component has been disabled via
  85          * SunToolkit.disableBackgroundErase().
  86          */
  87         boolean getBackgroundEraseDisabled(Component comp);
  88         /*
  89          *
  90          * Gets the bounds of this component in the form of a
  91          * {@code Rectangle} object. The bounds specify this
  92          * component's width, height, and location relative to
  93          * its parent.
  94          */
  95         Rectangle getBounds(Component comp);
  96         /*
  97          * Sets the shape of a lw component to cut out from hw components.
  98          *
  99          * See 6797587, 6776743, 6768307, and 6768332 for details
 100          */
 101         void setMixingCutoutShape(Component comp, Shape shape);
 102 
 103         /**
 104          * Sets GraphicsConfiguration value for the component.
 105          */
 106         void setGraphicsConfiguration(Component comp, GraphicsConfiguration gc);
 107         /*
 108          * Requests focus to the component.
 109          */
 110         void requestFocus(Component comp, Cause cause);
 111         /*
 112          * Determines if the component can gain focus.
 113          */
 114         boolean canBeFocusOwner(Component comp);
 115 
 116         /**
 117          * Returns whether the component is visible without invoking
 118          * any client code.
 119          */
 120         boolean isVisible(Component comp);
 121 
 122         /**
 123          * Sets the RequestFocusController.
 124          */
 125         void setRequestFocusController(RequestFocusController requestController);
 126 
 127         /**
 128          * Returns the appContext of the component.
 129          */
 130         AppContext getAppContext(Component comp);
 131 
 132         /**
 133          * Sets the appContext of the component.
 134          */
 135         void setAppContext(Component comp, AppContext appContext);
 136 
 137         /**
 138          * Returns the parent of the component.
 139          */
 140         Container getParent(Component comp);
 141 
 142         /**
 143          * Sets the parent of the component to the specified parent.
 144          */
 145         void setParent(Component comp, Container parent);
 146 
 147         /**
 148          * Resizes the component to the specified width and height.
 149          */
 150         void setSize(Component comp, int width, int height);
 151 
 152         /**
 153          * Returns the location of the component.
 154          */
 155         Point getLocation(Component comp);
 156 
 157         /**
 158          * Moves the component to the new location.
 159          */
 160         void setLocation(Component comp, int x, int y);
 161 
 162         /**
 163          * Determines whether this component is enabled.
 164          */
 165         boolean isEnabled(Component comp);
 166 
 167         /**
 168          * Determines whether this component is displayable.
 169          */
 170         boolean isDisplayable(Component comp);
 171 
 172         /**
 173          * Gets the cursor set in the component.
 174          */
 175         Cursor getCursor(Component comp);
 176 
 177         /**
 178          * Returns the peer of the component.
 179          */
 180         <T extends ComponentPeer> T getPeer(Component comp);
 181 
 182         /**
 183          * Sets the peer of the component to the specified peer.
 184          */
 185         void setPeer(Component comp, ComponentPeer peer);
 186 
 187         /**
 188          * Determines whether this component is lightweight.
 189          */
 190         boolean isLightweight(Component comp);
 191 
 192         /**
 193          * Returns whether or not paint messages received from
 194          * the operating system should be ignored.
 195          */
 196         boolean getIgnoreRepaint(Component comp);
 197 
 198         /**
 199          * Returns the width of the component.
 200          */
 201         int getWidth(Component comp);
 202 
 203         /**
 204          * Returns the height of the component.
 205          */
 206         int getHeight(Component comp);
 207 
 208         /**
 209          * Returns the x coordinate of the component.
 210          */
 211         int getX(Component comp);
 212 
 213         /**
 214          * Returns the y coordinate of the component.
 215          */
 216         int getY(Component comp);
 217 
 218         /**
 219          * Gets the foreground color of this component.
 220          */
 221         Color getForeground(Component comp);
 222 
 223         /**
 224          * Gets the background color of this component.
 225          */
 226         Color getBackground(Component comp);
 227 
 228         /**
 229          * Sets the background of this component to the specified color.
 230          */
 231         void setBackground(Component comp, Color background);
 232 
 233         /**
 234          * Gets the font of the component.
 235          */
 236         Font getFont(Component comp);
 237 
 238         /**
 239          * Processes events occurring on this component.
 240          */
 241         void processEvent(Component comp, AWTEvent e);
 242 
 243 
 244         /*
 245          * Returns the acc this component was constructed with.
 246          */
 247         AccessControlContext getAccessControlContext(Component comp);
 248 
 249         /**
 250          * Revalidates the component synchronously.
 251          */
 252         void revalidateSynchronously(Component comp);
 253 
 254         /**
 255          * Creates a new strategy for multi-buffering on this component.
 256          */
 257         void createBufferStrategy(Component comp, int numBuffers,
 258                 BufferCapabilities caps) throws AWTException;
 259 
 260         /**
 261          * returns the buffer strategy used by this component.
 262          */
 263         BufferStrategy getBufferStrategy(Component comp);
 264     }
 265 
 266     /*
 267      * An interface of accessor for the java.awt.Container class.
 268      */
 269     public interface ContainerAccessor {
 270         /**
 271          * Validates the container unconditionally.
 272          */
 273         void validateUnconditionally(Container cont);
 274 
 275         /**
 276          *
 277          * Access to the private version of findComponentAt method which has
 278          * a controllable behavior. Setting 'ignoreEnabled' to 'false'
 279          * bypasses disabled Components during the search.
 280          */
 281         Component findComponentAt(Container cont, int x, int y, boolean ignoreEnabled);
 282 
 283         /**
 284          * Starts LW Modal.
 285          */
 286         void startLWModal(Container cont);
 287 
 288         /**
 289          * Starts LW Modal.
 290          */
 291         void stopLWModal(Container cont);
 292     }
 293 
 294     /*
 295      * An interface of accessor for java.awt.Window class.
 296      */
 297     public interface WindowAccessor {
 298         /*
 299          * Get opacity level of the given window.
 300          */
 301         float getOpacity(Window window);
 302         /*
 303          * Set opacity level to the given window.
 304          */
 305         void setOpacity(Window window, float opacity);
 306         /*
 307          * Get a shape assigned to the given window.
 308          */
 309         Shape getShape(Window window);
 310         /*
 311          * Set a shape to the given window.
 312          */
 313         void setShape(Window window, Shape shape);
 314         /*
 315          * Set the opaque preoperty to the given window.
 316          */
 317         void setOpaque(Window window, boolean isOpaque);
 318         /*
 319          * Update the image of a non-opaque (translucent) window.
 320          */
 321         void updateWindow(Window window);
 322 
 323         /** Get the size of the security warning.
 324          */
 325         Dimension getSecurityWarningSize(Window w);
 326 
 327         /**
 328          * Set the size of the security warning.
 329          */
 330         void setSecurityWarningSize(Window w, int width, int height);
 331 
 332         /** Set the position of the security warning.
 333          */
 334         void setSecurityWarningPosition(Window w, Point2D point,
 335                 float alignmentX, float alignmentY);
 336 
 337         /** Request to recalculate the new position of the security warning for
 338          * the given window size/location as reported by the native system.
 339          */
 340         Point2D calculateSecurityWarningPosition(Window window,
 341                 double x, double y, double w, double h);
 342 
 343         /** Sets the synchronous status of focus requests on lightweight
 344          * components in the specified window to the specified value.
 345          */
 346         void setLWRequestStatus(Window changed, boolean status);
 347 
 348         /**
 349          * Indicates whether this window should receive focus on subsequently
 350          * being shown, or being moved to the front.
 351          */
 352         boolean isAutoRequestFocus(Window w);
 353 
 354         /**
 355          * Indicates whether the specified window is an utility window for TrayIcon.
 356          */
 357         boolean isTrayIconWindow(Window w);
 358 
 359         /**
 360          * Marks the specified window as an utility window for TrayIcon.
 361          */
 362         void setTrayIconWindow(Window w, boolean isTrayIconWindow);
 363 
 364         /**
 365          * Return an array containing all the windows this
 366          * window currently owns.
 367          */
 368         Window[] getOwnedWindows(Window w);
 369     }
 370 
 371     /**
 372      * An accessor for the AWTEvent class.
 373      */
 374     public interface AWTEventAccessor {
 375         /**
 376          * Marks the event as posted.
 377          */
 378         void setPosted(AWTEvent ev);
 379 
 380         /**
 381          * Sets the flag on this AWTEvent indicating that it was
 382          * generated by the system.
 383          */
 384         void setSystemGenerated(AWTEvent ev);
 385 
 386         /**
 387          * Indicates whether this AWTEvent was generated by the system.
 388          */
 389         boolean isSystemGenerated(AWTEvent ev);
 390 
 391         /**
 392          * Returns the acc this event was constructed with.
 393          */
 394         AccessControlContext getAccessControlContext(AWTEvent ev);
 395 
 396         /**
 397          * Returns binary data associated with this event;
 398          */
 399         byte[] getBData(AWTEvent ev);
 400 
 401         /**
 402          * Associates binary data with this event;
 403          */
 404         void setBData(AWTEvent ev, byte[] bdata);
 405     }
 406 
 407     public interface InputEventAccessor {
 408         /*
 409          * Accessor for InputEvent.getButtonDownMasks()
 410          */
 411         int[] getButtonDownMasks();
 412 
 413         /*
 414          * Accessor for InputEvent.canAccessSystemClipboard field
 415          */
 416         boolean canAccessSystemClipboard(InputEvent event);
 417         void setCanAccessSystemClipboard(InputEvent event,
 418                 boolean canAccessSystemClipboard);
 419     }
 420 
 421     /*
 422      * An accessor for the java.awt.Frame class.
 423      */
 424     public interface FrameAccessor {
 425         /*
 426          * Sets the state of this frame.
 427          */
 428         void setExtendedState(Frame frame, int state);
 429         /*
 430          * Gets the state of this frame.
 431          */
 432        int getExtendedState(Frame frame);
 433         /*
 434          * Gets the maximized bounds of this frame.
 435          */
 436        Rectangle getMaximizedBounds(Frame frame);
 437     }
 438 
 439     /**
 440      * An interface of accessor for the java.awt.KeyboardFocusManager class.
 441      */
 442     public interface KeyboardFocusManagerAccessor {
 443         /**
 444          * Indicates whether the native implementation should
 445          * proceed with a pending focus request for the heavyweight.
 446          */
 447         int shouldNativelyFocusHeavyweight(Component heavyweight,
 448                                            Component descendant,
 449                                            boolean temporary,
 450                                            boolean focusedWindowChangeAllowed,
 451                                            long time,
 452                                            Cause cause);
 453         /**
 454          * Delivers focus for the lightweight descendant of the heavyweight
 455          * synchronously.
 456          */
 457         boolean processSynchronousLightweightTransfer(Component heavyweight,
 458                                                       Component descendant,
 459                                                       boolean temporary,
 460                                                       boolean focusedWindowChangeAllowed,
 461                                                       long time);
 462         /**
 463          * Removes the last focus request for the heavyweight from the queue.
 464          */
 465         void removeLastFocusRequest(Component heavyweight);
 466 
 467         /**
 468          * Gets the most recent focus owner in the window.
 469          */
 470         Component getMostRecentFocusOwner(Window window);
 471 
 472         /**
 473          * Sets the most recent focus owner in the window.
 474          */
 475         void setMostRecentFocusOwner(Window window, Component component);
 476 
 477         /**
 478          * Returns current KFM of the specified AppContext.
 479          */
 480         KeyboardFocusManager getCurrentKeyboardFocusManager(AppContext ctx);
 481 
 482         /**
 483          * Return the current focus cycle root
 484          */
 485         Container getCurrentFocusCycleRoot();
 486     }
 487 
 488     /**
 489      * An accessor for the MenuComponent class.
 490      */
 491     public interface MenuComponentAccessor {
 492         /**
 493          * Returns the appContext of the menu component.
 494          */
 495         AppContext getAppContext(MenuComponent menuComp);
 496 
 497         /**
 498          * Sets the appContext of the menu component.
 499          */
 500         void setAppContext(MenuComponent menuComp, AppContext appContext);
 501 
 502         /**
 503          * Returns the peer of the menu component.
 504          */
 505         <T extends MenuComponentPeer> T getPeer(MenuComponent menuComp);
 506 
 507         /**
 508          * Returns the menu container of the menu component.
 509          */
 510         MenuContainer getParent(MenuComponent menuComp);
 511 
 512         /**
 513          * Sets the menu container of the menu component.
 514          */
 515         void  setParent(MenuComponent menuComp, MenuContainer menuContainer);
 516 
 517         /**
 518          * Gets the font used for this menu component.
 519          */
 520         Font getFont_NoClientCode(MenuComponent menuComp);
 521     }
 522 
 523     /**
 524      * An accessor for the EventQueue class
 525      */
 526     public interface EventQueueAccessor {
 527         /**
 528          * Gets the event dispatch thread.
 529          */
 530         Thread getDispatchThread(EventQueue eventQueue);
 531 
 532         /**
 533          * Checks if the current thread is EDT for the given EQ.
 534          */
 535         public boolean isDispatchThreadImpl(EventQueue eventQueue);
 536 
 537         /**
 538          * Removes any pending events for the specified source object.
 539          */
 540         void removeSourceEvents(EventQueue eventQueue, Object source, boolean removeAllEvents);
 541 
 542         /**
 543          * Returns whether an event is pending on any of the separate Queues.
 544          */
 545         boolean noEvents(EventQueue eventQueue);
 546 
 547         /**
 548          * Called from PostEventQueue.postEvent to notify that a new event
 549          * appeared.
 550          */
 551         void wakeup(EventQueue eventQueue, boolean isShutdown);
 552 
 553         /**
 554          * Static in EventQueue
 555          */
 556         void invokeAndWait(Object source, Runnable r)
 557             throws InterruptedException, InvocationTargetException;
 558 
 559         /**
 560          * Sets the delegate for the EventQueue used by FX/AWT single threaded mode
 561          */
 562         void setFwDispatcher(EventQueue eventQueue, FwDispatcher dispatcher);
 563 
 564         /**
 565          * Gets most recent event time in the EventQueue
 566          */
 567         long getMostRecentEventTime(EventQueue eventQueue);
 568     }
 569 
 570     /*
 571      * An accessor for the PopupMenu class
 572      */
 573     public interface PopupMenuAccessor {
 574         /*
 575          * Returns whether the popup menu is attached to a tray
 576          */
 577         boolean isTrayIconPopup(PopupMenu popupMenu);
 578     }
 579 
 580     /*
 581      * An accessor for the FileDialog class
 582      */
 583     public interface FileDialogAccessor {
 584         /*
 585          * Sets the files the user selects
 586          */
 587         void setFiles(FileDialog fileDialog, File files[]);
 588 
 589         /*
 590          * Sets the file the user selects
 591          */
 592         void setFile(FileDialog fileDialog, String file);
 593 
 594         /*
 595          * Sets the directory the user selects
 596          */
 597         void setDirectory(FileDialog fileDialog, String directory);
 598 
 599         /*
 600          * Returns whether the file dialog allows the multiple file selection.
 601          */
 602         boolean isMultipleMode(FileDialog fileDialog);
 603     }
 604 
 605     /*
 606      * An accessor for the ScrollPaneAdjustable class.
 607      */
 608     public interface ScrollPaneAdjustableAccessor {
 609         /*
 610          * Sets the value of this scrollbar to the specified value.
 611          */
 612         void setTypedValue(final ScrollPaneAdjustable adj, final int v,
 613                            final int type);
 614     }
 615 
 616     /**
 617      * An accessor for the CheckboxMenuItem class
 618      */
 619     public interface CheckboxMenuItemAccessor {
 620         /**
 621          * Returns whether menu item is checked
 622          */
 623         boolean getState(CheckboxMenuItem cmi);
 624     }
 625 
 626     /**
 627      * An accessor for the Cursor class
 628      */
 629     public interface CursorAccessor {
 630         /**
 631          * Returns pData of the Cursor class
 632          */
 633         long getPData(Cursor cursor);
 634 
 635         /**
 636          * Sets pData to the Cursor class
 637          */
 638         void setPData(Cursor cursor, long pData);
 639 
 640         /**
 641          * Return type of the Cursor class
 642          */
 643         int getType(Cursor cursor);
 644     }
 645 
 646     /**
 647      * An accessor for the MenuBar class
 648      */
 649     public interface MenuBarAccessor {
 650         /**
 651          * Returns help menu
 652          */
 653         Menu getHelpMenu(MenuBar menuBar);
 654 
 655         /**
 656          * Returns menus
 657          */
 658         Vector<Menu> getMenus(MenuBar menuBar);
 659     }
 660 
 661     /**
 662      * An accessor for the MenuItem class
 663      */
 664     public interface MenuItemAccessor {
 665         /**
 666          * Returns whether menu item is enabled
 667          */
 668         boolean isEnabled(MenuItem item);
 669 
 670         /**
 671          * Gets the command name of the action event that is fired
 672          * by this menu item.
 673          */
 674         String getActionCommandImpl(MenuItem item);
 675 
 676         /**
 677          * Returns true if the item and all its ancestors are
 678          * enabled, false otherwise
 679          */
 680         boolean isItemEnabled(MenuItem item);
 681 
 682         /**
 683          * Returns label
 684          */
 685         String getLabel(MenuItem item);
 686 
 687         /**
 688          * Returns shortcut
 689          */
 690         MenuShortcut getShortcut(MenuItem item);
 691     }
 692 
 693     /**
 694      * An accessor for the Menu class
 695      */
 696     public interface MenuAccessor {
 697         /**
 698          * Returns vector of the items that are part of the Menu
 699          */
 700         Vector<MenuItem> getItems(Menu menu);
 701     }
 702 
 703     /**
 704      * An accessor for the KeyEvent class
 705      */
 706     public interface KeyEventAccessor {
 707         /**
 708          * Sets rawCode field for KeyEvent
 709          */
 710         void setRawCode(KeyEvent ev, long rawCode);
 711 
 712         /**
 713          * Sets primaryLevelUnicode field for KeyEvent
 714          */
 715         void setPrimaryLevelUnicode(KeyEvent ev, long primaryLevelUnicode);
 716 
 717         /**
 718          * Sets extendedKeyCode field for KeyEvent
 719          */
 720         void setExtendedKeyCode(KeyEvent ev, long extendedKeyCode);
 721 
 722         /**
 723          * Gets original source for KeyEvent
 724          */
 725         Component getOriginalSource(KeyEvent ev);
 726 
 727         /**
 728          * Gets isProxyActive field for KeyEvent
 729          */
 730         boolean isProxyActive(KeyEvent ev);
 731     }
 732 
 733     /**
 734      * An accessor for the ClientPropertyKey class
 735      */
 736     public interface ClientPropertyKeyAccessor {
 737         /**
 738          * Retrieves JComponent_TRANSFER_HANDLER enum object
 739          */
 740         Object getJComponent_TRANSFER_HANDLER();
 741     }
 742 
 743     /**
 744      * An accessor for the SystemTray class
 745      */
 746     public interface SystemTrayAccessor {
 747         /**
 748          * Support for reporting bound property changes for Object properties.
 749          */
 750         void firePropertyChange(SystemTray tray, String propertyName, Object oldValue, Object newValue);
 751     }
 752 
 753     /**
 754      * An accessor for the TrayIcon class
 755      */
 756     public interface TrayIconAccessor {
 757         void addNotify(TrayIcon trayIcon) throws AWTException;
 758         void removeNotify(TrayIcon trayIcon);
 759     }
 760 
 761     /**
 762      * An accessor for the DefaultKeyboardFocusManager class
 763      */
 764     public interface DefaultKeyboardFocusManagerAccessor {
 765         public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);
 766     }
 767 
 768     /*
 769      * An accessor for the SequencedEventAccessor class
 770      */
 771     public interface SequencedEventAccessor {
 772         /*
 773          * Returns the nested event.
 774          */
 775         AWTEvent getNested(AWTEvent sequencedEvent);
 776 
 777         /*
 778          * Returns true if the event is an instances of SequencedEvent.
 779          */
 780         boolean isSequencedEvent(AWTEvent event);
 781 
 782         /*
 783          * Creates SequencedEvent with the given nested event
 784          */
 785         AWTEvent create(AWTEvent event);
 786     }
 787 
 788     /*
 789      * An accessor for the Toolkit class
 790      */
 791     public interface ToolkitAccessor {
 792         void setPlatformResources(ResourceBundle bundle);
 793     }
 794 
 795     /*
 796      * An accessor object for the InvocationEvent class
 797      */
 798     public interface InvocationEventAccessor {
 799         void dispose(InvocationEvent event);
 800     }
 801 
 802     /*
 803      * An accessor object for the SystemColor class
 804      */
 805     public interface SystemColorAccessor {
 806         void updateSystemColors();
 807     }
 808 
 809     /*
 810      * An accessor object for the AccessibleContext class
 811      */
 812     public interface AccessibleContextAccessor {
 813         void setAppContext(AccessibleContext accessibleContext, AppContext appContext);
 814         AppContext getAppContext(AccessibleContext accessibleContext);
 815         Object getNativeAXResource(AccessibleContext accessibleContext);
 816         void setNativeAXResource(AccessibleContext accessibleContext, Object value);
 817     }
 818 
 819     /*
 820      * An accessor object for the AccessibleContext class
 821      */
 822     public interface AccessibleBundleAccessor {
 823         String getKey(AccessibleBundle accessibleBundle);
 824     }
 825 
 826     /*
 827      * An accessor object for the DragSourceContext class
 828      */
 829     public interface DragSourceContextAccessor {
 830         /**
 831          * Returns the peer of the DragSourceContext.
 832          */
 833         DragSourceContextPeer getPeer(DragSourceContext dsc);
 834     }
 835 
 836     /*
 837      * An accessor object for the DropTargetContext class
 838      */
 839     public interface DropTargetContextAccessor {
 840         /**
 841          * Resets the DropTargetContext.
 842          */
 843         void reset(DropTargetContext dtc);
 844         /**
 845          * Sets the {@code DropTargetContextPeer}
 846          */
 847         void setDropTargetContextPeer(DropTargetContext dtc,
 848                                       DropTargetContextPeer dtcp);
 849     }
 850 
 851     /*
 852      * Accessor instances are initialized in the static initializers of
 853      * corresponding AWT classes by using setters defined below.
 854      */
 855     private static ComponentAccessor componentAccessor;
 856     private static ContainerAccessor containerAccessor;
 857     private static WindowAccessor windowAccessor;
 858     private static AWTEventAccessor awtEventAccessor;
 859     private static InputEventAccessor inputEventAccessor;
 860     private static FrameAccessor frameAccessor;
 861     private static KeyboardFocusManagerAccessor kfmAccessor;
 862     private static MenuComponentAccessor menuComponentAccessor;
 863     private static EventQueueAccessor eventQueueAccessor;
 864     private static PopupMenuAccessor popupMenuAccessor;
 865     private static FileDialogAccessor fileDialogAccessor;
 866     private static ScrollPaneAdjustableAccessor scrollPaneAdjustableAccessor;
 867     private static CheckboxMenuItemAccessor checkboxMenuItemAccessor;
 868     private static CursorAccessor cursorAccessor;
 869     private static MenuBarAccessor menuBarAccessor;
 870     private static MenuItemAccessor menuItemAccessor;
 871     private static MenuAccessor menuAccessor;
 872     private static KeyEventAccessor keyEventAccessor;
 873     private static ClientPropertyKeyAccessor clientPropertyKeyAccessor;
 874     private static SystemTrayAccessor systemTrayAccessor;
 875     private static TrayIconAccessor trayIconAccessor;
 876     private static DefaultKeyboardFocusManagerAccessor defaultKeyboardFocusManagerAccessor;
 877     private static SequencedEventAccessor sequencedEventAccessor;
 878     private static ToolkitAccessor toolkitAccessor;
 879     private static InvocationEventAccessor invocationEventAccessor;
 880     private static SystemColorAccessor systemColorAccessor;
 881     private static AccessibleContextAccessor accessibleContextAccessor;
 882     private static AccessibleBundleAccessor accessibleBundleAccessor;
 883     private static DragSourceContextAccessor dragSourceContextAccessor;
 884     private static DropTargetContextAccessor dropTargetContextAccessor;
 885 
 886     /*
 887      * Set an accessor object for the java.awt.Component class.
 888      */
 889     public static void setComponentAccessor(ComponentAccessor ca) {
 890         componentAccessor = ca;
 891     }
 892 
 893     /*
 894      * Retrieve the accessor object for the java.awt.Component class.
 895      */
 896     public static ComponentAccessor getComponentAccessor() {
 897         if (componentAccessor == null) {
 898             unsafe.ensureClassInitialized(Component.class);
 899         }
 900 
 901         return componentAccessor;
 902     }
 903 
 904     /*
 905      * Set an accessor object for the java.awt.Container class.
 906      */
 907     public static void setContainerAccessor(ContainerAccessor ca) {
 908         containerAccessor = ca;
 909     }
 910 
 911     /*
 912      * Retrieve the accessor object for the java.awt.Container class.
 913      */
 914     public static ContainerAccessor getContainerAccessor() {
 915         if (containerAccessor == null) {
 916             unsafe.ensureClassInitialized(Container.class);
 917         }
 918 
 919         return containerAccessor;
 920     }
 921 
 922     /*
 923      * Set an accessor object for the java.awt.Window class.
 924      */
 925     public static void setWindowAccessor(WindowAccessor wa) {
 926         windowAccessor = wa;
 927     }
 928 
 929     /*
 930      * Retrieve the accessor object for the java.awt.Window class.
 931      */
 932     public static WindowAccessor getWindowAccessor() {
 933         if (windowAccessor == null) {
 934             unsafe.ensureClassInitialized(Window.class);
 935         }
 936         return windowAccessor;
 937     }
 938 
 939     /*
 940      * Set an accessor object for the java.awt.AWTEvent class.
 941      */
 942     public static void setAWTEventAccessor(AWTEventAccessor aea) {
 943         awtEventAccessor = aea;
 944     }
 945 
 946     /*
 947      * Retrieve the accessor object for the java.awt.AWTEvent class.
 948      */
 949     public static AWTEventAccessor getAWTEventAccessor() {
 950         if (awtEventAccessor == null) {
 951             unsafe.ensureClassInitialized(AWTEvent.class);
 952         }
 953         return awtEventAccessor;
 954     }
 955 
 956     /*
 957      * Set an accessor object for the java.awt.event.InputEvent class.
 958      */
 959     public static void setInputEventAccessor(InputEventAccessor iea) {
 960         inputEventAccessor = iea;
 961     }
 962 
 963     /*
 964      * Retrieve the accessor object for the java.awt.event.InputEvent class.
 965      */
 966     public static InputEventAccessor getInputEventAccessor() {
 967         if (inputEventAccessor == null) {
 968             unsafe.ensureClassInitialized(InputEvent.class);
 969         }
 970         return inputEventAccessor;
 971     }
 972 
 973     /*
 974      * Set an accessor object for the java.awt.Frame class.
 975      */
 976     public static void setFrameAccessor(FrameAccessor fa) {
 977         frameAccessor = fa;
 978     }
 979 
 980     /*
 981      * Retrieve the accessor object for the java.awt.Frame class.
 982      */
 983     public static FrameAccessor getFrameAccessor() {
 984         if (frameAccessor == null) {
 985             unsafe.ensureClassInitialized(Frame.class);
 986         }
 987         return frameAccessor;
 988     }
 989 
 990     /*
 991      * Set an accessor object for the java.awt.KeyboardFocusManager class.
 992      */
 993     public static void setKeyboardFocusManagerAccessor(KeyboardFocusManagerAccessor kfma) {
 994         kfmAccessor = kfma;
 995     }
 996 
 997     /*
 998      * Retrieve the accessor object for the java.awt.KeyboardFocusManager class.
 999      */
1000     public static KeyboardFocusManagerAccessor getKeyboardFocusManagerAccessor() {
1001         if (kfmAccessor == null) {
1002             unsafe.ensureClassInitialized(KeyboardFocusManager.class);
1003         }
1004         return kfmAccessor;
1005     }
1006 
1007     /*
1008      * Set an accessor object for the java.awt.MenuComponent class.
1009      */
1010     public static void setMenuComponentAccessor(MenuComponentAccessor mca) {
1011         menuComponentAccessor = mca;
1012     }
1013 
1014     /*
1015      * Retrieve the accessor object for the java.awt.MenuComponent class.
1016      */
1017     public static MenuComponentAccessor getMenuComponentAccessor() {
1018         if (menuComponentAccessor == null) {
1019             unsafe.ensureClassInitialized(MenuComponent.class);
1020         }
1021         return menuComponentAccessor;
1022     }
1023 
1024     /*
1025      * Set an accessor object for the java.awt.EventQueue class.
1026      */
1027     public static void setEventQueueAccessor(EventQueueAccessor eqa) {
1028         eventQueueAccessor = eqa;
1029     }
1030 
1031     /*
1032      * Retrieve the accessor object for the java.awt.EventQueue class.
1033      */
1034     public static EventQueueAccessor getEventQueueAccessor() {
1035         if (eventQueueAccessor == null) {
1036             unsafe.ensureClassInitialized(EventQueue.class);
1037         }
1038         return eventQueueAccessor;
1039     }
1040 
1041     /*
1042      * Set an accessor object for the java.awt.PopupMenu class.
1043      */
1044     public static void setPopupMenuAccessor(PopupMenuAccessor pma) {
1045         popupMenuAccessor = pma;
1046     }
1047 
1048     /*
1049      * Retrieve the accessor object for the java.awt.PopupMenu class.
1050      */
1051     public static PopupMenuAccessor getPopupMenuAccessor() {
1052         if (popupMenuAccessor == null) {
1053             unsafe.ensureClassInitialized(PopupMenu.class);
1054         }
1055         return popupMenuAccessor;
1056     }
1057 
1058     /*
1059      * Set an accessor object for the java.awt.FileDialog class.
1060      */
1061     public static void setFileDialogAccessor(FileDialogAccessor fda) {
1062         fileDialogAccessor = fda;
1063     }
1064 
1065     /*
1066      * Retrieve the accessor object for the java.awt.FileDialog class.
1067      */
1068     public static FileDialogAccessor getFileDialogAccessor() {
1069         if (fileDialogAccessor == null) {
1070             unsafe.ensureClassInitialized(FileDialog.class);
1071         }
1072         return fileDialogAccessor;
1073     }
1074 
1075     /*
1076      * Set an accessor object for the java.awt.ScrollPaneAdjustable class.
1077      */
1078     public static void setScrollPaneAdjustableAccessor(ScrollPaneAdjustableAccessor adj) {
1079         scrollPaneAdjustableAccessor = adj;
1080     }
1081 
1082     /*
1083      * Retrieve the accessor object for the java.awt.ScrollPaneAdjustable
1084      * class.
1085      */
1086     public static ScrollPaneAdjustableAccessor getScrollPaneAdjustableAccessor() {
1087         if (scrollPaneAdjustableAccessor == null) {
1088             unsafe.ensureClassInitialized(ScrollPaneAdjustable.class);
1089         }
1090         return scrollPaneAdjustableAccessor;
1091     }
1092 
1093     /**
1094      * Set an accessor object for the java.awt.CheckboxMenuItem class.
1095      */
1096     public static void setCheckboxMenuItemAccessor(CheckboxMenuItemAccessor cmia) {
1097         checkboxMenuItemAccessor = cmia;
1098     }
1099 
1100     /**
1101      * Retrieve the accessor object for the java.awt.CheckboxMenuItem class.
1102      */
1103     public static CheckboxMenuItemAccessor getCheckboxMenuItemAccessor() {
1104         if (checkboxMenuItemAccessor == null) {
1105             unsafe.ensureClassInitialized(CheckboxMenuItemAccessor.class);
1106         }
1107         return checkboxMenuItemAccessor;
1108     }
1109 
1110     /**
1111      * Set an accessor object for the java.awt.Cursor class.
1112      */
1113     public static void setCursorAccessor(CursorAccessor ca) {
1114         cursorAccessor = ca;
1115     }
1116 
1117     /**
1118      * Retrieve the accessor object for the java.awt.Cursor class.
1119      */
1120     public static CursorAccessor getCursorAccessor() {
1121         if (cursorAccessor == null) {
1122             unsafe.ensureClassInitialized(CursorAccessor.class);
1123         }
1124         return cursorAccessor;
1125     }
1126 
1127     /**
1128      * Set an accessor object for the java.awt.MenuBar class.
1129      */
1130     public static void setMenuBarAccessor(MenuBarAccessor mba) {
1131         menuBarAccessor = mba;
1132     }
1133 
1134     /**
1135      * Retrieve the accessor object for the java.awt.MenuBar class.
1136      */
1137     public static MenuBarAccessor getMenuBarAccessor() {
1138         if (menuBarAccessor == null) {
1139             unsafe.ensureClassInitialized(MenuBarAccessor.class);
1140         }
1141         return menuBarAccessor;
1142     }
1143 
1144     /**
1145      * Set an accessor object for the java.awt.MenuItem class.
1146      */
1147     public static void setMenuItemAccessor(MenuItemAccessor mia) {
1148         menuItemAccessor = mia;
1149     }
1150 
1151     /**
1152      * Retrieve the accessor object for the java.awt.MenuItem class.
1153      */
1154     public static MenuItemAccessor getMenuItemAccessor() {
1155         if (menuItemAccessor == null) {
1156             unsafe.ensureClassInitialized(MenuItemAccessor.class);
1157         }
1158         return menuItemAccessor;
1159     }
1160 
1161     /**
1162      * Set an accessor object for the java.awt.Menu class.
1163      */
1164     public static void setMenuAccessor(MenuAccessor ma) {
1165         menuAccessor = ma;
1166     }
1167 
1168     /**
1169      * Retrieve the accessor object for the java.awt.Menu class.
1170      */
1171     public static MenuAccessor getMenuAccessor() {
1172         if (menuAccessor == null) {
1173             unsafe.ensureClassInitialized(MenuAccessor.class);
1174         }
1175         return menuAccessor;
1176     }
1177 
1178     /**
1179      * Set an accessor object for the java.awt.event.KeyEvent class.
1180      */
1181     public static void setKeyEventAccessor(KeyEventAccessor kea) {
1182         keyEventAccessor = kea;
1183     }
1184 
1185     /**
1186      * Retrieve the accessor object for the java.awt.event.KeyEvent class.
1187      */
1188     public static KeyEventAccessor getKeyEventAccessor() {
1189         if (keyEventAccessor == null) {
1190             unsafe.ensureClassInitialized(KeyEventAccessor.class);
1191         }
1192         return keyEventAccessor;
1193     }
1194 
1195     /**
1196      * Set an accessor object for the javax.swing.ClientPropertyKey class.
1197      */
1198     public static void setClientPropertyKeyAccessor(ClientPropertyKeyAccessor cpka) {
1199         clientPropertyKeyAccessor = cpka;
1200     }
1201 
1202     /**
1203      * Retrieve the accessor object for the javax.swing.ClientPropertyKey class.
1204      */
1205     public static ClientPropertyKeyAccessor getClientPropertyKeyAccessor() {
1206         if (clientPropertyKeyAccessor == null) {
1207             unsafe.ensureClassInitialized(ClientPropertyKeyAccessor.class);
1208         }
1209         return clientPropertyKeyAccessor;
1210     }
1211 
1212     /**
1213      * Set an accessor object for the java.awt.SystemTray class.
1214      */
1215     public static void setSystemTrayAccessor(SystemTrayAccessor sta) {
1216         systemTrayAccessor = sta;
1217     }
1218 
1219     /**
1220      * Retrieve the accessor object for the java.awt.SystemTray class.
1221      */
1222     public static SystemTrayAccessor getSystemTrayAccessor() {
1223         if (systemTrayAccessor == null) {
1224             unsafe.ensureClassInitialized(SystemTrayAccessor.class);
1225         }
1226         return systemTrayAccessor;
1227     }
1228 
1229     /**
1230      * Set an accessor object for the java.awt.TrayIcon class.
1231      */
1232     public static void setTrayIconAccessor(TrayIconAccessor tia) {
1233         trayIconAccessor = tia;
1234     }
1235 
1236     /**
1237      * Retrieve the accessor object for the java.awt.TrayIcon class.
1238      */
1239     public static TrayIconAccessor getTrayIconAccessor() {
1240         if (trayIconAccessor == null) {
1241             unsafe.ensureClassInitialized(TrayIconAccessor.class);
1242         }
1243         return trayIconAccessor;
1244     }
1245 
1246     /**
1247      * Set an accessor object for the java.awt.DefaultKeyboardFocusManager class.
1248      */
1249     public static void setDefaultKeyboardFocusManagerAccessor(DefaultKeyboardFocusManagerAccessor dkfma) {
1250         defaultKeyboardFocusManagerAccessor = dkfma;
1251     }
1252 
1253     /**
1254      * Retrieve the accessor object for the java.awt.DefaultKeyboardFocusManager class.
1255      */
1256     public static DefaultKeyboardFocusManagerAccessor getDefaultKeyboardFocusManagerAccessor() {
1257         if (defaultKeyboardFocusManagerAccessor == null) {
1258             unsafe.ensureClassInitialized(DefaultKeyboardFocusManagerAccessor.class);
1259         }
1260         return defaultKeyboardFocusManagerAccessor;
1261     }
1262     /*
1263      * Set an accessor object for the java.awt.SequencedEvent class.
1264      */
1265     public static void setSequencedEventAccessor(SequencedEventAccessor sea) {
1266         sequencedEventAccessor = sea;
1267     }
1268 
1269     /*
1270      * Get the accessor object for the java.awt.SequencedEvent class.
1271      */
1272     public static SequencedEventAccessor getSequencedEventAccessor() {
1273         if (sequencedEventAccessor == null) {
1274             try {
1275                 unsafe.ensureClassInitialized(
1276                         Class.forName("java.awt.SequencedEvent"));
1277             } catch (ClassNotFoundException ignore) {
1278             }
1279         }
1280         return sequencedEventAccessor;
1281     }
1282 
1283     /*
1284      * Set an accessor object for the java.awt.Toolkit class.
1285      */
1286     public static void setToolkitAccessor(ToolkitAccessor ta) {
1287         toolkitAccessor = ta;
1288     }
1289 
1290     /*
1291      * Get the accessor object for the java.awt.Toolkit class.
1292      */
1293     public static ToolkitAccessor getToolkitAccessor() {
1294         if (toolkitAccessor == null) {
1295             unsafe.ensureClassInitialized(Toolkit.class);
1296         }
1297 
1298         return toolkitAccessor;
1299     }
1300 
1301     /*
1302      * Get the accessor object for the java.awt.event.InvocationEvent class.
1303      */
1304     public static void setInvocationEventAccessor(InvocationEventAccessor invocationEventAccessor) {
1305         AWTAccessor.invocationEventAccessor = invocationEventAccessor;
1306     }
1307 
1308     /*
1309      * Set the accessor object for the java.awt.event.InvocationEvent class.
1310      */
1311     public static InvocationEventAccessor getInvocationEventAccessor() {
1312         return invocationEventAccessor;
1313     }
1314 
1315     /*
1316      * Get the accessor object for the java.awt.SystemColor class.
1317      */
1318     public static SystemColorAccessor getSystemColorAccessor() {
1319         if (systemColorAccessor == null) {
1320             unsafe.ensureClassInitialized(SystemColor.class);
1321         }
1322 
1323         return systemColorAccessor;
1324     }
1325 
1326      /*
1327      * Set the accessor object for the java.awt.SystemColor class.
1328      */
1329      public static void setSystemColorAccessor(SystemColorAccessor systemColorAccessor) {
1330          AWTAccessor.systemColorAccessor = systemColorAccessor;
1331      }
1332 
1333     /*
1334      * Get the accessor object for the javax.accessibility.AccessibleContext class.
1335      */
1336     public static AccessibleContextAccessor getAccessibleContextAccessor() {
1337         if (accessibleContextAccessor == null) {
1338             unsafe.ensureClassInitialized(AccessibleContext.class);
1339         }
1340         return accessibleContextAccessor;
1341     }
1342 
1343    /*
1344     * Set the accessor object for the javax.accessibility.AccessibleBundle class.
1345     */
1346     public static void setAccessibleBundleAccessor(AccessibleBundleAccessor accessor) {
1347         AWTAccessor.accessibleBundleAccessor = accessor;
1348     }
1349 
1350     /*
1351      * Get the accessor object for the javax.accessibility.AccessibleBundle class.
1352      */
1353     public static AccessibleBundleAccessor getAccessibleBundleAccessor() {
1354         if (accessibleBundleAccessor == null) {
1355             unsafe.ensureClassInitialized(AccessibleBundle.class);
1356         }
1357         return accessibleBundleAccessor;
1358     }
1359 
1360    /*
1361     * Set the accessor object for the javax.accessibility.AccessibleContext class.
1362     */
1363     public static void setAccessibleContextAccessor(AccessibleContextAccessor accessor) {
1364         AWTAccessor.accessibleContextAccessor = accessor;
1365     }
1366 
1367     /*
1368      * Get the accessor object for the java.awt.dnd.DragSourceContext class.
1369      */
1370     public static DragSourceContextAccessor getDragSourceContextAccessor() {
1371         if (dragSourceContextAccessor == null) {
1372             unsafe.ensureClassInitialized(DragSourceContext.class);
1373         }
1374         return dragSourceContextAccessor;
1375     }
1376 
1377     /*
1378      * Set the accessor object for the java.awt.dnd.DragSourceContext class.
1379      */
1380     public static void setDragSourceContextAccessor(DragSourceContextAccessor accessor) {
1381         AWTAccessor.dragSourceContextAccessor = accessor;
1382     }
1383 
1384     /*
1385      * Get the accessor object for the java.awt.dnd.DropTargetContext class.
1386      */
1387     public static DropTargetContextAccessor getDropTargetContextAccessor() {
1388         if (dropTargetContextAccessor == null) {
1389             unsafe.ensureClassInitialized(DropTargetContext.class);
1390         }
1391         return dropTargetContextAccessor;
1392     }
1393 
1394     /*
1395      * Set the accessor object for the java.awt.dnd.DropTargetContext class.
1396      */
1397     public static void setDropTargetContextAccessor(DropTargetContextAccessor accessor) {
1398         AWTAccessor.dropTargetContextAccessor = accessor;
1399     }
1400 
1401 }