diff options
| author | 2020-07-18 13:39:03 +0200 | |
|---|---|---|
| committer | 2020-07-18 13:39:03 +0200 | |
| commit | 3f1e1f84d1d875d7d84d862e39e22044b0ff1512 (patch) | |
| tree | d8de21e43126e46867883bb92dd76cccb1ceba96 /enigma-swing/src | |
| parent | Replace usages of GridBagConstraints with GridBagConstraintsBuilder (diff) | |
| download | enigma-3f1e1f84d1d875d7d84d862e39e22044b0ff1512.tar.gz enigma-3f1e1f84d1d875d7d84d862e39e22044b0ff1512.tar.xz enigma-3f1e1f84d1d875d7d84d862e39e22044b0ff1512.zip | |
Make ProgressDialog use a JDialog instead of a JFrame
Diffstat (limited to 'enigma-swing/src')
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java index fa40af75..4f47a24f 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java | |||
| @@ -11,19 +11,22 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.gui.dialog; | 12 | package cuchaz.enigma.gui.dialog; |
| 13 | 13 | ||
| 14 | import java.awt.BorderLayout; | ||
| 15 | import java.awt.Container; | ||
| 16 | import java.awt.FlowLayout; | ||
| 17 | import java.util.concurrent.CompletableFuture; | ||
| 18 | |||
| 19 | import javax.swing.*; | ||
| 20 | |||
| 14 | import cuchaz.enigma.Enigma; | 21 | import cuchaz.enigma.Enigma; |
| 15 | import cuchaz.enigma.ProgressListener; | 22 | import cuchaz.enigma.ProgressListener; |
| 16 | import cuchaz.enigma.gui.util.GuiUtil; | 23 | import cuchaz.enigma.gui.util.GuiUtil; |
| 17 | import cuchaz.enigma.utils.I18n; | ||
| 18 | import cuchaz.enigma.gui.util.ScaleUtil; | 24 | import cuchaz.enigma.gui.util.ScaleUtil; |
| 19 | 25 | import cuchaz.enigma.utils.I18n; | |
| 20 | import javax.swing.*; | ||
| 21 | import java.awt.*; | ||
| 22 | import java.util.concurrent.CompletableFuture; | ||
| 23 | 26 | ||
| 24 | public class ProgressDialog implements ProgressListener, AutoCloseable { | 27 | public class ProgressDialog implements ProgressListener, AutoCloseable { |
| 25 | 28 | ||
| 26 | private JFrame frame; | 29 | private JDialog dialog; |
| 27 | private JLabel labelTitle; | 30 | private JLabel labelTitle; |
| 28 | private JLabel labelText; | 31 | private JLabel labelText; |
| 29 | private JProgressBar progress; | 32 | private JProgressBar progress; |
| @@ -31,8 +34,8 @@ public class ProgressDialog implements ProgressListener, AutoCloseable { | |||
| 31 | public ProgressDialog(JFrame parent) { | 34 | public ProgressDialog(JFrame parent) { |
| 32 | 35 | ||
| 33 | // init frame | 36 | // init frame |
| 34 | this.frame = new JFrame(String.format(I18n.translate("progress.operation"), Enigma.NAME)); | 37 | this.dialog = new JDialog(parent, String.format(I18n.translate("progress.operation"), Enigma.NAME)); |
| 35 | final Container pane = this.frame.getContentPane(); | 38 | final Container pane = this.dialog.getContentPane(); |
| 36 | FlowLayout layout = new FlowLayout(); | 39 | FlowLayout layout = new FlowLayout(); |
| 37 | layout.setAlignment(FlowLayout.LEFT); | 40 | layout.setAlignment(FlowLayout.LEFT); |
| 38 | pane.setLayout(layout); | 41 | pane.setLayout(layout); |
| @@ -53,11 +56,11 @@ public class ProgressDialog implements ProgressListener, AutoCloseable { | |||
| 53 | 56 | ||
| 54 | // show the frame | 57 | // show the frame |
| 55 | pane.doLayout(); | 58 | pane.doLayout(); |
| 56 | this.frame.setSize(ScaleUtil.getDimension(400, 120)); | 59 | this.dialog.setSize(ScaleUtil.getDimension(400, 120)); |
| 57 | this.frame.setResizable(false); | 60 | this.dialog.setResizable(false); |
| 58 | this.frame.setLocationRelativeTo(parent); | 61 | this.dialog.setLocationRelativeTo(parent); |
| 59 | this.frame.setVisible(true); | 62 | this.dialog.setVisible(true); |
| 60 | this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); | 63 | this.dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); |
| 61 | } | 64 | } |
| 62 | 65 | ||
| 63 | public static CompletableFuture<Void> runOffThread(final JFrame parent, final ProgressRunnable runnable) { | 66 | public static CompletableFuture<Void> runOffThread(final JFrame parent, final ProgressRunnable runnable) { |
| @@ -77,7 +80,7 @@ public class ProgressDialog implements ProgressListener, AutoCloseable { | |||
| 77 | 80 | ||
| 78 | @Override | 81 | @Override |
| 79 | public void close() { | 82 | public void close() { |
| 80 | this.frame.dispose(); | 83 | this.dialog.dispose(); |
| 81 | } | 84 | } |
| 82 | 85 | ||
| 83 | @Override | 86 | @Override |
| @@ -99,8 +102,8 @@ public class ProgressDialog implements ProgressListener, AutoCloseable { | |||
| 99 | } | 102 | } |
| 100 | 103 | ||
| 101 | // update the frame | 104 | // update the frame |
| 102 | this.frame.validate(); | 105 | this.dialog.validate(); |
| 103 | this.frame.repaint(); | 106 | this.dialog.repaint(); |
| 104 | } | 107 | } |
| 105 | 108 | ||
| 106 | public interface ProgressRunnable { | 109 | public interface ProgressRunnable { |