1 /* 2 * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved. 3 * http://www.jaspersoft.com. 4 * 5 * Unless you have purchased a commercial license agreement from JasperSoft, 6 * the following license terms apply: 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License version 2 as published by 10 * the Free Software Foundation. 11 * 12 * This program is distributed WITHOUT ANY WARRANTY; and without the 13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 * See the GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt 18 * or write to: 19 * 20 * Free Software Foundation, Inc., 21 * 59 Temple Place - Suite 330, 22 * Boston, MA USA 02111-1307 23 * 24 * 25 * 26 * 27 * DTListener.java 28 * 29 * Created on June 1, 2006, 11:32 AM 30 * 31 */ 32 33 package it.businesslogic.ireport.gui; 34 import java.awt.datatransfer.DataFlavor; 35 import java.awt.datatransfer.Transferable; 36 import java.awt.dnd.DnDConstants; 37 import java.awt.dnd.DropTarget; 38 import java.awt.dnd.DropTargetContext; 39 import java.awt.dnd.DropTargetDragEvent; 40 import java.awt.dnd.DropTargetDropEvent; 41 import java.awt.dnd.DropTargetEvent; 42 import java.awt.dnd.DropTargetListener; 43 /** 44 * 45 * @author gtoffoli 46 */ 47 /** 48 * DTListener 49 * a listener that tracks the state of the operation 50 * @see java.awt.dnd.DropTargetListener 51 * @see java.awt.dnd.DropTarget 52 */ 53 public class DTListener implements DropTargetListener { 54 55 56 /** 57 * start "drag under" feedback on component 58 * invoke acceptDrag or rejectDrag based on isDragOk 59 */ 60 public void dragEnter(DropTargetDragEvent e) { 61 e.acceptDrag(e.getDropAction()); 62 } 63 64 /** 65 * continue "drag under" feedback on component 66 * invoke acceptDrag or rejectDrag based on isDragOk 67 */ 68 public void dragOver(DropTargetDragEvent e) { 69 e.acceptDrag(e.getDropAction()); 70 } 71 72 public void dropActionChanged(DropTargetDragEvent e) { 73 } 74 75 public void dragExit(DropTargetEvent e) { 76 } 77 78 /** 79 * perform action from getSourceActions on 80 * the transferrable 81 * invoke acceptDrop or rejectDrop 82 * invoke dropComplete 83 * if its a local (same JVM) transfer, use StringTransferable.localStringFlavor 84 * find a match for the flavor 85 * check the operation 86 * get the transferable according to the chosen flavor 87 * do the transfer 88 */ 89 public void drop(DropTargetDropEvent dtde) { 90 try { 91 92 DropTargetContext context = dtde.getDropTargetContext(); 93 94 Transferable tr = dtde.getTransferable(); 95 if (tr.isDataFlavorSupported (DataFlavor.javaFileListFlavor)) 96 { 97 dtde.acceptDrop ( 98 DnDConstants.ACTION_COPY_OR_MOVE); 99 java.util.List fileList = (java.util.List)tr.getTransferData(DataFlavor.javaFileListFlavor); 100 101 MainFrame.getMainInstance().openFiles(fileList); 102 } 103 104 context.dropComplete(true); 105 } catch (Exception ex) 106 { 107 ex.printStackTrace(); 108 } 109 } 110 111 } 112 113