src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java
author aghaisas
Mon, 10 Jun 2019 14:13:09 +0530
branchmetal-prototype-branch
changeset 57400 978ffc56771f
parent 57196 a95707a39ff5
parent 54874 631c31a5bf40
child 57416 e153174dba06
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
54874
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
     2
 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
package sun.lwawt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
54874
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    28
import java.awt.AWTEvent;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    29
import java.awt.AWTException;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    30
import java.awt.BufferCapabilities;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    31
import java.awt.Color;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    32
import java.awt.Component;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    33
import java.awt.Container;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    34
import java.awt.Cursor;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    35
import java.awt.Dimension;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    36
import java.awt.Font;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    37
import java.awt.FontMetrics;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    38
import java.awt.Graphics;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    39
import java.awt.GraphicsConfiguration;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    40
import java.awt.Image;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    41
import java.awt.Point;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    42
import java.awt.Rectangle;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    43
import java.awt.Toolkit;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    44
import java.awt.Window;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
import java.awt.dnd.DropTarget;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
import java.awt.dnd.peer.DropTargetPeer;
54874
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    47
import java.awt.event.AWTEventListener;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    48
import java.awt.event.ComponentEvent;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    49
import java.awt.event.FocusEvent;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    50
import java.awt.event.InputEvent;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    51
import java.awt.event.KeyEvent;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    52
import java.awt.event.MouseEvent;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    53
import java.awt.event.MouseWheelEvent;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    54
import java.awt.event.PaintEvent;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
import java.awt.image.ColorModel;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
import java.awt.image.ImageObserver;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
import java.awt.image.ImageProducer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
import java.awt.image.VolatileImage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
import java.awt.peer.ComponentPeer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
import java.awt.peer.ContainerPeer;
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
    61
import java.awt.peer.KeyboardFocusManagerPeer;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
import java.lang.reflect.Field;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
import java.security.AccessController;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
import java.security.PrivilegedAction;
54874
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    65
import java.util.concurrent.atomic.AtomicBoolean;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
54874
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    67
import javax.swing.JComponent;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    68
import javax.swing.RepaintManager;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    69
import javax.swing.SwingUtilities;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
54874
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    71
import com.sun.java.swing.SwingUtilities3;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    72
import sun.awt.AWTAccessor;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    73
import sun.awt.PaintEventDispatcher;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    74
import sun.awt.RepaintArea;
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
    75
import sun.awt.SunToolkit;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
import sun.awt.event.IgnorePaintEvent;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
import sun.awt.image.SunVolatileImage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
import sun.awt.image.ToolkitImage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
import sun.java2d.SunGraphics2D;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
import sun.java2d.opengl.OGLRenderQueue;
57196
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
    81
import sun.java2d.metal.MetalRenderQueue;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
import sun.java2d.pipe.Region;
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
    83
