~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/util/ProgressPanel.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.j2ee.persistence.util;
 
43
 
 
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;
 
59
 
 
60
/**
 
61
 * <p>
 
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>
 
66
 * </p>
 
67
 * 
 
68
 * @author Martin Adamek, Andrei Badea
 
69
 */
 
70
public class ProgressPanel extends javax.swing.JPanel {
 
71
 
 
72
    private Dialog dialog;
 
73
 
 
74
    public ProgressPanel() {
 
75
        initComponents();
 
76
    }
 
77
 
 
78
    public void open(JComponent progressComponent) {
 
79
        holder.add(progressComponent, BorderLayout.CENTER);
 
80
 
 
81
        DialogDescriptor dd = new DialogDescriptor(
 
82
                this,
 
83
                NbBundle.getMessage(ProgressPanel.class, "MSG_PleaseWait"),
 
84
                true,
 
85
                new Object[0],
 
86
                DialogDescriptor.NO_OPTION,
 
87
                DialogDescriptor.DEFAULT_ALIGN,
 
88
                null,
 
89
                null,
 
90
                true);
 
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();
 
101
                    }
 
102
                }
 
103
            });
 
104
        }
 
105
        dialog.setResizable(false);
 
106
        dialog.setVisible(true);
 
107
    }
 
108
 
 
109
    public void close() {
 
110
        if (dialog != null) {
 
111
            dialog.setVisible(false);
 
112
            dialog.dispose();
 
113
        }
 
114
    }
 
115
 
 
116
    public boolean isOpen() {
 
117
        return dialog != null && dialog.isVisible();
 
118
    }
 
119
 
 
120
    public void setText(String text) {
 
121
        info.setText(text);
 
122
    }
 
123
 
 
124
    /**
 
125
     * Used in tests.
 
126
     */
 
127
    String getText() {
 
128
        return info.getText();
 
129
    }
 
130
 
 
131
    public void setCancelVisible(boolean cancelVisible) {
 
132
        cancelButton.setVisible(cancelVisible);
 
133
    }
 
134
 
 
135
    /**
 
136
     * Used in tests.
 
137
     */
 
138
    boolean isCancelVisible() {
 
139
        return cancelButton.isVisible();
 
140
    }
 
141
 
 
142
    public void setCancelEnabled(boolean cancelEnabled) {
 
143
        cancelButton.setEnabled(cancelEnabled);
 
144
    }
 
145
 
 
146
    /**
 
147
     * Used in tests.
 
148
     */
 
149
    boolean isCancelEnabled() {
 
150
        return cancelButton.isEnabled();
 
151
    }
 
152
 
 
153
    public void addCancelActionListener(ActionListener listener) {
 
154
        cancelButton.addActionListener(listener);
 
155
    }
 
156
 
 
157
    /**
 
158
     * Used in tests.
 
159
     */
 
160
    JButton getCancelButton() {
 
161
        return cancelButton;
 
162
    }
 
163
 
 
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.
 
168
     */
 
169
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
 
170
    private void initComponents() {
 
171
        java.awt.GridBagConstraints gridBagConstraints;
 
172
 
 
173
        info = new javax.swing.JLabel();
 
174
        holder = new javax.swing.JPanel();
 
175
        cancelButton = new javax.swing.JButton();
 
176
 
 
177
        setLayout(new java.awt.GridBagLayout());
 
178
 
 
179
        info.setText(" ");
 
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);
 
184
 
 
185
        holder.setLayout(new java.awt.BorderLayout());
 
186
 
 
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);
 
195
 
 
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);
 
203
 
 
204
    }// </editor-fold>//GEN-END:initComponents
 
205
 
 
206
 
 
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
 
212
 
 
213
    public Dimension getPreferredSize() {
 
214
        Dimension orig = super.getPreferredSize();
 
215
        return new Dimension(500, orig.height);
 
216
    }
 
217
 
 
218
}