package com.bbn.openmap.tools.dnd; import java.awt.dnd.DragGestureEvent; import java.awt.dnd.DragGestureListener; import java.awt.dnd.DragSourceListener; import java.awt.dnd.InvalidDnDOperationException; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import com.bbn.openmap.util.Debug; /** * A DragGestureListener that supports multiple catchers. * * @author matt * @author last modified by $Author$ * @version $Revision$ $Date$ */ public class MultiCatcherDragGestureListener implements DragGestureListener { protected DragSourceListener dsl; // Supported catchers must subclass DefaultDnDCatcher as it includes the method // dragGestureRecognized. Perhaps this method should be elevated to the // DNDListener to allow a more generic DragGestureListener? TODO protected List dndCatchers = new LinkedList(); // Debug flag used for draggesture debugging. Could be "draggesturelistener" // per the single catcher implementation. public final static String DEBUG_DRAG = "dnd"; /** * Note that DefaultDnDCatcher is a DragSourceListener itself, so dndCatcher and dsl can be the * same object. */ public MultiCatcherDragGestureListener(DragSourceListener dsl) { this.dsl = dsl; Debug.message(DEBUG_DRAG, "Constructor: MultiCatcherDragGestureListener"); } public void addCatcher(DefaultDnDCatcher catcher) { dndCatchers.add(catcher); } /** * A DragGestureRecognizer has detected a platform-dependent drag initiating * gesture and is notifying this listener in order for it to initiate the action for the user. *

* * @param dge the DragGestureEvent describing the gesture that has just occurred */ public void dragGestureRecognized(DragGestureEvent dge) { Debug.message(DEBUG_DRAG, "MultiCatcherDragGestureListener dragGestureRecognized"); for (Iterator catcher = dndCatchers.iterator(); catcher.hasNext();) { DefaultDnDCatcher c = (DefaultDnDCatcher) catcher.next(); try { c.startDragAction(dge, dsl); } catch (InvalidDnDOperationException idoe) { Debug.message(DEBUG_DRAG, "MultiCatcherDragGestureListener InvalidDnDOperationException"); } } } }