KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > JUnitProgress


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  * JUnitProgress.java
21  *
22  * Created on February 1, 2001, 7:30 PM
23  */

24 package org.netbeans.modules.junit;
25
26 import java.awt.Dialog JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.SwingUtilities JavaDoc;
31 import org.openide.DialogDescriptor;
32 import org.openide.DialogDisplayer;
33 import org.openide.awt.StatusDisplayer;
34 import org.openide.util.NbBundle;
35
36 /**
37  *
38  * @author vstejskal
39  */

40 public class JUnitProgress extends JPanel JavaDoc implements ActionListener JavaDoc {
41     /** Creates new form JUnitProgress */
42     public JUnitProgress(String JavaDoc dialogTitle) {
43         if (dialogTitle != null) {
44             this.dialogTitle = dialogTitle;
45         }
46         initComponents();
47     }
48     public void showMe(boolean displayCancel) {
49         if (null == descriptor) {
50             Object JavaDoc[] options = null;
51             Object JavaDoc initOption = null;
52             
53             if (displayCancel) {
54                 options = new Object JavaDoc[] { DialogDescriptor.CANCEL_OPTION };
55                 initOption = DialogDescriptor.CANCEL_OPTION;
56             }
57             
58             descriptor = new DialogDescriptor (
59                 this,
60                 dialogTitle,
61                 false,
62                 options,
63                 initOption,
64                 DialogDescriptor.BOTTOM_ALIGN,
65                 null,
66                 this
67             );
68         }
69         
70         if (null != dialog)
71             dialog.dispose();
72         
73         canceled = false;
74         dialog = DialogDisplayer.getDefault().createDialog(descriptor);
75         dialog.getAccessibleContext().setAccessibleDescription(
76                 NbBundle.getMessage(JUnitProgress.class,
77                                     "ACS_StatusBar_CreateTests")); //NOI18N
78
dialog.setSize(400, 150);
79         dialog.setVisible(true);
80     }
81     
82     public void hideMe() {
83         if (null != dialog) {
84             dialog.dispose();
85         }
86     }
87     public void actionPerformed(ActionEvent JavaDoc ev) {
88         canceled = true;
89     }
90     
91     public void setMessage(final String JavaDoc msg) {
92         setMessage(msg,false);
93     }
94     
95     public void setMessage(final String JavaDoc msg, boolean displayStatus) {
96         if (SwingUtilities.isEventDispatchThread())
97             lblMessage.setText(msg);
98         else {
99             SwingUtilities.invokeLater(
100                 new Thread JavaDoc() {
101                     public void run() {
102                         lblMessage.setText(msg);
103                     }
104                 }
105             );
106         }
107         if (displayStatus) {
108             displayStatusText(msg);
109         }
110     }
111     
112     public boolean isCanceled() {
113         return canceled;
114     }
115     
116     // not defined as static and defined in this class, because
117
// it might show status also in the progress dialog in the future
118
public void displayStatusText(String JavaDoc statusText) {
119         StatusDisplayer.getDefault().setStatusText(statusText);
120     }
121     
122     
123     private DialogDescriptor descriptor = null;
124     private Dialog JavaDoc dialog = null;
125     private volatile boolean canceled = false;
126     private String JavaDoc dialogTitle = "";
127     
128     /** This method is called from within the constructor to
129      * initialize the form.
130      * WARNING: Do NOT modify this code. The content of this method is
131      * always regenerated by the Form Editor.
132      */

133     private void initComponents() {//GEN-BEGIN:initComponents
134
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
135
136         lblMessage = new javax.swing.JLabel JavaDoc();
137
138         setLayout(new java.awt.GridBagLayout JavaDoc());
139
140         lblMessage.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/junit/Bundle").getString("JUnitProgress.lblMessage.text"));
141         lblMessage.setAlignmentX(0.5F);
142         lblMessage.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
143         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
144         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
145         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 4, 4);
146         gridBagConstraints.weightx = 1.0;
147         gridBagConstraints.weighty = 1.0;
148         add(lblMessage, gridBagConstraints);
149
150     }//GEN-END:initComponents
151
// Variables declaration - do not modify//GEN-BEGIN:variables
152
private javax.swing.JLabel JavaDoc lblMessage;
153     // End of variables declaration//GEN-END:variables
154
}
155
Popular Tags