From e161d08125b5d0f83249a270fb85c401b8e14d21 Mon Sep 17 00:00:00 2001 From: Peter Gyorok Date: Wed, 15 Jun 2022 18:00:10 +0100 Subject: [PATCH] allow chart windows to be closed with Ctrl+W --- src/main/studio/ui/chart/Chart.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/studio/ui/chart/Chart.java b/src/main/studio/ui/chart/Chart.java index ad5650b1..7ff34e52 100755 --- a/src/main/studio/ui/chart/Chart.java +++ b/src/main/studio/ui/chart/Chart.java @@ -32,8 +32,12 @@ import javax.swing.Timer; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; +import java.awt.event.KeyEvent; +import java.awt.event.WindowEvent; import java.util.List; import java.util.*; @@ -43,6 +47,8 @@ public class Chart implements ComponentListener { private static final Logger log = LogManager.getLogger(); private static final Config config = Config.getInstance(); + public final static int menuShortcutKeyMask = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + private static final int CONFIG_UPDATE_DELAY = 1000; private Timer configUpdateTimer; @@ -142,6 +148,17 @@ private void initComponents() { frame.setVisible(true); frame.requestFocus(); frame.toFront(); + + JRootPane rootPane = frame.getRootPane(); + rootPane.registerKeyboardAction ( new ActionListener () + { + @Override + public void actionPerformed ( final ActionEvent e ) + { + frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_W, menuShortcutKeyMask), JComponent.WHEN_IN_FOCUSED_WINDOW ); + } finally { WindowsAppUserMode.setMainId(); }