Browse Source

Adds listeners to the TextPane for Control+Home/End and the appropriate behaviour

Fixes issue 3795
Change-Id: If77f1f08bc8733617d9f1e116dacf21dd9729324
Reviewed-on: http://gerrit.dmdirc.com/973
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
tags/0.6.4
Simon Mott 14 years ago
parent
commit
955061014d

+ 12
- 0
src/com/dmdirc/addons/ui_swing/components/frames/TextFrame.java View File

@@ -40,6 +40,8 @@ import com.dmdirc.addons.ui_swing.textpane.LineInfo;
40 40
 import com.dmdirc.addons.ui_swing.textpane.TextPane;
41 41
 import com.dmdirc.addons.ui_swing.textpane.TextPanePageDownAction;
42 42
 import com.dmdirc.addons.ui_swing.textpane.TextPanePageUpAction;
43
+import com.dmdirc.addons.ui_swing.textpane.TextPaneHomeAction;
44
+import com.dmdirc.addons.ui_swing.textpane.TextPaneEndAction;
43 45
 import com.dmdirc.commandparser.PopupManager;
44 46
 import com.dmdirc.commandparser.PopupMenu;
45 47
 import com.dmdirc.commandparser.PopupMenuItem;
@@ -537,11 +539,21 @@ public abstract class TextFrame extends JInternalFrame implements Window,
537 539
                 put(KeyStroke.getKeyStroke(KeyEvent.VK_F,
538 540
                 UIUtilities.getCtrlDownMask()), "searchAction");
539 541
 
542
+        getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
543
+                put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 
544
+                UIUtilities.getCtrlDownMask()), "homeAction");
545
+
546
+        getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
547
+                put(KeyStroke.getKeyStroke(KeyEvent.VK_END,
548
+                UIUtilities.getCtrlDownMask()), "endAction");
549
+
540 550
         getActionMap().put("pageUpAction",
541 551
                 new TextPanePageUpAction(getTextPane()));
542 552
         getActionMap().put("pageDownAction",
543 553
                 new TextPanePageDownAction(getTextPane()));
544 554
         getActionMap().put("searchAction", new SearchAction(searchBar));
555
+        getActionMap().put("homeAction", new TextPaneHomeAction(getTextPane()));
556
+        getActionMap().put("endAction", new TextPaneEndAction(getTextPane()));
545 557
     }
546 558
 
547 559
     /**

+ 10
- 0
src/com/dmdirc/addons/ui_swing/textpane/TextPane.java View File

@@ -405,6 +405,16 @@ public final class TextPane extends JComponent implements AdjustmentListener,
405 405
         scrollModel.setValue(scrollModel.getValue() - 10);
406 406
     }
407 407
 
408
+    /** Scrolls to the beginning of the TextPane */
409
+    public void goToHome() {
410
+        scrollModel.setValue(0);
411
+    }
412
+
413
+    /** Scrolls to the end of the TextPane */
414
+    public void goToEnd() {
415
+        scrollModel.setValue(document.getNumLines());
416
+    }
417
+
408 418
     /** {@inheritDoc}. */
409 419
     @Override
410 420
     public void lineAdded(final int line, final int size) {

+ 61
- 0
src/com/dmdirc/addons/ui_swing/textpane/TextPaneEndAction.java View File

@@ -0,0 +1,61 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes,
3
+ * Simon Mott
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.addons.ui_swing.textpane;
25
+
26
+import java.awt.event.ActionEvent;
27
+import javax.swing.AbstractAction;
28
+
29
+/**
30
+ * This listener waits to be triggered then scrolls the current active TextPane
31
+ * to the bottom most line.
32
+ */
33
+public class TextPaneEndAction extends AbstractAction {
34
+
35
+    /**
36
+     * A version number for this class. It should be changed whenever the class
37
+     * structure is changed (or anything else that would prevent serialized
38
+     * objects being unserialized with the new class).
39
+     */
40
+    private static final long serialVersionUID = 1;
41
+    /** TextPane instance. */
42
+    private TextPane textpane;
43
+
44
+    /**
45
+     * Instantiates a new action.
46
+     *
47
+     * @param textpane Textpane
48
+     */
49
+    public TextPaneEndAction(final TextPane textpane) {
50
+        this.textpane = textpane;
51
+    }
52
+
53
+    /**
54
+     * {@inheritDoc}.
55
+     * @param e Action event
56
+     */
57
+    @Override
58
+    public void actionPerformed(ActionEvent e) {
59
+        textpane.goToEnd();
60
+    }
61
+}

+ 61
- 0
src/com/dmdirc/addons/ui_swing/textpane/TextPaneHomeAction.java View File

@@ -0,0 +1,61 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes,
3
+ * Simon Mott
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.addons.ui_swing.textpane;
25
+
26
+import java.awt.event.ActionEvent;
27
+import javax.swing.AbstractAction;
28
+
29
+/**
30
+ * This listener waits to be triggered then scrolls the current active TextPane
31
+ * to the top most line.
32
+ */
33
+public class TextPaneHomeAction extends AbstractAction {
34
+
35
+    /**
36
+     * A version number for this class. It should be changed whenever the class
37
+     * structure is changed (or anything else that would prevent serialized
38
+     * objects being unserialized with the new class).
39
+     */
40
+    private static final long serialVersionUID = 1;
41
+    /** TextPane instance. */
42
+    private TextPane textpane;
43
+
44
+    /**
45
+     * Instantiates a new action.
46
+     *
47
+     * @param textpane Textpane
48
+     */
49
+    public TextPaneHomeAction(final TextPane textpane) {
50
+        this.textpane = textpane;
51
+    }
52
+
53
+    /**
54
+     * {@inheritDoc}.
55
+     * @param e Action event
56
+     */
57
+    @Override
58
+    public void actionPerformed(ActionEvent e) {
59
+        textpane.goToHome();
60
+    }
61
+}

Loading…
Cancel
Save