1 package net.suberic.pooka.gui.dnd; 2 3 import net.suberic.pooka.*; 4 import net.suberic.pooka.gui.*; 5 6 import java.awt.datatransfer.*; 7 import java.util.*; 8 9 import java.io.*; 10 11 19 public class MessageProxyTransferable implements Transferable { 20 21 public static DataFlavor sMessageProxyDataFlavor = null; 23 static { 24 try { 25 sMessageProxyDataFlavor = new DataFlavor(Class.forName("net.suberic.pooka.gui.MessageProxy"), "MessageProxy"); 26 } catch (Exception e) { 27 e.printStackTrace(); 28 } 29 } 30 31 MessageProxy mMessageProxy = null; 32 int mActionType = javax.swing.TransferHandler.COPY; 33 boolean mImportDone = false; 34 35 public MessageProxyTransferable(MessageProxy pMessageProxy) { 36 setMessageProxy(pMessageProxy); 37 } 38 39 public DataFlavor[] getTransferDataFlavors() { 40 return new DataFlavor[] { 41 sMessageProxyDataFlavor 42 }; 43 } 44 45 public boolean isDataFlavorSupported(DataFlavor flavor) { 46 if (flavor == sMessageProxyDataFlavor) 47 return true; 48 else 49 return false; 50 } 51 52 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { 53 if (flavor == sMessageProxyDataFlavor) { 54 return mMessageProxy; 55 70 } else { 71 throw new UnsupportedFlavorException(flavor); 72 } 73 } 74 75 78 private File extractMessageInfo(MessageInfo info) throws java.io.IOException { 79 try { 80 String name = "pooka_message"; 81 try { 82 javax.mail.Message m = info.getMessage(); 83 if (m instanceof net.suberic.pooka.UIDMimeMessage) { 84 name = "message_" + ((net.suberic.pooka.UIDMimeMessage) m).getUID() ; 85 } else { 86 name = "message_" + m.getMessageNumber(); 87 } 88 } catch (Exception me) { 89 } 91 File f = DndUtils.createTemporaryFile(name); 92 info.saveMessageAs(f); 93 return f; 94 } catch (javax.mail.MessagingException me) { 95 IOException ioe = new IOException("Error saving file"); 96 ioe.initCause(me); 97 throw ioe; 98 } 99 } 100 101 104 public MessageProxy getMessageProxy() { 105 return mMessageProxy; 106 } 107 108 111 public void setMessageProxy(MessageProxy pMessageProxy) { 112 mMessageProxy = pMessageProxy; 113 } 114 115 } 116 | Popular Tags |