jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
changeset 20153 d5bf90bfcb6d
parent 20109 e568ad7e1bf3
child 20465 b08b3909ee92
--- a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Mon Sep 23 16:14:42 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Mon Sep 23 16:17:26 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -72,19 +72,23 @@
 {
     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
 
-    // State lock is to be used for modifications to this
-    // peer's fields (e.g. bounds, background, font, etc.)
-    // It should be the last lock in the lock chain
-    private final Object stateLock =
-            new StringBuilder("LWComponentPeer.stateLock");
+    /**
+     * State lock is to be used for modifications to this peer's fields (e.g.
+     * bounds, background, font, etc.) It should be the last lock in the lock
+     * chain
+     */
+    private final Object stateLock = new Object();
 
-    // The lock to operate with the peers hierarchy. AWT tree
-    // lock is not used as there are many peers related ops
-    // to be done on the toolkit thread, and we don't want to
-    // depend on a public lock on this thread
-    private static final Object peerTreeLock =
-            new StringBuilder("LWComponentPeer.peerTreeLock");
+    /**
+     * The lock to operate with the peers hierarchy. AWT tree lock is not used
+     * as there are many peers related ops to be done on the toolkit thread, and
+     * we don't want to depend on a public lock on this thread
+     */
+    private static final Object peerTreeLock = new Object();
 
+    /**
+     * The associated AWT object.
+     */
     private final T target;
 
     /**
@@ -95,7 +99,7 @@
      * the hierarchy. The exception is LWWindowPeers: their containers are
      * always null
      */
-    private final LWContainerPeer containerPeer;
+    private final LWContainerPeer<?, ?> containerPeer;
 
     /**
      * Handy reference to the top-level window peer. Window peer is borrowed
@@ -147,11 +151,18 @@
      */
     private Image backBuffer;
 
+    /**
+     * All Swing delegates use delegateContainer as a parent. This container
+     * intentionally do not use parent of the peer.
+     */
+    @SuppressWarnings("serial")// Safe: outer class is non-serializable.
     private final class DelegateContainer extends Container {
         {
             enableEvents(0xFFFFFFFF);
         }
 
+        // Empty non private constructor was added because access to this
+        // class shouldn't be emulated by a synthetic accessor method.
         DelegateContainer() {
             super();
         }
@@ -182,7 +193,7 @@
         }
     }
 
