Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

DraggableList.java

00001 package edu.ksu.cis.bandera.pdgslicer.dependency;
00002 
00003 /**
00004  * This is an example of a component, which serves as a DragSource as 
00005  * well as Drop Target.
00006  * To illustrate the concept, JList has been used as a droppable target
00007  * and a draggable source.
00008  * Any component can be used instead of a JList.
00009  * The code also contains debugging messages which can be used for 
00010  * diagnostics and understanding the flow of events.
00011  * 
00012  * @version 1.0
00013  */
00014 
00015 import java.awt.*;
00016 import java.awt.dnd.*;
00017 import java.awt.datatransfer.*;
00018 
00019 import java.util.Hashtable;
00020 import java.util.List;
00021 import java.util.Iterator;
00022 
00023 import java.io.*;
00024 import java.io.IOException;
00025 
00026 import javax.swing.JList;
00027 import javax.swing.DefaultListModel;
00028 
00029 
00030 
00031 
00032 public abstract class DraggableList extends JList
00033     implements DragSourceListener, DragGestureListener    {
00034 
00035 
00036   /**
00037    * enables this component to be a Drag Source
00038    */
00039   DragSource dragSource = null;
00040 
00041     static Transferable currentDraggingListNode = null;
00042 /**
00043    * constructor - initializes the DropTarget and DragSource.
00044    */
00045 
00046 public DraggableList() {
00047     dragSource = new DragSource();
00048     setModel(new DefaultListModel());
00049     dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
00050 }
00051   /**
00052    * this message goes to DragSourceListener, informing it that the dragging 
00053    * has ended
00054    * 
00055    */
00056 
00057   public void dragDropEnd (DragSourceDropEvent event) {
00058       /*
00059     if ( event.getDropSuccess()){
00060         removeElement();
00061     }
00062     */
00063     currentDraggingListNode = null;
00064   }  
00065   /**
00066    * this message goes to DragSourceListener, informing it that the dragging 
00067    * has entered the DropSite
00068    * 
00069    */
00070 
00071   public void dragEnter (DragSourceDragEvent event) {
00072     //System.out.println( " dragEnter");
00073   }  
00074   /**
00075    * this message goes to DragSourceListener, informing it that the dragging 
00076    * has exited the DropSite
00077    * 
00078    */
00079 
00080   public void dragExit (DragSourceEvent event) {
00081     //System.out.println( "dragExit");
00082     currentDraggingListNode = null;
00083     
00084   }  
00085 /**
00086    * a drag gesture has been initiated
00087    * 
00088    */
00089 
00090 public abstract void dragGestureRecognized(DragGestureEvent event);
00091 /*
00092 {
00093     SliceVariable selected = (SliceVariable) getSelectedValue();
00094     if (selected != null) {
00095         currentDraggingListNode = new TransferableSliceVariable(selected);
00096         //StringSelection text = new StringSelection(selected.toString());
00097 
00098         // as the name suggests, starts the dragging
00099         dragSource.startDrag(event, DragSource.DefaultCopyDrop, currentDraggingListNode, this);
00100     } else {
00101         System.out.println("nothing was selected");
00102     }
00103 }
00104 */
00105   /**
00106    * this message goes to DragSourceListener, informing it that the dragging is currently 
00107    * ocurring over the DropSite
00108    * 
00109    */
00110 
00111   public void dragOver (DragSourceDragEvent event) {
00112     //System.out.println( "dragExit");
00113     
00114   }  
00115   /**
00116    * is invoked when the user changes the dropAction
00117    * 
00118    */
00119    
00120   public void dropActionChanged ( DragSourceDragEvent event) {
00121     System.out.println( "dropActionChanged"); 
00122   }  
00123 }

Generated at Thu Feb 7 06:44:38 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001