1 package SnowMailClient.view.actions; 2 3 import SnowMailClient.model.folders.*; 4 import SnowMailClient.model.*; 5 import SnowMailClient.view.folders.*; 6 import SnowMailClient.view.*; 7 import SnowMailClient.Language.Language; 8 9 import java.awt.*; 10 import java.awt.event.*; 11 import javax.swing.*; 12 import javax.swing.event.*; 13 import javax.swing.table.*; 14 import java.io.*; 15 16 18 public class SaveMailAction extends AbstractAction 19 { 20 FolderView folderView; 21 FolderTreeNode deletedNode; 22 23 public SaveMailAction(final FolderView folderView_) 24 { 25 super(Language.translate("Save mail As")+"..."); 26 this.folderView = folderView_; 27 28 31 folderView.getTableSelectionModel().addListSelectionListener( new ListSelectionListener() 32 { 33 public void valueChanged(ListSelectionEvent e) 34 { 35 setEnabled(folderView.getTableSelectionCount()==1); 36 } 37 }); 38 39 setEnabled(folderView.getTableSelectionCount()==1); 40 41 } 43 public void actionPerformed(ActionEvent e) 44 { 45 MailMessage[] messs = folderView.getSelectedMessages(); 46 if(messs.length==1) 47 { 48 MailMessage mess = messs[0]; 49 try 50 { 51 String cont = mess.getCompleteContentAsString(); 52 JFileChooser fileChooser = new JFileChooser(); 53 fileChooser.setDialogTitle("Choose the file to store the mail in"); 54 int rep = fileChooser.showSaveDialog(folderView); 55 if(rep==JFileChooser.APPROVE_OPTION) 56 { 57 File file = fileChooser.getSelectedFile(); 58 FileOutputStream fos = null; 59 try 60 { 61 fos = new FileOutputStream(file, false); 62 fos.write(cont.getBytes()); 63 } 64 catch(Exception ee) 65 { 66 throw ee; 67 } 68 finally 69 { 70 if(fos!=null) fos.close(); 71 } 72 } 73 74 75 } 76 catch(Exception ex) 77 { 78 ex.printStackTrace(); 79 } 80 } 81 } 82 83 84 85 } | Popular Tags |