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.ArrayList;
029: import java.util.Collections;
030: import java.util.Iterator;
031: import java.util.List;
032:
033: /**
034: * This class is a registry for the supported drag and drop protocols.
035: *
036: * @since 1.5
037: */
038: final class XDragAndDropProtocols {
039: private final static List dragProtocols;
040: private final static List dropProtocols;
041:
042: public static final String XDnD = "XDnD";
043: public static final String MotifDnD = "MotifDnD";
044:
045: static {
046: // Singleton listener for all drag source protocols.
047: XDragSourceProtocolListener dragSourceProtocolListener = XDragSourceContextPeer
048: .getXDragSourceProtocolListener();
049: // Singleton listener for all drop target protocols.
050: XDropTargetProtocolListener dropTargetProtocolListener = XDropTargetContextPeer
051: .getXDropTargetProtocolListener();
052:
053: List tDragSourceProtocols = new ArrayList();
054: XDragSourceProtocol xdndDragSourceProtocol = XDnDDragSourceProtocol
055: .createInstance(dragSourceProtocolListener);
056: tDragSourceProtocols.add(xdndDragSourceProtocol);
057: XDragSourceProtocol motifdndDragSourceProtocol = MotifDnDDragSourceProtocol
058: .createInstance(dragSourceProtocolListener);
059: tDragSourceProtocols.add(motifdndDragSourceProtocol);
060:
061: List tDropTargetProtocols = new ArrayList();
062: XDropTargetProtocol xdndDropTargetProtocol = XDnDDropTargetProtocol
063: .createInstance(dropTargetProtocolListener);
064: tDropTargetProtocols.add(xdndDropTargetProtocol);
065: XDropTargetProtocol motifdndDropTargetProtocol = MotifDnDDropTargetProtocol
066: .createInstance(dropTargetProtocolListener);
067: tDropTargetProtocols.add(motifdndDropTargetProtocol);
068:
069: dragProtocols = Collections
070: .unmodifiableList(tDragSourceProtocols);
071: dropProtocols = Collections
072: .unmodifiableList(tDropTargetProtocols);
073: }
074:
075: static Iterator getDragSourceProtocols() {
076: return dragProtocols.iterator();
077: }
078:
079: static Iterator getDropTargetProtocols() {
080: return dropProtocols.iterator();
081: }
082:
083: /*
084: * Returns a XDragSourceProtocol whose name equals to the specified string
085: * or null if no such protocol is registered.
086: */
087: public static XDragSourceProtocol getDragSourceProtocol(String name) {
088: // Protocol name cannot be null.
089: if (name == null) {
090: return null;
091: }
092:
093: Iterator dragProtocols = XDragAndDropProtocols
094: .getDragSourceProtocols();
095: while (dragProtocols.hasNext()) {
096: XDragSourceProtocol dragProtocol = (XDragSourceProtocol) dragProtocols
097: .next();
098: if (dragProtocol.getProtocolName().equals(name)) {
099: return dragProtocol;
100: }
101: }
102:
103: return null;
104: }
105:
106: /*
107: * Returns a XDropTargetProtocol which name equals to the specified string
108: * or null if no such protocol is registered.
109: */
110: public static XDropTargetProtocol getDropTargetProtocol(String name) {
111: // Protocol name cannot be null.
112: if (name == null) {
113: return null;
114: }
115:
116: Iterator dropProtocols = XDragAndDropProtocols
117: .getDropTargetProtocols();
118: while (dropProtocols.hasNext()) {
119: XDropTargetProtocol dropProtocol = (XDropTargetProtocol) dropProtocols
120: .next();
121: if (dropProtocol.getProtocolName().equals(name)) {
122: return dropProtocol;
123: }
124: }
125:
126: return null;
127: }
128: }
|