001: /*
002: * MessageMode.java
003: *
004: * Copyright (C) 2000-2002 Peter Graves
005: * $Id: MessageMode.java,v 1.4 2003/04/18 16:55:45 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.Formatter;
030: import org.armedbear.j.Frame;
031: import org.armedbear.j.HtmlLineSegment;
032: import org.armedbear.j.KeyMap;
033: import org.armedbear.j.Keywords;
034: import org.armedbear.j.Link;
035: import org.armedbear.j.Mode;
036: import org.armedbear.j.NavigationComponent;
037: import org.armedbear.j.Position;
038: import org.armedbear.j.Property;
039: import org.armedbear.j.ToolBar;
040: import org.armedbear.j.View;
041: import org.armedbear.j.WebLine;
042:
043: public final class MessageMode extends AbstractMode implements
044: Constants, Mode {
045: private static final Mode mode = new MessageMode();
046:
047: private MessageMode() {
048: super (MESSAGE_MODE, MESSAGE_MODE_NAME);
049: keywords = new Keywords(this , true); // Ignore case.
050: setProperty(Property.VERTICAL_RULE, 0);
051: setProperty(Property.SHOW_LINE_NUMBERS, false);
052: setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
053: setProperty(Property.HIGHLIGHT_BRACKETS, false);
054: }
055:
056: public static final Mode getMode() {
057: return mode;
058: }
059:
060: public NavigationComponent getSidebarComponent(Editor editor) {
061: View view = editor.getCurrentView();
062: if (view == null)
063: return null; // Shouldn't happen.
064: if (view.getSidebarComponent() == null)
065: view.setSidebarComponent(FolderTree.getInstance(editor
066: .getFrame()));
067: return view.getSidebarComponent();
068: }
069:
070: public final Formatter getFormatter(Buffer buffer) {
071: return new MessageFormatter(buffer);
072: }
073:
074: protected void setKeyMapDefaults(KeyMap km) {
075: km.mapKey('h', "messageToggleHeaders");
076: km.mapKey('f', "messageForward");
077: km.mapKey('F', "messageFlag");
078: km.mapKey('r', "messageReplyToSender");
079: km.mapKey('g', "messageReplyToGroup");
080: km.mapKey('d', "messageDelete");
081: km.mapKey('m', "messageMoveToFolder");
082: km.mapKey('n', "messageNext");
083: km.mapKey('p', "messagePrevious");
084: km.mapKey('N', "messageNextInThread");
085: km.mapKey('P', "messagePreviousInThread");
086: km.mapKey('i', "messageIndex");
087: km.mapKey('R', "messageToggleRaw");
088: km.mapKey('v', "messageViewAttachment");
089: km.mapKey(KeyEvent.VK_ENTER, 0, "messageViewAttachment");
090: km.mapKey('s', "messageSaveAttachment");
091: km.mapKey('b', "bounce");
092: km.mapKey(KeyEvent.VK_F12, CTRL_MASK, "messageToggleWrap");
093: }
094:
095: protected final ToolBar getDefaultToolBar(Frame frame) {
096: return new MessageModeToolBar(frame);
097: }
098:
099: public final String getContextString(Editor editor, boolean verbose /*ignored*/) {
100: return getContextString(editor.getDot());
101: }
102:
103: public final String getMouseMovedContextString(Editor editor,
104: Position pos) {
105: // We want to clear the status text if the mouse is not over a link, so
106: // return "" instead of null.
107: final String s = getContextString(pos);
108: return s != null ? s : "";
109: }
110:
111: private String getContextString(Position pos) {
112: if (pos != null && pos.getLine() instanceof WebLine) {
113: HtmlLineSegment segment = ((WebLine) pos.getLine())
114: .findSegment(pos.getOffset());
115: if (segment != null) {
116: Link link = segment.getLink();
117: if (link != null)
118: return link.getTarget();
119: }
120: }
121: return null;
122: }
123: }
|