Pressing the 'Esc' key closes selection editor dialog

This commit is contained in:
Bane Stojkovic
2026-03-26 19:57:18 +01:00
parent cd0cb776b0
commit 150e03c023
2 changed files with 20 additions and 2 deletions
@@ -369,6 +369,10 @@
<changeType>IMPROVEMENT</changeType>
<description>Better error handling for AI tools</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Pressing the 'Esc' key closes selection editor dialog</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Right click (or two finger tap on mac) after selecting a component with a regular click opens editor dialog in addition to the context menu</description>
@@ -27,6 +27,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.List;
@@ -35,6 +37,7 @@ import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
@@ -87,6 +90,19 @@ public class PropertyEditorDialog extends ButtonDialog {
layoutGui();
setLocationRelativeTo(owner);
KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
Action escapeAction = new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
getButton(ButtonDialog.CANCEL).doClick();
}
};
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke,
"PropertyEditorDialog.escape");
getRootPane().getActionMap().put("PropertyEditorDialog.escape", escapeAction);
}
@Override
@@ -156,8 +172,6 @@ public class PropertyEditorDialog extends ButtonDialog {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
getButton(OK).doClick();
} else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
getButton(CANCEL).doClick();
}
}
});