jdk/src/solaris/classes/sun/awt/X11/XDropTargetEventProcessor.java
author dcherepanov
Thu, 12 Feb 2009 18:24:35 +0300
changeset 2453 35e5fab82613
parent 439 3488710b02f8
child 5506 202f599c92aa
permissions -rw-r--r--
6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start Reviewed-by: art, ant
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This class is a registry for the supported drag and drop protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
final class XDropTargetEventProcessor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private static final XDropTargetEventProcessor theInstance =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        new XDropTargetEventProcessor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private static boolean active = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    // The current drop protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private XDropTargetProtocol protocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private XDropTargetEventProcessor() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private boolean doProcessEvent(XEvent ev) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
    46
        if (ev.get_type() == (int)XConstants.DestroyNotify &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            protocol != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            ev.get_xany().get_window() == protocol.getSourceWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            protocol.cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            protocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
    54
        if (ev.get_type() == (int)XConstants.PropertyNotify) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            XPropertyEvent xproperty = ev.get_xproperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            if (xproperty.get_atom() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                XDropTargetRegistry.getRegistry().updateEmbedderDropSite(xproperty.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
    63
        if (ev.get_type() != (int)XConstants.ClientMessage) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        boolean processed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        XClientMessageEvent xclient = ev.get_xclient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        XDropTargetProtocol curProtocol = protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        if (protocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            if (protocol.getMessageType(xclient) !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                XDropTargetProtocol.UNKNOWN_MESSAGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                processed = protocol.processClientMessage(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                protocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (protocol == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            Iterator dropTargetProtocols =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                XDragAndDropProtocols.getDropTargetProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            while (dropTargetProtocols.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                XDropTargetProtocol dropTargetProtocol =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    (XDropTargetProtocol)dropTargetProtocols.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                // Don't try to process it again with the current protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                if (dropTargetProtocol == curProtocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                if (dropTargetProtocol.getMessageType(xclient) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    XDropTargetProtocol.UNKNOWN_MESSAGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                protocol = dropTargetProtocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                processed = protocol.processClientMessage(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return processed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    static void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        theInstance.protocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    static void activate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        active = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // Fix for 4915454 - do not call doProcessEvent() until the first drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // target is registered to avoid premature loading of DnD protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    static boolean processEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return active ? theInstance.doProcessEvent(ev) : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
}