KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > composer > text > TextEditorView


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.undation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
package org.columba.mail.gui.composer.text;
17
18 import java.awt.Font JavaDoc;
19 import java.nio.charset.Charset JavaDoc;
20 import java.util.Observable JavaDoc;
21 import java.util.Observer JavaDoc;
22
23 import javax.swing.JTextPane JavaDoc;
24
25 import org.columba.core.charset.CharsetEvent;
26 import org.columba.core.charset.CharsetListener;
27 import org.columba.core.config.Config;
28 import org.columba.core.gui.base.HighlighterDocument;
29 import org.columba.core.gui.util.FontProperties;
30 import org.columba.core.xml.XmlElement;
31
32 /**
33  * @author frd
34  *
35  * To change this generated comment edit the template variable "typecomment":
36  * Window>Preferences>Java>Templates. To enable and disable the creation of type
37  * comments go to Window>Preferences>Java>Code Generation.
38  */

39 public class TextEditorView extends JTextPane JavaDoc implements Observer JavaDoc,
40         CharsetListener {
41
42     private HighlighterDocument message;
43
44     public TextEditorView(TextEditorController controller, HighlighterDocument m) {
45         super();
46
47         controller.getController().addCharsetListener(this);
48
49         message = m;
50
51         setStyledDocument(message);
52         setEditable(true);
53
54         Font JavaDoc font = FontProperties.getTextFont();
55         setFont(font);
56
57         XmlElement options = Config.getInstance().get("options").getElement(
58                 "/options");
59         XmlElement gui = options.getElement("gui");
60         XmlElement fonts = gui.getElement("fonts");
61
62         if (fonts == null) {
63             fonts = gui.addSubElement("fonts");
64         }
65
66         // register interest on configuratin changes
67
fonts.addObserver(this);
68     }
69
70 // public void installListener(TextEditorController controller) {
71
// message.addDocumentListener(controller);
72
// }
73

74     /**
75      *
76      * @see org.columba.mail.gui.config.general.MailOptionsDialog
77      *
78      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
79      */

80     public void update(Observable JavaDoc arg0, Object JavaDoc arg1) {
81         Font JavaDoc font = FontProperties.getTextFont();
82         setFont(font);
83     }
84
85     public void charsetChanged(CharsetEvent e) {
86         Charset JavaDoc charset = e.getCharset();
87
88         if (charset == null) {
89             charset = Charset.forName(System.getProperty("file.encoding"));
90         }
91
92         setContentType("text/plain; charset=\"" + charset.name() + "\"");
93     }
94
95     /**
96      * @see javax.swing.JEditorPane#getScrollableTracksViewportWidth()
97      */

98     public boolean getScrollableTracksViewportWidth() {
99         return true;
100     }
101 }
102
Popular Tags