Go to the documentation of this file.00001 package instruction.gui.dialog;
00002
00003 import instruction.importer.InstructionProgressListener;
00004
00005 import javax.swing.JPanel;
00006 import java.awt.Frame;
00007 import javax.swing.JDialog;
00008 import java.awt.Dimension;
00009 import javax.swing.BorderFactory;
00010 import javax.swing.JLabel;
00011 import javax.swing.JProgressBar;
00012 import javax.swing.JTextPane;
00013 import javax.swing.SwingUtilities;
00014 import java.awt.GridBagLayout;
00015 import java.awt.GridBagConstraints;
00016 import java.awt.Insets;
00017 import javax.swing.JButton;
00018 import java.awt.Font;
00019 import javax.swing.JScrollPane;
00020 import javax.swing.border.EtchedBorder;
00021
00022 public class InstructionProgressDlg extends JDialog implements InstructionProgressListener {
00023
00024 private static final long serialVersionUID = 1L;
00025 private JPanel jPanel = null;
00026 private JLabel jLabel = null;
00027 private JProgressBar progressBar = null;
00028 private JButton btnCancel = null;
00029 private JScrollPane jScrollPane = null;
00030 private JTextPane txtConsole = null;
00031
00035 public InstructionProgressDlg ( Frame owner ) {
00036
00037 super( owner, "", true );
00038 initialize();
00039 }
00040
00046 private void initialize() {
00047
00048 this.setSize( 364, 260 );
00049 this.setContentPane( getJPanel() );
00050 this.setTitle( "Transformation Progress" );
00051 }
00052
00058 private JPanel getJPanel() {
00059
00060 if ( jPanel == null ) {
00061 GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
00062 gridBagConstraints11.fill = GridBagConstraints.BOTH;
00063 gridBagConstraints11.gridy = 2;
00064 gridBagConstraints11.weightx = 1.0;
00065 gridBagConstraints11.weighty = 1.0;
00066 gridBagConstraints11.insets = new Insets( 0, 10, 0, 10 );
00067 gridBagConstraints11.gridx = 0;
00068 GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
00069 gridBagConstraints21.gridx = 0;
00070 gridBagConstraints21.insets = new Insets( 10, 10, 10, 10 );
00071 gridBagConstraints21.gridy = 3;
00072 GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
00073 gridBagConstraints1.gridx = 0;
00074 gridBagConstraints1.insets = new Insets( 10, 10, 10, 10 );
00075 gridBagConstraints1.fill = GridBagConstraints.BOTH;
00076 gridBagConstraints1.gridy = 1;
00077 GridBagConstraints gridBagConstraints = new GridBagConstraints();
00078 gridBagConstraints.gridx = 0;
00079 gridBagConstraints.insets = new Insets( 10, 10, 10, 10 );
00080 gridBagConstraints.anchor = GridBagConstraints.WEST;
00081 gridBagConstraints.fill = GridBagConstraints.VERTICAL;
00082 gridBagConstraints.gridy = 0;
00083 jLabel = new JLabel();
00084 jLabel.setText( "Please wait while the Howto is transformed..." );
00085 jPanel = new JPanel();
00086 jPanel.setLayout( new GridBagLayout() );
00087 jPanel.add( jLabel, gridBagConstraints );
00088 jPanel.add( getProgressBar(), gridBagConstraints1 );
00089 jPanel.add( getBtnCancel(), gridBagConstraints21 );
00090 jPanel.add( getJScrollPane(), gridBagConstraints11 );
00091 }
00092 return jPanel;
00093 }
00094
00100 private JProgressBar getProgressBar() {
00101
00102 if ( progressBar == null ) {
00103 progressBar = new JProgressBar();
00104 progressBar.setPreferredSize( new Dimension( 148, 20 ) );
00105 }
00106 return progressBar;
00107 }
00108
00114 private JButton getBtnCancel() {
00115
00116 if ( btnCancel == null ) {
00117 btnCancel = new JButton();
00118 btnCancel.setText( "Cancel" );
00119 }
00120 return btnCancel;
00121 }
00122
00123 public void setProgress( int percent ) {
00124
00125 progressBar.setValue( percent );
00126 }
00127
00128 public void progressNotification( int percentage, String msg ) {
00129
00130 if ( percentage != - 1 )
00131 progressBar.setValue( percentage );
00132
00133 String txt = txtConsole.getText();
00134 txtConsole.setText( txt + msg );
00135 SwingUtilities.invokeLater( new Runnable() {
00136 public void run() {
00137
00138 int max = jScrollPane.getVerticalScrollBar().getMaximum();
00139
00140 jScrollPane.getVerticalScrollBar().setValue( max );
00141 }
00142 } );
00143 }
00144
00150 private JScrollPane getJScrollPane() {
00151
00152 if ( jScrollPane == null ) {
00153 jScrollPane = new JScrollPane();
00154 jScrollPane.setBorder( BorderFactory.createEtchedBorder( EtchedBorder.LOWERED ) );
00155 jScrollPane.setViewportView( getTxtConsole() );
00156
00157 }
00158 return jScrollPane;
00159 }
00160
00166 private JTextPane getTxtConsole() {
00167
00168 if ( txtConsole == null ) {
00169 txtConsole = new JTextPane();
00170 txtConsole.setFont( new Font( "DialogInput", Font.PLAIN, 12 ) );
00171 txtConsole.setEditable( false );
00172 txtConsole.setBorder( BorderFactory.createEmptyBorder() );
00173 }
00174 return txtConsole;
00175 }
00176
00177 }