1 /*
   2  * Copyright (c) 2011, 2012, 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.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
  61     // of asynchronous requests to the windowing system)
  62     private int sysX;
  63     private int sysY;
  64     private int sysW;
  65     private int sysH;
  66 
  67     private static final int MINIMUM_WIDTH = 1;
  68     private static final int MINIMUM_HEIGHT = 1;
  69 
  70     private Insets insets = new Insets(0, 0, 0, 0);
  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     // check that the mouse is over the window
  92     private volatile boolean isMouseOver = false;
  93 
  94     // A peer where the last mouse event came to. Used by cursor manager to
  95     // find the component under cursor
  96     private static volatile LWComponentPeer lastCommonMouseEventPeer = null;
  97 
  98     // A peer where the last mouse event came to. Used to generate
  99     // MOUSE_ENTERED/EXITED notifications
 100     private volatile LWComponentPeer lastMouseEventPeer;
 101 
 102     // Peers where all dragged/released events should come to,
 103     // depending on what mouse button is being dragged according to Cocoa
 104     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
 105 
 106     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 107     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 108     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 109     private static int mouseClickButtons = 0;
 110 
 111     private volatile boolean isOpaque = true;
 112 
 113     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 114 
 115     private static LWWindowPeer grabbingWindow;
 116 
 117     private volatile boolean skipNextFocusChange;
 118 
 119     private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
 120 
 121     private volatile boolean textured;
 122 
 123     /**
 124      * Current modal blocker or null.
 125      *
 126      * Synchronization: peerTreeLock.
 127      */
 128     private LWWindowPeer blocker;
 129 
 130     public LWWindowPeer(Window target, PlatformComponent platformComponent,
 131                         PlatformWindow platformWindow)
 132     {
 133         super(target, platformComponent);
 134         this.platformWindow = platformWindow;
 135 
 136         Window owner = target.getOwner();
 137         LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
 138         PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
 139 
 140         // The delegate.initialize() needs a non-null GC on X11.
 141         GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
 142         synchronized (getStateLock()) {
 143             // graphicsConfig should be updated according to the real window
 144             // bounds when the window is shown, see 4868278
 145             this.graphicsConfig = gc;
 146         }
 147 
 148         if (!target.isFontSet()) {
 149             target.setFont(DEFAULT_FONT);
 150         }
 151 
 152         if (!target.isBackgroundSet()) {
 153             target.setBackground(SystemColor.window);
 154         } else {
 155             // first we check if user provided alpha for background. This is
 156             // similar to what Apple's Java do.
 157             // Since JDK7 we should rely on setOpacity() only.
 158             // this.opacity = c.getAlpha();
 159         }
 160 
 161         if (!target.isForegroundSet()) {
 162             target.setForeground(SystemColor.windowText);
 163             // we should not call setForeground because it will call a repaint
 164             // which the peer may not be ready to do yet.
 165         }
 166 
 167         platformWindow.initialize(target, this, ownerDelegate);
 168     }
 169 
 170     @Override
 171     void initializeImpl() {
 172         super.initializeImpl();
 173         if (getTarget() instanceof Frame) {
 174             setTitle(((Frame) getTarget()).getTitle());
 175             setState(((Frame) getTarget()).getExtendedState());
 176         } else if (getTarget() instanceof Dialog) {
 177             setTitle(((Dialog) getTarget()).getTitle());
 178         }
 179 
 180         setAlwaysOnTop(getTarget().isAlwaysOnTop());
 181         updateMinimumSize();
 182 
 183         final Shape shape = getTarget().getShape();
 184         if (shape != null) {
 185             applyShape(Region.getInstance(shape, null));
 186         }
 187 
 188         final float opacity = getTarget().getOpacity();
 189         if (opacity < 1.0f) {
 190             setOpacity(opacity);
 191         }
 192 
 193         setOpaque(getTarget().isOpaque());
 194 
 195         updateInsets(platformWindow.getInsets());
 196         if (getSurfaceData() == null) {
 197             replaceSurfaceData(false);
 198         }
 199     }
 200 
 201     // Just a helper method
 202     public PlatformWindow getPlatformWindow() {
 203         return platformWindow;
 204     }
 205 
 206     @Override
 207     protected LWWindowPeer getWindowPeerOrSelf() {
 208         return this;
 209     }
 210 
 211     @Override
 212     protected void initializeContainerPeer() {
 213         // No-op as LWWindowPeer doesn't have any containerPeer
 214     }
 215 
 216     // ---- PEER METHODS ---- //
 217 
 218     @Override
 219     protected void disposeImpl() {
 220         SurfaceData oldData = getSurfaceData();
 221         synchronized (surfaceDataLock){
 222             surfaceData = null;
 223         }
 224         if (oldData != null) {
 225             oldData.invalidate();
 226         }
 227         if (isGrabbing()) {
 228             ungrab();
 229         }
 230         destroyBuffers();
 231         platformWindow.dispose();
 232         super.disposeImpl();
 233     }
 234 
 235     @Override
 236     protected void setVisibleImpl(final boolean visible) {
 237         super.setVisibleImpl(visible);
 238         // TODO: update graphicsConfig, see 4868278
 239         platformWindow.setVisible(visible);
 240         if (isSimpleWindow()) {
 241             KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
 242 
 243             if (visible) {
 244                 if (!getTarget().isAutoRequestFocus()) {
 245                     return;
 246                 } else {
 247                     requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
 248                 }
 249             // Focus the owner in case this window is focused.
 250             } else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
 251                 // Transfer focus to the owner.
 252                 LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
 253                 if (owner != null) {
 254                     owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
 255                 }
 256             }
 257         }
 258     }
 259 
 260     @Override
 261     public GraphicsConfiguration getGraphicsConfiguration() {
 262         return graphicsConfig;
 263     }
 264 
 265     @Override
 266     public boolean updateGraphicsData(GraphicsConfiguration gc) {
 267         setGraphicsConfig(gc);
 268         return false;
 269     }
 270 
 271     protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
 272         if (getSurfaceData() == null) {
 273             return null;
 274         }
 275         if (fg == null) {
 276             fg = SystemColor.windowText;
 277         }
 278         if (bg == null) {
 279             bg = SystemColor.window;
 280         }
 281         if (f == null) {
 282             f = DEFAULT_FONT;
 283         }
 284         return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
 285     }
 286 
 287     @Override
 288     public void createBuffers(int numBuffers, BufferCapabilities caps)
 289         throws AWTException
 290     {
 291         try {
 292             // Assume this method is never called with numBuffers <= 1, as 0 is
 293             // unsupported, and 1 corresponds to a SingleBufferStrategy which
 294             // doesn't depend on the peer. Screen is considered as a separate
 295             // "buffer", that's why numBuffers - 1
 296             assert numBuffers > 1;
 297 
 298             replaceSurfaceData(numBuffers - 1, caps, false);
 299         } catch (InvalidPipeException z) {
 300             throw new AWTException(z.toString());
 301         }
 302     }
 303 
 304     @Override
 305     public final Image getBackBuffer() {
 306         synchronized (getStateLock()) {
 307             return backBuffer;
 308         }
 309     }
 310 
 311     @Override
 312     public void flip(int x1, int y1, int x2, int y2,
 313                      BufferCapabilities.FlipContents flipAction)
 314     {
 315         platformWindow.flip(x1, y1, x2, y2, flipAction);
 316     }
 317 
 318     @Override
 319     public final void destroyBuffers() {
 320         final Image oldBB = getBackBuffer();
 321         synchronized (getStateLock()) {
 322             backBuffer = null;
 323         }
 324         if (oldBB != null) {
 325             oldBB.flush();
 326         }
 327     }
 328 
 329     @Override
 330     public void setBounds(int x, int y, int w, int h, int op) {
 331         if ((op & SET_CLIENT_SIZE) != 0) {
 332             // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
 333             // instead of pulling 'insets' field up to LWComponentPeer
 334             // no need to add insets since Window's notion of width and height includes insets.
 335             op &= ~SET_CLIENT_SIZE;
 336             op |= SET_SIZE;
 337         }
 338 
 339         if (w < MINIMUM_WIDTH) {
 340             w = MINIMUM_WIDTH;
 341         }
 342         if (h < MINIMUM_HEIGHT) {
 343             h = MINIMUM_HEIGHT;
 344         }
 345 
 346         if (graphicsConfig instanceof TextureSizeConstraining) {
 347             final int maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth();
 348             final int maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight();
 349 
 350             if (w > maxW) {
 351                 w = maxW;
 352             }
 353             if (h > maxH) {
 354                 h = maxH;
 355             }
 356         }
 357 
 358         // Don't post ComponentMoved/Resized and Paint events
 359         // until we've got a notification from the delegate
 360         setBounds(x, y, w, h, op, false, false);
 361         // Get updated bounds, so we don't have to handle 'op' here manually
 362         Rectangle r = getBounds();
 363         platformWindow.setBounds(r.x, r.y, r.width, r.height);
 364     }
 365 
 366     @Override
 367     public Point getLocationOnScreen() {
 368         return platformWindow.getLocationOnScreen();
 369     }
 370 
 371     /**
 372      * Overridden from LWContainerPeer to return the correct insets.
 373      * Insets are queried from the delegate and are kept up to date by
 374      * requiering when needed (i.e. when the window geometry is changed).
 375      */
 376     @Override
 377     public Insets getInsets() {
 378         synchronized (getStateLock()) {
 379             return insets;
 380         }
 381     }
 382 
 383     @Override
 384     public FontMetrics getFontMetrics(Font f) {
 385         // TODO: check for "use platform metrics" settings
 386         return platformWindow.getFontMetrics(f);
 387     }
 388 
 389     @Override
 390     public void toFront() {
 391         platformWindow.toFront();
 392     }
 393 
 394     @Override
 395     public void toBack() {
 396         platformWindow.toBack();
 397     }
 398 
 399     @Override
 400     public void setZOrder(ComponentPeer above) {
 401         throw new RuntimeException("not implemented");
 402     }
 403 
 404     @Override
 405     public void setAlwaysOnTop(boolean value) {
 406         platformWindow.setAlwaysOnTop(value);
 407     }
 408 
 409     @Override
 410     public void updateFocusableWindowState() {
 411         platformWindow.updateFocusableWindowState();
 412     }
 413 
 414     @Override
 415     public void setModalBlocked(Dialog blocker, boolean blocked) {
 416         synchronized (getPeerTreeLock()) {
 417             this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null;
 418         }
 419 
 420         platformWindow.setModalBlocked(blocked);
 421     }
 422 
 423     @Override
 424     public void updateMinimumSize() {
 425         final Dimension min;
 426         if (getTarget().isMinimumSizeSet()) {
 427             min = getTarget().getMinimumSize();
 428             min.width = Math.max(min.width, MINIMUM_WIDTH);
 429             min.height = Math.max(min.height, MINIMUM_HEIGHT);
 430         } else {
 431             min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
 432         }
 433 
 434         final int maxW, maxH;
 435         if (graphicsConfig instanceof TextureSizeConstraining) {
 436             maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth();
 437             maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight();
 438         } else {
 439             maxW = maxH = Integer.MAX_VALUE;
 440         }
 441 
 442         final Dimension max;
 443         if (getTarget().isMaximumSizeSet()) {
 444             max = getTarget().getMaximumSize();
 445             max.width = Math.min(max.width, maxW);
 446             max.height = Math.min(max.height, maxH);
 447         } else {
 448             max = new Dimension(maxW, maxH);
 449         }
 450 
 451         platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height);
 452     }
 453 
 454     @Override
 455     public void updateIconImages() {
 456         getPlatformWindow().updateIconImages();
 457     }
 458 
 459     @Override
 460     public void setOpacity(float opacity) {
 461         getPlatformWindow().setOpacity(opacity);
 462         repaintPeer();
 463     }
 464 
 465     @Override
 466     public final void setOpaque(final boolean isOpaque) {
 467         if (this.isOpaque != isOpaque) {
 468             this.isOpaque = isOpaque;
 469             updateOpaque();
 470         }
 471     }
 472 
 473     private void updateOpaque() {
 474         getPlatformWindow().setOpaque(!isTranslucent());
 475         replaceSurfaceData(false);
 476         repaintPeer();
 477     }
 478 
 479     @Override
 480     public void updateWindow() {
 481     }
 482 
 483     public final boolean isTextured() {
 484         return textured;
 485     }
 486 
 487     public final void setTextured(final boolean isTextured) {
 488         textured = isTextured;
 489     }
 490 
 491     public final boolean isTranslucent() {
 492         synchronized (getStateLock()) {
 493             /*
 494              * Textured window is a special case of translucent window.
 495              * The difference is only in nswindow background. So when we set
 496              * texture property our peer became fully translucent. It doesn't
 497              * fill background, create non opaque backbuffers and layer etc.
 498              */
 499             return !isOpaque || isShaped() || isTextured();
 500         }
 501     }
 502 
 503     @Override
 504     final void applyShapeImpl(final Region shape) {
 505         super.applyShapeImpl(shape);
 506         updateOpaque();
 507     }
 508 
 509     @Override
 510     public void repositionSecurityWarning() {
 511         throw new RuntimeException("not implemented");
 512     }
 513 
 514     // ---- FRAME PEER METHODS ---- //
 515 
 516     @Override // FramePeer and DialogPeer
 517     public void setTitle(String title) {
 518         platformWindow.setTitle(title == null ? "" : title);
 519     }
 520 
 521     @Override
 522     public void setMenuBar(MenuBar mb) {
 523          platformWindow.setMenuBar(mb);
 524     }
 525 
 526     @Override // FramePeer and DialogPeer
 527     public void setResizable(boolean resizable) {
 528         platformWindow.setResizable(resizable);
 529     }
 530 
 531     @Override
 532     public void setState(int state) {
 533         platformWindow.setWindowState(state);
 534     }
 535 
 536     @Override
 537     public int getState() {
 538         return windowState;
 539     }
 540 
 541     @Override
 542     public void setMaximizedBounds(Rectangle bounds) {
 543         // TODO: not implemented
 544     }
 545 
 546     @Override
 547     public void setBoundsPrivate(int x, int y, int width, int height) {
 548         setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
 549     }
 550 
 551     @Override
 552     public Rectangle getBoundsPrivate() {
 553         throw new RuntimeException("not implemented");
 554     }
 555 
 556     // ---- DIALOG PEER METHODS ---- //
 557 
 558     @Override
 559     public void blockWindows(List<Window> windows) {
 560         //TODO: LWX will probably need some collectJavaToplevels to speed this up
 561         for (Window w : windows) {
 562             WindowPeer wp = (WindowPeer)w.getPeer();
 563             if (wp != null) {
 564                 wp.setModalBlocked((Dialog)getTarget(), true);
 565             }
 566         }
 567     }
 568 
 569     // ---- PEER NOTIFICATIONS ---- //
 570 
 571     public void notifyIconify(boolean iconify) {
 572         //The toplevel target is Frame and states are applicable to it.
 573         //Otherwise, the target is Window and it don't have state property.
 574         //Hopefully, no such events are posted in the queue so consider the
 575         //target as Frame in all cases.
 576 
 577         // REMIND: should we send it anyway if the state not changed since last
 578         // time?
 579         WindowEvent iconifyEvent = new WindowEvent(getTarget(),
 580                 iconify ? WindowEvent.WINDOW_ICONIFIED
 581                         : WindowEvent.WINDOW_DEICONIFIED);
 582         postEvent(iconifyEvent);
 583 
 584         int newWindowState = iconify ? Frame.ICONIFIED : Frame.NORMAL;
 585         postWindowStateChangedEvent(newWindowState);
 586 
 587         // REMIND: RepaintManager doesn't repaint iconified windows and
 588         // hence ignores any repaint request during deiconification.
 589         // So, we need to repaint window explicitly when it becomes normal.
 590         if (!iconify) {
 591             repaintPeer();
 592         }
 593     }
 594 
 595     public void notifyZoom(boolean isZoomed) {
 596         int newWindowState = isZoomed ? Frame.MAXIMIZED_BOTH : Frame.NORMAL;
 597         postWindowStateChangedEvent(newWindowState);
 598     }
 599 
 600     /**
 601      * Called by the {@code PlatformWindow} when any part of the window should
 602      * be repainted.
 603      */
 604     public final void notifyExpose(final Rectangle r) {
 605         repaintPeer(r);
 606     }
 607 
 608     /**
 609      * Called by the {@code PlatformWindow} when this window is moved/resized by
 610      * user. There's no notifyReshape() in LWComponentPeer as the only
 611      * components which could be resized by user are top-level windows.
 612      */
 613     public final void notifyReshape(int x, int y, int w, int h) {
 614         final boolean moved;
 615         final boolean resized;
 616         synchronized (getStateLock()) {
 617             moved = (x != sysX) || (y != sysY);
 618             resized = (w != sysW) || (h != sysH);
 619             sysX = x;
 620             sysY = y;
 621             sysW = w;
 622             sysH = h;
 623         }
 624 
 625         // Check if anything changed
 626         if (!moved && !resized) {
 627             return;
 628         }
 629         // First, update peer's bounds
 630         setBounds(x, y, w, h, SET_BOUNDS, false, false);
 631 
 632         // Second, update the graphics config and surface data
 633         checkIfOnNewScreen();
 634         if (resized) {
 635             replaceSurfaceData();
 636             flushOnscreenGraphics();
 637         }
 638 
 639         // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
 640         if (moved) {
 641             handleMove(x, y, true);
 642         }
 643         if (resized) {
 644             handleResize(w, h, true);
 645             repaintPeer();
 646         }
 647     }
 648 
 649     private void clearBackground(final int w, final int h) {
 650         final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
 651                                                getFont());
 652         if (g != null) {
 653             try {
 654                 if (g instanceof Graphics2D) {
 655                     ((Graphics2D) g).setComposite(AlphaComposite.Src);
 656                 }
 657                 if (isTranslucent()) {
 658                     g.setColor(nonOpaqueBackground);
 659                     g.fillRect(0, 0, w, h);
 660                 }
 661                 if (!isTextured()) {
 662                     if (g instanceof SunGraphics2D) {
 663                         SG2DConstraint((SunGraphics2D) g, getRegion());
 664                     }
 665                     g.setColor(getBackground());
 666                     g.fillRect(0, 0, w, h);
 667                 }
 668             } finally {
 669                 g.dispose();
 670             }
 671         }
 672     }
 673 
 674     public void notifyUpdateCursor() {
 675         getLWToolkit().getCursorManager().updateCursorLater(this);
 676     }
 677 
 678     public void notifyActivation(boolean activation) {
 679         changeFocusedWindow(activation);
 680     }
 681 
 682     // MouseDown in non-client area
 683     public void notifyNCMouseDown() {
 684         // Ungrab except for a click on a Dialog with the grabbing owner
 685         if (grabbingWindow != null &&
 686             grabbingWindow != getOwnerFrameDialog(this))
 687         {
 688             grabbingWindow.ungrab();
 689         }
 690     }
 691 
 692     // ---- EVENTS ---- //
 693 
 694     /*
 695      * Called by the delegate to dispatch the event to Java. Event
 696      * coordinates are relative to non-client window are, i.e. the top-left
 697      * point of the client area is (insets.top, insets.left).
 698      */
 699     public void dispatchMouseEvent(int id, long when, int button,
 700                                    int x, int y, int screenX, int screenY,
 701                                    int modifiers, int clickCount, boolean popupTrigger,
 702                                    byte[] bdata)
 703     {
 704         // TODO: fill "bdata" member of AWTEvent
 705         Rectangle r = getBounds();
 706         // findPeerAt() expects parent coordinates
 707         LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 708 
 709         if (id == MouseEvent.MOUSE_EXITED) {
 710             isMouseOver = false;
 711             if (lastMouseEventPeer != null) {
 712                 if (lastMouseEventPeer.isEnabled()) {
 713                     Point lp = lastMouseEventPeer.windowToLocal(x, y,
 714                             this);
 715                     postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 716                             MouseEvent.MOUSE_EXITED, when,
 717                             modifiers, lp.x, lp.y, screenX,
 718                             screenY, clickCount, popupTrigger,
 719                             button));
 720                 }
 721 
 722                 // Sometimes we may get MOUSE_EXITED after lastCommonMouseEventPeer is switched
 723                 // to a peer from another window. So we must first check if this peer is
 724                 // the same as lastWindowPeer
 725                 if (lastCommonMouseEventPeer != null && lastCommonMouseEventPeer.getWindowPeerOrSelf() == this) {
 726                     lastCommonMouseEventPeer = null;
 727                 }
 728                 lastMouseEventPeer = null;
 729             }
 730         } else if(id == MouseEvent.MOUSE_ENTERED) {
 731             isMouseOver = true;
 732             if (targetPeer != null) {
 733                 if (targetPeer.isEnabled()) {
 734                     Point lp = targetPeer.windowToLocal(x, y, this);
 735                         postEvent(new MouseEvent(targetPeer.getTarget(),
 736                             MouseEvent.MOUSE_ENTERED, when,
 737                             modifiers, lp.x, lp.y, screenX,
 738                             screenY, clickCount, popupTrigger,
 739                             button));
 740                 }
 741                 lastCommonMouseEventPeer = targetPeer;
 742                 lastMouseEventPeer = targetPeer;
 743             }
 744         } else {
 745             PlatformWindow topmostPlatforWindow =
 746                     platformWindow.getTopmostPlatformWindowUnderMouse();
 747 
 748             LWWindowPeer topmostWindowPeer =
 749                     topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null;
 750 
 751             // topmostWindowPeer == null condition is added for the backward
 752             // compatibility with applets. It can be removed when the
 753             // getTopmostPlatformWindowUnderMouse() method will be properly
 754             // implemented in CPlatformEmbeddedFrame class
 755             if (topmostWindowPeer == this || topmostWindowPeer == null) {
 756                 generateMouseEnterExitEventsForComponents(when, button, x, y,
 757                         screenX, screenY, modifiers, clickCount, popupTrigger,
 758                         targetPeer);
 759             } else {
 760                 LWComponentPeer topmostTargetPeer =
 761                         topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null;
 762                 topmostWindowPeer.generateMouseEnterExitEventsForComponents(when, button, x, y,
 763                         screenX, screenY, modifiers, clickCount, popupTrigger,
 764                         topmostTargetPeer);
 765             }
 766 
 767             // TODO: fill "bdata" member of AWTEvent
 768 
 769             int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0;
 770             int otherButtonsPressed = modifiers & ~eventButtonMask;
 771 
 772             // For pressed/dragged/released events OS X treats other
 773             // mouse buttons as if they were BUTTON2, so we do the same
 774             int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
 775 
 776             // MOUSE_ENTERED/EXITED are generated for the components strictly under
 777             // mouse even when dragging. That's why we first update lastMouseEventPeer
 778             // based on initial targetPeer value and only then recalculate targetPeer
 779             // for MOUSE_DRAGGED/RELEASED events
 780             if (id == MouseEvent.MOUSE_PRESSED) {
 781 
 782                 // Ungrab only if this window is not an owned window of the grabbing one.
 783                 if (!isGrabbing() && grabbingWindow != null &&
 784                     grabbingWindow != getOwnerFrameDialog(this))
 785                 {
 786                     grabbingWindow.ungrab();
 787                 }
 788                 if (otherButtonsPressed == 0) {
 789                     mouseClickButtons = eventButtonMask;
 790                 } else {
 791                     mouseClickButtons |= eventButtonMask;
 792                 }
 793 
 794                 // The window should be focused on mouse click. If it gets activated by the native platform,
 795                 // this request will be no op. It will take effect when:
 796                 // 1. A simple not focused window is clicked.
 797                 // 2. An active but not focused owner frame/dialog is clicked.
 798                 // The mouse event then will trigger a focus request "in window" to the component, so the window
 799                 // should gain focus before.
 800                 requestWindowFocus(CausedFocusEvent.Cause.MOUSE_EVENT);
 801 
 802                 mouseDownTarget[targetIdx] = targetPeer;
 803             } else if (id == MouseEvent.MOUSE_DRAGGED) {
 804                 // Cocoa dragged event has the information about which mouse
 805                 // button is being dragged. Use it to determine the peer that
 806                 // should receive the dragged event.
 807                 targetPeer = mouseDownTarget[targetIdx];
 808                 mouseClickButtons &= ~modifiers;
 809             } else if (id == MouseEvent.MOUSE_RELEASED) {
 810                 // TODO: currently, mouse released event goes to the same component
 811                 // that received corresponding mouse pressed event. For most cases,
 812                 // it's OK, however, we need to make sure that our behavior is consistent
 813                 // with 1.6 for cases where component in question have been
 814                 // hidden/removed in between of mouse pressed/released events.
 815                 targetPeer = mouseDownTarget[targetIdx];
 816 
 817                 if ((modifiers & eventButtonMask) == 0) {
 818                     mouseDownTarget[targetIdx] = null;
 819                 }
 820 
 821                 // mouseClickButtons is updated below, after MOUSE_CLICK is sent
 822             }
 823 
 824             if (targetPeer == null) {
 825                 //TODO This can happen if this window is invisible. this is correct behavior in this case?
 826                 targetPeer = this;
 827             }
 828 
 829 
 830             Point lp = targetPeer.windowToLocal(x, y, this);
 831             if (targetPeer.isEnabled()) {
 832                 MouseEvent event = new MouseEvent(targetPeer.getTarget(), id,
 833                                                   when, modifiers, lp.x, lp.y,
 834                                                   screenX, screenY, clickCount,
 835                                                   popupTrigger, button);
 836                 postEvent(event);
 837             }
 838 
 839             if (id == MouseEvent.MOUSE_RELEASED) {
 840                 if ((mouseClickButtons & eventButtonMask) != 0
 841                     && targetPeer.isEnabled()) {
 842                     postEvent(new MouseEvent(targetPeer.getTarget(),
 843                                              MouseEvent.MOUSE_CLICKED,
 844                                              when, modifiers,
 845                                              lp.x, lp.y, screenX, screenY,
 846                                              clickCount, popupTrigger, button));
 847                 }
 848                 mouseClickButtons &= ~eventButtonMask;
 849             }
 850         }
 851         notifyUpdateCursor();
 852     }
 853 
 854     private void generateMouseEnterExitEventsForComponents(long when,
 855             int button, int x, int y, int screenX, int screenY,
 856             int modifiers, int clickCount, boolean popupTrigger,
 857             LWComponentPeer targetPeer) {
 858 
 859         if (!isMouseOver || targetPeer == lastMouseEventPeer) {
 860             return;
 861         }
 862 
 863         // Generate Mouse Exit for components
 864         if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
 865             Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
 866             postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 867                     MouseEvent.MOUSE_EXITED,
 868                     when, modifiers,
 869                     oldp.x, oldp.y, screenX, screenY,
 870                     clickCount, popupTrigger, button));
 871         }
 872         lastCommonMouseEventPeer = targetPeer;
 873         lastMouseEventPeer = targetPeer;
 874 
 875         // Generate Mouse Enter for components
 876         if (targetPeer != null && targetPeer.isEnabled()) {
 877             Point newp = targetPeer.windowToLocal(x, y, this);
 878             postEvent(new MouseEvent(targetPeer.getTarget(),
 879                     MouseEvent.MOUSE_ENTERED,
 880                     when, modifiers,
 881                     newp.x, newp.y, screenX, screenY,
 882                     clickCount, popupTrigger, button));
 883         }
 884     }
 885 
 886     public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers,
 887                                         int scrollType, int scrollAmount,
 888                                         int wheelRotation, double preciseWheelRotation,
 889                                         byte[] bdata)
 890     {
 891         // TODO: could we just use the last mouse event target here?
 892         Rectangle r = getBounds();
 893         // findPeerAt() expects parent coordinates
 894         final LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 895         if (targetPeer == null || !targetPeer.isEnabled()) {
 896             return;
 897         }
 898 
 899         Point lp = targetPeer.windowToLocal(x, y, this);
 900         // TODO: fill "bdata" member of AWTEvent
 901         // TODO: screenX/screenY
 902         postEvent(new MouseWheelEvent(targetPeer.getTarget(),
 903                                       MouseEvent.MOUSE_WHEEL,
 904                                       when, modifiers,
 905                                       lp.x, lp.y,
 906                                       0, 0, /* screenX, Y */
 907                                       0 /* clickCount */, false /* popupTrigger */,
 908                                       scrollType, scrollAmount,
 909                                       wheelRotation, preciseWheelRotation));
 910     }
 911 
 912     /*
 913      * Called by the delegate when a key is pressed.
 914      */
 915     public void dispatchKeyEvent(int id, long when, int modifiers,
 916                                  int keyCode, char keyChar, int keyLocation)
 917     {
 918         LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
 919         Component focusOwner = kfmPeer.getCurrentFocusOwner();
 920 
 921         if (focusOwner == null) {
 922             focusOwner = kfmPeer.getCurrentFocusedWindow();
 923             if (focusOwner == null) {
 924                 focusOwner = this.getTarget();
 925             }
 926         }
 927         postEvent(new KeyEvent(focusOwner, id, when, modifiers, keyCode, keyChar, keyLocation));
 928     }
 929 
 930 
 931     // ---- UTILITY METHODS ---- //
 932 
 933     private void postWindowStateChangedEvent(int newWindowState) {
 934         if (getTarget() instanceof Frame) {
 935             AWTAccessor.getFrameAccessor().setExtendedState(
 936                     (Frame)getTarget(), newWindowState);
 937         }
 938         WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
 939                 WindowEvent.WINDOW_STATE_CHANGED,
 940                 windowState, newWindowState);
 941         postEvent(stateChangedEvent);
 942         windowState = newWindowState;
 943     }
 944 
 945     private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
 946         // TODO: this method can be implemented in a more
 947         // efficient way by forwarding to the delegate
 948         GraphicsDevice gd = gc.getDevice();
 949         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 950         GraphicsDevice[] gds = ge.getScreenDevices();
 951         for (int i = 0; i < gds.length; i++) {
 952             if (gds[i] == gd) {
 953                 return i;
 954             }
 955         }
 956         // Should never happen if gc is a screen device config
 957         return 0;
 958     }
 959 
 960     /*
 961      * This method is called when window's graphics config is changed from
 962      * the app code (e.g. when the window is made non-opaque) or when
 963      * the window is moved to another screen by user.
 964      *
 965      * Returns true if the graphics config has been changed, false otherwise.
 966      */
 967     private boolean setGraphicsConfig(GraphicsConfiguration gc) {
 968         synchronized (getStateLock()) {
 969             if (graphicsConfig == gc) {
 970                 return false;
 971             }
 972             // If window's graphics config is changed from the app code, the
 973             // config correspond to the same device as before; when the window
 974             // is moved by user, graphicsDevice is updated in checkIfOnNewScreen().
 975             // In either case, there's nothing to do with screenOn here
 976             graphicsConfig = gc;
 977         }
 978         // SurfaceData is replaced later in updateGraphicsData()
 979         return true;
 980     }
 981 
 982     private void checkIfOnNewScreen() {
 983         GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
 984         synchronized (getStateLock()) {
 985             if (graphicsDevice == newGraphicsDevice) {
 986                 return;
 987             }
 988             graphicsDevice = newGraphicsDevice;
 989         }
 990 
 991         // TODO: DisplayChangedListener stuff
 992         final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
 993 
 994         if (!setGraphicsConfig(newGC)) return;
 995 
 996         SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
 997             public void run() {
 998                 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
 999             }
1000         });
1001     }
1002 
1003     /*
1004      * May be called by delegate to provide SD to Java2D code.
1005      */
1006     public SurfaceData getSurfaceData() {
1007         synchronized (surfaceDataLock) {
1008             return surfaceData;
1009         }
1010     }
1011 
1012     private void replaceSurfaceData() {
1013         replaceSurfaceData(true);
1014     }
1015 
1016     private void replaceSurfaceData(boolean blit) {
1017         replaceSurfaceData(backBufferCount, backBufferCaps, blit);
1018     }
1019 
1020     private void replaceSurfaceData(int newBackBufferCount,
1021                                     BufferCapabilities newBackBufferCaps,
1022                                     boolean blit) {
1023         synchronized (surfaceDataLock) {
1024             final SurfaceData oldData = getSurfaceData();
1025             surfaceData = platformWindow.replaceSurfaceData();
1026             // TODO: volatile image
1027     //        VolatileImage oldBB = backBuffer;
1028             BufferedImage oldBB = backBuffer;
1029             backBufferCount = newBackBufferCount;
1030             backBufferCaps = newBackBufferCaps;
1031             final Rectangle size = getSize();
1032             if (getSurfaceData() != null && oldData != getSurfaceData()) {
1033                 clearBackground(size.width, size.height);
1034             }
1035 
1036             if (blit) {
1037                 blitSurfaceData(oldData, getSurfaceData());
1038             }
1039 
1040             if (oldData != null && oldData != getSurfaceData()) {
1041                 // TODO: drop oldData for D3D/WGL pipelines
1042                 // This can only happen when this peer is being created
1043                 oldData.flush();
1044             }
1045 
1046             // TODO: volatile image
1047     //        backBuffer = (VolatileImage)delegate.createBackBuffer();
1048             backBuffer = (BufferedImage) platformWindow.createBackBuffer();
1049             if (backBuffer != null) {
1050                 Graphics g = backBuffer.getGraphics();
1051                 try {
1052                     Rectangle r = getBounds();
1053                     if (g instanceof Graphics2D) {
1054                         ((Graphics2D) g).setComposite(AlphaComposite.Src);
1055                     }
1056                     g.setColor(nonOpaqueBackground);
1057                     g.fillRect(0, 0, r.width, r.height);
1058                     if (g instanceof SunGraphics2D) {
1059                         SG2DConstraint((SunGraphics2D) g, getRegion());
1060                     }
1061                     if (!isTextured()) {
1062                         g.setColor(getBackground());
1063                         g.fillRect(0, 0, r.width, r.height);
1064                     }
1065                     if (oldBB != null) {
1066                         // Draw the old back buffer to the new one
1067                         g.drawImage(oldBB, 0, 0, null);
1068                         oldBB.flush();
1069                     }
1070                 } finally {
1071                     g.dispose();
1072                 }
1073             }
1074         }
1075     }
1076 
1077     private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
1078         //TODO blit. proof-of-concept
1079         if (src != dst && src != null && dst != null
1080             && !(dst instanceof NullSurfaceData)
1081             && !(src instanceof NullSurfaceData)
1082             && src.getSurfaceType().equals(dst.getSurfaceType())) {
1083             final Rectangle size = getSize();
1084             final Blit blit = Blit.locate(src.getSurfaceType(),
1085                                           CompositeType.Src,
1086                                           dst.getSurfaceType());
1087             if (blit != null) {
1088                 blit.Blit(src, dst, AlphaComposite.Src,
1089                           getRegion(), 0, 0, 0, 0, size.width, size.height);
1090             }
1091         }
1092     }
1093 
1094     public int getBackBufferCount() {
1095         return backBufferCount;
1096     }
1097 
1098     public BufferCapabilities getBackBufferCaps() {
1099         return backBufferCaps;
1100     }
1101 
1102     /*
1103      * Request the window insets from the delegate and compares it
1104      * with the current one. This method is mostly called by the
1105      * delegate, e.g. when the window state is changed and insets
1106      * should be recalculated.
1107      *
1108      * This method may be called on the toolkit thread.
1109      */
1110     public boolean updateInsets(Insets newInsets) {
1111         boolean changed = false;
1112         synchronized (getStateLock()) {
1113             changed = (insets.equals(newInsets));
1114             insets = newInsets;
1115         }
1116 
1117         if (changed) {
1118             replaceSurfaceData();
1119             repaintPeer();
1120         }
1121 
1122         return changed;
1123     }
1124 
1125     public static LWWindowPeer getWindowUnderCursor() {
1126         return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null;
1127     }
1128 
1129     public static LWComponentPeer<?, ?> getPeerUnderCursor() {
1130         return lastCommonMouseEventPeer;
1131     }
1132 
1133     /*
1134      * Requests platform to set native focus on a frame/dialog.
1135      * In case of a simple window, triggers appropriate java focus change.
1136      */
1137     public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
1138         if (focusLog.isLoggable(PlatformLogger.FINE)) {
1139             focusLog.fine("requesting native focus to " + this);
1140         }
1141 
1142         if (!focusAllowedFor()) {
1143             focusLog.fine("focus is not allowed");
1144             return false;
1145         }
1146 
1147         if (platformWindow.rejectFocusRequest(cause)) {
1148             return false;
1149         }
1150 
1151         Window currentActive = KeyboardFocusManager.
1152             getCurrentKeyboardFocusManager().getActiveWindow();
1153 
1154         // Make the owner active window.
1155         if (isSimpleWindow()) {
1156             LWWindowPeer owner = getOwnerFrameDialog(this);
1157 
1158             // If owner is not natively active, request native
1159             // activation on it w/o sending events up to java.
1160             if (owner != null && !owner.platformWindow.isActive()) {
1161                 if (focusLog.isLoggable(PlatformLogger.FINE)) {
1162                     focusLog.fine("requesting native focus to the owner " + owner);
1163                 }
1164                 LWWindowPeer currentActivePeer = (currentActive != null ?
1165                     (LWWindowPeer)currentActive.getPeer() : null);
1166 
1167                 // Ensure the opposite is natively active and suppress sending events.
1168                 if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
1169                     if (focusLog.isLoggable(PlatformLogger.FINE)) {
1170                         focusLog.fine("the opposite is " + currentActivePeer);
1171                     }
1172                     currentActivePeer.skipNextFocusChange = true;
1173                 }
1174                 owner.skipNextFocusChange = true;
1175 
1176                 owner.platformWindow.requestWindowFocus();
1177             }
1178 
1179             // DKFM will synthesize all the focus/activation events correctly.
1180             changeFocusedWindow(true);
1181             return true;
1182 
1183         // In case the toplevel is active but not focused, change focus directly,
1184         // as requesting native focus on it will not have effect.
1185         } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
1186 
1187             changeFocusedWindow(true);
1188             return true;
1189         }
1190         return platformWindow.requestWindowFocus();
1191     }
1192 
1193     private boolean focusAllowedFor() {
1194         Window window = getTarget();
1195         // TODO: check if modal blocked
1196         return window.isVisible() && window.isEnabled() && isFocusableWindow();
1197     }
1198 
1199     private boolean isFocusableWindow() {
1200         boolean focusable = getTarget().isFocusableWindow();
1201         if (isSimpleWindow()) {
1202             LWWindowPeer ownerPeer = getOwnerFrameDialog(this);
1203             if (ownerPeer == null) {
1204                 return false;
1205             }
1206             return focusable && ownerPeer.getTarget().isFocusableWindow();
1207         }
1208         return focusable;
1209     }
1210 
1211     public boolean isSimpleWindow() {
1212         Window window = getTarget();
1213         return !(window instanceof Dialog || window instanceof Frame);
1214     }
1215 
1216     /*
1217      * Changes focused window on java level.
1218      */
1219     private void changeFocusedWindow(boolean becomesFocused) {
1220         if (focusLog.isLoggable(PlatformLogger.FINE)) {
1221             focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
1222         }
1223         if (skipNextFocusChange) {
1224             focusLog.fine("skipping focus change");
1225             skipNextFocusChange = false;
1226             return;
1227         }
1228         if (!isFocusableWindow() && becomesFocused) {
1229             focusLog.fine("the window is not focusable");
1230             return;
1231         }
1232         if (becomesFocused) {
1233             synchronized (getPeerTreeLock()) {
1234                 if (blocker != null) {
1235                     if (focusLog.isLoggable(PlatformLogger.FINEST)) {
1236                         focusLog.finest("the window is blocked by " + blocker);
1237                     }
1238                     return;
1239                 }
1240             }
1241         }
1242 
1243         KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
1244         Window oppositeWindow = becomesFocused ? kfmPeer.getCurrentFocusedWindow() : null;
1245 
1246         // Note, the method is not called:
1247         // - when the opposite (gaining focus) window is an owned/owner window.
1248         // - for a simple window in any case.
1249         if (!becomesFocused &&
1250             (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this))
1251         {
1252             focusLog.fine("ungrabbing on " + grabbingWindow);
1253             // ungrab a simple window if its owner looses activation.
1254             grabbingWindow.ungrab();
1255         }
1256 
1257         kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
1258 
1259         int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
1260         WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, oppositeWindow, System.currentTimeMillis());
1261 
1262         // TODO: wrap in SequencedEvent
1263         postEvent(windowEvent);
1264     }
1265 
1266     static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
1267         Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1268         while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
1269             owner = owner.getOwner();
1270         }
1271         return owner != null ? (LWWindowPeer)owner.getPeer() : null;
1272     }
1273 
1274     /**
1275      * Returns the foremost modal blocker of this window, or null.
1276      */
1277     public LWWindowPeer getBlocker() {
1278         synchronized (getPeerTreeLock()) {
1279             LWWindowPeer blocker = this.blocker;
1280             if (blocker == null) {
1281                 return null;
1282             }
1283             while (blocker.blocker != null) {
1284                 blocker = blocker.blocker;
1285             }
1286             return blocker;
1287         }
1288     }
1289 
1290     public void enterFullScreenMode() {
1291         platformWindow.enterFullScreenMode();
1292     }
1293 
1294     public void exitFullScreenMode() {
1295         platformWindow.exitFullScreenMode();
1296     }
1297 
1298     public long getLayerPtr() {
1299         return getPlatformWindow().getLayerPtr();
1300     }
1301 
1302     void grab() {
1303         if (grabbingWindow != null && !isGrabbing()) {
1304             grabbingWindow.ungrab();
1305         }
1306         grabbingWindow = this;
1307     }
1308 
1309     void ungrab() {
1310         if (isGrabbing()) {
1311             grabbingWindow = null;
1312             postEvent(new UngrabEvent(getTarget()));
1313         }
1314     }
1315 
1316     private boolean isGrabbing() {
1317         return this == grabbingWindow;
1318     }
1319 
1320     @Override
1321     public String toString() {
1322         return super.toString() + " [target is " + getTarget() + "]";
1323     }
1324 }