import sun.util.logging.PlatformLogger;
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
    84
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
public abstract class LWComponentPeer<T extends Component, D extends JComponent>
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
    86
    implements ComponentPeer, DropTargetPeer
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
    87
{
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
    88
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
    89
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    90
    /**
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    91
     * State lock is to be used for modifications to this peer's fields (e.g.
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    92
     * bounds, background, font, etc.) It should be the last lock in the lock
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    93
     * chain
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    94
     */
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    95
    private final Object stateLock = new Object();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    97
    /**
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    98
     * The lock to operate with the peers hierarchy. AWT tree lock is not used
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    99
     * as there are many peers related ops to be done on the toolkit thread, and
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   100
     * we don't want to depend on a public lock on this thread
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   101
     */
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   102
    private static final Object peerTreeLock = new Object();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   104
    /**
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   105
     * The associated AWT object.
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   106
     */
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   107
    private final T target;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
17150
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   109
    /**
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   110
     * Container peer. It may not be the peer of the target's direct parent, for
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   111
     * example, in the case of hw/lw mixing. However, let's skip this scenario
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   112
     * for the time being. We also assume the container peer is not null, which
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   113
     * might also be false if addNotify() is called for a component outside of
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   114
     * the hierarchy. The exception is LWWindowPeers: their containers are
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   115
     * always null
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   116
     */
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   117
    private final LWContainerPeer<?, ?> containerPeer;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
17150
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   119
    /**
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   120
     * Handy reference to the top-level window peer. Window peer is borrowed
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   121
     * from the containerPeer in constructor, and should also be updated when
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   122
     * the component is reparented to another container
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   123
     */
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   124
    private final LWWindowPeer windowPeer;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   126
    private final AtomicBoolean disposed = new AtomicBoolean(false);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
    // Bounds are relative to parent peer
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   129
    private final Rectangle bounds = new Rectangle();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
    private Region region;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
    // Component state. Should be accessed under the state lock
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
    private boolean visible = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
    private boolean enabled = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
    private Color background;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
    private Color foreground;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
    private Font font;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   140
    /**
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   141
     * Paint area to coalesce all the paint events and store the target dirty
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   142
     * area.
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   143
     */
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   144
    private final RepaintArea targetPaintArea;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
    //   private volatile boolean paintPending;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
    private volatile boolean isLayouting;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   149
    private final D delegate;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
    private Container delegateContainer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
    private Component delegateDropTarget;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    private final Object dropTargetLock = new Object();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
    private int fNumDropTargets = 0;
24551
cccf7dd14729 8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents: 21789
diff changeset
   155
    private PlatformDropTarget fDropTarget = null;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   157
    private final PlatformComponent platformComponent;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   159
    /**
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   160
     * Character with reasonable value between the minimum width and maximum.
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   161
     */
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   162
    static final char WIDE_CHAR = '0';
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   163
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   164
    /**
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   165
     * The back buffer provide user with a BufferStrategy.
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   166
     */
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   167
    private Image backBuffer;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   168
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   169
    /**
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   170
     * All Swing delegates use delegateContainer as a parent. This container
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   171
     * intentionally do not use parent of the peer.
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   172
     */
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   173
    @SuppressWarnings("serial")// Safe: outer class is non-serializable.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
    private final class DelegateContainer extends Container {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
        {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
            enableEvents(0xFFFFFFFF);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
        @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
        public boolean isLightweight() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
            return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
        @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
        public Point getLocation() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
            return getLocationOnScreen();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
        @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
        public Point getLocationOnScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
            return LWComponentPeer.this.getLocationOnScreen();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
        @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
        public int getX() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
            return getLocation().x;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
        @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
        public int getY() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
            return getLocation().y;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   205
    LWComponentPeer(final T target, final PlatformComponent platformComponent) {
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   206
        targetPaintArea = new LWRepaintArea();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
        this.target = target;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
        this.platformComponent = platformComponent;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
        // Container peer is always null for LWWindowPeers, so
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
        // windowPeer is always null for them as well. On the other
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
        // hand, LWWindowPeer shouldn't use windowPeer at all
17150
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   213
        final Container container = SunToolkit.getNativeContainer(target);
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   214
        containerPeer = (LWContainerPeer) LWToolkit.targetToPeer(container);
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   215
        windowPeer = containerPeer != null ? containerPeer.getWindowPeerOrSelf()
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16840
diff changeset
   216
                                           : null;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
        // don't bother about z-order here as updateZOrder()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
        // will be called from addNotify() later anyway
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
        if (containerPeer != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
            containerPeer.addChildPeer(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
        // the delegate must be created after the target is set
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
        AWTEventListener toolkitListener = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
        synchronized (Toolkit.getDefaultToolkit()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
            try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
                toolkitListener = getToolkitAWTEventListener();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
                setToolkitAWTEventListener(null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
                synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
                    delegate = createDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
                    if (delegate != null) {
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   233
                        delegate.setVisible(false);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
                        delegateContainer = new DelegateContainer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
                        delegateContainer.add(delegate);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
                        delegateContainer.addNotify();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
                        delegate.addNotify();
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   238
                        resetColorsAndFont(delegate);
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   239
                        delegate.setOpaque(true);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
                    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
                        return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
            } finally {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
                setToolkitAWTEventListener(toolkitListener);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
            // todo swing: later on we will probably have one global RM
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
            SwingUtilities3.setDelegateRepaintManager(delegate, new RepaintManager() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
                @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
                public void addDirtyRegion(final JComponent c, final int x, final int y, final int w, final int h) {
12398
8e4c529b8184 7149913: [macosx] Deadlock in LWTextComponentPeer
serb
parents: 12396
diff changeset
   253
                    repaintPeer(SwingUtilities.convertRectangle(
8e4c529b8184 7149913: [macosx] Deadlock in LWTextComponentPeer
serb
parents: 12396
diff changeset
   254
                            c, new Rectangle(x, y, w, h), getDelegate()));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
            });
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
     * This method must be called under Toolkit.getDefaultToolkit() lock
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
     * and followed by setToolkitAWTEventListener()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
    protected final AWTEventListener getToolkitAWTEventListener() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
        return AccessController.doPrivileged(new PrivilegedAction<AWTEventListener>() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
            public AWTEventListener run() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
                Toolkit toolkit = Toolkit.getDefaultToolkit();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
                try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
                    Field field = Toolkit.class.getDeclaredField("eventListener");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
                    field.setAccessible(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
                    return (AWTEventListener) field.get(toolkit);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
                } catch (Exception e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
                    throw new InternalError(e.toString());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
        });
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
    protected final void setToolkitAWTEventListener(final AWTEventListener listener) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
            public Void run() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
                Toolkit toolkit = Toolkit.getDefaultToolkit();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
                try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
                    Field field = Toolkit.class.getDeclaredField("eventListener");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
                    field.setAccessible(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
                    field.set(toolkit, listener);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
                } catch (Exception e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
                    throw new InternalError(e.toString());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
                return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
        });
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
     * This method is called under getDelegateLock().
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
     * Overridden in subclasses.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
     */
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   299
    D createDelegate() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   303
    final D getDelegate() {
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   304
        return delegate;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   307
    /**
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   308
     * This method should be called under getDelegateLock().
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   309
     */
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   310
    Component getDelegateFocusOwner() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
        return getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   314
    /**
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   315
     * Initializes this peer. The call to initialize() is not placed to
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   316
     * LWComponentPeer ctor to let the subclass ctor to finish completely first.
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   317
     * Instead, it's the LWToolkit object who is responsible for initialization.
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   318
     * Note that we call setVisible() at the end of initialization.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
     */
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   320
    public final void initialize() {
13544
bd136eb2a932 7172187: [macosx] JAWT native CALayer not positioned over Canvas
serb
parents: 13233
diff changeset
   321
        platformComponent.initialize(getPlatformWindow());
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   322
        initializeImpl();
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   323
        setVisible(target.isVisible());
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   324
    }
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   325
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   326
    /**
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   327
     * Fetching general properties from the target. Should be overridden in
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   328
     * subclasses to initialize specific peers properties.
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   329
     */
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   330
    void initializeImpl() {
25196
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 24551
diff changeset
   331
        // note that these methods can be overridden by the user and
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 24551
diff changeset
   332
        // can return some strange values like null.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
        setBackground(target.getBackground());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
        setForeground(target.getForeground());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
        setFont(target.getFont());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
        setBounds(target.getBounds());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
        setEnabled(target.isEnabled());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
    private static void resetColorsAndFont(final Container c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
        c.setBackground(null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
        c.setForeground(null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
        c.setFont(null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
        for (int i = 0; i < c.getComponentCount(); i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
            resetColorsAndFont((Container) c.getComponent(i));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
    final Object getStateLock() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
        return stateLock;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   353
    /**
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   354
     * Synchronize all operations with the Swing delegates under AWT tree lock,
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   355
     * using a new separate lock to synchronize access to delegates may lead
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   356
     * deadlocks. Think of it as a 'virtual EDT'.
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   357
     *
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   358
     * @return DelegateLock
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   359
     */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
    final Object getDelegateLock() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
        return getTarget().getTreeLock();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   364
    protected static final Object getPeerTreeLock() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
        return peerTreeLock;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
16710
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15991
diff changeset
   368
    public final T getTarget() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
        return target;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
    // Just a helper method
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
    // Returns the window peer or null if this is a window peer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
    protected final LWWindowPeer getWindowPeer() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
        return windowPeer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
    // Returns the window peer or 'this' if this is a window peer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
    protected LWWindowPeer getWindowPeerOrSelf() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
        return getWindowPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
    // Just a helper method
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   384
    protected final LWContainerPeer<?, ?> getContainerPeer() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
        return containerPeer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
    public PlatformWindow getPlatformWindow() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
        LWWindowPeer windowPeer = getWindowPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
        return windowPeer.getPlatformWindow();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
    // ---- PEER METHODS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   394
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   395
    // Just a helper method
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   396
    public LWToolkit getLWToolkit() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   397
        return LWToolkit.getLWToolkit();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   398
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   399
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   400
    @Override
12639
c1634bcec0a8 7160623: [macosx] Editable TextArea/TextField are blocking GUI applications from exit
serb
parents: 12416
diff changeset
   401
    public final void dispose() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   402
        if (disposed.compareAndSet(false, true)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   403
            disposeImpl();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   405
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   406
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
    protected void disposeImpl() {
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   408
        destroyBuffers();
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   409
        LWContainerPeer<?, ?> cp = getContainerPeer();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
        if (cp != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
            cp.removeChildPeer(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
        platformComponent.dispose();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
        LWToolkit.targetDisposedPeer(getTarget(), this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   415
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
    public final boolean isDisposed() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
        return disposed.get();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
     * GraphicsConfiguration is borrowed from the parent peer. The
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
     * return value must not be null.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
     * Overridden in LWWindowPeer.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
    public GraphicsConfiguration getGraphicsConfiguration() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
        // Don't check windowPeer for null as it can only happen
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
        // for windows, but this method is overridden in
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
        // LWWindowPeer and doesn't call super()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
        return getWindowPeer().getGraphicsConfiguration();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   435
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   436
    // Just a helper method
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   437
    public final LWGraphicsConfig getLWGC() {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   438
        return (LWGraphicsConfig) getGraphicsConfiguration();
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   439
    }
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   440
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
     * Overridden in LWWindowPeer to replace its surface
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
     * data and back buffer.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
    public boolean updateGraphicsData(GraphicsConfiguration gc) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
//        throw new RuntimeException("Has not been implemented yet.");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   450
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   451
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
    @Override
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15327
diff changeset
   453
    public Graphics getGraphics() {
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   454
        final Graphics g = getOnscreenGraphics();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
        if (g != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
            synchronized (getPeerTreeLock()){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
                applyConstrain(g);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   458
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
        return g;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   463
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   464
     * Peer Graphics is borrowed from the parent peer, while
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
     * foreground and background colors and font are specific to
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
     * this peer.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   468
    public final Graphics getOnscreenGraphics() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   469
        final LWWindowPeer wp = getWindowPeerOrSelf();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   470
        return wp.getOnscreenGraphics(getForeground(), getBackground(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
                                      getFont());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   474
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   475
    private void applyConstrain(final Graphics g) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   476
        final SunGraphics2D sg2d = (SunGraphics2D) g;
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16710
diff changeset
   477
        final Rectangle size = localToWindow(getSize());
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16710
diff changeset
   478
        sg2d.constrain(size.x, size.y, size.width, size.height, getVisibleRegion());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   479
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   480
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   481
    Region getVisibleRegion() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
        return computeVisibleRect(this, getRegion());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   484
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   485
    static final Region computeVisibleRect(final LWComponentPeer<?, ?> c,
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   486
                                           Region region) {
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   487
        final LWContainerPeer<?, ?> p = c.getContainerPeer();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   488
        if (p != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   489
            final Rectangle r = c.getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   490
            region = region.getTranslatedRegion(r.x, r.y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   491
            region = region.getIntersection(p.getRegion());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   492
            region = region.getIntersection(p.getContentSize());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   493
            region = p.cutChildren(region, c);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   494
            region = computeVisibleRect(p, region);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   495
            region = region.getTranslatedRegion(-r.x, -r.y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   496
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   497
        return region;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   498
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   499
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   500
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   501
    public ColorModel getColorModel() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   502
        // Is it a correct implementation?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   503
        return getGraphicsConfiguration().getColorModel();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   504
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   505
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   506
    public boolean isTranslucent() {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   507
        // Translucent windows of the top level are supported only
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   508
        return false;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   509
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   510
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   511
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   512
    public final void createBuffers(int numBuffers, BufferCapabilities caps)
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   513
            throws AWTException {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   514
        getLWGC().assertOperationSupported(numBuffers, caps);
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   515
        final Image buffer = getLWGC().createBackBuffer(this);
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   516
        synchronized (getStateLock()) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   517
            backBuffer = buffer;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   518
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   519
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   520
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   521
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   522
    public final Image getBackBuffer() {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   523
        synchronized (getStateLock()) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   524
            if (backBuffer != null) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   525
                return backBuffer;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   526
            }
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   527
        }
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   528
        throw new IllegalStateException("Buffers have not been created");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   529
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   530
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   531
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   532
    public final void flip(int x1, int y1, int x2, int y2,
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   533
                     BufferCapabilities.FlipContents flipAction) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   534
        getLWGC().flip(this, getBackBuffer(), x1, y1, x2, y2, flipAction);
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   535
    }
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   536
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   537
    @Override
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   538
    public final void destroyBuffers() {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   539
        final Image oldBB;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   540
        synchronized (getStateLock()) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   541
            oldBB = backBuffer;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   542
            backBuffer = null;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   543
        }
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   544
        getLWGC().destroyBackBuffer(oldBB);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   545
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
    // Helper method
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   548
    public void setBounds(Rectangle r) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   549
        setBounds(r.x, r.y, r.width, r.height, SET_BOUNDS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   550
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   551
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   552
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   553
     * This method could be called on the toolkit thread.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   554
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   555
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   556
    public void setBounds(int x, int y, int w, int h, int op) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   557
        setBounds(x, y, w, h, op, true, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   558
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   559
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   560
    protected void setBounds(int x, int y, int w, int h, int op, boolean notify,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   561
                             final boolean updateTarget) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   562
        Rectangle oldBounds;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   563
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   564
            oldBounds = new Rectangle(bounds);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   565
            if ((op & (SET_LOCATION | SET_BOUNDS)) != 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   566
                bounds.x = x;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   567
                bounds.y = y;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   568
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   569
            if ((op & (SET_SIZE | SET_BOUNDS)) != 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   570
                bounds.width = w;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   571
                bounds.height = h;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   572
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   573
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   574
        boolean moved = (oldBounds.x != x) || (oldBounds.y != y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   575
        boolean resized = (oldBounds.width != w) || (oldBounds.height != h);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   576
        if (!moved && !resized) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   577
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   578
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   579
        final D delegate = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   580
        if (delegate != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   581
            synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   582
                delegateContainer.setBounds(0, 0, w, h);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   583
                delegate.setBounds(delegateContainer.getBounds());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   584
                // TODO: the following means that the delegateContainer NEVER gets validated. That's WRONG!
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   585
                delegate.validate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   586
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   587
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   588
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   589
        final Point locationInWindow = localToWindow(0, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   590
        platformComponent.setBounds(locationInWindow.x, locationInWindow.y, w,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   591
                                    h);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   592
        if (notify) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   593
            repaintOldNewBounds(oldBounds);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   594
            if (resized) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   595
                handleResize(w, h, updateTarget);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   596
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   597
            if (moved) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   598
                handleMove(x, y, updateTarget);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   599
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   600
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   601
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   602
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   603
    public final Rectangle getBounds() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   604
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   605
            // Return a copy to prevent subsequent modifications
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   606
            return bounds.getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   609
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   610
    public final Rectangle getSize() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   611
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   612
            // Return a copy to prevent subsequent modifications
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   613
            return new Rectangle(bounds.width, bounds.height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   614
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   615
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   616
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   617
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
    public Point getLocationOnScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
        Point windowLocation = getWindowPeer().getLocationOnScreen();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
        Point locationInWindow = localToWindow(0, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
        return new Point(windowLocation.x + locationInWindow.x,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   622
                windowLocation.y + locationInWindow.y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   623
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   624
12396
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   625
    /**
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   626
     * Returns the cursor of the peer, which is cursor of the target by default,
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   627
     * but peer can override this behavior.
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   628
     *
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   629
     * @param p Point relative to the peer.
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   630
     * @return Cursor of the peer or null if default cursor should be used.
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   631
     */
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   632
    Cursor getCursor(final Point p) {
12396
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   633
        return getTarget().getCursor();
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   634
    }
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
   635
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   636
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
    public void setBackground(final Color c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   638
        final Color oldBg = getBackground();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   639
        if (oldBg == c || (oldBg != null && oldBg.equals(c))) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   640
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   641
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   642
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   643
            background = c;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   644
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   645
        final D delegate = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   646
        if (delegate != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   647
            synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   648
                // delegate will repaint the target
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   649
                delegate.setBackground(c);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   650
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   651
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   652
            repaintPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   653
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   654
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   655
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   656
    public final Color getBackground() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   657
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   658
            return background;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   659
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   660
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   661
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   662
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   663
    public void setForeground(final Color c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   664
        final Color oldFg = getForeground();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   665
        if (oldFg == c || (oldFg != null && oldFg.equals(c))) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   666
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   667
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   668
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   669
            foreground = c;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   670
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   671
        final D delegate = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   672
        if (delegate != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   673
            synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   674
                // delegate will repaint the target
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   675
                delegate.setForeground(c);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   676
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   677
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   678
            repaintPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   679
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   680
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   681
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   682
    protected final Color getForeground() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   683
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   684
            return foreground;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   685
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   686
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   687
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   688
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   689
    public void setFont(final Font f) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   690
        final Font oldF = getFont();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   691
        if (oldF == f || (oldF != null && oldF.equals(f))) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   692
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   693
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   694
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   695
            font = f;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   696
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   697
        final D delegate = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   698
        if (delegate != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   699
            synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   700
                // delegate will repaint the target
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   701
                delegate.setFont(f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   702
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   703
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   704
            repaintPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   705
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   706
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   707
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   708
    protected final Font getFont() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   709
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   710
            return font;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   711
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   712
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   713
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   714
    @Override
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   715
    public FontMetrics getFontMetrics(final Font f) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   716
        // Borrow the metrics from the top-level window
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   717
//        return getWindowPeer().getFontMetrics(f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   718
        // Obtain the metrics from the offscreen window where this peer is
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   719
        // mostly drawn to.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   720
        // TODO: check for "use platform metrics" settings
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   721
        final Graphics g = getOnscreenGraphics();
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   722
        if (g != null) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   723
            try {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   724
                return g.getFontMetrics(f);
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   725
            } finally {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   726
                g.dispose();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   727
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   728
        }
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   729
        synchronized (getDelegateLock()) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   730
            return delegateContainer.getFontMetrics(f);
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   731
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   732
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   733
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   734
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   735
    public void setEnabled(final boolean e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   736
        boolean status = e;
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   737
        final LWComponentPeer<?, ?> cp = getContainerPeer();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   738
        if (cp != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   739
            status &= cp.isEnabled();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   740
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   741
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   742
            if (enabled == status) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   743
                return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   744
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   745
            enabled = status;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   746
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   747
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   748
        final D delegate = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   749
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   750
        if (delegate != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   751
            synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   752
                delegate.setEnabled(status);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   753
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   754
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   755
            repaintPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   756
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   757
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   758
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   759
    // Helper method
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   760
    public final boolean isEnabled() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   761
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   762
            return enabled;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   763
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   764
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   765
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   766
    @Override
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   767
    public void setVisible(final boolean v) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   768
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   769
            if (visible == v) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   770
                return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   771
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   772
            visible = v;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   773
        }
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   774
        setVisibleImpl(v);
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   775
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   776
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
   777
    protected void setVisibleImpl(final boolean v) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   778
        final D delegate = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   779
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   780
        if (delegate != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   781
            synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   782
                delegate.setVisible(v);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   783
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   784
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   785
        if (visible) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   786
            repaintPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   787
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   788
            repaintParent(getBounds());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   789
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   790
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   791
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   792
    // Helper method
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   793
    public final boolean isVisible() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   794
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   795
            return visible;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   796
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   797
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   798
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   799
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   800
    public void paint(final Graphics g) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   801
        getTarget().paint(g);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   802
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   803
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   804
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   805
    public void print(final Graphics g) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   806
        getTarget().print(g);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   807
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   808
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   809
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   810
    public void reparent(ContainerPeer newContainer) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   811
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   812
        throw new UnsupportedOperationException("ComponentPeer.reparent()");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   813
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   814
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   815
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   816
    public boolean isReparentSupported() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   817
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   818
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   819
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   820
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   821
    @Override
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   822
    public void setZOrder(final ComponentPeer above) {
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   823
        LWContainerPeer<?, ?> cp = getContainerPeer();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   824
        // Don't check containerPeer for null as it can only happen
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   825
        // for windows, but this method is overridden in
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   826
        // LWWindowPeer and doesn't call super()
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   827
        cp.setChildPeerZOrder(this, (LWComponentPeer<?, ?>) above);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   828
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   829
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   830
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   831
    public void coalescePaintEvent(PaintEvent e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   832
        if (!(e instanceof IgnorePaintEvent)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   833
            Rectangle r = e.getUpdateRect();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   834
            if ((r != null) && !r.isEmpty()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   835
                targetPaintArea.add(r, e.getID());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   836
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   837
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   838
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   839
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   840
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   841
     * Should be overridden in subclasses which use complex Swing components.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   842
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   843
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   844
    public void layout() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   845
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   846
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   847
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   848
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   849
    public boolean isObscured() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   850
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   851
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   852
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   853
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   854
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   855
    public boolean canDetermineObscurity() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   856
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   857
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   858
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   859
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   860
    /**
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   861
     * Determines the preferred size of the component. By default forwards the
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   862
     * request to the Swing helper component. Should be overridden in subclasses
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   863
     * if required.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   864
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   865
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   866
    public Dimension getPreferredSize() {
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   867
        final Dimension size;
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   868
        synchronized (getDelegateLock()) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   869
            size = getDelegate().getPreferredSize();
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   870
        }
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   871
        return validateSize(size);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   872
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   873
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   874
    /**
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   875
     * Determines the minimum size of the component. By default forwards the
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   876
     * request to the Swing helper component. Should be overridden in subclasses
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   877
     * if required.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   878
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   879
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   880
    public Dimension getMinimumSize() {
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   881
        final Dimension size;
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   882
        synchronized (getDelegateLock()) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   883
            size = getDelegate().getMinimumSize();
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   884
        }
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   885
        return validateSize(size);
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   886
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   887
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   888
    /**
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   889
     * In some situations delegates can return empty minimum/preferred size.
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   890
     * (For example: empty JLabel, etc), but awt components never should be
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   891
     * empty. In the XPeers or WPeers we use some magic constants, but here we
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   892
     * try to use something more useful,
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   893
     */
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   894
    private Dimension validateSize(final Dimension size) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   895
        if (size.width == 0 || size.height == 0) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   896
            final FontMetrics fm = getFontMetrics(getFont());
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   897
            size.width = fm.charWidth(WIDE_CHAR);
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   898
            size.height = fm.getHeight();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   899
        }
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13652
diff changeset
   900
        return size;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   901
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   902
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   903
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   904
    public void updateCursorImmediately() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   905
        getLWToolkit().getCursorManager().updateCursor();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   906
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   907
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   908
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   909
    public boolean isFocusable() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   910
        // Overridden in focusable subclasses like buttons
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   911
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   912
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   913
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   914
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   915
    public boolean requestFocus(Component lightweightChild, boolean temporary,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   916
                                boolean focusedWindowChangeAllowed, long time,
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 30469
diff changeset
   917
                                FocusEvent.Cause cause)
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   918
    {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17150
diff changeset
   919
        if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   920
            focusLog.finest("lightweightChild=" + lightweightChild + ", temporary=" + temporary +
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   921
                            ", focusedWindowChangeAllowed=" + focusedWindowChangeAllowed +
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   922
                            ", time= " + time + ", cause=" + cause);
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   923
        }
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
   924
        if (LWKeyboardFocusManagerPeer.processSynchronousLightweightTransfer(
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
   925
                getTarget(), lightweightChild, temporary,
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
   926
                focusedWindowChangeAllowed, time)) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   927
            return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   928
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   929
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
   930
        int result = LWKeyboardFocusManagerPeer.shouldNativelyFocusHeavyweight(
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
   931
                getTarget(), lightweightChild, temporary,
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
   932
                focusedWindowChangeAllowed, time, cause);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   933
        switch (result) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   934
            case LWKeyboardFocusManagerPeer.SNFH_FAILURE:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   935
                return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   936
            case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   937
                Window parentWindow = SunToolkit.getContainingWindow(getTarget());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   938
                if (parentWindow == null) {
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   939
                    focusLog.fine("request rejected, parentWindow is null");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   940
                    LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   941
                    return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   942
                }
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   943
                final LWWindowPeer parentPeer =
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 26037
diff changeset
   944
                        AWTAccessor.getComponentAccessor()
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 26037
diff changeset
   945
                                   .getPeer(parentWindow);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   946
                if (parentPeer == null) {
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   947
                    focusLog.fine("request rejected, parentPeer is null");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   948
                    LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   949
                    return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   950
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   951
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   952
                // A fix for 7145768. Ensure the parent window is currently natively focused.
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   953
                // The more evident place to perform this check is in KFM.shouldNativelyFocusHeavyweight,
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   954
                // however that is the shared code and this particular problem's reproducibility has
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   955
                // platform specifics. So, it was decided to narrow down the fix to lwawt (OSX) in
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   956
                // current release. TODO: consider fixing it in the shared code.
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   957
                if (!focusedWindowChangeAllowed) {
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   958
                    LWWindowPeer decoratedPeer = parentPeer.isSimpleWindow() ?
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   959
                        LWWindowPeer.getOwnerFrameDialog(parentPeer) : parentPeer;
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   960
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   961
                    if (decoratedPeer == null || !decoratedPeer.getPlatformWindow().isActive()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17150
diff changeset
   962
                        if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   963
                            focusLog.fine("request rejected, focusedWindowChangeAllowed==false, " +
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   964
                                          "decoratedPeer is inactive: " + decoratedPeer);
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   965
                        }
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   966
                        LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   967
                        return false;
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   968
                    }
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   969
                }
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   970
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   971
                boolean res = parentPeer.requestWindowFocus(cause);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   972
                // If parent window can be made focused and has been made focused (synchronously)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   973
                // then we can proceed with children, otherwise we retreat
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   974
                if (!res || !parentWindow.isFocused()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17150
diff changeset
   975
                    if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   976
                        focusLog.fine("request rejected, res= " + res + ", parentWindow.isFocused()=" +
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   977
                                      parentWindow.isFocused());
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12639
diff changeset
   978
                    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   979
                    LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   980
                    return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   981
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   982
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
   983
                KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
   984
                Component focusOwner = kfmPeer.getCurrentFocusOwner();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   985
                return LWKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   986
                        getTarget(), temporary,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   987
                        focusedWindowChangeAllowed,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   988
                        time, cause, focusOwner);
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
   989
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   990
            case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   991
                return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   992
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   993
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   994
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   995
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   996
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   997
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
   998
    public final Image createImage(final ImageProducer producer) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   999
        return new ToolkitImage(producer);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1000
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1001
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1002
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1003
    public final Image createImage(final int width, final int height) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1004
        return getLWGC().createAcceleratedImage(getTarget(), width, height);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1005
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1006
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1007
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1008
    public final VolatileImage createVolatileImage(final int w, final int h) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1009
        return new SunVolatileImage(getTarget(), w, h);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1010
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1011
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1012
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1013
    public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1014
        // TODO: is it a right/complete implementation?
20465
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20153
diff changeset
  1015
        return Toolkit.getDefaultToolkit().prepareImage(img, w, h, o);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1016
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1017
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1018
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1019
    public int checkImage(Image img, int w, int h, ImageObserver o) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1020
        // TODO: is it a right/complete implementation?
20465
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20153
diff changeset
  1021
        return Toolkit.getDefaultToolkit().checkImage(img, w, h, o);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1022
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1023
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1024
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1025
    public boolean handlesWheelScrolling() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1026
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1027
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1028
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1029
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1030
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1031
    public final void applyShape(final Region shape) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1032
        synchronized (getStateLock()) {
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1033
            if (region == shape || (region != null && region.equals(shape))) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1034
                return;
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1035
            }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1036
        }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1037
        applyShapeImpl(shape);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1038
    }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1039
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1040
    void applyShapeImpl(final Region shape) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1041
        synchronized (getStateLock()) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1042
            if (shape != null) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1043
                region = Region.WHOLE_REGION.getIntersection(shape);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1044
            } else {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1045
                region = null;
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1046
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1047
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1048
        repaintParent(getBounds());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1049
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1050
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1051
    protected final Region getRegion() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1052
        synchronized (getStateLock()) {
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1053
            return isShaped() ? region : Region.getInstance(getSize());
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1054
        }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1055
    }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1056
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1057
    public boolean isShaped() {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1058
        synchronized (getStateLock()) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1059
            return region != null;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1060
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1061
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1062
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1063
    // DropTargetPeer Method
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1064
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1065
    public void addDropTarget(DropTarget dt) {
12416
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1066
        LWWindowPeer winPeer = getWindowPeerOrSelf();
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1067
        if (winPeer != null && winPeer != this) {
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1068
            // We need to register the DropTarget in the
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1069
            // peer of the window ancestor of the component
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1070
            winPeer.addDropTarget(dt);
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1071
        } else {
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1072
            synchronized (dropTargetLock) {
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1073
                // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1074
                // if it's the first (or last) one for the component. Otherwise this call is a no-op.
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1075
                if (++fNumDropTargets == 1) {
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1076
                    // Having a non-null drop target would be an error but let's check just in case:
24551
cccf7dd14729 8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents: 21789
diff changeset
  1077
                    if (fDropTarget != null) {
cccf7dd14729 8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents: 21789
diff changeset
  1078
                        throw new IllegalStateException("Current drop target is not null");
cccf7dd14729 8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents: 21789
diff changeset
  1079
                    }
12416
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1080
                    // Create a new drop target:
24551
cccf7dd14729 8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents: 21789
diff changeset
  1081
                    fDropTarget = LWToolkit.getLWToolkit().createDropTarget(dt, target, this);
12416
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1082
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1083
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1084
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1085
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1086
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1087
    // DropTargetPeer Method
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1088
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1089
    public void removeDropTarget(DropTarget dt) {
12416
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1090
        LWWindowPeer winPeer = getWindowPeerOrSelf();
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1091
        if (winPeer != null && winPeer != this) {
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1092
            // We need to unregister the DropTarget in the
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1093
            // peer of the window ancestor of the component
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1094
            winPeer.removeDropTarget(dt);
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1095
        } else {
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1096
            synchronized (dropTargetLock){
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1097
                // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1098
                // if it's the first (or last) one for the component. Otherwise this call is a no-op.
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1099
                if (--fNumDropTargets == 0) {
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1100
                    // Having a null drop target would be an error but let's check just in case:
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1101
                    if (fDropTarget != null) {
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1102
                        // Dispose of the drop target:
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1103
                        fDropTarget.dispose();
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1104
                        fDropTarget = null;
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1105
                    } else
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1106
                        System.err.println("CComponent.removeDropTarget(): current drop target is null.");
7f39181f3c6e 7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents: 12398
diff changeset
  1107
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1108
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1109
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1110
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1111
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1112
    // ---- PEER NOTIFICATIONS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1113
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1114
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1115
     * Called when this peer's location has been changed either as a result
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1116
     * of target.setLocation() or as a result of user actions (window is
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1117
     * dragged with mouse).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1118
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1119
     * This method could be called on the toolkit thread.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1120
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1121
    protected final void handleMove(final int x, final int y,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1122
                                    final boolean updateTarget) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1123
        if (updateTarget) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1124
            AWTAccessor.getComponentAccessor().setLocation(getTarget(), x, y);
54874
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
  1125
            postEvent(new ComponentEvent(getTarget(),
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
  1126
                                         ComponentEvent.COMPONENT_MOVED));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1127
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1128
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1129
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1130
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1131
     * Called when this peer's size has been changed either as a result of
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1132
     * target.setSize() or as a result of user actions (window is resized).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1133
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1134
     * This method could be called on the toolkit thread.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1135
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1136
    protected final void handleResize(final int w, final int h,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1137
                                      final boolean updateTarget) {
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1138
        Image oldBB = null;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1139
        synchronized (getStateLock()) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1140
            if (backBuffer != null) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1141
                oldBB = backBuffer;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1142
                backBuffer = getLWGC().createBackBuffer(this);
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1143
            }
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1144
        }
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1145
        getLWGC().destroyBackBuffer(oldBB);
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13993
diff changeset
  1146
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1147
        if (updateTarget) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1148
            AWTAccessor.getComponentAccessor().setSize(getTarget(), w, h);
54874
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
  1149
            postEvent(new ComponentEvent(getTarget(),
631c31a5bf40 8144125: [macOS] java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
serb
parents: 51911
diff changeset
  1150
                                         ComponentEvent.COMPONENT_RESIZED));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1151
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1152
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1153
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1154
    protected final void repaintOldNewBounds(final Rectangle oldB) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1155
        repaintParent(oldB);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1156
        repaintPeer(getSize());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1157
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1158
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1159
    protected final void repaintParent(final Rectangle oldB) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1160
        final LWContainerPeer<?, ?> cp = getContainerPeer();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1161
        if (cp != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1162
            // Repaint unobscured part of the parent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1163
            cp.repaintPeer(cp.getContentSize().intersection(oldB));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1164
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1165
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1166
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1167
    // ---- EVENTS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1168
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1169
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1170
     * Post an event to the proper Java EDT.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1171
     */
21789
ebce9726e754 8027479: [macosx] Appletviewer is broken after 8014718
serb
parents: 20465
diff changeset
  1172
    public void postEvent(final AWTEvent event) {
ebce9726e754 8027479: [macosx] Appletviewer is broken after 8014718
serb
parents: 20465
diff changeset
  1173
        LWToolkit.postEvent(event);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1174
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1175
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1176
    protected void postPaintEvent(int x, int y, int w, int h) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1177
        // TODO: call getIgnoreRepaint() directly with the right ACC
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1178
        if (AWTAccessor.getComponentAccessor().getIgnoreRepaint(target)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1179
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1180
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1181
        PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1182
                createPaintEvent(getTarget(), x, y, w, h);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1183
        if (event != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1184
            postEvent(event);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1185
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1186
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1187
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1188
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1189
     * Gives a chance for the peer to handle the event after it's been
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1190
     * processed by the target.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1191
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1192
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1193
    public void handleEvent(AWTEvent e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1194
        if ((e instanceof InputEvent) && ((InputEvent) e).isConsumed()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1195
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1196
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1197
        switch (e.getID()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1198
            case FocusEvent.FOCUS_GAINED:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1199
            case FocusEvent.FOCUS_LOST:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1200
                handleJavaFocusEvent((FocusEvent) e);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1201
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1202
            case PaintEvent.PAINT:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1203
                // Got a native paint event
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1204
//                paintPending = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1205
                // fall through to the next statement
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1206
            case PaintEvent.UPDATE:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1207
                handleJavaPaintEvent();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1208
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1209
            case MouseEvent.MOUSE_PRESSED:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1210
                handleJavaMouseEvent((MouseEvent)e);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1211
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1212
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1213
        sendEventToDelegate(e);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1214
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1215
15327
37781d0e61b4 7132793: [macosx] setWheelScrollEnabled action reversed
alexp
parents: 14647
diff changeset
  1216
    protected void sendEventToDelegate(final AWTEvent e) {
15991
848515979585 7194902: [macosx] closed/java/awt/Button/DoubleActionEventTest/DoubleActionEventTest failed since jdk8b49
serb
parents: 15983
diff changeset
  1217
        if (getDelegate() == null || !isShowing() || !isEnabled()) {
848515979585 7194902: [macosx] closed/java/awt/Button/DoubleActionEventTest/DoubleActionEventTest failed since jdk8b49
serb
parents: 15983
diff changeset
  1218
            return;
848515979585 7194902: [macosx] closed/java/awt/Button/DoubleActionEventTest/DoubleActionEventTest failed since jdk8b49
serb
parents: 15983
diff changeset
  1219
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1220
        synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1221
            AWTEvent delegateEvent = createDelegateEvent(e);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1222
            if (delegateEvent != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1223
                AWTAccessor.getComponentAccessor()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1224
                        .processEvent((Component) delegateEvent.getSource(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1225
                                delegateEvent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1226
                if (delegateEvent instanceof KeyEvent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1227
                    KeyEvent ke = (KeyEvent) delegateEvent;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1228
                    SwingUtilities.processKeyBindings(ke);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1229
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1230
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1231
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1232
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1233
15991
848515979585 7194902: [macosx] closed/java/awt/Button/DoubleActionEventTest/DoubleActionEventTest failed since jdk8b49
serb
parents: 15983
diff changeset
  1234
    /**
848515979585 7194902: [macosx] closed/java/awt/Button/DoubleActionEventTest/DoubleActionEventTest failed since jdk8b49
serb
parents: 15983
diff changeset
  1235
     * Changes the target of the AWTEvent from awt component to appropriate
848515979585 7194902: [macosx] closed/java/awt/Button/DoubleActionEventTest/DoubleActionEventTest failed since jdk8b49
serb
parents: 15983
diff changeset
  1236
     * swing delegate.
848515979585 7194902: [macosx] closed/java/awt/Button/DoubleActionEventTest/DoubleActionEventTest failed since jdk8b49
serb
parents: 15983
diff changeset
  1237
     */
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 37694
diff changeset
  1238
    @SuppressWarnings("deprecation")
15991
848515979585 7194902: [macosx] closed/java/awt/Button/DoubleActionEventTest/DoubleActionEventTest failed since jdk8b49
serb
parents: 15983
diff changeset
  1239
    private AWTEvent createDelegateEvent(final AWTEvent e) {
848515979585 7194902: [macosx] closed/java/awt/Button/DoubleActionEventTest/DoubleActionEventTest failed since jdk8b49
serb
parents: 15983
diff changeset
  1240
        // TODO modifiers should be changed to getModifiers()|getModifiersEx()?
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1241
        AWTEvent delegateEvent = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1242
        if (e instanceof MouseWheelEvent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1243
            MouseWheelEvent me = (MouseWheelEvent) e;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1244
            delegateEvent = new MouseWheelEvent(
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1245
                    delegate, me.getID(), me.getWhen(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1246
                    me.getModifiers(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1247
                    me.getX(), me.getY(),
26032
a60a06edaf4e 8049533: SwingUtilities.convertMouseEvent misses MouseWheelEvent.preciseWheelRotation
alexsch
parents: 25196
diff changeset
  1248
                    me.getXOnScreen(), me.getYOnScreen(),
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1249
                    me.getClickCount(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1250
                    me.isPopupTrigger(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1251
                    me.getScrollType(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1252
                    me.getScrollAmount(),
26032
a60a06edaf4e 8049533: SwingUtilities.convertMouseEvent misses MouseWheelEvent.preciseWheelRotation
alexsch
parents: 25196
diff changeset
  1253
                    me.getWheelRotation(),
a60a06edaf4e 8049533: SwingUtilities.convertMouseEvent misses MouseWheelEvent.preciseWheelRotation
alexsch
parents: 25196
diff changeset
  1254
                    me.getPreciseWheelRotation());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1255
        } else if (e instanceof MouseEvent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1256
            MouseEvent me = (MouseEvent) e;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1257
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1258
            Component eventTarget = SwingUtilities.getDeepestComponentAt(delegate, me.getX(), me.getY());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1259
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1260
            if (me.getID() == MouseEvent.MOUSE_DRAGGED) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1261
                if (delegateDropTarget == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1262
                    delegateDropTarget = eventTarget;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1263
                } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1264
                    eventTarget = delegateDropTarget;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1265
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1266
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1267
            if (me.getID() == MouseEvent.MOUSE_RELEASED && delegateDropTarget != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1268
                eventTarget = delegateDropTarget;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1269
                delegateDropTarget = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1270
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1271
            if (eventTarget == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1272
                eventTarget = delegate;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1273
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1274
            delegateEvent = SwingUtilities.convertMouseEvent(getTarget(), me, eventTarget);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1275
        } else if (e instanceof KeyEvent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1276
            KeyEvent ke = (KeyEvent) e;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1277
            delegateEvent = new KeyEvent(getDelegateFocusOwner(), ke.getID(), ke.getWhen(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1278
                    ke.getModifiers(), ke.getKeyCode(), ke.getKeyChar(), ke.getKeyLocation());
20109
e568ad7e1bf3 8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents: 18178
diff changeset
  1279
            AWTAccessor.getKeyEventAccessor().setExtendedKeyCode((KeyEvent) delegateEvent,
e568ad7e1bf3 8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents: 18178
diff changeset
  1280
                    ke.getExtendedKeyCode());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1281
        } else if (e instanceof FocusEvent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1282
            FocusEvent fe = (FocusEvent) e;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1283
            delegateEvent = new FocusEvent(getDelegateFocusOwner(), fe.getID(), fe.isTemporary());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1284
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1285
        return delegateEvent;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1286
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1287
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1288
    protected void handleJavaMouseEvent(MouseEvent e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1289
        Component target = getTarget();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1290
        assert (e.getSource() == target);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1291
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1292
        if (!target.isFocusOwner() && LWKeyboardFocusManagerPeer.shouldFocusOnClick(target)) {
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 30469
diff changeset
  1293
            LWKeyboardFocusManagerPeer.requestFocusFor(target, FocusEvent.Cause.MOUSE_EVENT);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1294
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1295
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1296
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1297
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1298
     * Handler for FocusEvents.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1299
     */
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1300
    void handleJavaFocusEvent(final FocusEvent e) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1301
        // Note that the peer receives all the FocusEvents from
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1302
        // its lightweight children as well
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
  1303
        KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13544
diff changeset
  1304
        kfmPeer.setCurrentFocusOwner(e.getID() == FocusEvent.FOCUS_GAINED ? getTarget() : null);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1305
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1306
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1307
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1308
     * All peers should clear background before paint.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1309
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1310
     * @return false on components that DO NOT require a clearRect() before
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1311
     *         painting.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1312
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1313
    protected final boolean shouldClearRectBeforePaint() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1314
        // TODO: sun.awt.noerasebackground
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1315
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1316
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1317
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1318
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1319
     * Handler for PAINT and UPDATE PaintEvents.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1320
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1321
    private void handleJavaPaintEvent() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1322
        // Skip all painting while layouting and all UPDATEs
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1323
        // while waiting for native paint
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1324
//        if (!isLayouting && !paintPending) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1325
        if (!isLayouting()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1326
            targetPaintArea.paint(getTarget(), shouldClearRectBeforePaint());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1327
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1328
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1329
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1330
    // ---- UTILITY METHODS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1331
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1332
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1333
     * Finds a top-most visible component for the given point. The location is
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1334
     * specified relative to the peer's parent.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1335
     */
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1336
    LWComponentPeer<?, ?> findPeerAt(final int x, final int y) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1337
        final Rectangle r = getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1338
        final Region sh = getRegion();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1339
        final boolean found = isVisible() && sh.contains(x - r.x, y - r.y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1340
        return found ? this : null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1341
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1342
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1343
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1344
     * Translated the given point in Window coordinates to the point in
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1345
     * coordinates local to this component. The given window peer must be
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1346
     * the window where this component is in.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1347
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1348
    public Point windowToLocal(int x, int y, LWWindowPeer wp) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1349
        return windowToLocal(new Point(x, y), wp);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1350
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1351
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1352
    public Point windowToLocal(Point p, LWWindowPeer wp) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1353
        LWComponentPeer<?, ?> cp = this;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1354
        while (cp != wp) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1355
            Rectangle cpb = cp.getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1356
            p.x -= cpb.x;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1357
            p.y -= cpb.y;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1358
            cp = cp.getContainerPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1359
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1360
        // Return a copy to prevent subsequent modifications
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1361
        return new Point(p);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1362
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1363
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1364
    public Rectangle windowToLocal(Rectangle r, LWWindowPeer wp) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1365
        Point p = windowToLocal(r.getLocation(), wp);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1366
        return new Rectangle(p, r.getSize());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1367
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1368
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1369
    public Point localToWindow(int x, int y) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1370
        return localToWindow(new Point(x, y));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1371
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1372
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1373
    public Point localToWindow(Point p) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1374
        LWComponentPeer<?, ?> cp = getContainerPeer();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1375
        Rectangle r = getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1376
        while (cp != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1377
            p.x += r.x;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1378
            p.y += r.y;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1379
            r = cp.getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1380
            cp = cp.getContainerPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1381
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1382
        // Return a copy to prevent subsequent modifications
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1383
        return new Point(p);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1384
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1385
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1386
    public Rectangle localToWindow(Rectangle r) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1387
        Point p = localToWindow(r.getLocation());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1388
        return new Rectangle(p, r.getSize());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1389
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1390
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1391
    public final void repaintPeer() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1392
        repaintPeer(getSize());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1393
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1394
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1395
    void repaintPeer(final Rectangle r) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1396
        final Rectangle toPaint = getSize().intersection(r);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1397
        if (!isShowing() || toPaint.isEmpty()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1398
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1399
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1400
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1401
        postPaintEvent(toPaint.x, toPaint.y, toPaint.width, toPaint.height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1402
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1403
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1404
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1405
     * Determines whether this peer is showing on screen. This means that the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1406
     * peer must be visible, and it must be in a container that is visible and
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1407
     * showing.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1408
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1409
     * @see #isVisible()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1410
     */
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12667
diff changeset
  1411
    protected final boolean isShowing() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1412
        synchronized (getPeerTreeLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1413
            if (isVisible()) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1414
                final LWContainerPeer<?, ?> container = getContainerPeer();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1415
                return (container == null) || container.isShowing();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1416
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1417
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1418
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1419
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1420
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1421
    /**
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1422
     * Paints the peer. Delegate the actual painting to Swing components.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1423
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1424
    protected final void paintPeer(final Graphics g) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1425
        final D delegate = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1426
        if (delegate != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1427
            if (!SwingUtilities.isEventDispatchThread()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1428
                throw new InternalError("Painting must be done on EDT");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1429
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1430
            synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1431
                // JComponent.print() is guaranteed to not affect the double buffer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1432
                getDelegate().print(g);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1433
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1434
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1435
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1436
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1437
    protected static final void flushOnscreenGraphics(){
57196
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1438
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1439
        // Check for metal
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1440
        boolean isMetal = false;
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1441
        String str = System.getProperty("sun.java2d.metal");
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1442
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1443
        if (str != null) {
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1444
           //System.out.println("Property : sun.java2d.metal=" + str);
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1445
            if (str.equals("true")) {
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1446
                isMetal = true;
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1447
            }
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1448
        }
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1449
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1450
        if (isMetal) {
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1451
            final MetalRenderQueue rq = MetalRenderQueue.getInstance();
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1452
            rq.lock();
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1453
            try {
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1454
                rq.flushNow();
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1455
            } finally {
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1456
                rq.unlock();
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1457
            }
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1458
        } else {
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1459
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1460
            final OGLRenderQueue rq = OGLRenderQueue.getInstance();
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1461
            rq.lock();
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1462
            try {
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1463
                rq.flushNow();
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1464
            } finally {
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1465
                rq.unlock();
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1466
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1467
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1468
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1469
57196
a95707a39ff5 Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents: 51911
diff changeset
  1470
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1471
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1472
     * Used by ContainerPeer to skip all the paint events during layout.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1473
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1474
     * @param isLayouting layouting state.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1475
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1476
    protected final void setLayouting(final boolean isLayouting) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1477
        this.isLayouting = isLayouting;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1478
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1479
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1480
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1481
     * Returns layouting state. Used by ComponentPeer to skip all the paint
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1482
     * events during layout.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1483
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1484
     * @return true during layout, false otherwise.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1485
     */
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47216
diff changeset
  1486
    private boolean isLayouting() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1487
        return isLayouting;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1488
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1489
}