1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support;
14
15 import java.awt.BorderLayout;
16 import java.awt.HeadlessException;
17 import java.awt.event.ActionEvent;
18
19 import javax.swing.AbstractAction;
20 import javax.swing.BorderFactory;
21 import javax.swing.JButton;
22 import javax.swing.JDialog;
23 import javax.swing.JLabel;
24 import javax.swing.JProgressBar;
25
26 import com.eviware.soapui.SoapUI;
27 import com.jgoodies.forms.builder.ButtonBarBuilder;
28
29 /***
30 * Dialog for creating progress-dialogs
31 *
32 * @author Ole.Matzura
33 */
34
35 public class ProgressDialog extends JDialog
36 {
37 private JProgressBar progressBar;
38
39 private JLabel progressLabel;
40
41 private final CancelHandler cancelHandler;
42
43 private JButton cancelButton;
44
45 public ProgressDialog(String title, String label, int length, String initialValue, CancelHandler cancelHandler ) throws HeadlessException
46 {
47 super(SoapUI.getInstance().getFrame(), title, true);
48 this.cancelHandler = cancelHandler;
49
50 setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
51 setModal( true );
52
53 progressBar = new JProgressBar(0, length);
54 progressBar.setStringPainted(true);
55 progressBar.setString(initialValue );
56 progressBar.setIndeterminate(true);
57 progressBar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
58
59 getContentPane().setLayout(new BorderLayout());
60 progressLabel = new JLabel(label);
61 progressLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
62
63 getContentPane().add(progressLabel, BorderLayout.NORTH);
64 getContentPane().add(progressBar, BorderLayout.CENTER);
65
66 if( cancelHandler != null )
67 {
68 ButtonBarBuilder builder = ButtonBarBuilder.createLeftToRightBuilder();
69 builder.addGlue();
70 cancelButton = new JButton( new CancelAction());
71 builder.addFixed( cancelButton );
72 builder.addGlue();
73 builder.setBorder( BorderFactory.createEmptyBorder(0, 10, 10, 10) );
74 getContentPane().add( builder.getPanel(), BorderLayout.SOUTH );
75 }
76
77 pack();
78 }
79
80 public void setProgress( int value, String string )
81 {
82 progressBar.setValue( value );
83 progressBar.setString( string );
84 }
85
86 public void setVisible( boolean visible )
87 {
88 if( visible == true )
89 {
90 SoapUI.centerDialog( this );
91 }
92
93 super.setVisible( visible );
94 }
95
96 public interface CancelHandler
97 {
98 public boolean onCancel();
99 }
100
101 private class CancelAction extends AbstractAction
102 {
103 public CancelAction()
104 {
105 super( "Cancel" );
106 }
107
108 public void actionPerformed(ActionEvent e)
109 {
110 if( cancelHandler.onCancel() )
111 ProgressDialog.this.setVisible( false );
112 }
113 }
114
115 public void setCancelLabel(String label)
116 {
117 if( cancelButton != null )
118 cancelButton.setText( label );
119 }
120 }