extracted key strokes creation from logui
diff --git a/src/main/java/org/apache/log4j/chainsaw/LogUI.java b/src/main/java/org/apache/log4j/chainsaw/LogUI.java
index 74defd2..293f698 100644
--- a/src/main/java/org/apache/log4j/chainsaw/LogUI.java
+++ b/src/main/java/org/apache/log4j/chainsaw/LogUI.java
@@ -339,64 +339,9 @@
}
});
- KeyStroke ksRight =
- KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
- KeyStroke ksLeft =
- KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
- KeyStroke ksGotoLine =
- KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
-
- getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
- ksRight, "MoveRight");
- getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
- ksLeft, "MoveLeft");
- getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
- ksGotoLine, "GotoLine");
-
- Action moveRight =
- new AbstractAction() {
- public void actionPerformed(ActionEvent e) {
- int temp = getTabbedPane().getSelectedIndex();
- ++temp;
-
- if (temp != getTabbedPane().getTabCount()) {
- getTabbedPane().setSelectedTab(temp);
- }
- }
- };
-
- Action moveLeft =
- new AbstractAction() {
- public void actionPerformed(ActionEvent e) {
- int temp = getTabbedPane().getSelectedIndex();
- --temp;
-
- if (temp > -1) {
- getTabbedPane().setSelectedTab(temp);
- }
- }
- };
-
- Action gotoLine =
- new AbstractAction() {
- public void actionPerformed(ActionEvent e) {
- String inputLine = JOptionPane.showInputDialog(LogUI.this, "Enter the line number to go:", "Goto Line", JOptionPane.PLAIN_MESSAGE);
- try {
- int lineNumber = Integer.parseInt(inputLine);
- int row = getCurrentLogPanel().setSelectedEvent(lineNumber);
- if (row == -1) {
- JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number", "Error", JOptionPane.ERROR_MESSAGE);
- }
- } catch (NumberFormatException nfe) {
- JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number", "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- };
-
-
- getTabbedPane().getActionMap().put("MoveRight", moveRight);
- getTabbedPane().getActionMap().put("MoveLeft", moveLeft);
- getTabbedPane().getActionMap().put("GotoLine", gotoLine);
+ LogUiKeyStrokeCreator.createKeyStrokeRight(tabbedPane);
+ LogUiKeyStrokeCreator.createKeyStrokeLeft(tabbedPane);
+ LogUiKeyStrokeCreator.createKeyStrokeGotoLine(tabbedPane, this);
/**
* We listen for double clicks, and auto-undock currently selected Tab if
@@ -564,7 +509,6 @@
chainsawToolBarAndMenus.stateChange();
}
-
/**
* Display the log tree pane, using the last known divider location
*/
diff --git a/src/main/java/org/apache/log4j/chainsaw/LogUiKeyStrokeCreator.java b/src/main/java/org/apache/log4j/chainsaw/LogUiKeyStrokeCreator.java
new file mode 100644
index 0000000..dff2ce7
--- /dev/null
+++ b/src/main/java/org/apache/log4j/chainsaw/LogUiKeyStrokeCreator.java
@@ -0,0 +1,75 @@
+package org.apache.log4j.chainsaw;
+
+import org.apache.log4j.chainsaw.components.tabbedpane.ChainsawTabbedPane;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
+public class LogUiKeyStrokeCreator {
+
+ static void createKeyStrokeGotoLine(ChainsawTabbedPane tabbedPane, LogUI logUI) {
+ KeyStroke ksGotoLine =
+ KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
+ tabbedPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
+ ksGotoLine, "GotoLine");
+
+ Action gotoLine =
+ new AbstractAction() {
+ public void actionPerformed(ActionEvent e) {
+ String inputLine = JOptionPane.showInputDialog(logUI, "Enter the line number to go:", "Goto Line", JOptionPane.PLAIN_MESSAGE);
+ try {
+ int lineNumber = Integer.parseInt(inputLine);
+ int row = logUI.getCurrentLogPanel().setSelectedEvent(lineNumber);
+ if (row == -1) {
+ JOptionPane.showMessageDialog(logUI, "You have entered an invalid line number", "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ } catch (NumberFormatException nfe) {
+ JOptionPane.showMessageDialog(logUI, "You have entered an invalid line number", "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ };
+
+ tabbedPane.getActionMap().put("GotoLine", gotoLine);
+ }
+
+ static void createKeyStrokeLeft(ChainsawTabbedPane tabbedPane) {
+ KeyStroke ksLeft =
+ KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
+ tabbedPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
+ ksLeft, "MoveLeft");
+
+ Action moveLeft =
+ new AbstractAction() {
+ public void actionPerformed(ActionEvent e) {
+ int temp = tabbedPane.getSelectedIndex();
+ --temp;
+
+ if (temp > -1) {
+ tabbedPane.setSelectedTab(temp);
+ }
+ }
+ };
+ tabbedPane.getActionMap().put("MoveLeft", moveLeft);
+ }
+
+ static void createKeyStrokeRight(ChainsawTabbedPane tabbedPane) {
+ KeyStroke ksRight =
+ KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
+ tabbedPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
+ ksRight, "MoveRight");
+ Action moveRight =
+ new AbstractAction() {
+ public void actionPerformed(ActionEvent e) {
+ int temp = tabbedPane.getSelectedIndex();
+ ++temp;
+
+ if (temp != tabbedPane.getTabCount()) {
+ tabbedPane.setSelectedTab(temp);
+ }
+ }
+ };
+ tabbedPane.getActionMap().put("MoveRight", moveRight);
+ }
+}