001: /*
002: * ListRegistersMode.java
003: *
004: * Copyright (C) 2002 Peter Graves
005: * $Id: ListRegistersMode.java,v 1.1.1.1 2002/09/24 16:08:12 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.event.KeyEvent;
025:
026: public class ListRegistersMode extends AbstractMode implements
027: Constants, Mode {
028: private static final ListRegistersMode mode = new ListRegistersMode();
029:
030: private ListRegistersMode() {
031: super (LIST_REGISTERS_MODE, LIST_REGISTERS_MODE_NAME);
032: setProperty(Property.SHOW_LINE_NUMBERS, false);
033: setProperty(Property.SHOW_CHANGE_MARKS, false);
034: setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
035: setProperty(Property.HIGHLIGHT_BRACKETS, false);
036: }
037:
038: public static final ListRegistersMode getMode() {
039: return mode;
040: }
041:
042: public Formatter getFormatter(Buffer buffer) {
043: return new ListRegistersFormatter(buffer);
044: }
045:
046: protected void setKeyMapDefaults(KeyMap km) {
047: km.mapKey(KeyEvent.VK_ENTER, 0,
048: "ListRegistersMode._editRegister");
049: km.mapKey(KeyEvent.VK_ENTER, CTRL_MASK,
050: "ListRegistersMode._insertRegister");
051: km.mapKey(KeyEvent.VK_G, CTRL_MASK | SHIFT_MASK,
052: "ListRegistersMode._editRegister");
053: km.mapKey(KeyEvent.VK_DELETE, 0,
054: "ListRegistersMode._clearRegister");
055: km.mapKey(KeyEvent.VK_UP, 0, "ListRegistersMode.registerUp");
056: km.mapKey(KeyEvent.VK_KP_UP, 0, "ListRegistersMode.registerUp");
057: km
058: .mapKey(KeyEvent.VK_DOWN, 0,
059: "ListRegistersMode.registerDown");
060: km.mapKey(KeyEvent.VK_KP_DOWN, 0,
061: "ListRegistersMode.registerDown");
062: }
063:
064: public static final void _editRegister() {
065: final Editor editor = Editor.currentEditor();
066: if (editor.getDot() == null)
067: return;
068: final Buffer buffer = editor.getBuffer();
069: if (!(buffer instanceof ListRegistersBuffer))
070: return;
071: Line line = editor.getDotLine();
072: while (!(line instanceof ListRegistersLine)) {
073: line = line.previous();
074: if (line == null)
075: return;
076: }
077: Debug.assertTrue(line instanceof ListRegistersLine);
078: String name = ((ListRegistersLine) line).getRegisterName();
079: if (name != null)
080: Registers.editRegister(name);
081: }
082:
083: public static final void _insertRegister() {
084: final Editor editor = Editor.currentEditor();
085: final Editor other = editor.getOtherEditor();
086: if (other == null)
087: return;
088: if (editor.getDot() == null)
089: return;
090: final Buffer buffer = editor.getBuffer();
091: if (!(buffer instanceof ListRegistersBuffer))
092: return;
093: Line line = editor.getDotLine();
094: while (!(line instanceof ListRegistersLine)) {
095: line = line.previous();
096: if (line == null)
097: return;
098: }
099: Debug.assertTrue(line instanceof ListRegistersLine);
100: String name = ((ListRegistersLine) line).getRegisterName();
101: if (name != null) {
102: String text = Registers.getText(name);
103: if (text != null)
104: other.paste(text);
105: }
106: }
107:
108: public static final void _clearRegister() {
109: final Editor editor = Editor.currentEditor();
110: if (editor.getDot() == null)
111: return;
112: final Buffer buffer = editor.getBuffer();
113: if (!(buffer instanceof ListRegistersBuffer))
114: return;
115: Line line = editor.getDotLine();
116: while (!(line instanceof ListRegistersLine)) {
117: line = line.previous();
118: if (line == null)
119: return;
120: }
121: Debug.assertTrue(line instanceof ListRegistersLine);
122: String name = ((ListRegistersLine) line).getRegisterName();
123: if (name != null)
124: Registers.clearRegister(name);
125: }
126:
127: public static void registerDown() {
128: final Editor editor = Editor.currentEditor();
129: final Buffer buffer = editor.getBuffer();
130: if (buffer instanceof ListRegistersBuffer) {
131: for (Line line = editor.getDotLine().next(); line != null; line = line
132: .next()) {
133: if (line instanceof ListRegistersLine
134: && line.getText().startsWith("Register ")) {
135: editor.moveDotTo(line, 0);
136: break;
137: }
138: }
139: }
140: }
141:
142: public static void registerUp() {
143: final Editor editor = Editor.currentEditor();
144: final Buffer buffer = editor.getBuffer();
145: if (buffer instanceof ListRegistersBuffer) {
146: for (Line line = editor.getDotLine().previous(); line != null; line = line
147: .previous()) {
148: if (line instanceof ListRegistersLine
149: && line.getText().startsWith("Register ")) {
150: editor.moveDotTo(line, 0);
151: break;
152: }
153: }
154: }
155: }
156: }
|