001: /*
002: * ListTagsMode.java
003: *
004: * Copyright (C) 2002 Peter Graves
005: * $Id: ListTagsMode.java,v 1.1.1.1 2002/09/24 16:08:39 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;
023:
024: import java.awt.AWTEvent;
025: import java.awt.event.KeyEvent;
026: import java.awt.event.MouseEvent;
027: import javax.swing.JPopupMenu;
028:
029: public final class ListTagsMode extends AbstractMode implements
030: Constants, Mode {
031: private static final ListTagsMode mode = new ListTagsMode();
032:
033: private ListTagsMode() {
034: super (LIST_TAGS_MODE, LIST_TAGS_MODE_NAME);
035: setProperty(Property.VERTICAL_RULE, 0);
036: setProperty(Property.SHOW_LINE_NUMBERS, false);
037: setProperty(Property.SHOW_CHANGE_MARKS, false);
038: setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
039: setProperty(Property.HIGHLIGHT_BRACKETS, false);
040: }
041:
042: public static final ListTagsMode getMode() {
043: return mode;
044: }
045:
046: public JPopupMenu getContextMenu(Editor editor) {
047: return null;
048: }
049:
050: public Formatter getFormatter(Buffer buffer) {
051: return new ListTagsFormatter(buffer);
052: }
053:
054: protected void setKeyMapDefaults(KeyMap km) {
055: km.mapKey(KeyEvent.VK_UP, 0, "tagUp");
056: km.mapKey(KeyEvent.VK_KP_UP, 0, "tagUp");
057: km.mapKey(KeyEvent.VK_DOWN, 0, "tagDown");
058: km.mapKey(KeyEvent.VK_KP_DOWN, 0, "tagDown");
059: km.mapKey(KeyEvent.VK_ENTER, 0, "jumpToTag");
060: km.mapKey(KeyEvent.VK_ENTER, CTRL_MASK, "jumpToTagAndKillList");
061: km.mapKey(KeyEvent.VK_G, CTRL_MASK | SHIFT_MASK, "jumpToTag");
062: km.mapKey(VK_DOUBLE_MOUSE_1, 0, "mouseJumpToTag");
063: km.mapKey(VK_MOUSE_2, 0, "mouseJumpToTag");
064: }
065:
066: public static void jumpToTag() {
067: final Editor editor = Editor.currentEditor();
068: final Buffer buffer = editor.getBuffer();
069: if (buffer instanceof ListTagsBuffer)
070: ((ListTagsBuffer) buffer).jumpToTag(editor, false);
071: }
072:
073: public static void jumpToTagAndKillList() {
074: final Editor editor = Editor.currentEditor();
075: final Buffer buffer = editor.getBuffer();
076: if (buffer instanceof ListTagsBuffer)
077: ((ListTagsBuffer) buffer).jumpToTag(editor, true);
078: }
079:
080: public static void mouseJumpToTag() {
081: final Editor editor = Editor.currentEditor();
082: final Buffer buffer = editor.getBuffer();
083: if (buffer instanceof ListTagsBuffer) {
084: AWTEvent e = editor.getDispatcher().getLastEvent();
085: if (e instanceof MouseEvent) {
086: editor.mouseMoveDotToPoint((MouseEvent) e);
087: ((ListTagsBuffer) buffer).jumpToTag(editor, false);
088: }
089: }
090: }
091:
092: public static void tagDown() {
093: final Editor editor = Editor.currentEditor();
094: final Buffer buffer = editor.getBuffer();
095: if (buffer instanceof ListTagsBuffer) {
096: for (Line line = editor.getDotLine().next(); line != null; line = line
097: .next()) {
098: if (line instanceof TagLine) {
099: editor.moveDotTo(line, 0);
100: break;
101: }
102: }
103: }
104: }
105:
106: public static void tagUp() {
107: final Editor editor = Editor.currentEditor();
108: final Buffer buffer = editor.getBuffer();
109: if (buffer instanceof ListTagsBuffer) {
110: for (Line line = editor.getDotLine().previous(); line != null; line = line
111: .previous()) {
112: if (line instanceof TagLine) {
113: editor.moveDotTo(line, 0);
114: break;
115: }
116: }
117: }
118: }
119: }
|