From c026441a476b85fbc84064c23ee012a1b14af04b Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 26 Aug 2023 11:29:08 +0100 Subject: [PATCH] Correct for escape operation --- .../DeploymentSelectionDialog.java | 7 +++---- .../net/sf/openrocket/gui/util/GUIUtil.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/DeploymentSelectionDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/DeploymentSelectionDialog.java index eb3701df3..86ea30c3d 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/DeploymentSelectionDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/DeploymentSelectionDialog.java @@ -66,8 +66,7 @@ public class DeploymentSelectionDialog extends JDialog { buttonGroup.add(defaultButton); buttonGroup.add(overrideButton); - // Select the button based on current configuration. If the configuration is overridden - // The the overrideButton is selected. + // Select the button based on current configuration. If the configuration is overridden, the overrideButton is selected. boolean isOverridden = !component.getDeploymentConfigurations().isDefault(id); if (isOverridden) { overrideButton.setSelected(true); @@ -77,7 +76,7 @@ public class DeploymentSelectionDialog extends JDialog { //// Deploys at: panel.add(new JLabel(trans.get("ParachuteCfg.lbl.Deploysat")), ""); - final JComboBox deployEvent = new JComboBox(new EnumModel(newConfiguration, "DeployEvent")); + final JComboBox deployEvent = new JComboBox(new EnumModel<>(newConfiguration, "DeployEvent")); if( (component.getStageNumber() + 1 ) == rocket.getStageCount() ){ // This is the bottom stage: Restrict deployment options. deployEvent.removeItem( DeployEvent.LOWER_STAGE_SEPARATION ); @@ -147,7 +146,7 @@ public class DeploymentSelectionDialog extends JDialog { this.setContentPane(panel); GUIUtil.setDisposableDialogOptions(this, okButton); - // TODO: closes wrong, doesn't use okButton action + GUIUtil.installEscapeCloseButtonOperation(this, okButton); } private void updateState() { diff --git a/swing/src/net/sf/openrocket/gui/util/GUIUtil.java b/swing/src/net/sf/openrocket/gui/util/GUIUtil.java index 4fac6edd7..ef0fb870b 100644 --- a/swing/src/net/sf/openrocket/gui/util/GUIUtil.java +++ b/swing/src/net/sf/openrocket/gui/util/GUIUtil.java @@ -165,6 +165,25 @@ public class GUIUtil { installEscapeCloseOperation(dialog, null); } + public static void installEscapeCloseButtonOperation(final JDialog dialog, final JButton buttonToClick) { + Action triggerButtonAndClose = new AbstractAction() { + private static final long serialVersionUID = 9196153713666242274L; + + @Override + public void actionPerformed(ActionEvent event) { + log.info(Markers.USER_MARKER, "Closing dialog " + dialog); + + if (buttonToClick != null) { + buttonToClick.doClick(); // Programmatically "press" the button + } + + dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); + } + }; + + installEscapeCloseOperation(dialog, triggerButtonAndClose); + } + /** * Add the correct action to close a JDialog when the ESC key is pressed. * The dialog is closed by sending it a WINDOW_CLOSING event.