src/macosx/classes/sun/lwawt/LWWindowPeer.java

Print this page




  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.lwawt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.image.BufferedImage;
  31 import java.awt.peer.*;
  32 import java.util.List;
  33 
  34 import javax.swing.*;
  35 
  36 import sun.awt.*;
  37 import sun.java2d.*;
  38 import sun.java2d.loops.Blit;
  39 import sun.java2d.loops.CompositeType;
  40 import sun.java2d.pipe.Region;

  41 import sun.util.logging.PlatformLogger;
  42 
  43 public class LWWindowPeer
  44     extends LWContainerPeer<Window, JComponent>
  45     implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
  46 {
  47     public static enum PeerType {
  48         SIMPLEWINDOW,
  49         FRAME,
  50         DIALOG,
  51         EMBEDDEDFRAME
  52     }
  53 
  54     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  55 
  56     private PlatformWindow platformWindow;
  57 
  58     // Window bounds reported by the native system (as opposed to
  59     // regular bounds inherited from LWComponentPeer which are
  60     // requested by user and may haven't been applied yet because


  71 
  72     private GraphicsDevice graphicsDevice;
  73     private GraphicsConfiguration graphicsConfig;
  74 
  75     private SurfaceData surfaceData;
  76     private final Object surfaceDataLock = new Object();
  77 
  78     private int backBufferCount;
  79     private BufferCapabilities backBufferCaps;
  80 
  81     // The back buffer is used for two purposes:
  82     // 1. To render all the lightweight peers
  83     // 2. To provide user with a BufferStrategy
  84     // Need to check if a single back buffer can be used for both
  85 // TODO: VolatileImage
  86 //    private VolatileImage backBuffer;
  87     private volatile BufferedImage backBuffer;
  88 
  89     private volatile int windowState = Frame.NORMAL;
  90 
  91     // A peer where the last mouse event came to. Used to generate
  92     // MOUSE_ENTERED/EXITED notifications and by cursor manager to


  93     // find the component under cursor
  94     private static volatile LWComponentPeer lastMouseEventPeer = null;




  95 
  96     // Peers where all dragged/released events should come to,
  97     // depending on what mouse button is being dragged according to Cocoa
  98     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  99 
 100     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 101     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 102     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 103     private static int mouseClickButtons = 0;
 104 
 105     private volatile boolean isOpaque = true;
 106 
 107     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 108 
 109     private static LWWindowPeer grabbingWindow;
 110 
 111     private volatile boolean skipNextFocusChange;
 112 
 113     private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
 114 


 659             grabbingWindow.ungrab();
 660         }
 661     }
 662 
 663     // ---- EVENTS ---- //
 664 
 665     /*
 666      * Called by the delegate to dispatch the event to Java. Event
 667      * coordinates are relative to non-client window are, i.e. the top-left
 668      * point of the client area is (insets.top, insets.left).
 669      */
 670     public void dispatchMouseEvent(int id, long when, int button,
 671                                    int x, int y, int screenX, int screenY,
 672                                    int modifiers, int clickCount, boolean popupTrigger,
 673                                    byte[] bdata)
 674     {
 675         // TODO: fill "bdata" member of AWTEvent
 676         Rectangle r = getBounds();
 677         // findPeerAt() expects parent coordinates
 678         LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 679         LWWindowPeer lastWindowPeer =
 680             (lastMouseEventPeer != null) ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
 681         LWWindowPeer curWindowPeer =
 682             (targetPeer != null) ? targetPeer.getWindowPeerOrSelf() : null;
 683 
 684         if (id == MouseEvent.MOUSE_EXITED) {
 685             // Sometimes we may get MOUSE_EXITED after lastMouseEventPeer is switched
 686             // to a peer from another window. So we must first check if this peer is
 687             // the same as lastWindowPeer
 688             if (lastWindowPeer == this) {
 689                 if (isEnabled()) {
 690                     Point lp = lastMouseEventPeer.windowToLocal(x, y,
 691                                                                 lastWindowPeer);
 692                     postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 693                                              MouseEvent.MOUSE_EXITED, when,
 694                                              modifiers, lp.x, lp.y, screenX,
 695                                              screenY, clickCount, popupTrigger,
 696                                              button));
 697                 }
 698                 lastMouseEventPeer = null;
 699             }
 700         } else {
 701             if (targetPeer != lastMouseEventPeer) {
 702 
 703                 if (id != MouseEvent.MOUSE_DRAGGED || lastMouseEventPeer == null) {
 704                     // lastMouseEventPeer may be null if mouse was out of Java windows
 705                     if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
 706                         // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit
 707                         // later), in which case lastWindowPeer is another window
 708                         if (lastWindowPeer != this) {
 709                             Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
 710                             // Additionally translate from this to lastWindowPeer coordinates
 711                             Rectangle lr = lastWindowPeer.getBounds();
 712                             oldp.x += r.x - lr.x;
 713                             oldp.y += r.y - lr.y;
 714                             postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 715                                                      MouseEvent.MOUSE_EXITED,
 716                                                      when, modifiers,
 717                                                      oldp.x, oldp.y, screenX, screenY,
 718                                                      clickCount, popupTrigger, button));
 719                         } else {
 720                             Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
 721                             postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 722                                                      MouseEvent.MOUSE_EXITED,
 723                                                      when, modifiers,
 724                                                      oldp.x, oldp.y, screenX, screenY,
 725                                                      clickCount, popupTrigger, button));
 726                         }

 727                     }
 728                     if (targetPeer != null && targetPeer.isEnabled() && id != MouseEvent.MOUSE_ENTERED) {
 729                         Point newp = targetPeer.windowToLocal(x, y, curWindowPeer);



 730                         postEvent(new MouseEvent(targetPeer.getTarget(),
 731                                                  MouseEvent.MOUSE_ENTERED,
 732                                                  when, modifiers,
 733                                                  newp.x, newp.y, screenX, screenY,
 734                                                  clickCount, popupTrigger, button));
 735                     }
 736                 }

 737                 lastMouseEventPeer = targetPeer;
 738             }




















 739             // TODO: fill "bdata" member of AWTEvent
 740 
 741             int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0;
 742             int otherButtonsPressed = modifiers & ~eventButtonMask;
 743 
 744             // For pressed/dragged/released events OS X treats other
 745             // mouse buttons as if they were BUTTON2, so we do the same
 746             int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
 747 
 748             // MOUSE_ENTERED/EXITED are generated for the components strictly under
 749             // mouse even when dragging. That's why we first update lastMouseEventPeer
 750             // based on initial targetPeer value and only then recalculate targetPeer
 751             // for MOUSE_DRAGGED/RELEASED events
 752             if (id == MouseEvent.MOUSE_PRESSED) {
 753 
 754                 // Ungrab only if this window is not an owned window of the grabbing one.
 755                 if (!isGrabbing() && grabbingWindow != null &&
 756                     grabbingWindow != getOwnerFrameDialog(this))
 757                 {
 758                     grabbingWindow.ungrab();


 768                 // Cocoa dragged event has the information about which mouse
 769                 // button is being dragged. Use it to determine the peer that
 770                 // should receive the dragged event.
 771                 targetPeer = mouseDownTarget[targetIdx];
 772                 mouseClickButtons &= ~modifiers;
 773             } else if (id == MouseEvent.MOUSE_RELEASED) {
 774                 // TODO: currently, mouse released event goes to the same component
 775                 // that received corresponding mouse pressed event. For most cases,
 776                 // it's OK, however, we need to make sure that our behavior is consistent
 777                 // with 1.6 for cases where component in question have been
 778                 // hidden/removed in between of mouse pressed/released events.
 779                 targetPeer = mouseDownTarget[targetIdx];
 780 
 781                 if ((modifiers & eventButtonMask) == 0) {
 782                     mouseDownTarget[targetIdx] = null;
 783                 }
 784 
 785                 // mouseClickButtons is updated below, after MOUSE_CLICK is sent
 786             }
 787 
 788             // check if we receive mouseEvent from outside the window's bounds
 789             // it can be either mouseDragged or mouseReleased
 790             if (curWindowPeer == null) {
 791                 //TODO This can happen if this window is invisible. this is correct behavior in this case?
 792                 curWindowPeer = this;
 793             }
 794             if (targetPeer == null) {
 795                 //TODO This can happen if this window is invisible. this is correct behavior in this case?
 796                 targetPeer = this;
 797             }
 798 
 799 
 800             Point lp = targetPeer.windowToLocal(x, y, curWindowPeer);
 801             if (targetPeer.isEnabled()) {
 802                 MouseEvent event = new MouseEvent(targetPeer.getTarget(), id,
 803                                                   when, modifiers, lp.x, lp.y,
 804                                                   screenX, screenY, clickCount,
 805                                                   popupTrigger, button);
 806                 postEvent(event);
 807             }
 808 
 809             if (id == MouseEvent.MOUSE_RELEASED) {
 810                 if ((mouseClickButtons & eventButtonMask) != 0
 811                     && targetPeer.isEnabled()) {
 812                     postEvent(new MouseEvent(targetPeer.getTarget(),
 813                                              MouseEvent.MOUSE_CLICKED,
 814                                              when, modifiers,
 815                                              lp.x, lp.y, screenX, screenY,
 816                                              clickCount, popupTrigger, button));
 817                 }
 818                 mouseClickButtons &= ~eventButtonMask;
 819             }
 820         }
 821         notifyUpdateCursor();
 822     }
 823 
































 824     public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers,
 825                                         int scrollType, int scrollAmount,
 826                                         int wheelRotation, double preciseWheelRotation,
 827                                         byte[] bdata)
 828     {
 829         // TODO: could we just use the last mouse event target here?
 830         Rectangle r = getBounds();
 831         // findPeerAt() expects parent coordinates
 832         final LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 833         if (targetPeer == null || !targetPeer.isEnabled()) {
 834             return;
 835         }
 836 
 837         Point lp = targetPeer.windowToLocal(x, y, this);
 838         // TODO: fill "bdata" member of AWTEvent
 839         // TODO: screenX/screenY
 840         postEvent(new MouseWheelEvent(targetPeer.getTarget(),
 841                                       MouseEvent.MOUSE_WHEEL,
 842                                       when, modifiers,
 843                                       lp.x, lp.y,


1048      * should be recalculated.
1049      *
1050      * This method may be called on the toolkit thread.
1051      */
1052     public boolean updateInsets(Insets newInsets) {
1053         boolean changed = false;
1054         synchronized (getStateLock()) {
1055             changed = (insets.equals(newInsets));
1056             insets = newInsets;
1057         }
1058 
1059         if (changed) {
1060             replaceSurfaceData();
1061             repaintPeer();
1062         }
1063 
1064         return changed;
1065     }
1066 
1067     public static LWWindowPeer getWindowUnderCursor() {
1068         return lastMouseEventPeer != null ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
1069     }
1070 
1071     public static LWComponentPeer<?, ?> getPeerUnderCursor() {
1072         return lastMouseEventPeer;
1073     }
1074 
1075     /*
1076      * Requests platform to set native focus on a frame/dialog.
1077      * In case of a simple window, triggers appropriate java focus change.
1078      */
1079     public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
1080         if (focusLog.isLoggable(PlatformLogger.FINE)) {
1081             focusLog.fine("requesting native focus to " + this);
1082         }
1083 
1084         if (!focusAllowedFor()) {
1085             focusLog.fine("focus is not allowed");
1086             return false;
1087         }
1088 
1089         if (platformWindow.rejectFocusRequest(cause)) {
1090             return false;
1091         }
1092 




  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.lwawt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.image.BufferedImage;
  31 import java.awt.peer.*;
  32 import java.util.List;
  33 
  34 import javax.swing.*;
  35 
  36 import sun.awt.*;
  37 import sun.java2d.*;
  38 import sun.java2d.loops.Blit;
  39 import sun.java2d.loops.CompositeType;
  40 import sun.java2d.pipe.Region;
  41 import sun.lwawt.macosx.CPlatformWindow;
  42 import sun.util.logging.PlatformLogger;
  43 
  44 public class LWWindowPeer
  45     extends LWContainerPeer<Window, JComponent>
  46     implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
  47 {
  48     public static enum PeerType {
  49         SIMPLEWINDOW,
  50         FRAME,
  51         DIALOG,
  52         EMBEDDEDFRAME
  53     }
  54 
  55     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  56 
  57     private PlatformWindow platformWindow;
  58 
  59     // Window bounds reported by the native system (as opposed to
  60     // regular bounds inherited from LWComponentPeer which are
  61     // requested by user and may haven't been applied yet because


  72 
  73     private GraphicsDevice graphicsDevice;
  74     private GraphicsConfiguration graphicsConfig;
  75 
  76     private SurfaceData surfaceData;
  77     private final Object surfaceDataLock = new Object();
  78 
  79     private int backBufferCount;
  80     private BufferCapabilities backBufferCaps;
  81 
  82     // The back buffer is used for two purposes:
  83     // 1. To render all the lightweight peers
  84     // 2. To provide user with a BufferStrategy
  85     // Need to check if a single back buffer can be used for both
  86 // TODO: VolatileImage
  87 //    private VolatileImage backBuffer;
  88     private volatile BufferedImage backBuffer;
  89 
  90     private volatile int windowState = Frame.NORMAL;
  91 
  92     // check that the mouse is over the window
  93     private volatile boolean isMouseOver = false;
  94 
  95     // A peer where the last mouse event came to. Used by cursor manager to
  96     // find the component under cursor
  97     private static volatile LWComponentPeer lastCommonMouseEventPeer = null;
  98 
  99     // A peer where the last mouse event came to. Used to generate
 100     // MOUSE_ENTERED/EXITED notifications
 101     private volatile LWComponentPeer lastMouseEventPeer;
 102 
 103     // Peers where all dragged/released events should come to,
 104     // depending on what mouse button is being dragged according to Cocoa
 105     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
 106 
 107     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 108     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 109     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 110     private static int mouseClickButtons = 0;
 111 
 112     private volatile boolean isOpaque = true;
 113 
 114     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 115 
 116     private static LWWindowPeer grabbingWindow;
 117 
 118     private volatile boolean skipNextFocusChange;
 119 
 120     private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
 121 


 666             grabbingWindow.ungrab();
 667         }
 668     }
 669 
 670     // ---- EVENTS ---- //
 671 
 672     /*
 673      * Called by the delegate to dispatch the event to Java. Event
 674      * coordinates are relative to non-client window are, i.e. the top-left
 675      * point of the client area is (insets.top, insets.left).
 676      */
 677     public void dispatchMouseEvent(int id, long when, int button,
 678                                    int x, int y, int screenX, int screenY,
 679                                    int modifiers, int clickCount, boolean popupTrigger,
 680                                    byte[] bdata)
 681     {
 682         // TODO: fill "bdata" member of AWTEvent
 683         Rectangle r = getBounds();
 684         // findPeerAt() expects parent coordinates
 685         LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);




 686 
 687         if (id == MouseEvent.MOUSE_EXITED) {
 688             isMouseOver = false;
 689             if (lastMouseEventPeer != null) {
 690                 if (lastMouseEventPeer.isEnabled()) {


 691                     Point lp = lastMouseEventPeer.windowToLocal(x, y,
 692                             this);
 693                     postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 694                             MouseEvent.MOUSE_EXITED, when,
 695                             modifiers, lp.x, lp.y, screenX,
 696                             screenY, clickCount, popupTrigger,
 697                             button));
 698                 }




 699 
 700                 // Sometimes we may get MOUSE_EXITED after lastCommonMouseEventPeer is switched
 701                 // to a peer from another window. So we must first check if this peer is
 702                 // the same as lastWindowPeer
 703                 if (lastCommonMouseEventPeer != null || lastCommonMouseEventPeer.getWindowPeerOrSelf() == this) {
 704                     lastCommonMouseEventPeer = null;


















 705                 }
 706                 lastMouseEventPeer = null;
 707             }
 708         } else if(id == MouseEvent.MOUSE_ENTERED) {
 709             isMouseOver = true;
 710             if (targetPeer != null) {
 711                 if (targetPeer.isEnabled()) {
 712                     Point lp = targetPeer.windowToLocal(x, y, this);
 713                         postEvent(new MouseEvent(targetPeer.getTarget(),
 714                             MouseEvent.MOUSE_ENTERED, when,
 715                             modifiers, lp.x, lp.y, screenX,
 716                             screenY, clickCount, popupTrigger,
 717                             button));

 718                 }
 719                 lastCommonMouseEventPeer = targetPeer;
 720                 lastMouseEventPeer = targetPeer;
 721             }
 722         } else {
 723             CPlatformWindow topmostPlatforWindow =
 724                     CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
 725             LWWindowPeer topmostWindowPeer =
 726                     topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null;
 727 
 728             if (topmostWindowPeer == this) {
 729                 //current window is the topmost window under mouse
 730                 generateMouseEnterExitEventsForComponents(when, button, x, y,
 731                         screenX, screenY, modifiers, clickCount, popupTrigger,
 732                         targetPeer);
 733             } else if (topmostWindowPeer != null) {
 734                 // the topmost window under mouse is differ from the current window
 735                 LWComponentPeer topmostTargetPeer =
 736                         topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null;
 737                 topmostWindowPeer.generateMouseEnterExitEventsForComponents(when, button, x, y,
 738                         screenX, screenY, modifiers, clickCount, popupTrigger,
 739                         topmostTargetPeer);
 740             }
 741 
 742             // TODO: fill "bdata" member of AWTEvent
 743 
 744             int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0;
 745             int otherButtonsPressed = modifiers & ~eventButtonMask;
 746 
 747             // For pressed/dragged/released events OS X treats other
 748             // mouse buttons as if they were BUTTON2, so we do the same
 749             int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
 750 
 751             // MOUSE_ENTERED/EXITED are generated for the components strictly under
 752             // mouse even when dragging. That's why we first update lastMouseEventPeer
 753             // based on initial targetPeer value and only then recalculate targetPeer
 754             // for MOUSE_DRAGGED/RELEASED events
 755             if (id == MouseEvent.MOUSE_PRESSED) {
 756 
 757                 // Ungrab only if this window is not an owned window of the grabbing one.
 758                 if (!isGrabbing() && grabbingWindow != null &&
 759                     grabbingWindow != getOwnerFrameDialog(this))
 760                 {
 761                     grabbingWindow.ungrab();


 771                 // Cocoa dragged event has the information about which mouse
 772                 // button is being dragged. Use it to determine the peer that
 773                 // should receive the dragged event.
 774                 targetPeer = mouseDownTarget[targetIdx];
 775                 mouseClickButtons &= ~modifiers;
 776             } else if (id == MouseEvent.MOUSE_RELEASED) {
 777                 // TODO: currently, mouse released event goes to the same component
 778                 // that received corresponding mouse pressed event. For most cases,
 779                 // it's OK, however, we need to make sure that our behavior is consistent
 780                 // with 1.6 for cases where component in question have been
 781                 // hidden/removed in between of mouse pressed/released events.
 782                 targetPeer = mouseDownTarget[targetIdx];
 783 
 784                 if ((modifiers & eventButtonMask) == 0) {
 785                     mouseDownTarget[targetIdx] = null;
 786                 }
 787 
 788                 // mouseClickButtons is updated below, after MOUSE_CLICK is sent
 789             }
 790 






 791             if (targetPeer == null) {
 792                 //TODO This can happen if this window is invisible. this is correct behavior in this case?
 793                 targetPeer = this;
 794             }
 795 
 796 
 797             Point lp = targetPeer.windowToLocal(x, y, this);
 798             if (targetPeer.isEnabled()) {
 799                 MouseEvent event = new MouseEvent(targetPeer.getTarget(), id,
 800                                                   when, modifiers, lp.x, lp.y,
 801                                                   screenX, screenY, clickCount,
 802                                                   popupTrigger, button);
 803                 postEvent(event);
 804             }
 805 
 806             if (id == MouseEvent.MOUSE_RELEASED) {
 807                 if ((mouseClickButtons & eventButtonMask) != 0
 808                     && targetPeer.isEnabled()) {
 809                     postEvent(new MouseEvent(targetPeer.getTarget(),
 810                                              MouseEvent.MOUSE_CLICKED,
 811                                              when, modifiers,
 812                                              lp.x, lp.y, screenX, screenY,
 813                                              clickCount, popupTrigger, button));
 814                 }
 815                 mouseClickButtons &= ~eventButtonMask;
 816             }
 817         }
 818         notifyUpdateCursor();
 819     }
 820 
 821     private void generateMouseEnterExitEventsForComponents(long when,
 822             int button, int x, int y, int screenX, int screenY,
 823             int modifiers, int clickCount, boolean popupTrigger,
 824             LWComponentPeer targetPeer) {
 825 
 826         if (!isMouseOver || targetPeer == lastMouseEventPeer) {
 827             return;
 828         }
 829 
 830         // Generate Mouse Exit for components
 831         if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
 832             Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
 833             postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 834                     MouseEvent.MOUSE_EXITED,
 835                     when, modifiers,
 836                     oldp.x, oldp.y, screenX, screenY,
 837                     clickCount, popupTrigger, button));
 838         }
 839         lastCommonMouseEventPeer = targetPeer;
 840         lastMouseEventPeer = targetPeer;
 841 
 842         // Generate Mouse Enter for components
 843         if (targetPeer != null && targetPeer.isEnabled()) {
 844             Point newp = targetPeer.windowToLocal(x, y, this);
 845             postEvent(new MouseEvent(targetPeer.getTarget(),
 846                     MouseEvent.MOUSE_ENTERED,
 847                     when, modifiers,
 848                     newp.x, newp.y, screenX, screenY,
 849                     clickCount, popupTrigger, button));
 850         }
 851     }
 852 
 853     public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers,
 854                                         int scrollType, int scrollAmount,
 855                                         int wheelRotation, double preciseWheelRotation,
 856                                         byte[] bdata)
 857     {
 858         // TODO: could we just use the last mouse event target here?
 859         Rectangle r = getBounds();
 860         // findPeerAt() expects parent coordinates
 861         final LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 862         if (targetPeer == null || !targetPeer.isEnabled()) {
 863             return;
 864         }
 865 
 866         Point lp = targetPeer.windowToLocal(x, y, this);
 867         // TODO: fill "bdata" member of AWTEvent
 868         // TODO: screenX/screenY
 869         postEvent(new MouseWheelEvent(targetPeer.getTarget(),
 870                                       MouseEvent.MOUSE_WHEEL,
 871                                       when, modifiers,
 872                                       lp.x, lp.y,


1077      * should be recalculated.
1078      *
1079      * This method may be called on the toolkit thread.
1080      */
1081     public boolean updateInsets(Insets newInsets) {
1082         boolean changed = false;
1083         synchronized (getStateLock()) {
1084             changed = (insets.equals(newInsets));
1085             insets = newInsets;
1086         }
1087 
1088         if (changed) {
1089             replaceSurfaceData();
1090             repaintPeer();
1091         }
1092 
1093         return changed;
1094     }
1095 
1096     public static LWWindowPeer getWindowUnderCursor() {
1097         return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null;
1098     }
1099 
1100     public static LWComponentPeer<?, ?> getPeerUnderCursor() {
1101         return lastCommonMouseEventPeer;
1102     }
1103 
1104     /*
1105      * Requests platform to set native focus on a frame/dialog.
1106      * In case of a simple window, triggers appropriate java focus change.
1107      */
1108     public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
1109         if (focusLog.isLoggable(PlatformLogger.FINE)) {
1110             focusLog.fine("requesting native focus to " + this);
1111         }
1112 
1113         if (!focusAllowedFor()) {
1114             focusLog.fine("focus is not allowed");
1115             return false;
1116         }
1117 
1118         if (platformWindow.rejectFocusRequest(cause)) {
1119             return false;
1120         }
1121