01: /*
02: * Copyright (c) 2000, Jacob Smullyan.
03: *
04: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
05: * for the latest version.
06: *
07: * SkunkDAV is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License as published
09: * by the Free Software Foundation; either version 2, or (at your option)
10: * any later version.
11: *
12: * SkunkDAV 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 GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with SkunkDAV; see the file COPYING. If not, write to the Free
19: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20: * 02111-1307, USA.
21: */
22:
23: package org.skunk.dav.client.gui.editor;
24:
25: import java.awt.event.InputEvent;
26: import java.awt.event.KeyEvent;
27: import javax.swing.AbstractAction;
28: import javax.swing.KeyStroke;
29: import javax.swing.JTextPane;
30: import javax.swing.text.DefaultEditorKit;
31: import javax.swing.text.JTextComponent;
32: import javax.swing.text.Keymap;
33:
34: public class KeyMapper {
35: public static final JTextComponent.KeyBinding[] defaultBindings = new JTextComponent.KeyBinding[] {
36: //move to start of line
37: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
38: KeyEvent.VK_A, InputEvent.CTRL_MASK),
39: DefaultEditorKit.beginLineAction),
40: //move to end of line
41: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
42: KeyEvent.VK_E, InputEvent.CTRL_MASK),
43: DefaultEditorKit.endLineAction),
44: //move forward one character
45: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
46: KeyEvent.VK_F, InputEvent.CTRL_MASK),
47: DefaultEditorKit.forwardAction),
48: //move backward one character
49: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
50: KeyEvent.VK_B, InputEvent.CTRL_MASK),
51: DefaultEditorKit.backwardAction),
52: //move down one row
53: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
54: KeyEvent.VK_N, InputEvent.CTRL_MASK),
55: DefaultEditorKit.downAction),
56: //move up one row
57: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
58: KeyEvent.VK_P, InputEvent.CTRL_MASK),
59: DefaultEditorKit.upAction),
60: //page down
61: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
62: KeyEvent.VK_F, InputEvent.CTRL_MASK
63: | InputEvent.SHIFT_MASK),
64: DefaultEditorKit.pageDownAction),
65: //page up
66: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
67: KeyEvent.VK_F, InputEvent.ALT_MASK
68: | InputEvent.SHIFT_MASK),
69: DefaultEditorKit.pageUpAction),
70: //delete forward one char
71: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
72: KeyEvent.VK_D, InputEvent.CTRL_MASK),
73: DefaultEditorKit.deleteNextCharAction),
74: //move back by paragraph
75: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
76: KeyEvent.VK_BRACELEFT, InputEvent.ALT_MASK),
77: DefaultEditorKit.beginParagraphAction),
78: //move forward by paragraph
79: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
80: KeyEvent.VK_BRACERIGHT, InputEvent.ALT_MASK),
81: DefaultEditorKit.endParagraphAction),
82: //move back by word
83: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
84: KeyEvent.VK_B, InputEvent.ALT_MASK),
85: DefaultEditorKit.beginWordAction),
86: //move forward by word
87: new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(
88: KeyEvent.VK_F, InputEvent.ALT_MASK),
89: DefaultEditorKit.nextWordAction) };
90:
91: public static void loadKeymap(JTextComponent c) {
92: Keymap k = c.getKeymap();
93: JTextComponent.loadKeymap(k, defaultBindings, c.getActions());
94: }
95: }
|