feisty meow concerns codebase  2.140
DragonTransferHandler.java
Go to the documentation of this file.
1 package org.feistymeow.dragdrop;
2 
3 import java.awt.datatransfer.DataFlavor;
4 import java.awt.datatransfer.Transferable;
5 import java.util.List;
6 
7 import javax.swing.JComponent;
8 import javax.swing.TransferHandler;
9 
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 
23 @SuppressWarnings("serial")
24 public class DragonTransferHandler extends TransferHandler
25 {
26  static private Log logger = LogFactory.getLog(DragonTransferHandler.class);
27  IDragonDropDataProvider c_provider;
28 
30  {
31  c_provider = provider;
32  }
33 
34  @Override
35  public boolean canImport(TransferSupport support)
36  {
37  if (support == null) return false;
38  if (!support.isDrop())
39  return false; // we don't support cut&paste here.
40  logger.debug("canImport: base just saying okay.");
41  return true;
42  }
43 
44  @Override
45  protected Transferable createTransferable(JComponent c)
46  {
47  logger.debug("createTransferable: at base, returning ListTransferable.");
48  return new ListTransferable(c_provider.provideDragList());
49  }
50 
51  @Override
52  protected void exportDone(JComponent source, Transferable data, int action)
53  {
54  logger.debug("exportDone: base got event for component " + source.toString());
55  }
56 
57  @Override
58  public int getSourceActions(JComponent c)
59  {
60  return COPY;
61  }
62 
63  @Override
64  public boolean importData(TransferSupport support)
65  {
66  if (support == null) return false;
67  logger.debug("importData: at base...");
68 
69  if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
70  logger.debug("importing data with java files flavor");
71  List<Object> files = ListTransferable.extractData(support.getTransferable());
72  if ((files != null) && (files.size() != 0)) {
73  c_provider.consumeDropList(files, support.getDropLocation().getDropPoint());
74  return true;
75  }
76  } else if (support.isDataFlavorSupported(ListTransferable.getURIListFlavor1())
77  || support.isDataFlavorSupported(ListTransferable.getURIListFlavor2())) {
78  logger.debug("importing data with uri list flavor");
79  List<Object> files = ListTransferable.extractData(support.getTransferable());
80  if ((files != null) && (files.size() != 0)) {
81  c_provider.consumeDropList(files, support.getDropLocation().getDropPoint());
82  return true;
83  }
84  }
85  logger.warn("passing importData request to superclass, which will probably fail.");
86  return super.importData(support);
87  }
88 }
void exportDone(JComponent source, Transferable data, int action)
DragonTransferHandler(IDragonDropDataProvider provider)
static List< Object > extractData(Transferable tran)
boolean consumeDropList(List< Object > dropSet, Point cursor)
list files
Definition: eml_to_txt.py:157
@ COPY