KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > frame > AbstractMailFrameController


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.gui.frame;
19
20 import java.nio.charset.Charset JavaDoc;
21
22 import javax.swing.event.EventListenerList JavaDoc;
23
24 import org.columba.api.selection.ISelectionListener;
25 import org.columba.core.charset.CharsetEvent;
26 import org.columba.core.charset.CharsetListener;
27 import org.columba.core.charset.CharsetOwnerInterface;
28 import org.columba.core.config.ViewItem;
29 import org.columba.core.gui.frame.DockFrameController;
30 import org.columba.mail.command.IMailFolderCommandReference;
31 import org.columba.mail.command.MailFolderCommandReference;
32 import org.columba.mail.folderoptions.FolderOptionsController;
33 import org.columba.mail.folderoptions.IFolderOptionsController;
34 import org.columba.mail.gui.message.IMessageController;
35 import org.columba.mail.gui.message.MessageController;
36 import org.columba.mail.gui.table.selection.TableSelectionHandler;
37 import org.columba.mail.gui.tree.selection.TreeSelectionHandler;
38
39 /**
40  * @author fdietz
41  *
42  */

43 public abstract class AbstractMailFrameController extends DockFrameController
44         implements MailFrameMediator, MessageViewOwner, CharsetOwnerInterface {
45
46     public MessageController messageController;
47
48     private IFolderOptionsController folderOptionsController;
49
50     protected EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
51
52     // needs to be private so that subclasses won't forget calling
53
// fireCharsetChanged
54
private Charset JavaDoc charset;
55
56     public AbstractMailFrameController(String JavaDoc id) {
57         super(id);
58
59         initComponents();
60
61     }
62
63     /**
64      * @param id
65      * @param viewItem
66      */

67     public AbstractMailFrameController(ViewItem viewItem) {
68         super(viewItem);
69
70         initComponents();
71     }
72
73     private void initComponents() {
74         messageController = new MessageController(this);
75         
76         folderOptionsController = new FolderOptionsController(this);
77     }
78     
79     /*
80      * protected XmlElement createDefaultConfiguration(String id) { XmlElement
81      * child = super.createDefaultConfiguration(id);
82      *
83      * XmlElement splitpanes = new XmlElement("splitpanes");
84      * splitpanes.addAttribute("main", "200"); splitpanes.addAttribute("header",
85      * "200"); splitpanes.addAttribute("attachment", "100");
86      * child.addElement(splitpanes);
87      *
88      * return child; }
89      */

90
91     public IMailFolderCommandReference getTableSelection() {
92         MailFolderCommandReference r = (MailFolderCommandReference) getSelectionManager()
93                 .getSelection(TableSelectionHandler.HANDLER_ID);
94
95         return r;
96     }
97
98     public void setTableSelection(IMailFolderCommandReference r) {
99         getSelectionManager().setSelection(TableSelectionHandler.HANDLER_ID, r);
100     }
101
102     public IMailFolderCommandReference getTreeSelection() {
103         MailFolderCommandReference r = (MailFolderCommandReference) getSelectionManager()
104                 .getSelection(TreeSelectionHandler.HANDLER_ID);
105
106         return r;
107     }
108
109     public void setTreeSelection(IMailFolderCommandReference r) {
110         getSelectionManager().setSelection(TreeSelectionHandler.HANDLER_ID, r);
111     }
112
113     public void registerTableSelectionListener(ISelectionListener l) {
114         getSelectionManager().registerSelectionListener(
115                 TableSelectionHandler.HANDLER_ID, l);
116     }
117
118     public void registerTreeSelectionListener(ISelectionListener l) {
119         getSelectionManager().registerSelectionListener(
120                 TreeSelectionHandler.HANDLER_ID, l);
121     }
122
123     /**
124      * @see org.columba.mail.gui.frame.MailFrameMediator#removeTableSelectionListener(org.columba.api.selection.ISelectionListener)
125      */

126     public void removeTableSelectionListener(ISelectionListener l) {
127         getSelectionManager().removeSelectionListener(
128                 TableSelectionHandler.HANDLER_ID, l);
129     }
130
131     /**
132      * @see org.columba.mail.gui.frame.MailFrameMediator#removeTreeSelectionListener(org.columba.api.selection.ISelectionListener)
133      */

134     public void removeTreeSelectionListener(ISelectionListener l) {
135         getSelectionManager().removeSelectionListener(
136                 TreeSelectionHandler.HANDLER_ID, l);
137     }
138
139     /**
140      * @see org.columba.mail.gui.frame.MailFrameMediator#getFolderOptionsController()
141      */

142     public IFolderOptionsController getFolderOptionsController() {
143         return folderOptionsController;
144     }
145
146     /**
147      * @see org.columba.mail.gui.frame.MessageViewOwner#getMessageController()
148      */

149     public IMessageController getMessageController() {
150         return messageController;
151     }
152
153     public void setCharset(Charset JavaDoc charset) {
154         this.charset = charset;
155         fireCharsetChanged(new CharsetEvent(this, charset));
156     }
157
158     public void removeCharsetListener(CharsetListener l) {
159         listenerList.remove(CharsetListener.class, l);
160     }
161
162     public Charset JavaDoc getCharset() {
163         return charset;
164     }
165
166     public void addCharsetListener(CharsetListener l) {
167         listenerList.add(CharsetListener.class, l);
168     }
169
170     protected void fireCharsetChanged(CharsetEvent e) {
171         // Guaranteed to return a non-null array
172
Object JavaDoc[] listeners = listenerList.getListenerList();
173
174         // Process the listeners last to first, notifying
175
// those that are interested in this event
176
for (int i = listeners.length - 2; i >= 0; i -= 2) {
177             if (listeners[i] == CharsetListener.class) {
178                 ((CharsetListener) listeners[i + 1]).charsetChanged(e);
179             }
180         }
181     }
182
183     
184
185 }
Popular Tags