KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > client > WizardStepProgressSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.subversion.client;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import javax.swing.JButton JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.JLabel JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.SwingUtilities JavaDoc;
30 import org.netbeans.api.progress.ProgressHandle;
31 import org.netbeans.api.progress.ProgressHandleFactory;
32 import org.netbeans.modules.subversion.ui.wizards.repositorystep.RepositoryStep;
33 import org.openide.util.Cancellable;
34
35 /**
36  *
37  * @author Tomas Stupka
38  */

39 public abstract class WizardStepProgressSupport extends SvnProgressSupport implements Runnable JavaDoc, Cancellable {
40
41     private JPanel JavaDoc progressComponent;
42     private JLabel JavaDoc progressLabel;
43     private JPanel JavaDoc panel;
44
45     public WizardStepProgressSupport(JPanel JavaDoc panel) {
46         this.panel = panel;
47
48
49     }
50
51     public void performInCurrentThread(String JavaDoc displayName) {
52         setDisplayName(displayName);
53         performIntern();
54     }
55
56     public abstract void setEditable(boolean bl);
57
58     public void startProgress() {
59         SwingUtilities.invokeLater(new Runnable JavaDoc() {
60             public void run() {
61                 ProgressHandle progress = getProgressHandle(); // NOI18N
62
JComponent JavaDoc bar = ProgressHandleFactory.createProgressComponent(progress);
63                 JButton JavaDoc stopButton = new JButton JavaDoc(org.openide.util.NbBundle.getMessage(RepositoryStep.class, "BK2022")); // NOI18N
64
stopButton.addActionListener(new ActionListener JavaDoc() {
65                     public void actionPerformed(ActionEvent JavaDoc e) {
66                         cancel();
67                     }
68                 });
69                 progressComponent = new JPanel JavaDoc();
70                 progressComponent.setLayout(new BorderLayout JavaDoc(6, 0));
71                 progressLabel = new JLabel JavaDoc();
72                 progressLabel.setText(getDisplayName());
73                 progressComponent.add(progressLabel, BorderLayout.NORTH);
74                 progressComponent.add(bar, BorderLayout.CENTER);
75                 progressComponent.add(stopButton, BorderLayout.LINE_END);
76                 WizardStepProgressSupport.super.startProgress();
77                 panel.setVisible(true);
78                 panel.add(progressComponent, BorderLayout.SOUTH);
79                 panel.revalidate();
80             }
81         });
82     }
83
84     protected void finnishProgress() {
85         SwingUtilities.invokeLater(new Runnable JavaDoc() {
86             public void run() {
87                 WizardStepProgressSupport.super.finnishProgress();
88                 panel.remove(progressComponent);
89                 panel.revalidate();
90                 panel.repaint();
91                 panel.setVisible(false);
92                 setEditable(true);
93             }
94         });
95     }
96
97     public void setDisplayName(String JavaDoc displayName) {
98         if(progressLabel != null) {
99             progressLabel.setText(displayName);
100         }
101         super.setDisplayName(displayName);
102     }
103     
104 }
105
Popular Tags