Path: blob/master/src/java.desktop/unix/classes/sun/awt/X11/XDropTargetEventProcessor.java
41159 views
/*1* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt.X11;2627import java.util.Iterator;2829/**30* This class is a registry for the supported drag and drop protocols.31*32* @since 1.533*/34final class XDropTargetEventProcessor {35private static final XDropTargetEventProcessor theInstance =36new XDropTargetEventProcessor();37private static boolean active = false;3839// The current drop protocol.40private XDropTargetProtocol protocol = null;4142private XDropTargetEventProcessor() {}4344private boolean doProcessEvent(XEvent ev) {45if (ev.get_type() == XConstants.DestroyNotify &&46protocol != null &&47ev.get_xany().get_window() == protocol.getSourceWindow()) {48protocol.cleanup();49protocol = null;50return false;51}5253if (ev.get_type() == XConstants.PropertyNotify) {54XPropertyEvent xproperty = ev.get_xproperty();55if (xproperty.get_atom() ==56MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom()) {5758XDropTargetRegistry.getRegistry().updateEmbedderDropSite(xproperty.get_window());59}60}6162if (ev.get_type() != XConstants.ClientMessage) {63return false;64}6566boolean processed = false;67XClientMessageEvent xclient = ev.get_xclient();6869XDropTargetProtocol curProtocol = protocol;7071if (protocol != null) {72if (protocol.getMessageType(xclient) !=73XDropTargetProtocol.UNKNOWN_MESSAGE) {74processed = protocol.processClientMessage(xclient);75} else {76protocol = null;77}78}7980if (protocol == null) {81Iterator<XDropTargetProtocol> dropTargetProtocols =82XDragAndDropProtocols.getDropTargetProtocols();8384while (dropTargetProtocols.hasNext()) {85XDropTargetProtocol dropTargetProtocol = dropTargetProtocols.next();86// Don't try to process it again with the current protocol.87if (dropTargetProtocol == curProtocol) {88continue;89}9091if (dropTargetProtocol.getMessageType(xclient) ==92XDropTargetProtocol.UNKNOWN_MESSAGE) {93continue;94}9596protocol = dropTargetProtocol;97processed = protocol.processClientMessage(xclient);98break;99}100}101102return processed;103}104105static void reset() {106theInstance.protocol = null;107}108109static void activate() {110active = true;111}112113// Fix for 4915454 - do not call doProcessEvent() until the first drop114// target is registered to avoid premature loading of DnD protocol115// classes.116static boolean processEvent(XEvent ev) {117return active ? theInstance.doProcessEvent(ev) : false;118}119}120121122