Skip to content

Commit

Permalink
Merge pull request #4971 from bubblobill/dialogClosingFixes
Browse files Browse the repository at this point in the history
Escape key closes export screenshot dialogs
  • Loading branch information
cwisniew authored Oct 4, 2024
2 parents 0ffa3e3 + 02c433f commit 866eb94
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Transparency;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
Expand All @@ -33,11 +35,7 @@
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.event.IIOWriteProgressListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JToggleButton;
import javax.swing.*;
import net.rptools.lib.net.FTPLocation;
import net.rptools.lib.net.LocalLocation;
import net.rptools.lib.net.Location;
Expand All @@ -64,6 +62,13 @@
* the 'board' image/tile. The file can be saved to disk or sent to an FTP location.
*/
public class ExportDialog extends JDialog implements IIOWriteProgressListener {
public enum Status {
OK,
CANCEL
}

private ExportDialog.Status status;

//
// Dialog/ UI related vars
//
Expand Down Expand Up @@ -426,6 +431,20 @@ private ExportDialog() {
interactPanel.getButton("exportButton").addActionListener(evt -> exportButtonAction());
interactPanel.getButton("cancelButton").addActionListener(evt -> dispose());
interactPanel.getButton("browseButton").addActionListener(evt -> browseButtonAction());

// Escape key
interactPanel
.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
interactPanel
.getActionMap()
.put(
"cancel",
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
cancel();
}
});
}

@Override
Expand All @@ -450,6 +469,11 @@ public void setVisible(boolean b) {
super.setVisible(b);
}

private void cancel() {
status = ExportDialog.Status.CANCEL;
setVisible(false);
}

//
// These get/set the convenience variables zone and renderer
//
Expand Down

0 comments on commit 866eb94

Please sign in to comment.