-    public LWComponentPeer(T target, PlatformComponent platformComponent) {
+    LWComponentPeer(final T target, final PlatformComponent platformComponent) {
         targetPaintArea = new LWRepaintArea();
         this.target = target;
         this.platformComponent = platformComponent;
@@ -276,15 +287,18 @@
      * This method is called under getDelegateLock().
      * Overridden in subclasses.
      */
-    protected D createDelegate() {
+    D createDelegate() {
         return null;
     }
 
-    protected final D getDelegate() {
+    final D getDelegate() {
         return delegate;
     }
 
-    protected Component getDelegateFocusOwner() {
+    /**
+     * This method should be called under getDelegateLock().
+     */
+    Component getDelegateFocusOwner() {
         return getDelegate();
     }
 
@@ -356,7 +370,7 @@
     }
 
     // Just a helper method
-    protected final LWContainerPeer getContainerPeer() {
+    protected final LWContainerPeer<?, ?> getContainerPeer() {
         return containerPeer;
     }
 
@@ -390,7 +404,7 @@
 
     protected void disposeImpl() {
         destroyBuffers();
-        LWContainerPeer cp = getContainerPeer();
+        LWContainerPeer<?, ?> cp = getContainerPeer();
         if (cp != null) {
             cp.removeChildPeer(this);
         }
@@ -462,12 +476,13 @@
         sg2d.constrain(size.x, size.y, size.width, size.height, getVisibleRegion());
     }
 
-    public Region getVisibleRegion() {
+    Region getVisibleRegion() {
         return computeVisibleRect(this, getRegion());
     }
 
-    static final Region computeVisibleRect(LWComponentPeer c, Region region) {
-        final LWContainerPeer p = c.getContainerPeer();
+    static final Region computeVisibleRect(final LWComponentPeer<?, ?> c,
+                                           Region region) {
+        final LWContainerPeer<?, ?> p = c.getContainerPeer();
         if (p != null) {
             final Rectangle r = c.getBounds();
             region = region.getTranslatedRegion(r.x, r.y);
@@ -612,7 +627,7 @@
      * @param p Point relative to the peer.
      * @return Cursor of the peer or null if default cursor should be used.
      */
-    protected Cursor getCursor(final Point p) {
+    Cursor getCursor(final Point p) {
         return getTarget().getCursor();
     }
 
@@ -717,7 +732,7 @@
     @Override
     public void setEnabled(final boolean e) {
         boolean status = e;
-        final LWComponentPeer cp = getContainerPeer();
+        final LWComponentPeer<?, ?> cp = getContainerPeer();
         if (cp != null) {
             status &= cp.isEnabled();
         }
@@ -802,12 +817,12 @@
     }
 
     @Override
-    public void setZOrder(ComponentPeer above) {
-        LWContainerPeer cp = getContainerPeer();
+    public void setZOrder(final ComponentPeer above) {
+        LWContainerPeer<?, ?> cp = getContainerPeer();
         // Don't check containerPeer for null as it can only happen
         // for windows, but this method is overridden in
         // LWWindowPeer and doesn't call super()
-        cp.setChildPeerZOrder(this, (LWComponentPeer) above);
+        cp.setChildPeerZOrder(this, (LWComponentPeer<?, ?>) above);
     }
 
     @Override
@@ -923,7 +938,9 @@
                     LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
                     return false;
                 }
-                LWWindowPeer parentPeer = (LWWindowPeer) parentWindow.getPeer();
+                final LWWindowPeer parentPeer =
+                        (LWWindowPeer) AWTAccessor.getComponentAccessor()
+                                                  .getPeer(parentWindow);
                 if (parentPeer == null) {
                     focusLog.fine("request rejected, parentPeer is null");
                     LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
@@ -1138,7 +1155,7 @@
     }
 
     protected final void repaintParent(final Rectangle oldB) {
-        final LWContainerPeer cp = getContainerPeer();
+        final LWContainerPeer<?, ?> cp = getContainerPeer();
         if (cp != null) {
             // Repaint unobscured part of the parent
             cp.repaintPeer(cp.getContentSize().intersection(oldB));
@@ -1275,7 +1292,7 @@
     /**
      * Handler for FocusEvents.
      */
-    protected void handleJavaFocusEvent(FocusEvent e) {
+    void handleJavaFocusEvent(final FocusEvent e) {
         // Note that the peer receives all the FocusEvents from
         // its lightweight children as well
         KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
@@ -1311,7 +1328,7 @@
      * Finds a top-most visible component for the given point. The location is
      * specified relative to the peer's parent.
      */
-    public LWComponentPeer findPeerAt(final int x, final int y) {
+    LWComponentPeer<?, ?> findPeerAt(final int x, final int y) {
         final Rectangle r = getBounds();
         final Region sh = getRegion();
         final boolean found = isVisible() && sh.contains(x - r.x, y - r.y);
@@ -1328,7 +1345,7 @@
     }
 
     public Point windowToLocal(Point p, LWWindowPeer wp) {
-        LWComponentPeer cp = this;
+        LWComponentPeer<?, ?> cp = this;
         while (cp != wp) {
             Rectangle cpb = cp.getBounds();
             p.x -= cpb.x;
@@ -1349,7 +1366,7 @@
     }
 
     public Point localToWindow(Point p) {
-        LWComponentPeer cp = getContainerPeer();
+        LWComponentPeer<?, ?> cp = getContainerPeer();
         Rectangle r = getBounds();
         while (cp != null) {
             p.x += r.x;
@@ -1370,7 +1387,7 @@
         repaintPeer(getSize());
     }
 
-    public void repaintPeer(final Rectangle r) {
+    void repaintPeer(final Rectangle r) {
         final Rectangle toPaint = getSize().intersection(r);
         if (!isShowing() || toPaint.isEmpty()) {
             return;
@@ -1389,7 +1406,7 @@
     protected final boolean isShowing() {
         synchronized (getPeerTreeLock()) {
             if (isVisible()) {
-                final LWContainerPeer container = getContainerPeer();
+                final LWContainerPeer<?, ?> container = getContainerPeer();
                 return (container == null) || container.isShowing();
             }
         }
@@ -1397,8 +1414,7 @@
     }
 
     /**
-     * Paints the peer. Overridden in subclasses to delegate the actual painting
-     * to Swing components.
+     * Paints the peer. Delegate the actual painting to Swing components.
      */
     protected final void paintPeer(final Graphics g) {
         final D delegate = getDelegate();