KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > composer > SubjectController


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.
16
package org.columba.mail.gui.composer;
17
18 import java.util.Observable JavaDoc;
19 import java.util.Observer JavaDoc;
20
21 import javax.swing.event.DocumentEvent JavaDoc;
22 import javax.swing.event.DocumentListener JavaDoc;
23
24 import org.columba.core.xml.XmlElement;
25 import org.columba.mail.config.MailConfig;
26 import org.columba.mail.gui.composer.util.SubjectDialog;
27 import org.columba.mail.util.MailResourceLoader;
28
29
30 /**
31  * Subject editor component.
32  *
33  * @author fdietz
34  */

35 public class SubjectController implements DocumentListener JavaDoc, Observer JavaDoc {
36     private SubjectView view;
37     private ComposerController controller;
38     private XmlElement subject;
39     private boolean ask;
40
41     public SubjectController(ComposerController controller) {
42         this.controller = controller;
43
44         view = new SubjectView(this);
45
46         XmlElement composerOptions = MailConfig.getInstance().getComposerOptionsConfig()
47                                                          .getRoot().getElement("/options");
48         subject = composerOptions.getElement("subject");
49
50         if (subject == null) {
51             subject = composerOptions.addSubElement("subject");
52         }
53
54         subject.addObserver(this);
55
56         String JavaDoc askSubject = subject.getAttribute("ask_if_empty", "true");
57
58         if (askSubject.equals("true")) {
59             ask = true;
60         } else {
61             ask = false;
62         }
63     }
64
65     public void installListener() {
66         view.installListener(this);
67     }
68
69     public void updateComponents(boolean b) {
70         if (b) {
71             view.setText(controller.getModel().getHeaderField("Subject"));
72         } else {
73             controller.getModel().setHeaderField("Subject", view.getText());
74         }
75     }
76
77     public boolean checkState() {
78         String JavaDoc subject = controller.getModel().getHeaderField("Subject");
79
80         if (ask == true) {
81             if (subject.length() == 0) {
82                 subject = new String JavaDoc(MailResourceLoader.getString("dialog",
83                             "composer", "composer_no_subject")); //$NON-NLS-1$
84

85                 //SubjectDialog dialog = new SubjectDialog(composerInterface.composerFrame);
86
SubjectDialog dialog = new SubjectDialog();
87                 dialog.showDialog(subject);
88
89                 if (dialog.success()) {
90                     subject = dialog.getSubject();
91                 }
92
93                 controller.getModel().setHeaderField("Subject", subject);
94             }
95         }
96
97         return true;
98     }
99
100     /**************** DocumentListener implementation ***************/
101     public void insertUpdate(DocumentEvent JavaDoc e) {
102     }
103
104     public void removeUpdate(DocumentEvent JavaDoc e) {
105     }
106
107     public void changedUpdate(DocumentEvent JavaDoc e) {
108     }
109
110     /*
111      * Gets fired if configuration has changed.
112      *
113      * @see org.columba.mail.gui.config.general.MailOptionsDialog
114      *
115      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
116      */

117     public void update(Observable JavaDoc arg0, Object JavaDoc arg1) {
118         String JavaDoc askSubject = subject.getAttribute("ask_if_empty", "true");
119
120         if (askSubject.equals("true")) {
121             ask = true;
122         } else {
123             ask = false;
124         }
125     }
126
127     public SubjectView getView() {
128         return view;
129     }
130 }
131
Popular Tags