1 package SnowMailClient.view.actions; 2 3 import SnowMailClient.model.folders.*; 4 import SnowMailClient.model.MailMessage; 5 import SnowMailClient.model.accounts.*; 6 import SnowMailClient.model.Address; 7 import SnowMailClient.view.folders.*; 8 import SnowMailClient.view.*; 9 import SnowMailClient.SnowMailClientApp; 10 import SnowMailClient.Language.Language; 11 12 import java.awt.*; 13 import java.util.*; 14 import java.awt.event.*; 15 import javax.swing.*; 16 import javax.swing.event.*; 17 import javax.swing.tree.*; 18 19 public class ReplyAction extends AbstractAction 20 { 21 private FolderTreeNode inbox; 22 private MailAccounts accounts; 23 private FolderView folderView; 24 private boolean copyContent = true; 25 private final boolean replyToAll; 26 27 28 public ReplyAction(FolderView _folderView, MailAccounts accounts, FolderTreeNode inbox, boolean replyToAll) 29 { 30 super((replyToAll ? Language.translate("Reply All") : Language.translate("Reply"))); 31 32 this.replyToAll = replyToAll; 33 this.inbox = inbox; 34 this.accounts = accounts; 35 this.folderView = _folderView; 36 37 putValue(AbstractAction.SMALL_ICON, 38 SnowMailClientApp.loadImageIcon("pics/reply.PNG") ); 39 40 putValue(AbstractAction.ACCELERATOR_KEY, 41 KeyStroke.getKeyStroke( KeyEvent.VK_L, KeyEvent.CTRL_MASK ) ); 42 43 putValue(AbstractAction.SHORT_DESCRIPTION, 44 Language.translate("Reply to the actual message")); 45 46 folderView.getTableSelectionModel().addListSelectionListener( new ListSelectionListener() 47 { 48 public void valueChanged(ListSelectionEvent e) 49 { 50 setEnabled(folderView.getTableSelectionCount()==1); 51 } 52 }); 53 setEnabled(folderView.getTableSelectionCount()==1); 54 55 } 57 public void actionPerformed(ActionEvent e) 58 { 59 MailMessage[] messs = folderView.getSelectedMessages(); 60 if(messs.length==1) 61 { 62 MailMessage mess = messs[0]; 63 64 Address to = mess.getFromAddress(); 65 66 Address from = new Address(); 68 MailAccount ma = accounts.getSendMailAccount(); 69 if(ma!=null) 70 { 71 from.setMailAddress( ma.getAddress() ); 72 from.setName( ma.getName() ); 73 } 74 75 MailMessage replyMessage = new MailMessage(); 76 replyMessage.setIsReplyMessage(mess.getMessageID()); 77 String body = ""; 78 if(this.copyContent) 79 { 80 body = Language.translate("In reply to:")+"\n\n"+mess.getMessageBody(); 81 } 82 Vector<Address> tos =new Vector<Address>(); 83 tos.add(to); 84 if(replyToAll) 85 { 86 tos.addAll(mess.getToAddresses()); 87 } 88 replyMessage.setMessage(from, 89 tos, 90 "Re: "+mess.getHeader().getEntryValue("subject", "?"), 91 body); 92 replyMessage.setEditable(true); 93 94 95 try 96 { 97 inbox.getMailFolder().addMessage(replyMessage); 98 inbox.saveMailFolder(false); } 100 catch(Exception ex) 101 { 102 ex.printStackTrace(); 103 } 104 } 105 } 106 107 108 109 } | Popular Tags |