KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > view > actions > ImportMailMessage


1 package SnowMailClient.view.actions;
2
3 import SnowMailClient.model.*;
4 import SnowMailClient.model.accounts.*;
5 import snow.utils.storage.*;
6 import SnowMailClient.view.*;
7 import SnowMailClient.SnowMailClientApp;
8 import SnowMailClient.Language.Language;
9
10 import java.awt.*;
11 import java.io.*;
12 import java.awt.event.*;
13 import javax.swing.*;
14 import javax.swing.event.*;
15 import javax.swing.tree.*;
16
17 /**
18 */

19 public class ImportMailMessage extends AbstractAction
20 {
21   FolderView folderView;
22
23   public ImportMailMessage(FolderView folderView)
24   {
25      super(Language.translate("Import Mail message"));
26      this.folderView = folderView;
27
28 /* putValue(AbstractAction.SMALL_ICON,
29               SnowMailClientApp.loadImageIcon("pics/new.PNG") );
30
31      putValue(AbstractAction.ACCELERATOR_KEY,
32               KeyStroke.getKeyStroke( KeyEvent.VK_N, KeyEvent.CTRL_MASK ) );
33               */

34
35      putValue(AbstractAction.SHORT_DESCRIPTION,
36                Language.translate("Import a mail message from a file in the current mail folder"));
37
38   } // Constructor
39

40   public void actionPerformed(ActionEvent e)
41   {
42     String JavaDoc defDir = SnowMailClientApp.getInstance().getProperties().getProperty("ImportMailMessage_dir", System.getProperty("user.home", ""));
43     JFileChooser fileLoad = new JFileChooser(defDir);
44     fileLoad.setDialogTitle("Select the mail file(s) to import");
45     fileLoad.setMultiSelectionEnabled(true);
46
47     int rep = fileLoad.showOpenDialog(SnowMailClientApp.getInstance());
48     if(rep==JFileChooser.APPROVE_OPTION)
49     {
50        File[] files = fileLoad.getSelectedFiles();
51        for(int i=0; i<files.length; i++)
52        {
53           if(i==0)
54           {
55             SnowMailClientApp.getInstance().getProperties().setProperty("ImportMailMessage_dir",
56                files[0].getParent());
57           }
58           try
59           {
60              byte[] content = FileUtils.getFileContent(files[i]);
61              MailMessage mess = new MailMessage();
62              mess.parse(new String JavaDoc(content));
63              mess.setEditable(true);
64
65              folderView.getMailFolder().addMessage(mess);
66           }
67           catch(Exception JavaDoc ex)
68           {
69              JOptionPane.showMessageDialog(
70                  SnowMailClientApp.getInstance(),
71                  "Error: "+ex.getMessage(),
72                  "Error importing message",
73                  JOptionPane.ERROR_MESSAGE);
74           }
75
76        }
77     }
78
79
80
81   }
82
83
84
85 } // ImportMailMessage
Popular Tags