diff options
Diffstat (limited to 'src/cuchaz/enigma/gui/ProgressDialog.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/ProgressDialog.java | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/gui/ProgressDialog.java b/src/cuchaz/enigma/gui/ProgressDialog.java new file mode 100644 index 0000000..40ac6a6 --- /dev/null +++ b/src/cuchaz/enigma/gui/ProgressDialog.java | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 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.BorderFactory; | ||
| 19 | import javax.swing.JFrame; | ||
| 20 | import javax.swing.JLabel; | ||
| 21 | import javax.swing.JPanel; | ||
| 22 | import javax.swing.JProgressBar; | ||
| 23 | import javax.swing.WindowConstants; | ||
| 24 | |||
| 25 | import cuchaz.enigma.Constants; | ||
| 26 | import cuchaz.enigma.Deobfuscator.ProgressListener; | ||
| 27 | |||
| 28 | public class ProgressDialog implements ProgressListener | ||
| 29 | { | ||
| 30 | private JFrame m_frame; | ||
| 31 | private JLabel m_text; | ||
| 32 | private JProgressBar m_progress; | ||
| 33 | |||
| 34 | public ProgressDialog( JFrame parent ) | ||
| 35 | { | ||
| 36 | // init frame | ||
| 37 | m_frame = new JFrame( Constants.Name + " - Export" ); | ||
| 38 | final Container pane = m_frame.getContentPane(); | ||
| 39 | FlowLayout layout = new FlowLayout(); | ||
| 40 | layout.setAlignment( FlowLayout.LEFT ); | ||
| 41 | pane.setLayout( layout ); | ||
| 42 | |||
| 43 | pane.add( new JLabel( "Decompiling classes..." ) ); | ||
| 44 | |||
| 45 | // set up the progress bar | ||
| 46 | JPanel panel = new JPanel(); | ||
| 47 | pane.add( panel ); | ||
| 48 | panel.setLayout( new BorderLayout() ); | ||
| 49 | m_text = GuiTricks.unboldLabel( new JLabel() ); | ||
| 50 | m_progress = new JProgressBar(); | ||
| 51 | m_text.setBorder( BorderFactory.createEmptyBorder( 0, 0, 10, 0 ) ); | ||
| 52 | panel.add( m_text, BorderLayout.NORTH ); | ||
| 53 | panel.add( m_progress, BorderLayout.CENTER ); | ||
| 54 | panel.setPreferredSize( new Dimension( 360, 50 ) ); | ||
| 55 | |||
| 56 | // show the frame | ||
| 57 | pane.doLayout(); | ||
| 58 | m_frame.setSize( 400, 120 ); | ||
| 59 | m_frame.setResizable( false ); | ||
| 60 | m_frame.setLocationRelativeTo( parent ); | ||
| 61 | m_frame.setVisible( true ); | ||
| 62 | m_frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); | ||
| 63 | } | ||
| 64 | |||
| 65 | public void close( ) | ||
| 66 | { | ||
| 67 | m_frame.dispose(); | ||
| 68 | } | ||
| 69 | |||
| 70 | @Override | ||
| 71 | public void init( int totalWork ) | ||
| 72 | { | ||
| 73 | m_text.setText( "Decompiling " + totalWork + " classes..." ); | ||
| 74 | m_progress.setMinimum( 0 ); | ||
| 75 | m_progress.setMaximum( totalWork ); | ||
| 76 | m_progress.setValue( 0 ); | ||
| 77 | } | ||
| 78 | |||
| 79 | @Override | ||
| 80 | public void onProgress( int numDone, String message ) | ||
| 81 | { | ||
| 82 | m_text.setText( message ); | ||
| 83 | m_progress.setValue( numDone ); | ||
| 84 | |||
| 85 | // update the frame | ||
| 86 | m_frame.validate(); | ||
| 87 | m_frame.repaint(); | ||
| 88 | } | ||
| 89 | } | ||