Path: blob/master/src/java.desktop/unix/classes/sun/awt/X11/XDragAndDropProtocols.java
41159 views
/*1* Copyright (c) 2003, 2007, 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.ArrayList;28import java.util.Collections;29import java.util.Iterator;30import java.util.List;3132/**33* This class is a registry for the supported drag and drop protocols.34*35* @since 1.536*/37final class XDragAndDropProtocols {38private static final List<XDragSourceProtocol> dragProtocols;39private static final List<XDropTargetProtocol> dropProtocols;4041public static final String XDnD = "XDnD";42public static final String MotifDnD = "MotifDnD";4344static {45// Singleton listener for all drag source protocols.46XDragSourceProtocolListener dragSourceProtocolListener =47XDragSourceContextPeer.getXDragSourceProtocolListener();48// Singleton listener for all drop target protocols.49XDropTargetProtocolListener dropTargetProtocolListener =50XDropTargetContextPeer.getXDropTargetProtocolListener();5152List<XDragSourceProtocol> tDragSourceProtocols = new ArrayList<>();53XDragSourceProtocol xdndDragSourceProtocol =54XDnDDragSourceProtocol.createInstance(dragSourceProtocolListener);55tDragSourceProtocols.add(xdndDragSourceProtocol);56XDragSourceProtocol motifdndDragSourceProtocol =57MotifDnDDragSourceProtocol.createInstance(dragSourceProtocolListener);58tDragSourceProtocols.add(motifdndDragSourceProtocol);5960List<XDropTargetProtocol> tDropTargetProtocols = new ArrayList<>();61XDropTargetProtocol xdndDropTargetProtocol =62XDnDDropTargetProtocol.createInstance(dropTargetProtocolListener);63tDropTargetProtocols.add(xdndDropTargetProtocol);64XDropTargetProtocol motifdndDropTargetProtocol =65MotifDnDDropTargetProtocol.createInstance(dropTargetProtocolListener);66tDropTargetProtocols.add(motifdndDropTargetProtocol);6768dragProtocols = Collections.unmodifiableList(tDragSourceProtocols);69dropProtocols = Collections.unmodifiableList(tDropTargetProtocols);70}7172static Iterator<XDragSourceProtocol> getDragSourceProtocols() {73return dragProtocols.iterator();74}7576static Iterator<XDropTargetProtocol> getDropTargetProtocols() {77return dropProtocols.iterator();78}7980/*81* Returns a XDragSourceProtocol whose name equals to the specified string82* or null if no such protocol is registered.83*/84public static XDragSourceProtocol getDragSourceProtocol(String name) {85// Protocol name cannot be null.86if (name == null) {87return null;88}8990Iterator<XDragSourceProtocol> dragProtocols =91XDragAndDropProtocols.getDragSourceProtocols();92while (dragProtocols.hasNext()) {93XDragSourceProtocol dragProtocol = dragProtocols.next();94if (dragProtocol.getProtocolName().equals(name)) {95return dragProtocol;96}97}9899return null;100}101102/*103* Returns a XDropTargetProtocol which name equals to the specified string104* or null if no such protocol is registered.105*/106public static XDropTargetProtocol getDropTargetProtocol(String name) {107// Protocol name cannot be null.108if (name == null) {109return null;110}111112Iterator<XDropTargetProtocol> dropProtocols =113XDragAndDropProtocols.getDropTargetProtocols();114while (dropProtocols.hasNext()) {115XDropTargetProtocol dropProtocol = dropProtocols.next();116if (dropProtocol.getProtocolName().equals(name)) {117return dropProtocol;118}119}120121return null;122}123}124125126