001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.gui.frame;
019:
020: import java.nio.charset.Charset;
021:
022: import javax.swing.event.EventListenerList;
023:
024: import org.columba.api.selection.ISelectionListener;
025: import org.columba.core.charset.CharsetEvent;
026: import org.columba.core.charset.CharsetListener;
027: import org.columba.core.charset.CharsetOwnerInterface;
028: import org.columba.core.config.ViewItem;
029: import org.columba.core.gui.frame.DockFrameController;
030: import org.columba.mail.command.IMailFolderCommandReference;
031: import org.columba.mail.command.MailFolderCommandReference;
032: import org.columba.mail.folderoptions.FolderOptionsController;
033: import org.columba.mail.folderoptions.IFolderOptionsController;
034: import org.columba.mail.gui.message.IMessageController;
035: import org.columba.mail.gui.message.MessageController;
036: import org.columba.mail.gui.table.selection.TableSelectionHandler;
037: import org.columba.mail.gui.tree.selection.TreeSelectionHandler;
038:
039: /**
040: * @author fdietz
041: *
042: */
043: public abstract class AbstractMailFrameController extends
044: DockFrameController implements MailFrameMediator,
045: MessageViewOwner, CharsetOwnerInterface {
046:
047: public MessageController messageController;
048:
049: private IFolderOptionsController folderOptionsController;
050:
051: protected EventListenerList listenerList = new EventListenerList();
052:
053: // needs to be private so that subclasses won't forget calling
054: // fireCharsetChanged
055: private Charset charset;
056:
057: public AbstractMailFrameController(String id) {
058: super (id);
059:
060: initComponents();
061:
062: }
063:
064: /**
065: * @param id
066: * @param viewItem
067: */
068: public AbstractMailFrameController(ViewItem viewItem) {
069: super (viewItem);
070:
071: initComponents();
072: }
073:
074: private void initComponents() {
075: messageController = new MessageController(this );
076:
077: folderOptionsController = new FolderOptionsController(this );
078: }
079:
080: /*
081: * protected XmlElement createDefaultConfiguration(String id) { XmlElement
082: * child = super.createDefaultConfiguration(id);
083: *
084: * XmlElement splitpanes = new XmlElement("splitpanes");
085: * splitpanes.addAttribute("main", "200"); splitpanes.addAttribute("header",
086: * "200"); splitpanes.addAttribute("attachment", "100");
087: * child.addElement(splitpanes);
088: *
089: * return child; }
090: */
091:
092: public IMailFolderCommandReference getTableSelection() {
093: MailFolderCommandReference r = (MailFolderCommandReference) getSelectionManager()
094: .getSelection(TableSelectionHandler.HANDLER_ID);
095:
096: return r;
097: }
098:
099: public void setTableSelection(IMailFolderCommandReference r) {
100: getSelectionManager().setSelection(
101: TableSelectionHandler.HANDLER_ID, r);
102: }
103:
104: public IMailFolderCommandReference getTreeSelection() {
105: MailFolderCommandReference r = (MailFolderCommandReference) getSelectionManager()
106: .getSelection(TreeSelectionHandler.HANDLER_ID);
107:
108: return r;
109: }
110:
111: public void setTreeSelection(IMailFolderCommandReference r) {
112: getSelectionManager().setSelection(
113: TreeSelectionHandler.HANDLER_ID, r);
114: }
115:
116: public void registerTableSelectionListener(ISelectionListener l) {
117: getSelectionManager().registerSelectionListener(
118: TableSelectionHandler.HANDLER_ID, l);
119: }
120:
121: public void registerTreeSelectionListener(ISelectionListener l) {
122: getSelectionManager().registerSelectionListener(
123: TreeSelectionHandler.HANDLER_ID, l);
124: }
125:
126: /**
127: * @see org.columba.mail.gui.frame.MailFrameMediator#removeTableSelectionListener(org.columba.api.selection.ISelectionListener)
128: */
129: public void removeTableSelectionListener(ISelectionListener l) {
130: getSelectionManager().removeSelectionListener(
131: TableSelectionHandler.HANDLER_ID, l);
132: }
133:
134: /**
135: * @see org.columba.mail.gui.frame.MailFrameMediator#removeTreeSelectionListener(org.columba.api.selection.ISelectionListener)
136: */
137: public void removeTreeSelectionListener(ISelectionListener l) {
138: getSelectionManager().removeSelectionListener(
139: TreeSelectionHandler.HANDLER_ID, l);
140: }
141:
142: /**
143: * @see org.columba.mail.gui.frame.MailFrameMediator#getFolderOptionsController()
144: */
145: public IFolderOptionsController getFolderOptionsController() {
146: return folderOptionsController;
147: }
148:
149: /**
150: * @see org.columba.mail.gui.frame.MessageViewOwner#getMessageController()
151: */
152: public IMessageController getMessageController() {
153: return messageController;
154: }
155:
156: public void setCharset(Charset charset) {
157: this .charset = charset;
158: fireCharsetChanged(new CharsetEvent(this , charset));
159: }
160:
161: public void removeCharsetListener(CharsetListener l) {
162: listenerList.remove(CharsetListener.class, l);
163: }
164:
165: public Charset getCharset() {
166: return charset;
167: }
168:
169: public void addCharsetListener(CharsetListener l) {
170: listenerList.add(CharsetListener.class, l);
171: }
172:
173: protected void fireCharsetChanged(CharsetEvent e) {
174: // Guaranteed to return a non-null array
175: Object[] listeners = listenerList.getListenerList();
176:
177: // Process the listeners last to first, notifying
178: // those that are interested in this event
179: for (int i = listeners.length - 2; i >= 0; i -= 2) {
180: if (listeners[i] == CharsetListener.class) {
181: ((CharsetListener) listeners[i + 1]).charsetChanged(e);
182: }
183: }
184: }
185:
186: }
|