KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > common > ProgressPanel


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.j2ee.common;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Dialog JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import java.awt.event.KeyEvent JavaDoc;
28 import javax.swing.AbstractAction JavaDoc;
29 import javax.swing.JButton JavaDoc;
30 import javax.swing.JComponent JavaDoc;
31 import javax.swing.JDialog JavaDoc;
32 import javax.swing.JRootPane JavaDoc;
33 import javax.swing.KeyStroke JavaDoc;
34 import org.openide.DialogDescriptor;
35 import org.openide.DialogDisplayer;
36 import org.openide.util.NbBundle;
37
38 /**
39  *
40  * @author Martin Adamek, Andrei Badea
41  */

42 public class ProgressPanel extends javax.swing.JPanel JavaDoc {
43
44     private Dialog JavaDoc dialog;
45
46     public ProgressPanel() {
47         initComponents();
48     }
49
50     public void open(JComponent JavaDoc progressComponent) {
51         holder.add(progressComponent, BorderLayout.CENTER);
52
53         DialogDescriptor dd = new DialogDescriptor(
54                 this,
55                 NbBundle.getMessage(ProgressPanel.class, "MSG_PleaseWait"),
56                 true,
57                 new Object JavaDoc[0],
58                 DialogDescriptor.NO_OPTION,
59                 DialogDescriptor.DEFAULT_ALIGN,
60                 null,
61                 null,
62                 true);
63         dialog = DialogDisplayer.getDefault().createDialog(dd);
64         if (dialog instanceof JDialog JavaDoc) {
65             JDialog JavaDoc jDialog = ((JDialog JavaDoc)dialog);
66             jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
67             JRootPane JavaDoc rootPane = jDialog.getRootPane();
68             rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NOI18N
69
rootPane.getActionMap().put("cancel", new AbstractAction JavaDoc() { // NOI18N
70
public void actionPerformed(ActionEvent JavaDoc event) {
71                     if (cancelButton.isEnabled()) {
72                         cancelButton.doClick();
73                     }
74                 }
75             });
76         }
77         dialog.setResizable(false);
78         dialog.setVisible(true);
79     }
80
81     public void close() {
82     if (dialog != null) {
83         dialog.setVisible(false);
84         dialog.dispose();
85     }
86     }
87
88     public boolean isOpen() {
89         return dialog != null && dialog.isVisible();
90     }
91
92     public void setText(String JavaDoc text) {
93         info.setText(text);
94     }
95
96     /**
97      * Used in tests.
98      */

99     String JavaDoc getText() {
100         return info.getText();
101     }
102
103     public void setCancelVisible(boolean cancelVisible) {
104         cancelButton.setVisible(cancelVisible);
105     }
106
107     /**
108      * Used in tests.
109      */

110     boolean isCancelVisible() {
111         return cancelButton.isVisible();
112     }
113
114     public void setCancelEnabled(boolean cancelEnabled) {
115         cancelButton.setEnabled(cancelEnabled);
116     }
117
118     /**
119      * Used in tests.
120      */

121     boolean isCancelEnabled() {
122         return cancelButton.isEnabled();
123     }
124
125     public void addCancelActionListener(ActionListener JavaDoc listener) {
126         cancelButton.addActionListener(listener);
127     }
128
129     /**
130      * Used in tests.
131      */

132     JButton JavaDoc getCancelButton() {
133         return cancelButton;
134     }
135
136     /** This method is called from within the constructor to
137      * initialize the form.
138      * WARNING: Do NOT modify this code. The content of this method is
139      * always regenerated by the Form Editor.
140      */

141     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
142
private void initComponents() {
143         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
144
145         info = new javax.swing.JLabel JavaDoc();
146         holder = new javax.swing.JPanel JavaDoc();
147         cancelButton = new javax.swing.JButton JavaDoc();
148
149         setLayout(new java.awt.GridBagLayout JavaDoc());
150
151         info.setText(" ");
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
154         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 11, 11);
155         add(info, gridBagConstraints);
156
157         holder.setLayout(new java.awt.BorderLayout JavaDoc());
158
159         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
160         gridBagConstraints.gridx = 0;
161         gridBagConstraints.gridy = 1;
162         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
163         gridBagConstraints.weightx = 1.0;
164         gridBagConstraints.weighty = 1.0;
165         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 11, 11);
166         add(holder, gridBagConstraints);
167
168         cancelButton.setText(org.openide.util.NbBundle.getMessage(ProgressPanel.class, "LBL_Cancel"));
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.gridx = 0;
171         gridBagConstraints.gridy = 2;
172         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
173         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 11, 11);
174         add(cancelButton, gridBagConstraints);
175
176     }// </editor-fold>//GEN-END:initComponents
177

178
179     // Variables declaration - do not modify//GEN-BEGIN:variables
180
private javax.swing.JButton JavaDoc cancelButton;
181     private javax.swing.JPanel JavaDoc holder;
182     private javax.swing.JLabel JavaDoc info;
183     // End of variables declaration//GEN-END:variables
184

185     public Dimension JavaDoc getPreferredSize() {
186         Dimension JavaDoc orig = super.getPreferredSize();
187         return new Dimension JavaDoc(500, orig.height);
188     }
189
190 }
191
Popular Tags