001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.undation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: package org.columba.mail.gui.composer.text;
017:
018: import java.awt.Font;
019: import java.nio.charset.Charset;
020: import java.util.Observable;
021: import java.util.Observer;
022:
023: import javax.swing.JTextPane;
024:
025: import org.columba.core.charset.CharsetEvent;
026: import org.columba.core.charset.CharsetListener;
027: import org.columba.core.config.Config;
028: import org.columba.core.gui.base.HighlighterDocument;
029: import org.columba.core.gui.util.FontProperties;
030: import org.columba.core.xml.XmlElement;
031:
032: /**
033: * @author frd
034: *
035: * To change this generated comment edit the template variable "typecomment":
036: * Window>Preferences>Java>Templates. To enable and disable the creation of type
037: * comments go to Window>Preferences>Java>Code Generation.
038: */
039: public class TextEditorView extends JTextPane implements Observer,
040: CharsetListener {
041:
042: private HighlighterDocument message;
043:
044: public TextEditorView(TextEditorController controller,
045: HighlighterDocument m) {
046: super ();
047:
048: controller.getController().addCharsetListener(this );
049:
050: message = m;
051:
052: setStyledDocument(message);
053: setEditable(true);
054:
055: Font font = FontProperties.getTextFont();
056: setFont(font);
057:
058: XmlElement options = Config.getInstance().get("options")
059: .getElement("/options");
060: XmlElement gui = options.getElement("gui");
061: XmlElement fonts = gui.getElement("fonts");
062:
063: if (fonts == null) {
064: fonts = gui.addSubElement("fonts");
065: }
066:
067: // register interest on configuratin changes
068: fonts.addObserver(this );
069: }
070:
071: // public void installListener(TextEditorController controller) {
072: // message.addDocumentListener(controller);
073: // }
074:
075: /**
076: *
077: * @see org.columba.mail.gui.config.general.MailOptionsDialog
078: *
079: * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
080: */
081: public void update(Observable arg0, Object arg1) {
082: Font font = FontProperties.getTextFont();
083: setFont(font);
084: }
085:
086: public void charsetChanged(CharsetEvent e) {
087: Charset charset = e.getCharset();
088:
089: if (charset == null) {
090: charset = Charset.forName(System
091: .getProperty("file.encoding"));
092: }
093:
094: setContentType("text/plain; charset=\"" + charset.name() + "\"");
095: }
096:
097: /**
098: * @see javax.swing.JEditorPane#getScrollableTracksViewportWidth()
099: */
100: public boolean getScrollableTracksViewportWidth() {
101: return true;
102: }
103: }
|