KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > util > 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.persistence.util;
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  * <p>
40  * <i>This class is a copy of the <code>org.netbeans.modules.j2ee.common.ProgressPanel</code>,
41  * which can't be directly used because of dependencies. If a more appropriate place within
42  * the IDE cluster is found for the original class along with the
43  * <code>org.netbeans.modules.j2ee.common.EventRequestProcessor</code>, this copy should be removed.</i>
44  * </p>
45  *
46  * @author Martin Adamek, Andrei Badea
47  */

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

105     String JavaDoc getText() {
106         return info.getText();
107     }
108
109     public void setCancelVisible(boolean cancelVisible) {
110         cancelButton.setVisible(cancelVisible);
111     }
112
113     /**
114      * Used in tests.
115      */

116     boolean isCancelVisible() {
117         return cancelButton.isVisible();
118     }
119
120     public void setCancelEnabled(boolean cancelEnabled) {
121         cancelButton.setEnabled(cancelEnabled);
122     }
123
124     /**
125      * Used in tests.
126      */

127     boolean isCancelEnabled() {
128         return cancelButton.isEnabled();
129     }
130
131     public void addCancelActionListener(ActionListener JavaDoc listener) {
132         cancelButton.addActionListener(listener);
133     }
134
135     /**
136      * Used in tests.
137      */

138     JButton JavaDoc getCancelButton() {
139         return cancelButton;
140     }
141
142     /** This method is called from within the constructor to
143      * initialize the form.
144      * WARNING: Do NOT modify this code. The content of this method is
145      * always regenerated by the Form Editor.
146      */

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

184
185     // Variables declaration - do not modify//GEN-BEGIN:variables
186
private javax.swing.JButton JavaDoc cancelButton;
187     private javax.swing.JPanel JavaDoc holder;
188     private javax.swing.JLabel JavaDoc info;
189     // End of variables declaration//GEN-END:variables
190

191     public Dimension JavaDoc getPreferredSize() {
192         Dimension JavaDoc orig = super.getPreferredSize();
193         return new Dimension JavaDoc(500, orig.height);
194     }
195
196 }
197
Popular Tags