KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** Create a new folder */
30 final class NewFolderFrame extends JFrame
31 {
32     private JPanel panel;
33
34     private JTree foldersTree;
35     private JScrollPane scrollPane;
36
37     private JTextField folderName;
38
39     private JCheckBox folders;
40     private JCheckBox messages;
41
42     private JButton ok;
43     private JButton cancel;
44
45     private NewFolderListener listener;
46
47     /** User profile */
48     private Profile profile;
49
50     private Store store;
51
52     /** Language resource */
53     private ResourceBundle msgBundle;
54
55     /** Constructor
56      * @param store the connection
57      * @param profile user profile
58      * @param msgBundle language resource
59      */

60     protected NewFolderFrame(Store store, Profile profile, ResourceBundle msgBundle)
61     {
62     super(msgBundle.getString("NewFolder.frameTitle"));
63
64     this.msgBundle = msgBundle;
65
66     this.store = store;
67
68     this.profile = profile;
69
70     init();
71
72     pack();
73     setVisible(true);
74     }
75
76     /** Alternate constructor
77      * @param store the connection
78      * @param profile user profile
79      * @param row tells the row number
80      * @param msgBundle language resource
81      */

82     protected NewFolderFrame(Store store, Profile profile, int row, ResourceBundle msgBundle)
83     {
84     super(msgBundle.getString("NewFolder.frameTitle"));
85
86     this.msgBundle = msgBundle;
87
88     this.store = store;
89
90     this.profile = profile;
91
92     init();
93
94     foldersTree.setSelectionRow(row);
95
96     pack();
97     setVisible(true);
98     }
99
100     /** Inits all the panel stuff */
101     private void init()
102     {
103     listener = new NewFolderListener();
104
105     panel = new JPanel();
106
107     if(store != null)
108         foldersTree = MailClient.getFolders(store, profile);
109
110     else
111     {
112         DefaultMutableTreeNode top = new DefaultMutableTreeNode();
113         top.add(new DefaultMutableTreeNode());
114         foldersTree = new JTree(top);
115     }
116
117     foldersTree.setRootVisible(false);
118     foldersTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
119     foldersTree.putClientProperty("JTree.lineStyle", "Angled");
120     
121     int nb = foldersTree.getRowCount();
122
123     for(int i = 0; i < nb; i++)
124         foldersTree.expandRow(i);
125
126     scrollPane = new JScrollPane(foldersTree);
127     panel.add(scrollPane);
128
129     folderName = new JTextField(msgBundle.getString("NewFolder.defaultName"));
130     panel.add(folderName);
131
132     folders = new JCheckBox("HOLDS_FOLDERS");
133     panel.add(folders);
134
135     messages = new JCheckBox("HOLDS_MESSAGES", true);
136     panel.add(messages);
137
138     ok = new JButton("OK");
139     ok.addActionListener(listener);
140     panel.add(ok);
141
142     cancel = new JButton(msgBundle.getString("NewFolder.cancelLabel"));
143     cancel.addActionListener(listener);
144     panel.add(cancel);
145
146     setContentPane(panel);
147     }
148
149     /** Listener for this class */
150     private final class NewFolderListener implements ActionListener
151     {
152     /** This method is invoked when an event is triggered
153      * @param e event
154      */

155     public final void actionPerformed(ActionEvent e)
156     {
157         JButton b = (JButton)e.getSource();
158
159         if(b == ok)
160         {
161         int type;
162
163         if(folders.isSelected())
164         {
165             type = Folder.HOLDS_FOLDERS;
166
167             if(messages.isSelected())
168             type &= Folder.HOLDS_MESSAGES;
169         }
170
171         else if(messages.isSelected())
172             type = Folder.HOLDS_MESSAGES;
173
174         else
175             return;
176
177         DefaultMutableTreeNode n = (DefaultMutableTreeNode)foldersTree.getLastSelectedPathComponent();
178
179         if(n != null)
180         {
181             String JavaDoc selected = n.toString();
182
183             String JavaDoc newNod = selected + "." + folderName.getText();
184
185             MailClient.createFolder(store, profile, newNod, type);
186
187             dispose();
188         }
189
190         else
191             JOptionPane.showMessageDialog(null, msgBundle.getString("NewFolder.noParent"), "NewFolder", JOptionPane.INFORMATION_MESSAGE);
192         }
193
194         else if(b == cancel)
195         dispose();
196     }
197     }
198 }
199
200
Popular Tags