001: /*
002: * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.X11;
027:
028: import java.util.Iterator;
029:
030: /**
031: * This class is a registry for the supported drag and drop protocols.
032: *
033: * @since 1.5
034: */
035: final class XDropTargetEventProcessor {
036: private static final XDropTargetEventProcessor theInstance = new XDropTargetEventProcessor();
037: private static boolean active = false;
038:
039: // The current drop protocol.
040: private XDropTargetProtocol protocol = null;
041:
042: private XDropTargetEventProcessor() {
043: }
044:
045: private boolean doProcessEvent(XEvent ev) {
046: if (ev.get_type() == (int) XlibWrapper.DestroyNotify
047: && protocol != null
048: && ev.get_xany().get_window() == protocol
049: .getSourceWindow()) {
050: protocol.cleanup();
051: protocol = null;
052: return false;
053: }
054:
055: if (ev.get_type() == (int) XlibWrapper.PropertyNotify) {
056: XPropertyEvent xproperty = ev.get_xproperty();
057: if (xproperty.get_atom() == MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO
058: .getAtom()) {
059:
060: XDropTargetRegistry.getRegistry()
061: .updateEmbedderDropSite(xproperty.get_window());
062: }
063: }
064:
065: if (ev.get_type() != (int) XlibWrapper.ClientMessage) {
066: return false;
067: }
068:
069: boolean processed = false;
070: XClientMessageEvent xclient = ev.get_xclient();
071:
072: XDropTargetProtocol curProtocol = protocol;
073:
074: if (protocol != null) {
075: if (protocol.getMessageType(xclient) != XDropTargetProtocol.UNKNOWN_MESSAGE) {
076: processed = protocol.processClientMessage(xclient);
077: } else {
078: protocol = null;
079: }
080: }
081:
082: if (protocol == null) {
083: Iterator dropTargetProtocols = XDragAndDropProtocols
084: .getDropTargetProtocols();
085:
086: while (dropTargetProtocols.hasNext()) {
087: XDropTargetProtocol dropTargetProtocol = (XDropTargetProtocol) dropTargetProtocols
088: .next();
089: // Don't try to process it again with the current protocol.
090: if (dropTargetProtocol == curProtocol) {
091: continue;
092: }
093:
094: if (dropTargetProtocol.getMessageType(xclient) == XDropTargetProtocol.UNKNOWN_MESSAGE) {
095: continue;
096: }
097:
098: protocol = dropTargetProtocol;
099: processed = protocol.processClientMessage(xclient);
100: break;
101: }
102: }
103:
104: return processed;
105: }
106:
107: static void reset() {
108: theInstance.protocol = null;
109: }
110:
111: static void activate() {
112: active = true;
113: }
114:
115: // Fix for 4915454 - do not call doProcessEvent() until the first drop
116: // target is registered to avoid premature loading of DnD protocol
117: // classes.
118: static boolean processEvent(XEvent ev) {
119: return active ? theInstance.doProcessEvent(ev) : false;
120: }
121: }
|