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.
016: package org.columba.mail.gui.composer;
017:
018: import java.util.Observable;
019: import java.util.Observer;
020:
021: import javax.swing.event.DocumentEvent;
022: import javax.swing.event.DocumentListener;
023:
024: import org.columba.core.xml.XmlElement;
025: import org.columba.mail.config.MailConfig;
026: import org.columba.mail.gui.composer.util.SubjectDialog;
027: import org.columba.mail.util.MailResourceLoader;
028:
029: /**
030: * Subject editor component.
031: *
032: * @author fdietz
033: */
034: public class SubjectController implements DocumentListener, Observer {
035: private SubjectView view;
036: private ComposerController controller;
037: private XmlElement subject;
038: private boolean ask;
039:
040: public SubjectController(ComposerController controller) {
041: this .controller = controller;
042:
043: view = new SubjectView(this );
044:
045: XmlElement composerOptions = MailConfig.getInstance()
046: .getComposerOptionsConfig().getRoot().getElement(
047: "/options");
048: subject = composerOptions.getElement("subject");
049:
050: if (subject == null) {
051: subject = composerOptions.addSubElement("subject");
052: }
053:
054: subject.addObserver(this );
055:
056: String askSubject = subject
057: .getAttribute("ask_if_empty", "true");
058:
059: if (askSubject.equals("true")) {
060: ask = true;
061: } else {
062: ask = false;
063: }
064: }
065:
066: public void installListener() {
067: view.installListener(this );
068: }
069:
070: public void updateComponents(boolean b) {
071: if (b) {
072: view.setText(controller.getModel()
073: .getHeaderField("Subject"));
074: } else {
075: controller.getModel().setHeaderField("Subject",
076: view.getText());
077: }
078: }
079:
080: public boolean checkState() {
081: String subject = controller.getModel()
082: .getHeaderField("Subject");
083:
084: if (ask == true) {
085: if (subject.length() == 0) {
086: subject = new String(MailResourceLoader.getString(
087: "dialog", "composer", "composer_no_subject")); //$NON-NLS-1$
088:
089: //SubjectDialog dialog = new SubjectDialog(composerInterface.composerFrame);
090: SubjectDialog dialog = new SubjectDialog();
091: dialog.showDialog(subject);
092:
093: if (dialog.success()) {
094: subject = dialog.getSubject();
095: }
096:
097: controller.getModel()
098: .setHeaderField("Subject", subject);
099: }
100: }
101:
102: return true;
103: }
104:
105: /**************** DocumentListener implementation ***************/
106: public void insertUpdate(DocumentEvent e) {
107: }
108:
109: public void removeUpdate(DocumentEvent e) {
110: }
111:
112: public void changedUpdate(DocumentEvent e) {
113: }
114:
115: /*
116: * Gets fired if configuration has changed.
117: *
118: * @see org.columba.mail.gui.config.general.MailOptionsDialog
119: *
120: * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
121: */
122: public void update(Observable arg0, Object arg1) {
123: String askSubject = subject
124: .getAttribute("ask_if_empty", "true");
125:
126: if (askSubject.equals("true")) {
127: ask = true;
128: } else {
129: ask = false;
130: }
131: }
132:
133: public SubjectView getView() {
134: return view;
135: }
136: }
|