KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > dnd > listeners > BackendTransferListener


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.dnd.listeners;
26
27 import java.awt.Component JavaDoc;
28 import java.awt.datatransfer.DataFlavor JavaDoc;
29 import java.awt.datatransfer.Transferable JavaDoc;
30 import java.awt.dnd.DnDConstants JavaDoc;
31 import java.awt.dnd.DropTarget JavaDoc;
32 import java.awt.dnd.DropTargetDropEvent JavaDoc;
33
34 import javax.swing.JButton JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36
37 import org.objectweb.cjdbc.console.gui.CjdbcGui;
38
39 /**
40  * This class defines a BackendTransferListener. Listens for DnD on backends
41  *
42  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
43  * @version 1.0
44  */

45 public class BackendTransferListener extends AbstractGuiDropListener
46 {
47
48   /**
49    * Creates a new <code>BackendTransferListener.java</code> object
50    *
51    * @param gui link to the main gui
52    */

53   public BackendTransferListener(CjdbcGui gui)
54   {
55     super(gui);
56   }
57
58   /**
59    * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
60    */

61   public void drop(DropTargetDropEvent JavaDoc dtde)
62   {
63     dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
64     DropTarget JavaDoc target = dtde.getDropTargetContext().getDropTarget();
65     Transferable JavaDoc transfer = dtde.getTransferable();
66     
67     
68     Component JavaDoc comp = target.getComponent();
69     try
70     {
71       Object JavaDoc data = transfer.getTransferData(DataFlavor.stringFlavor);
72       if (comp instanceof JButton JavaDoc)
73         gui.publicActionExecuteBackendDrop((JButton JavaDoc) comp, data.toString());
74       else if (comp instanceof JPanel JavaDoc)
75         gui.publicActionExecuteBackendDrop((JPanel JavaDoc) comp, data.toString());
76
77     }
78     catch (Exception JavaDoc e)
79     {
80       gui.appendDebugText("Failed to execute Drag and drop for target:"
81           + comp.getName(),e);
82     }
83     finally
84     {
85       dtde.getDropTargetContext().removeNotify();
86       dtde.dropComplete(true);
87       gui.publicActionRefreshCursorShape();
88     }
89     dtde.getDropTargetContext().removeNotify();
90     
91     dtde.dropComplete(true);
92     
93   }
94 }
95
Popular Tags