Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind escape to the close action on various dialogs #5256

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions megamek/src/megamek/client/ui/dialogs/BotConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -550,16 +550,20 @@ 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)) {
// OK: this name is not taken. Save the preset
writePreset(name);
updatePresets();
presetsList.setSelectedValue(name, true);
getFrame().setAlwaysOnTop(false);
return;
}
// Incorrect name: notify the player and ask again
Expand Down
24 changes: 8 additions & 16 deletions megamek/src/megamek/client/ui/swing/PlanetaryConditionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions megamek/src/megamek/client/ui/swing/RandomArmyDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 7 additions & 4 deletions megamek/src/megamek/client/ui/swing/RandomMapDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions megamek/src/megamek/client/ui/swing/RandomNameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions megamek/src/megamek/client/ui/swing/UnitEditorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 6 additions & 0 deletions megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading