KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > jmail > base > MoveMessageFrame


1 package org.lucane.applications.jmail.base;
2
3 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4  * This file is part of JMail *
5  * Copyright (C) 2002-2003 Yvan Norsa <norsay@wanadoo.fr> *
6  * *
7  * JMail is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * any later version. *
11  * *
12  * JMail is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License along *
18  * with JMail; if not, write to the Free Software Foundation, Inc., *
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20  * *
21  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

22
23 import java.awt.event.*;
24 import java.util.*;
25 import javax.mail.*;
26 import javax.swing.*;
27 import javax.swing.tree.*;
28
29 /** Move/Copy a message in another folder */
30 final class MoveMessageFrame extends JFrame
31 {
32     /** Language resource */
33     private ResourceBundle msgBundle;
34
35     private JPanel panel;
36
37     private JTree foldersTree;
38     private JScrollPane scrollPane;
39
40     private JButton ok;
41     private JButton cancel;
42
43     private String JavaDoc originalFolder;
44     private String JavaDoc id;
45
46     private MoveMessageListener listener;
47
48     /** User profile */
49     private Profile profile;
50
51     /** Mode */
52     private int mode;
53
54     private Store store;
55     private Folder currentFolder;
56
57     protected final static int MOVE_MODE = 0;
58     protected final static int COPY_MODE = 1;
59
60     /** Constructor
61      * @param store the connection
62      * @param currentFolder the folder where the mail currently is
63      * @param profile user profile
64      * @param id mail's id
65      * @param mode mode
66      * @param msgBundle language resource
67      */

68     protected MoveMessageFrame(Store store, Folder currentFolder, Profile profile, String JavaDoc originalFolder, String JavaDoc id, int mode, ResourceBundle msgBundle)
69     {
70     super(msgBundle.getString("MoveMessage.frameTitle"));
71
72     this.msgBundle = msgBundle;
73
74     this.store = store;
75     this.currentFolder = currentFolder;
76
77     this.profile = profile;
78     this.id = id;
79     this.mode = mode;
80
81     listener = new MoveMessageListener();
82
83     panel = new JPanel();
84      
85     foldersTree = MailClient.getFolders(store, this.profile);
86
87     foldersTree.setRootVisible(false);
88     foldersTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
89     foldersTree.putClientProperty("JTree.lineStyle", "Angled");
90
91     int nb = foldersTree.getRowCount();
92
93     for(int i = 0; i < nb; i++)
94         foldersTree.expandRow(i);
95
96     scrollPane = new JScrollPane(foldersTree);
97     panel.add(scrollPane);
98
99     ok = new JButton("OK");
100     ok.addActionListener(listener);
101     panel.add(ok);
102
103     cancel = new JButton(msgBundle.getString("MoveMessage.cancelLabel"));
104     cancel.addActionListener(listener);
105     panel.add(cancel);
106
107     setContentPane(panel);
108
109     setSize(200, 500);
110     pack();
111     setVisible(true);
112     }
113
114     /** Listener for this class */
115     private final class MoveMessageListener implements ActionListener
116     {
117     /** This method is invoked when an event is triggered
118      * @param e event
119      */

120     public final void actionPerformed(ActionEvent e)
121     {
122         JButton b = (JButton)e.getSource();
123
124         if(b == ok)
125         {
126         DefaultMutableTreeNode n = (DefaultMutableTreeNode)foldersTree.getLastSelectedPathComponent();
127         String JavaDoc selected = n.toString();
128
129         if(selected.compareTo(currentFolder.getFullName()) == 0)
130         {
131             JOptionPane.showMessageDialog(null, msgBundle.getString("MoveMessage.sameFoldersWarningLabel"), "MoveMessage", JOptionPane.INFORMATION_MESSAGE);
132             return;
133         }
134
135         if(mode == MOVE_MODE)
136         {
137             boolean bool = MailClient.moveMsg(store, currentFolder, id, selected);
138             
139             if(!bool)
140             JOptionPane.showMessageDialog(null, msgBundle.getString("MoveMessage.failureLabel"), "MoveMessage", JOptionPane.ERROR_MESSAGE);
141             
142         }
143
144         else //if(mode == COPY_MODE)
145
{
146             boolean bool = MailClient.copyMsg(store, currentFolder, id, selected);
147             
148             if(!bool)
149             JOptionPane.showMessageDialog(null, msgBundle.getString("MoveMessage.failureLabel"), "MoveMessage", JOptionPane.ERROR_MESSAGE);
150             
151         }
152
153         dispose();
154         }
155
156         else if(b == cancel)
157         dispose();
158     }
159     }
160 }
161
Popular Tags