changeset 98:778130f1a4c4

F2 now opens a new window
author Fox
date Tue, 21 Mar 2023 01:30:52 +0100
parents babc1a1305fd
children 40f1ea8f49ef
files src/junotu/Window.java
diffstat 1 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/junotu/Window.java	Tue Mar 21 01:13:00 2023 +0100
+++ b/src/junotu/Window.java	Tue Mar 21 01:30:52 2023 +0100
@@ -3,6 +3,11 @@
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.event.WindowEvent;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.KeyStroke;
 
 import javax.swing.JFrame;
 import javax.swing.JPanel;
@@ -22,7 +27,7 @@
 import junotu.TabBoard;
 import junotu.TabCalendarBoard;
 
-public class Window extends JFrame {
+public class Window extends JFrame implements ActionListener {
 
     public static interface TabInterface {
 	void onSwitchedTo();
@@ -42,6 +47,8 @@
 	"Calendar board",
     };
 
+    public final String KEY_ACTION_NEW_WINDOW = "new_window";
+
     public TabSimpleSearch  tabSearch;
     public TabEdit          tabEdit;
     public TabBoard         tabBoard;
@@ -74,6 +81,14 @@
 	}
     }
 
+    @Override
+    public void actionPerformed( ActionEvent e )
+    {
+	if( e.getActionCommand() == KEY_ACTION_NEW_WINDOW ) {
+	    Main.windowAdd( Tab.SEARCH );
+	}
+    }
+
     public void tabSwitch( Tab tab )
     {
 	if( tab == activeTab ) {
@@ -119,6 +134,13 @@
 	tabsLayout.addLayoutComponent( tabEdit,          TAB_NAMES[Tab.EDIT.ordinal()] );
 	tabsLayout.addLayoutComponent( tabBoard,         TAB_NAMES[Tab.BOARD.ordinal()] );
 	tabsLayout.addLayoutComponent( tabCalendarBoard, TAB_NAMES[Tab.CALENDAR_BOARD.ordinal()] );
+
+	tabs.registerKeyboardAction(
+	    this,
+	    KEY_ACTION_NEW_WINDOW,
+	    KeyStroke.getKeyStroke( KeyEvent.VK_F2, 0 ),
+	    JPanel.WHEN_IN_FOCUSED_WINDOW
+	);
 	
     }