changeset 94:ce163f6cecdb

TabBoard/TabCalendarBoard: Can now use ESCAPE to go back
author Fox
date Wed, 22 Feb 2023 23:09:46 +0100
parents 1df77c040218
children 666e6253fbdf
files src/junotu/TabBoard.java src/junotu/TabCalendarBoard.java
diffstat 2 files changed, 36 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/junotu/TabBoard.java	Sun Feb 19 09:25:43 2023 +0100
+++ b/src/junotu/TabBoard.java	Wed Feb 22 23:09:46 2023 +0100
@@ -53,6 +53,8 @@
     final static int COLUMN_CONTENT_WIDTH = 256;
     final static int COLUMN_WIDTH = COLUMN_CONTENT_WIDTH+16;
 
+    public final String KEY_ACTION_BACK            = "back";
+    public final String KEY_ACTION_COMMIT          = "commit";
     public final String KEY_ACTION_CARD_UP         = "card_up";
     public final String KEY_ACTION_CARD_DOWN       = "card_down";
     public final String KEY_ACTION_CARD_FULL_UP    = "card_full_up";
@@ -458,7 +460,10 @@
 	addColumn.addActionListener(this);
 	editAsCard.addActionListener(this);
 
-	back.setToolTipText("Go back to where the card was accessed from.");
+	registerKeyboardAction( this, KEY_ACTION_BACK, KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), WHEN_IN_FOCUSED_WINDOW );
+	registerKeyboardAction( this, KEY_ACTION_COMMIT, KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK ), WHEN_IN_FOCUSED_WINDOW );
+
+	back.setToolTipText("Go back to where the card was accessed from. Can also use [ESC].");
 	addColumn.setToolTipText("Add new column to the board.");
 	editAsCard.setToolTipText("Edit the board as a regular card.");
 	
@@ -598,19 +603,34 @@
 
     public void actionPerformed( ActionEvent e )
     {
-	if( e.getSource() == back ) {
+	Object source = e.getSource();
+	if( source == this ){
+	    switch( e.getActionCommand() ) {
+
+	    case KEY_ACTION_COMMIT: {
+		boardSave();
+		return;
+	    }
+
+	    case KEY_ACTION_BACK: {
+		buttonClickedBack();
+		return;
+	    }
+
+	    }
+	} else if( source == back ) {
 	    buttonClickedBack();
 	    return;
-	} else if( e.getSource() == addColumn ) {
+	} else if( source == addColumn ) {
 	    insertColumn();
 	    return;
-	} else if( e.getSource() == editAsCard ) {
+	} else if( source == editAsCard ) {
 	    buttonClickedAsCard();
 	    return;
 	}
 
-	ColumnWidget sourceColumn = (ColumnWidget)e.getSource();
-	if( sourceColumn != null ) {
+	if( source instanceof ColumnWidget ) {
+	    ColumnWidget sourceColumn = (ColumnWidget)source;
 	    int columnIndex = findColumn(sourceColumn);
 	    switch( e.getActionCommand() ){
 
--- a/src/junotu/TabCalendarBoard.java	Sun Feb 19 09:25:43 2023 +0100
+++ b/src/junotu/TabCalendarBoard.java	Wed Feb 22 23:09:46 2023 +0100
@@ -72,6 +72,7 @@
     final static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
     final static SimpleDateFormat DEBUG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
+    public final String KEY_ACTION_BACK            = "back";
     public final String KEY_ACTION_COMMIT          = "commit";
     public final String KEY_ACTION_CARD_UP         = "card_up";
     public final String KEY_ACTION_CARD_DOWN       = "card_down";
@@ -489,9 +490,10 @@
 	options.addActionListener(this);
 	menu_onlyFilled.addActionListener(this);
 
+	registerKeyboardAction( this, KEY_ACTION_BACK, KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), WHEN_IN_FOCUSED_WINDOW );
 	registerKeyboardAction( this, KEY_ACTION_COMMIT, KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK ), WHEN_IN_FOCUSED_WINDOW );
 
-	back.setToolTipText("Go back to where the calendar board was accessed from.");
+	back.setToolTipText("Go back to where the calendar board was accessed from. Can also use [ESC].");
 	options.setToolTipText("Show calendar options.");
 	menu_onlyFilled.setToolTipText("If checked, days with no cards will be hidden.");
 	
@@ -736,6 +738,11 @@
 		boardSave();
 		return;
 	    }
+
+	    case KEY_ACTION_BACK: {
+		buttonClickedBack();
+		return;
+	    }
 		
 	    }
 	} else if( source == back ) {
@@ -750,8 +757,8 @@
 	    return;
 	}
 
-	ColumnWidget sourceColumn = (ColumnWidget)e.getSource();
-	if( sourceColumn != null ) {
+	if( source instanceof ColumnWidget ) {
+	    ColumnWidget sourceColumn = (ColumnWidget)e.getSource();
 	    int columnIndex = findColumn(sourceColumn);
 	    switch( e.getActionCommand() ){