jdk/src/macosx/classes/sun/lwawt/LWChoicePeer.java
author mcherkas
Mon, 28 Jul 2014 16:09:26 +0400
changeset 26008 ccab11700f07
parent 24565 b63e70ae575d
permissions -rw-r--r--
8047288: Fixes endless loop on mac caused by invoking Windows.isFocusable() on Appkit thread. Reviewed-by: ant, pchelko Contributed-by: artem.malinko@oracle.com
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
/*
20146
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
     2
 * Copyright (c) 2011, 2013, 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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
package sun.lwawt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
20146
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
    29
import java.awt.*;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
import java.awt.event.ItemEvent;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
import java.awt.event.ItemListener;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
import java.awt.peer.ChoicePeer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
20146
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
    34
import javax.accessibility.Accessible;
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
    35
import javax.swing.*;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20146
diff changeset
    37
/**
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20146
diff changeset
    38
 * Lightweight implementation of {@link ChoicePeer}. Delegates most of the work
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20146
diff changeset
    39
 * to the {@link JComboBox}.
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20146
diff changeset
    40
 */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
        implements ChoicePeer, ItemListener {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
     * According to Choice specification item events are sent in response to
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
     * user input, but not in response to calls to select(). But JComboBox are
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
     * sent item events in both cases. Should be used under delegateLock.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
    private boolean skipPostMessage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
    LWChoicePeer(final Choice target,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
                 final PlatformComponent platformComponent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
        super(target, platformComponent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
    @Override
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20146
diff changeset
    57
    JComboBox<String> createDelegate() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
        return new JComboBoxDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    @Override
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12047
diff changeset
    62
    void initializeImpl() {
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12047
diff changeset
    63
        super.initializeImpl();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
        final Choice choice = getTarget();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
        final JComboBox<String> combo = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
        synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
            final int count = choice.getItemCount();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
            for (int i = 0; i < count; ++i) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
                combo.addItem(choice.getItem(i));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
            select(choice.getSelectedIndex());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
            // NOTE: the listener must be added at the very end, otherwise it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
            // fires events upon initialization of the combo box.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
            combo.addItemListener(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    public void itemStateChanged(final ItemEvent e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
        // AWT Choice sends SELECTED event only whereas JComboBox
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
        // sends both SELECTED and DESELECTED.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
        if (e.getStateChange() == ItemEvent.SELECTED) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
            synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
                if (skipPostMessage) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
                    return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
                getTarget().select(getDelegate().getSelectedIndex());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
            postEvent(new ItemEvent(getTarget(), ItemEvent.ITEM_STATE_CHANGED,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
                                    e.getItem(), ItemEvent.SELECTED));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    public void add(final String item, final int index) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
        synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
            getDelegate().insertItemAt(item, index);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    public void remove(final int index) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
        synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
            // We shouldn't post event, if selected item was removed.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
            skipPostMessage = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
            getDelegate().removeItemAt(index);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
            skipPostMessage = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
    public void removeAll() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
        synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
            getDelegate().removeAllItems();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    public void select(final int index) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
        synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
            if (index != getDelegate().getSelectedIndex()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
                skipPostMessage = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
                getDelegate().setSelectedIndex(index);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
                skipPostMessage = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
            }
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
    public boolean isFocusable() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20146
diff changeset
   135
    @SuppressWarnings("serial")// Safe: outer class is non-serializable.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
    private final class JComboBoxDelegate extends JComboBox<String> {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
        // Empty non private constructor was added because access to this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
        // class shouldn't be emulated by a synthetic accessor method.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
        JComboBoxDelegate() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
            super();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
        @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
        public boolean hasFocus() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
            return getTarget().hasFocus();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
        //Needed for proper popup menu location
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
        @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
        public Point getLocationOnScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
            return LWChoicePeer.this.getLocationOnScreen();
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
        /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
         * We should post ITEM_STATE_CHANGED event when the same element is
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
         * reselected.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
         */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
        @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
        public void setSelectedItem(final Object anObject) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
            final Object oldSelection = selectedItemReminder;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
            if (oldSelection != null && oldSelection.equals(anObject)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
                selectedItemChanged();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
            super.setSelectedItem(anObject);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
        }
20146
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   167
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   168
        @Override
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   169
        public void firePopupMenuWillBecomeVisible() {
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   170
            super.firePopupMenuWillBecomeVisible();
23246
c85233c6357c 7159566: The choice positioned in the top of applet when clicking the choice.
pchelko
parents: 20153
diff changeset
   171
            SwingUtilities.invokeLater(() -> {
c85233c6357c 7159566: The choice positioned in the top of applet when clicking the choice.
pchelko
parents: 20153
diff changeset
   172
                JPopupMenu popupMenu = getPopupMenu();
c85233c6357c 7159566: The choice positioned in the top of applet when clicking the choice.
pchelko
parents: 20153
diff changeset
   173
                // Need to override the invoker for proper grab handling
24565
b63e70ae575d 8041896: Test closed/java/awt/Choice/RemoveAllShrinkTest/RemoveAllShrinkTest fails with java.awt.IllegalComponentStateException
azvegint
parents: 23246
diff changeset
   174
                if (popupMenu != null
b63e70ae575d 8041896: Test closed/java/awt/Choice/RemoveAllShrinkTest/RemoveAllShrinkTest fails with java.awt.IllegalComponentStateException
azvegint
parents: 23246
diff changeset
   175
                        && popupMenu.isShowing()
b63e70ae575d 8041896: Test closed/java/awt/Choice/RemoveAllShrinkTest/RemoveAllShrinkTest fails with java.awt.IllegalComponentStateException
azvegint
parents: 23246
diff changeset
   176
                        && popupMenu.getInvoker() != getTarget()) {
23246
c85233c6357c 7159566: The choice positioned in the top of applet when clicking the choice.
pchelko
parents: 20153
diff changeset
   177
                    // The popup is now visible with correct location
c85233c6357c 7159566: The choice positioned in the top of applet when clicking the choice.
pchelko
parents: 20153
diff changeset
   178
                    // Save it and restore after toggling visibility and changing invoker
c85233c6357c 7159566: The choice positioned in the top of applet when clicking the choice.
pchelko
parents: 20153
diff changeset
   179
                    Point loc = popupMenu.getLocationOnScreen();
c85233c6357c 7159566: The choice positioned in the top of applet when clicking the choice.
pchelko
parents: 20153
diff changeset
   180
                    SwingUtilities.convertPointFromScreen(loc, this);
c85233c6357c 7159566: The choice positioned in the top of applet when clicking the choice.
pchelko
parents: 20153
diff changeset
   181
                    popupMenu.setVisible(false);
c85233c6357c 7159566: The choice positioned in the top of applet when clicking the choice.
pchelko
parents: 20153
diff changeset
   182
                    popupMenu.show(getTarget(), loc.x, loc.y);
20146
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   183
                }
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   184
            });
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   185
        }
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   186
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   187
        private JPopupMenu getPopupMenu() {
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   188
            for (int i = 0; i < getAccessibleContext().getAccessibleChildrenCount(); i++) {
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   189
                Accessible child = getAccessibleContext().getAccessibleChild(i);
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   190
                if (child instanceof JPopupMenu) {
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   191
                    return  (JPopupMenu) child;
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   192
                }
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   193
            }
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   194
            return null;
019d103c3e40 7144065: [macosx] Orphaned Choice popup window
leonidr
parents: 13143
diff changeset
   195
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
}