001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.projectimport.j2seimport.ui;
043:
044: import java.awt.Dialog;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import javax.swing.JDialog;
048: import javax.swing.Timer;
049: import javax.swing.WindowConstants;
050: import org.netbeans.api.progress.ProgressHandle;
051: import org.netbeans.api.progress.ProgressHandleFactory;
052: import org.netbeans.modules.projectimport.j2seimport.ImportProcess;
053: import org.openide.DialogDescriptor;
054: import org.openide.DialogDisplayer;
055: import org.openide.util.NbBundle;
056:
057: /**
058: * Shows status(progress) of importing.
059: *
060: * @author Radek Matous
061: */
062: public class ProgressPanel extends javax.swing.JPanel {
063: public static void showProgress(final ImportProcess iProcess) {
064: final ProgressHandle ph = iProcess.getProgressHandle();
065: final ProgressPanel progressPanel = new ProgressPanel(ph);
066: String title = NbBundle.getMessage(ProgressPanel.class,
067: "CTL_ProgressDialogTitle");//NOI18N
068:
069: DialogDescriptor desc = new DialogDescriptor(progressPanel,
070: title, true, new Object[] {}, null, 0, null, null);
071: desc.setClosingOptions(new Object[] {});
072:
073: final Dialog progressDialog = DialogDisplayer.getDefault()
074: .createDialog(desc);
075: ((JDialog) progressDialog)
076: .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
077:
078: // progress timer for periodically update progress
079: final Timer progressTimer = new Timer(50, null);
080: progressTimer.addActionListener(new ActionListener() {
081: public void actionPerformed(ActionEvent e) {
082: if (iProcess.isFinished()) {
083: progressTimer.stop();
084: progressDialog.setVisible(false);
085: progressDialog.dispose();
086: }
087: }
088: });
089: iProcess.startImport(true); // runs importing in separate thread
090: progressTimer.start();
091: progressDialog.setVisible(true);
092: }
093:
094: /** Creates new form ProgressPanel */
095: private ProgressPanel(final ProgressHandle progressHandle) {
096: initComponents(progressHandle);
097: }
098:
099: private void initComponents(final ProgressHandle progressHandle) {
100: java.awt.GridBagConstraints gridBagConstraints;
101:
102: setLayout(new java.awt.GridBagLayout());
103:
104: setPreferredSize(new java.awt.Dimension(450, 80));
105: gridBagConstraints = new java.awt.GridBagConstraints();
106: gridBagConstraints.gridx = 0;
107: gridBagConstraints.gridy = 0;
108: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
109: gridBagConstraints.weightx = 1.0;
110: gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
111: add(ProgressHandleFactory
112: .createProgressComponent(progressHandle),
113: gridBagConstraints);
114: }
115: }
|