1 package net.suberic.pooka.gui.dnd; 2 3 import javax.swing.*; 4 import java.io.*; 5 import java.util.*; 6 import java.awt.*; 7 import java.awt.datatransfer.*; 8 import java.awt.event.*; 9 10 import net.suberic.pooka.*; 11 import net.suberic.pooka.gui.*; 12 13 17 public class AttachmentTransferHandler extends TransferHandler { 18 19 protected Transferable createTransferable(JComponent c) { 20 Attachment attachment = null; 21 MessageProxy proxy = null; 22 if (c instanceof net.suberic.pooka.gui.AttachmentPane) { 23 attachment = ((AttachmentPane) c).getSelectedAttachment(); 24 proxy = ((AttachmentPane) c).getMessageProxy(); 25 } else if (c instanceof JTable) { 26 try { 27 Object o = SwingUtilities.getAncestorOfClass(Class.forName("net.suberic.pooka.gui.AttachmentPane"), c); 28 if (o != null ) { 29 attachment = ((AttachmentPane) o).getSelectedAttachment(); 30 proxy = ((AttachmentPane) o).getMessageProxy(); 31 } else { 32 return null; 33 } 34 } catch ( Exception e) { 35 return null; 36 } 37 } 38 39 if (attachment != null && proxy != null) { 40 try { 41 return new AttachmentTransferable(attachment, proxy); 42 } catch (java.io.IOException ioe) { 43 return null; 44 } 45 } else { 46 return null; 47 } 48 49 } 50 51 public int getSourceActions(JComponent c) { 52 return COPY; 53 } 54 55 public boolean canImport(JComponent c, DataFlavor[] flavors) { 56 return false; 57 } 58 59 protected void exportDone(JComponent source, Transferable data, int action) { 60 65 } 66 67 } 68 | Popular Tags |