001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.support.components;
014:
015: import java.awt.BorderLayout;
016: import java.awt.HeadlessException;
017: import java.awt.event.ActionEvent;
018:
019: import javax.swing.AbstractAction;
020: import javax.swing.BorderFactory;
021: import javax.swing.JButton;
022: import javax.swing.JDialog;
023: import javax.swing.JLabel;
024: import javax.swing.JPanel;
025: import javax.swing.JProgressBar;
026:
027: import com.eviware.soapui.support.UISupport;
028: import com.eviware.soapui.support.swing.SwingWorkerDelegator;
029: import com.eviware.x.dialogs.Worker;
030: import com.eviware.x.dialogs.XProgressDialog;
031: import com.eviware.x.dialogs.XProgressMonitor;
032: import com.jgoodies.forms.builder.ButtonBarBuilder;
033:
034: /**
035: * Dialog for creating progress-dialogs
036: *
037: * @author Ole.Matzura
038: */
039:
040: public class ProgressDialog extends JDialog implements XProgressDialog,
041: XProgressMonitor {
042: private JProgressBar progressBar;
043: private JLabel progressLabel;
044: private JButton cancelButton;
045: private Worker worker;
046:
047: public ProgressDialog(String title, String label, int length,
048: String initialValue, boolean allowCancel)
049: throws HeadlessException {
050: super (UISupport.getMainFrame(), title, true);
051:
052: setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
053:
054: progressBar = new JProgressBar(0, length);
055: JPanel panel = UISupport.createProgressBarPanel(progressBar,
056: 10, true);
057: progressBar.setString(initialValue);
058:
059: getContentPane().setLayout(new BorderLayout());
060: progressLabel = new JLabel(label);
061: progressLabel.setBorder(BorderFactory.createEmptyBorder(10, 10,
062: 0, 10));
063:
064: getContentPane().add(progressLabel, BorderLayout.NORTH);
065: getContentPane().add(panel, BorderLayout.CENTER);
066:
067: if (allowCancel) {
068: ButtonBarBuilder builder = ButtonBarBuilder
069: .createLeftToRightBuilder();
070: builder.addGlue();
071: cancelButton = new JButton(new CancelAction());
072: builder.addFixed(cancelButton);
073: builder.addGlue();
074: builder.setBorder(BorderFactory.createEmptyBorder(0, 10,
075: 10, 10));
076: getContentPane()
077: .add(builder.getPanel(), BorderLayout.SOUTH);
078: }
079:
080: pack();
081: }
082:
083: public void run(Worker worker) {
084: this .worker = worker;
085: SwingWorkerDelegator swingWorker = new SwingWorkerDelegator(
086: this , this , worker) {
087: @Override
088: public void finished() {
089: super .finished();
090: ProgressDialog.this .worker = null;
091: }
092: };
093:
094: swingWorker.start();
095: setVisible(true);
096: }
097:
098: /* (non-Javadoc)
099: * @see com.eviware.soapui.support.components.XProgressMonitor#setProgress(int, java.lang.String)
100: */
101: public void setProgress(int value, String string) {
102: progressBar.setValue(value);
103: progressBar.setString(string);
104: }
105:
106: /* (non-Javadoc)
107: * @see com.eviware.soapui.support.components.XProgressMonitor#setVisible(boolean)
108: */
109: public void setVisible(boolean visible) {
110: if (visible == true) {
111: UISupport.centerDialog(this );
112: }
113:
114: super .setVisible(visible);
115: }
116:
117: private class CancelAction extends AbstractAction {
118: public CancelAction() {
119: super ("Cancel");
120: }
121:
122: public void actionPerformed(ActionEvent e) {
123: worker.onCancel();
124: }
125: }
126:
127: public void setCancelLabel(String label) {
128: if (cancelButton != null)
129: cancelButton.setText(label);
130: }
131: }
|