001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * DTListener.java
028: *
029: * Created on June 1, 2006, 11:32 AM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import java.awt.datatransfer.DataFlavor;
036: import java.awt.datatransfer.Transferable;
037: import java.awt.dnd.DnDConstants;
038: import java.awt.dnd.DropTarget;
039: import java.awt.dnd.DropTargetContext;
040: import java.awt.dnd.DropTargetDragEvent;
041: import java.awt.dnd.DropTargetDropEvent;
042: import java.awt.dnd.DropTargetEvent;
043: import java.awt.dnd.DropTargetListener;
044:
045: /**
046: *
047: * @author gtoffoli
048: */
049: /**
050: * DTListener
051: * a listener that tracks the state of the operation
052: * @see java.awt.dnd.DropTargetListener
053: * @see java.awt.dnd.DropTarget
054: */
055: public class DTListener implements DropTargetListener {
056:
057: /**
058: * start "drag under" feedback on component
059: * invoke acceptDrag or rejectDrag based on isDragOk
060: */
061: public void dragEnter(DropTargetDragEvent e) {
062: e.acceptDrag(e.getDropAction());
063: }
064:
065: /**
066: * continue "drag under" feedback on component
067: * invoke acceptDrag or rejectDrag based on isDragOk
068: */
069: public void dragOver(DropTargetDragEvent e) {
070: e.acceptDrag(e.getDropAction());
071: }
072:
073: public void dropActionChanged(DropTargetDragEvent e) {
074: }
075:
076: public void dragExit(DropTargetEvent e) {
077: }
078:
079: /**
080: * perform action from getSourceActions on
081: * the transferrable
082: * invoke acceptDrop or rejectDrop
083: * invoke dropComplete
084: * if its a local (same JVM) transfer, use StringTransferable.localStringFlavor
085: * find a match for the flavor
086: * check the operation
087: * get the transferable according to the chosen flavor
088: * do the transfer
089: */
090: public void drop(DropTargetDropEvent dtde) {
091: try {
092:
093: DropTargetContext context = dtde.getDropTargetContext();
094:
095: Transferable tr = dtde.getTransferable();
096: if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
097: dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
098: java.util.List fileList = (java.util.List) tr
099: .getTransferData(DataFlavor.javaFileListFlavor);
100:
101: MainFrame.getMainInstance().openFiles(fileList);
102: }
103:
104: context.dropComplete(true);
105: } catch (Exception ex) {
106: ex.printStackTrace();
107: }
108: }
109:
110: }
|