/*
 * JDragTable.java
 *
 * Created on 14 novembre 2003, 0.43
 */

package it.businesslogic.ireport.gui;
import java.awt.dnd.*;
import it.businesslogic.ireport.*;
import it.businesslogic.ireport.gui.dnd.*;
import java.awt.datatransfer.*;

/**
 *
 * @author  Administrator
 */
public class JDragTable extends javax.swing.JTable implements DragGestureListener,
                DragSourceListener {    

   public JDragTable() {

      DragSource dragSource = DragSource.getDefaultDragSource();

      // creating the recognizer is all that's necessary - it
      // does not need to be manipulated after creation
      dragSource.createDefaultDragGestureRecognizer(
         this, // component where drag originates
         DnDConstants.ACTION_COPY, // actions
         this); // drag gesture listener
      }
      
       public void dragGestureRecognized(DragGestureEvent e) {
         // drag anything ...
         
         TransferableObject  to =   new TransferableObject(this.getValueAt(this.getSelectedRow(), this.getSelectedColumn() ));
         
         try{
         if (to != null)
         e.startDrag(DragSource.DefaultCopyDrop , // cursor
            to); //, // transferable
            //this); // drag source listener
         } catch (Exception ex) {

            ex.printStackTrace();

         }

      }

      public void dragDropEnd(DragSourceDropEvent e) {}
      public void dragEnter(DragSourceDragEvent e) {}
      public void dragExit(DragSourceEvent e) {}
      public void dragOver(DragSourceDragEvent e) {}
      public void dropActionChanged(DragSourceDragEvent e) {}

}
