001: /*
002: * MailboxMode.java
003: *
004: * Copyright (C) 1998-2002 Peter Graves
005: * $Id: MailboxMode.java,v 1.3 2002/11/15 20:23:09 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 javax.swing.JCheckBoxMenuItem;
026: import org.armedbear.j.AbstractMode;
027: import org.armedbear.j.Buffer;
028: import org.armedbear.j.Constants;
029: import org.armedbear.j.Dispatcher;
030: import org.armedbear.j.Editor;
031: import org.armedbear.j.Formatter;
032: import org.armedbear.j.Frame;
033: import org.armedbear.j.KeyMap;
034: import org.armedbear.j.Line;
035: import org.armedbear.j.Menu;
036: import org.armedbear.j.Mode;
037: import org.armedbear.j.NavigationComponent;
038: import org.armedbear.j.Position;
039: import org.armedbear.j.Property;
040: import org.armedbear.j.ToolBar;
041: import org.armedbear.j.View;
042:
043: public class MailboxMode extends AbstractMode implements Constants,
044: Mode {
045: private static final MailboxMode mode = new MailboxMode();
046:
047: private MailboxMode() {
048: this (MAILBOX_MODE, MAILBOX_MODE_NAME);
049: }
050:
051: protected MailboxMode(int id, String displayName) {
052: super (id, displayName);
053: setProperty(Property.VERTICAL_RULE, 0);
054: setProperty(Property.SHOW_LINE_NUMBERS, false);
055: setProperty(Property.SHOW_CHANGE_MARKS, false);
056: setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
057: setProperty(Property.HIGHLIGHT_BRACKETS, false);
058: }
059:
060: public static Mode getMode() {
061: return mode;
062: }
063:
064: public NavigationComponent getSidebarComponent(Editor editor) {
065: View view = editor.getCurrentView();
066: if (view == null)
067: return null; // Shouldn't happen.
068: if (view.getSidebarComponent() == null)
069: view.setSidebarComponent(FolderTree.getInstance(editor
070: .getFrame()));
071: return view.getSidebarComponent();
072: }
073:
074: public Formatter getFormatter(Buffer buffer) {
075: return new MailboxFormatter(buffer);
076: }
077:
078: protected void setKeyMapDefaults(KeyMap km) {
079: km.mapKey(KeyEvent.VK_HOME, 0, "bol");
080: km.mapKey(KeyEvent.VK_END, CTRL_MASK, "mailboxLastMessage");
081: km
082: .mapKey(KeyEvent.VK_ENTER, 0,
083: "mailboxReadMessageOtherWindow");
084: km.mapKey(KeyEvent.VK_ENTER, CTRL_MASK, "mailboxReadMessage");
085: km.mapKey(KeyEvent.VK_G, CTRL_MASK | SHIFT_MASK,
086: "mailboxReadMessage");
087: km
088: .mapKey(VK_DOUBLE_MOUSE_1, 0,
089: "mailboxReadMessageOtherWindow");
090: km.mapKey(VK_MOUSE_2, 0, "mailboxReadMessageOtherWindow");
091: km.mapKey('G', "mailboxGetNewMessages");
092: km.mapKey('s', "mailboxSaveToFolder");
093: km.mapKey('m', "mailboxMoveToFolder");
094: km.mapKey('d', "mailboxDelete");
095: km.mapKey('u', "mailboxUndelete");
096: km.mapKey('M', "mailboxMarkRead");
097: km.mapKey(KeyEvent.VK_M, CTRL_MASK | SHIFT_MASK,
098: "mailboxMarkUnread");
099: km.mapKey('t', "mailboxTag");
100: km.mapKey(KeyEvent.VK_T, CTRL_MASK, "mailboxTagPattern");
101: km.mapKey('T', "mailboxUntagAll");
102: km.mapKey('R', "mailboxToggleRaw");
103: km.mapKey('$', "mailboxExpunge");
104: km.mapKey('c', "compose");
105: km.mapKey('l', "mailboxLimit");
106: km.mapKey('L', "mailboxUnlimit");
107: km.mapKey('b', "bounce");
108: km.mapKey('F', "mailboxFlag");
109: }
110:
111: public void populateMenu(Editor editor, Menu menu) {
112: final String text = menu.getText();
113: if (text == "View") {
114: final Dispatcher dispatcher = editor.getDispatcher();
115: JCheckBoxMenuItem toolbarMenuItem = new JCheckBoxMenuItem(
116: "Toolbar");
117: toolbarMenuItem.setMnemonic('T');
118: toolbarMenuItem.setActionCommand("toggleToolbar");
119: toolbarMenuItem.addActionListener(dispatcher);
120: toolbarMenuItem.setSelected(editor.getFrame()
121: .getShowToolbar());
122: menu.add(toolbarMenuItem);
123: JCheckBoxMenuItem sidebarMenuItem = new JCheckBoxMenuItem(
124: "Sidebar");
125: sidebarMenuItem.setMnemonic('S');
126: sidebarMenuItem.setActionCommand("toggleSidebar");
127: sidebarMenuItem.addActionListener(dispatcher);
128: sidebarMenuItem.setSelected(editor.getSidebar() != null);
129: menu.add(sidebarMenuItem);
130: menu.addSeparator();
131: JCheckBoxMenuItem groupByThread = new JCheckBoxMenuItem(
132: "Group Messages By Thread");
133: groupByThread.setMnemonic('G');
134: groupByThread.setActionCommand("toggleGroupByThread");
135: groupByThread.addActionListener(dispatcher);
136: if (editor.getBuffer() instanceof Mailbox) {
137: groupByThread.setSelected(editor.getBuffer()
138: .getBooleanProperty(Property.GROUP_BY_THREAD));
139: }
140: menu.add(groupByThread);
141: menu.addSeparator();
142: menu.add(editor, "Split Window", 'W', "splitWindow");
143: menu.add(editor, "Unsplit Window", 'U', "unsplitWindow");
144: menu.add(editor, "Close Window", 'C', "killWindow");
145: } else
146: super .populateMenu(editor, menu);
147: }
148:
149: protected ToolBar getDefaultToolBar(Frame frame) {
150: return new MailboxModeToolBar(frame);
151: }
152:
153: public String getContextString(Editor editor, boolean verbose) {
154: Position dot = editor.getDot();
155: if (dot != null) {
156: final Line dotLine = dot.getLine();
157: if (dotLine instanceof MailboxLine) {
158: MailboxEntry entry = ((MailboxLine) dotLine)
159: .getMailboxEntry();
160: if (entry != null)
161: return entry.getSubject();
162: }
163: }
164: return null;
165: }
166: }
|