KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > ListTagsMode


1 /*
2  * ListTagsMode.java
3  *
4  * Copyright (C) 2002 Peter Graves
5  * $Id: ListTagsMode.java,v 1.1.1.1 2002/09/24 16:08:39 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;
23
24 import java.awt.AWTEvent JavaDoc;
25 import java.awt.event.KeyEvent JavaDoc;
26 import java.awt.event.MouseEvent JavaDoc;
27 import javax.swing.JPopupMenu JavaDoc;
28
29 public final class ListTagsMode extends AbstractMode implements Constants, Mode
30 {
31     private static final ListTagsMode mode = new ListTagsMode();
32
33     private ListTagsMode()
34     {
35         super(LIST_TAGS_MODE, LIST_TAGS_MODE_NAME);
36         setProperty(Property.VERTICAL_RULE, 0);
37         setProperty(Property.SHOW_LINE_NUMBERS, false);
38         setProperty(Property.SHOW_CHANGE_MARKS, false);
39         setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
40         setProperty(Property.HIGHLIGHT_BRACKETS, false);
41     }
42
43     public static final ListTagsMode getMode()
44     {
45         return mode;
46     }
47
48     public JPopupMenu JavaDoc getContextMenu(Editor editor)
49     {
50         return null;
51     }
52
53     public Formatter getFormatter(Buffer buffer)
54     {
55         return new ListTagsFormatter(buffer);
56     }
57
58     protected void setKeyMapDefaults(KeyMap km)
59     {
60         km.mapKey(KeyEvent.VK_UP, 0, "tagUp");
61         km.mapKey(KeyEvent.VK_KP_UP, 0, "tagUp");
62         km.mapKey(KeyEvent.VK_DOWN, 0, "tagDown");
63         km.mapKey(KeyEvent.VK_KP_DOWN, 0, "tagDown");
64         km.mapKey(KeyEvent.VK_ENTER, 0, "jumpToTag");
65         km.mapKey(KeyEvent.VK_ENTER, CTRL_MASK, "jumpToTagAndKillList");
66         km.mapKey(KeyEvent.VK_G, CTRL_MASK | SHIFT_MASK, "jumpToTag");
67         km.mapKey(VK_DOUBLE_MOUSE_1, 0, "mouseJumpToTag");
68         km.mapKey(VK_MOUSE_2, 0, "mouseJumpToTag");
69     }
70
71     public static void jumpToTag()
72     {
73         final Editor editor = Editor.currentEditor();
74         final Buffer buffer = editor.getBuffer();
75         if (buffer instanceof ListTagsBuffer)
76             ((ListTagsBuffer)buffer).jumpToTag(editor, false);
77     }
78
79     public static void jumpToTagAndKillList()
80     {
81         final Editor editor = Editor.currentEditor();
82         final Buffer buffer = editor.getBuffer();
83         if (buffer instanceof ListTagsBuffer)
84             ((ListTagsBuffer)buffer).jumpToTag(editor, true);
85     }
86
87     public static void mouseJumpToTag()
88     {
89         final Editor editor = Editor.currentEditor();
90         final Buffer buffer = editor.getBuffer();
91         if (buffer instanceof ListTagsBuffer) {
92             AWTEvent JavaDoc e = editor.getDispatcher().getLastEvent();
93             if (e instanceof MouseEvent JavaDoc) {
94                 editor.mouseMoveDotToPoint((MouseEvent JavaDoc)e);
95                 ((ListTagsBuffer)buffer).jumpToTag(editor, false);
96             }
97         }
98     }
99
100     public static void tagDown()
101     {
102         final Editor editor = Editor.currentEditor();
103         final Buffer buffer = editor.getBuffer();
104         if (buffer instanceof ListTagsBuffer) {
105             for (Line line = editor.getDotLine().next(); line != null; line = line.next()) {
106                 if (line instanceof TagLine) {
107                     editor.moveDotTo(line, 0);
108                     break;
109                 }
110             }
111         }
112     }
113
114     public static void tagUp()
115     {
116         final Editor editor = Editor.currentEditor();
117         final Buffer buffer = editor.getBuffer();
118         if (buffer instanceof ListTagsBuffer) {
119             for (Line line = editor.getDotLine().previous(); line != null; line = line.previous()) {
120                 if (line instanceof TagLine) {
121                     editor.moveDotTo(line, 0);
122                     break;
123                 }
124             }
125         }
126     }
127 }
128
Popular Tags