2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.persistence.util;
44
import java.awt.BorderLayout;
45
import java.awt.Dialog;
46
import java.awt.Dimension;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49
import java.awt.event.KeyEvent;
50
import javax.swing.AbstractAction;
51
import javax.swing.JButton;
52
import javax.swing.JComponent;
53
import javax.swing.JDialog;
54
import javax.swing.JRootPane;
55
import javax.swing.KeyStroke;
56
import org.openide.DialogDescriptor;
57
import org.openide.DialogDisplayer;
58
import org.openide.util.NbBundle;
62
* <i>This class is a copy of the <code>org.netbeans.modules.j2ee.common.ProgressPanel</code>,
63
* which can't be directly used because of dependencies. If a more appropriate place within
64
* the IDE cluster is found for the original class along with the
65
* <code>org.netbeans.modules.j2ee.common.EventRequestProcessor</code>, this copy should be removed.</i>
68
* @author Martin Adamek, Andrei Badea
70
public class ProgressPanel extends javax.swing.JPanel {
72
private Dialog dialog;
74
public ProgressPanel() {
78
public void open(JComponent progressComponent) {
79
holder.add(progressComponent, BorderLayout.CENTER);
81
DialogDescriptor dd = new DialogDescriptor(
83
NbBundle.getMessage(ProgressPanel.class, "MSG_PleaseWait"),
86
DialogDescriptor.NO_OPTION,
87
DialogDescriptor.DEFAULT_ALIGN,
91
dialog = DialogDisplayer.getDefault().createDialog(dd);
92
if (dialog instanceof JDialog) {
93
JDialog jDialog = ((JDialog)dialog);
94
jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
95
JRootPane rootPane = jDialog.getRootPane();
96
rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NOI18N
97
rootPane.getActionMap().put("cancel", new AbstractAction() { // NOI18N
98
public void actionPerformed(ActionEvent event) {
99
if (cancelButton.isEnabled()) {
100
cancelButton.doClick();
105
dialog.setResizable(false);
106
dialog.setVisible(true);
109
public void close() {
110
if (dialog != null) {
111
dialog.setVisible(false);
116
public boolean isOpen() {
117
return dialog != null && dialog.isVisible();
120
public void setText(String text) {
128
return info.getText();
131
public void setCancelVisible(boolean cancelVisible) {
132
cancelButton.setVisible(cancelVisible);
138
boolean isCancelVisible() {
139
return cancelButton.isVisible();
142
public void setCancelEnabled(boolean cancelEnabled) {
143
cancelButton.setEnabled(cancelEnabled);
149
boolean isCancelEnabled() {
150
return cancelButton.isEnabled();
153
public void addCancelActionListener(ActionListener listener) {
154
cancelButton.addActionListener(listener);
160
JButton getCancelButton() {
164
/** This method is called from within the constructor to
165
* initialize the form.
166
* WARNING: Do NOT modify this code. The content of this method is
167
* always regenerated by the Form Editor.
169
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
170
private void initComponents() {
171
java.awt.GridBagConstraints gridBagConstraints;
173
info = new javax.swing.JLabel();
174
holder = new javax.swing.JPanel();
175
cancelButton = new javax.swing.JButton();
177
setLayout(new java.awt.GridBagLayout());
180
gridBagConstraints = new java.awt.GridBagConstraints();
181
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
182
gridBagConstraints.insets = new java.awt.Insets(12, 12, 11, 11);
183
add(info, gridBagConstraints);
185
holder.setLayout(new java.awt.BorderLayout());
187
gridBagConstraints = new java.awt.GridBagConstraints();
188
gridBagConstraints.gridx = 0;
189
gridBagConstraints.gridy = 1;
190
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
191
gridBagConstraints.weightx = 1.0;
192
gridBagConstraints.weighty = 1.0;
193
gridBagConstraints.insets = new java.awt.Insets(0, 12, 11, 11);
194
add(holder, gridBagConstraints);
196
cancelButton.setText(org.openide.util.NbBundle.getMessage(ProgressPanel.class, "LBL_Cancel"));
197
gridBagConstraints = new java.awt.GridBagConstraints();
198
gridBagConstraints.gridx = 0;
199
gridBagConstraints.gridy = 2;
200
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
201
gridBagConstraints.insets = new java.awt.Insets(0, 12, 11, 11);
202
add(cancelButton, gridBagConstraints);
204
}// </editor-fold>//GEN-END:initComponents
207
// Variables declaration - do not modify//GEN-BEGIN:variables
208
private javax.swing.JButton cancelButton;
209
private javax.swing.JPanel holder;
210
private javax.swing.JLabel info;
211
// End of variables declaration//GEN-END:variables
213
public Dimension getPreferredSize() {
214
Dimension orig = super.getPreferredSize();
215
return new Dimension(500, orig.height);