001: /*
002: * SendMailMode.java
003: *
004: * Copyright (C) 2000-2004 Peter Graves
005: * $Id: SendMailMode.java,v 1.4 2004/09/21 00:03:22 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j.mail;
023:
024: import java.awt.event.KeyEvent;
025: import org.armedbear.j.AbstractMode;
026: import org.armedbear.j.Buffer;
027: import org.armedbear.j.Constants;
028: import org.armedbear.j.Editor;
029: import org.armedbear.j.File;
030: import org.armedbear.j.Formatter;
031: import org.armedbear.j.Frame;
032: import org.armedbear.j.KeyMap;
033: import org.armedbear.j.Keywords;
034: import org.armedbear.j.Line;
035: import org.armedbear.j.Mode;
036: import org.armedbear.j.NavigationComponent;
037: import org.armedbear.j.Property;
038: import org.armedbear.j.ToolBar;
039: import org.armedbear.j.View;
040:
041: public final class SendMailMode extends AbstractMode implements
042: Constants, Mode {
043: private static final SendMailMode mode = new SendMailMode();
044:
045: private SendMailMode() {
046: super (SEND_MAIL_MODE, SEND_MAIL_MODE_NAME);
047: keywords = new Keywords(this , true); // Ignore case.
048: setProperty(Property.WRAP_COL, 72);
049: setProperty(Property.WRAP, true);
050: // If user has turned on vertical rule, its default position should be
051: // the wrap column.
052: if (Editor.preferences().getIntegerProperty(
053: Property.VERTICAL_RULE) != 0)
054: setProperty(Property.VERTICAL_RULE,
055: getIntegerProperty(Property.WRAP_COL));
056: else
057: setProperty(Property.VERTICAL_RULE, 0);
058: setProperty(Property.SHOW_LINE_NUMBERS, false);
059: setProperty(Property.SHOW_CHANGE_MARKS, false);
060: setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
061: setProperty(Property.HIGHLIGHT_BRACKETS, false);
062: }
063:
064: public static SendMailMode getMode() {
065: return mode;
066: }
067:
068: public Buffer createBuffer(File file) {
069: return new SendMail(file);
070: }
071:
072: public NavigationComponent getSidebarComponent(Editor editor) {
073: View view = editor.getCurrentView();
074: if (view == null)
075: return null; // Shouldn't happen.
076: if (view.getSidebarComponent() == null)
077: view.setSidebarComponent(FolderTree.getInstance(editor
078: .getFrame()));
079: return view.getSidebarComponent();
080: }
081:
082: public Formatter getFormatter(Buffer buffer) {
083: return new MessageFormatter(buffer);
084: }
085:
086: protected void setKeyMapDefaults(KeyMap km) {
087: km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
088: km.mapKey(':', "sendMailElectricColon");
089: km.mapKey(KeyEvent.VK_ENTER, CTRL_MASK, "send");
090: km.mapKey(KeyEvent.VK_TAB, 0, "sendMailTab");
091: km.mapKey(KeyEvent.VK_TAB, SHIFT_MASK, "sendMailBackTab");
092: km.mapKey(KeyEvent.VK_F12, CTRL_MASK | SHIFT_MASK,
093: "wrapParagraphsInRegion");
094: }
095:
096: protected ToolBar getDefaultToolBar(Frame frame) {
097: return new SendMailModeToolBar(frame);
098: }
099:
100: public boolean canIndent() {
101: return true;
102: }
103:
104: public boolean canIndentPaste() {
105: return false;
106: }
107:
108: public int getCorrectIndentation(Line line, Buffer buffer) {
109: if (buffer instanceof SendMail)
110: if (((SendMail) buffer).isHeaderLine(line))
111: return buffer.getIndentSize();
112:
113: return 0;
114: }
115:
116: public boolean confirmClose(Editor editor, Buffer buffer) {
117: if (buffer instanceof SendMail) {
118: if (((SendMail) buffer).hasBeenSent())
119: return true;
120: else if (!buffer.isModified())
121: return true;
122: else
123: return editor.confirm(buffer.toString(),
124: "Message has not been sent; kill anyway?");
125: }
126: return super.confirmClose(editor, buffer);
127: }
128: }
|