KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > mail > SendMailMode


1 /*
2  * SendMailMode.java
3  *
4  * Copyright (C) 2000-2004 Peter Graves
5  * $Id: SendMailMode.java,v 1.4 2004/09/21 00:03:22 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j.mail;
23
24 import java.awt.event.KeyEvent JavaDoc;
25 import org.armedbear.j.AbstractMode;
26 import org.armedbear.j.Buffer;
27 import org.armedbear.j.Constants;
28 import org.armedbear.j.Editor;
29 import org.armedbear.j.File;
30 import org.armedbear.j.Formatter;
31 import org.armedbear.j.Frame;
32 import org.armedbear.j.KeyMap;
33 import org.armedbear.j.Keywords;
34 import org.armedbear.j.Line;
35 import org.armedbear.j.Mode;
36 import org.armedbear.j.NavigationComponent;
37 import org.armedbear.j.Property;
38 import org.armedbear.j.ToolBar;
39 import org.armedbear.j.View;
40
41 public final class SendMailMode extends AbstractMode implements Constants, Mode
42 {
43     private static final SendMailMode mode = new SendMailMode();
44
45     private SendMailMode()
46     {
47         super(SEND_MAIL_MODE, SEND_MAIL_MODE_NAME);
48         keywords = new Keywords(this, true); // Ignore case.
49
setProperty(Property.WRAP_COL, 72);
50         setProperty(Property.WRAP, true);
51         // If user has turned on vertical rule, its default position should be
52
// the wrap column.
53
if (Editor.preferences().getIntegerProperty(Property.VERTICAL_RULE) != 0)
54             setProperty(Property.VERTICAL_RULE, getIntegerProperty(Property.WRAP_COL));
55         else
56             setProperty(Property.VERTICAL_RULE, 0);
57         setProperty(Property.SHOW_LINE_NUMBERS, false);
58         setProperty(Property.SHOW_CHANGE_MARKS, false);
59         setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
60         setProperty(Property.HIGHLIGHT_BRACKETS, false);
61     }
62
63     public static SendMailMode getMode()
64     {
65         return mode;
66     }
67
68     public Buffer createBuffer(File file)
69     {
70         return new SendMail(file);
71     }
72
73     public NavigationComponent getSidebarComponent(Editor editor)
74     {
75         View view = editor.getCurrentView();
76         if (view == null)
77             return null; // Shouldn't happen.
78
if (view.getSidebarComponent() == null)
79             view.setSidebarComponent(FolderTree.getInstance(editor.getFrame()));
80         return view.getSidebarComponent();
81     }
82
83     public Formatter getFormatter(Buffer buffer)
84     {
85         return new MessageFormatter(buffer);
86     }
87
88     protected void setKeyMapDefaults(KeyMap km)
89     {
90         km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
91         km.mapKey(':', "sendMailElectricColon");
92         km.mapKey(KeyEvent.VK_ENTER, CTRL_MASK, "send");
93         km.mapKey(KeyEvent.VK_TAB, 0, "sendMailTab");
94         km.mapKey(KeyEvent.VK_TAB, SHIFT_MASK, "sendMailBackTab");
95         km.mapKey(KeyEvent.VK_F12, CTRL_MASK | SHIFT_MASK,
96                   "wrapParagraphsInRegion");
97     }
98
99     protected ToolBar getDefaultToolBar(Frame frame)
100     {
101         return new SendMailModeToolBar(frame);
102     }
103
104     public boolean canIndent()
105     {
106         return true;
107     }
108
109     public boolean canIndentPaste()
110     {
111         return false;
112     }
113
114     public int getCorrectIndentation(Line line, Buffer buffer)
115     {
116         if (buffer instanceof SendMail)
117             if (((SendMail)buffer).isHeaderLine(line))
118                 return buffer.getIndentSize();
119
120         return 0;
121     }
122
123     public boolean confirmClose(Editor editor, Buffer buffer)
124     {
125         if (buffer instanceof SendMail) {
126             if (((SendMail)buffer).hasBeenSent())
127                 return true;
128             else if (!buffer.isModified())
129                 return true;
130             else
131                 return editor.confirm(buffer.toString(),
132                     "Message has not been sent; kill anyway?");
133         }
134         return super.confirmClose(editor, buffer);
135     }
136 }
137
Popular Tags