diff options
| author | 2016-07-03 00:05:04 +1000 | |
|---|---|---|
| committer | 2016-07-03 00:05:04 +1000 | |
| commit | 9a3e5a9d132735f818c379ba72c554362650690d (patch) | |
| tree | 2a454f96d99bdcfc5bdf0f6814a2ea7857698d1b /src/main/java/cuchaz/enigma/gui/ProgressDialog.java | |
| parent | Fixed #4 (diff) | |
| download | enigma-fork-9a3e5a9d132735f818c379ba72c554362650690d.tar.gz enigma-fork-9a3e5a9d132735f818c379ba72c554362650690d.tar.xz enigma-fork-9a3e5a9d132735f818c379ba72c554362650690d.zip | |
Started Gui Refactor
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/ProgressDialog.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/ProgressDialog.java | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/ProgressDialog.java b/src/main/java/cuchaz/enigma/gui/ProgressDialog.java deleted file mode 100644 index 70bca15..0000000 --- a/src/main/java/cuchaz/enigma/gui/ProgressDialog.java +++ /dev/null | |||
| @@ -1,100 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.gui; | ||
| 12 | |||
| 13 | import java.awt.BorderLayout; | ||
| 14 | import java.awt.Container; | ||
| 15 | import java.awt.Dimension; | ||
| 16 | import java.awt.FlowLayout; | ||
| 17 | |||
| 18 | import javax.swing.*; | ||
| 19 | |||
| 20 | import cuchaz.enigma.Constants; | ||
| 21 | import cuchaz.enigma.Deobfuscator.ProgressListener; | ||
| 22 | |||
| 23 | public class ProgressDialog implements ProgressListener, AutoCloseable { | ||
| 24 | |||
| 25 | private JFrame frame; | ||
| 26 | private JLabel labelTitle; | ||
| 27 | private JLabel labelText; | ||
| 28 | private JProgressBar progress; | ||
| 29 | |||
| 30 | public ProgressDialog(JFrame parent) { | ||
| 31 | |||
| 32 | // init frame | ||
| 33 | this.frame = new JFrame(Constants.NAME + " - Operation in progress"); | ||
| 34 | final Container pane = this.frame.getContentPane(); | ||
| 35 | FlowLayout layout = new FlowLayout(); | ||
| 36 | layout.setAlignment(FlowLayout.LEFT); | ||
| 37 | pane.setLayout(layout); | ||
| 38 | |||
| 39 | this.labelTitle = new JLabel(); | ||
| 40 | pane.add(this.labelTitle); | ||
| 41 | |||
| 42 | // set up the progress bar | ||
| 43 | JPanel panel = new JPanel(); | ||
| 44 | pane.add(panel); | ||
| 45 | panel.setLayout(new BorderLayout()); | ||
| 46 | this.labelText = GuiTricks.unboldLabel(new JLabel()); | ||
| 47 | this.progress = new JProgressBar(); | ||
| 48 | this.labelText.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); | ||
| 49 | panel.add(this.labelText, BorderLayout.NORTH); | ||
| 50 | panel.add(this.progress, BorderLayout.CENTER); | ||
| 51 | panel.setPreferredSize(new Dimension(360, 50)); | ||
| 52 | |||
| 53 | // show the frame | ||
| 54 | pane.doLayout(); | ||
| 55 | this.frame.setSize(400, 120); | ||
| 56 | this.frame.setResizable(false); | ||
| 57 | this.frame.setLocationRelativeTo(parent); | ||
| 58 | this.frame.setVisible(true); | ||
| 59 | this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); | ||
| 60 | } | ||
| 61 | |||
| 62 | public void close() { | ||
| 63 | this.frame.dispose(); | ||
| 64 | } | ||
| 65 | |||
| 66 | @Override | ||
| 67 | public void init(int totalWork, String title) { | ||
| 68 | this.labelTitle.setText(title); | ||
| 69 | this.progress.setMinimum(0); | ||
| 70 | this.progress.setMaximum(totalWork); | ||
| 71 | this.progress.setValue(0); | ||
| 72 | } | ||
| 73 | |||
| 74 | @Override | ||
| 75 | public void onProgress(int numDone, String message) { | ||
| 76 | this.labelText.setText(message); | ||
| 77 | this.progress.setValue(numDone); | ||
| 78 | |||
| 79 | // update the frame | ||
| 80 | this.frame.validate(); | ||
| 81 | this.frame.repaint(); | ||
| 82 | } | ||
| 83 | |||
| 84 | public interface ProgressRunnable { | ||
| 85 | void run(ProgressListener listener) throws Exception; | ||
| 86 | } | ||
| 87 | |||
| 88 | public static void runInThread(final JFrame parent, final ProgressRunnable runnable) { | ||
| 89 | new Thread() { | ||
| 90 | @Override | ||
| 91 | public void run() { | ||
| 92 | try (ProgressDialog progress = new ProgressDialog(parent)) { | ||
| 93 | runnable.run(progress); | ||
| 94 | } catch (Exception ex) { | ||
| 95 | throw new Error(ex); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | }.start(); | ||
| 99 | } | ||
| 100 | } | ||