diff --git a/megamek/src/megamek/client/ui/dialogs/BotConfigDialog.java b/megamek/src/megamek/client/ui/dialogs/BotConfigDialog.java index 55b56193720..b28acdfd642 100644 --- a/megamek/src/megamek/client/ui/dialogs/BotConfigDialog.java +++ b/megamek/src/megamek/client/ui/dialogs/BotConfigDialog.java @@ -550,9 +550,12 @@ public void actionPerformed(ActionEvent e) { /** Asks for a name and adds the current Behavior as a new Behavior Preset. */ private void saveAsNewPreset() { + getFrame().setAlwaysOnTop(true); while (true) { + String name = JOptionPane.showInputDialog(getFrame(), Messages.getString("BotConfigDialog.saveNewPrompt")); if (name == null || name.isBlank()) { + getFrame().setAlwaysOnTop(false); return; } if (!behaviorSettingsFactory.getBehaviorNameList().contains(name)) { @@ -560,6 +563,7 @@ private void saveAsNewPreset() { writePreset(name); updatePresets(); presetsList.setSelectedValue(name, true); + getFrame().setAlwaysOnTop(false); return; } // Incorrect name: notify the player and ask again diff --git a/megamek/src/megamek/client/ui/swing/PlanetaryConditionsDialog.java b/megamek/src/megamek/client/ui/swing/PlanetaryConditionsDialog.java index ad6c673fac5..0731c5bfdb5 100644 --- a/megamek/src/megamek/client/ui/swing/PlanetaryConditionsDialog.java +++ b/megamek/src/megamek/client/ui/swing/PlanetaryConditionsDialog.java @@ -24,24 +24,10 @@ import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Image; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; +import java.awt.event.*; import java.io.File; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.SwingConstants; +import javax.swing.*; import javax.swing.border.EmptyBorder; import megamek.client.ui.Messages; @@ -155,6 +141,12 @@ private void setupDialog() { mainPanel.add(Box.createVerticalGlue()); setupCombos(); + + String closeAction = "closeAction"; + final KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, closeAction); + getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(escape, closeAction); + getRootPane().getActionMap().put(closeAction, new CloseAction(this)); } private JPanel headerSection() { diff --git a/megamek/src/megamek/client/ui/swing/RandomArmyDialog.java b/megamek/src/megamek/client/ui/swing/RandomArmyDialog.java index 9d2b55b775e..f64ecd62abe 100644 --- a/megamek/src/megamek/client/ui/swing/RandomArmyDialog.java +++ b/megamek/src/megamek/client/ui/swing/RandomArmyDialog.java @@ -230,6 +230,12 @@ public RandomArmyDialog(ClientGUI cl) { adaptToGUIScale(); + String closeAction = "closeAction"; + final KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, closeAction); + getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(escape, closeAction); + getRootPane().getActionMap().put(closeAction, new CloseAction(this)); + m_client.getGame().addGameListener(gameListener); addWindowListener(windowListener); } diff --git a/megamek/src/megamek/client/ui/swing/RandomMapDialog.java b/megamek/src/megamek/client/ui/swing/RandomMapDialog.java index 37b5c863be1..66dbd65e757 100644 --- a/megamek/src/megamek/client/ui/swing/RandomMapDialog.java +++ b/megamek/src/megamek/client/ui/swing/RandomMapDialog.java @@ -27,10 +27,7 @@ import javax.swing.border.TitledBorder; import javax.swing.filechooser.FileFilter; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; +import java.awt.event.*; import java.io.*; import java.util.List; import java.util.Set; @@ -125,6 +122,12 @@ public RandomMapDialog(JFrame parent, IMapSettingsObserver mapSettingsObserver, validate(); setSize(new Dimension(600, 600)); setLocationRelativeTo(PARENT); + + String closeAction = "closeAction"; + final KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, closeAction); + getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(escape, closeAction); + getRootPane().getActionMap().put(closeAction, new CloseAction(this)); } private void initGUI() { diff --git a/megamek/src/megamek/client/ui/swing/RandomNameDialog.java b/megamek/src/megamek/client/ui/swing/RandomNameDialog.java index b743162a652..30a7be2f160 100644 --- a/megamek/src/megamek/client/ui/swing/RandomNameDialog.java +++ b/megamek/src/megamek/client/ui/swing/RandomNameDialog.java @@ -17,6 +17,7 @@ import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -73,6 +74,12 @@ private void init() { butCancel.addActionListener(this); chPlayer.addActionListener(this); setLocationRelativeTo(clientgui.frame); + + String closeAction = "closeAction"; + final KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, closeAction); + getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(escape, closeAction); + getRootPane().getActionMap().put(closeAction, new CloseAction(this)); } private void updateFactions() { diff --git a/megamek/src/megamek/client/ui/swing/UnitEditorDialog.java b/megamek/src/megamek/client/ui/swing/UnitEditorDialog.java index 5b85fd9907b..ccd05be353a 100644 --- a/megamek/src/megamek/client/ui/swing/UnitEditorDialog.java +++ b/megamek/src/megamek/client/ui/swing/UnitEditorDialog.java @@ -21,6 +21,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; import java.util.*; import java.util.function.BiConsumer; @@ -142,6 +143,12 @@ private void initComponents() { // TODO: size right + String closeAction = "closeAction"; + final KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, closeAction); + getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(escape, closeAction); + getRootPane().getActionMap().put(closeAction, new CloseAction(this)); + adaptToGUIScale(); pack(); } diff --git a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java index 20db798a734..73676de9f83 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java +++ b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java @@ -777,6 +777,12 @@ public void componentShown(ComponentEvent e) { boardPreviewW.add(bpPanel); boardPreviewW.setSize(clientgui.frame.getWidth() / 2, clientgui.frame.getHeight() / 2); + String closeAction = "closeAction"; + final KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + boardPreviewW.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, closeAction); + boardPreviewW.getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(escape, closeAction); + boardPreviewW.getRootPane().getActionMap().put(closeAction, new CloseAction(boardPreviewW)); + Ruler.color1 = GUIP.getRulerColor1(); Ruler.color2 = GUIP.getRulerColor2(); Ruler ruler = new Ruler(clientgui.frame, client(), previewBV, boardPreviewGame);