1 package org.columba.mail.gui.composer; 17 18 import java.util.Observable ; 19 import java.util.Observer ; 20 21 import javax.swing.event.DocumentEvent ; 22 import javax.swing.event.DocumentListener ; 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 35 public class SubjectController implements DocumentListener , Observer { 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 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 subject = controller.getModel().getHeaderField("Subject"); 79 80 if (ask == true) { 81 if (subject.length() == 0) { 82 subject = new String (MailResourceLoader.getString("dialog", 83 "composer", "composer_no_subject")); 85 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 101 public void insertUpdate(DocumentEvent e) { 102 } 103 104 public void removeUpdate(DocumentEvent e) { 105 } 106 107 public void changedUpdate(DocumentEvent e) { 108 } 109 110 117 public void update(Observable arg0, Object arg1) { 118 String 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 |