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.dbschema.jdbcimpl.wizard;
043:
044: import java.beans.PropertyChangeListener;
045: import java.beans.PropertyChangeSupport;
046: import java.text.MessageFormat;
047: import java.util.ResourceBundle;
048: import javax.swing.JComponent;
049: import javax.swing.SwingUtilities;
050: import org.netbeans.api.progress.ProgressHandle;
051: import org.netbeans.api.progress.ProgressHandleFactory;
052:
053: import org.openide.util.NbBundle;
054:
055: public class ProgressFrame extends javax.swing.JFrame {
056:
057: ResourceBundle bundle = NbBundle
058: .getBundle("org.netbeans.modules.dbschema.jdbcimpl.resources.Bundle"); //NOI18N
059: public PropertyChangeSupport propertySupport;
060: private ProgressHandle progressHandle;
061: private JComponent progressComponent;
062: private int workunits;
063: private boolean finished = false;
064:
065: /** Creates new form ProgressFrame */
066: public ProgressFrame() {
067: propertySupport = new PropertyChangeSupport(this );
068:
069: initComponents();
070: this .getAccessibleContext().setAccessibleDescription(
071: bundle.getString("ACS_ProgressFrameTabA11yDesc")); // NOI18N
072: okButton.getAccessibleContext().setAccessibleDescription(
073: bundle.getString("ACS_CancelButtonA11yDesc")); // NOI18N
074:
075: progressHandle = ProgressHandleFactory.createHandle(null);
076: progressComponent = ProgressHandleFactory
077: .createProgressComponent(progressHandle);
078: progressPanel.add(progressComponent);
079: progressHandle.start();
080:
081: javax.swing.ImageIcon ideIcon = new javax.swing.ImageIcon(
082: "/org/netbeans/core/resources/frames/ide.gif"); //NOI18N
083: setIconImage(ideIcon.getImage());
084:
085: java.awt.Dimension dim = java.awt.Toolkit.getDefaultToolkit()
086: .getScreenSize();
087: setSize(380, 150);
088: setLocation(dim.width / 2 - 190, dim.height / 2 - 80);
089: }
090:
091: public void dispose() {
092: if (!finished) {
093: progressHandle.finish();
094: finished = true;
095: }
096: super .dispose();
097: }
098:
099: /** This method is called from within the constructor to
100: * initialize the form.
101: * WARNING: Do NOT modify this code. The content of this method is
102: * always regenerated by the FormEditor.
103: */
104: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
105: private void initComponents() {
106: java.awt.GridBagConstraints gridBagConstraints;
107:
108: progressPanel = new javax.swing.JPanel();
109: msgLabel = new javax.swing.JLabel();
110: okButton = new javax.swing.JButton();
111:
112: getContentPane().setLayout(new java.awt.GridBagLayout());
113:
114: setTitle(bundle.getString("Title"));
115: setResizable(false);
116: progressPanel.setLayout(new java.awt.BorderLayout());
117:
118: progressPanel.setMinimumSize(new java.awt.Dimension(20, 20));
119: progressPanel.setPreferredSize(new java.awt.Dimension(20, 20));
120: gridBagConstraints = new java.awt.GridBagConstraints();
121: gridBagConstraints.gridx = 0;
122: gridBagConstraints.gridy = 1;
123: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124: gridBagConstraints.insets = new java.awt.Insets(0, 11, 11, 11);
125: getContentPane().add(progressPanel, gridBagConstraints);
126:
127: msgLabel
128: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
129: msgLabel.setText(bundle.getString("PreparingToCapture"));
130: gridBagConstraints = new java.awt.GridBagConstraints();
131: gridBagConstraints.gridx = 0;
132: gridBagConstraints.gridy = 0;
133: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
134: gridBagConstraints.insets = new java.awt.Insets(6, 11, 6, 11);
135: getContentPane().add(msgLabel, gridBagConstraints);
136:
137: okButton.setText(bundle.getString("Close"));
138: okButton
139: .setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
140: okButton.addActionListener(new java.awt.event.ActionListener() {
141: public void actionPerformed(java.awt.event.ActionEvent evt) {
142: okButtonActionPerformed(evt);
143: }
144: });
145:
146: gridBagConstraints = new java.awt.GridBagConstraints();
147: gridBagConstraints.gridx = 0;
148: gridBagConstraints.gridy = 2;
149: gridBagConstraints.weightx = 0.3;
150: gridBagConstraints.insets = new java.awt.Insets(0, 11, 11, 11);
151: getContentPane().add(okButton, gridBagConstraints);
152:
153: }
154:
155: // </editor-fold>//GEN-END:initComponents
156:
157: private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
158: setVisible(false);
159: propertySupport
160: .firePropertyChange("cancel", null, Boolean.TRUE); //NOI18N
161:
162: dispose();
163: }//GEN-LAST:event_okButtonActionPerformed
164:
165: // Variables declaration - do not modify//GEN-BEGIN:variables
166: private javax.swing.JLabel msgLabel;
167: private javax.swing.JButton okButton;
168: private javax.swing.JPanel progressPanel;
169:
170: // End of variables declaration//GEN-END:variables
171:
172: public void setMaximum(final int max) {
173: progressHandle.switchToDeterminate(max);
174: workunits = max;
175: }
176:
177: public void setValue(final int value) {
178: String message;
179:
180: progressHandle.progress(value);
181:
182: if (value >= workunits) {
183: SwingUtilities.invokeLater(new Runnable() {
184: public void run() {
185: String message = MessageFormat.format(bundle
186: .getString("Complete"),
187: new String[] { Integer.toString(value) }); //NOI18N
188: msgLabel.setText(message);
189: }
190: });
191: }
192: }
193:
194: public void setMessage(String msg) {
195: msgLabel.setText(msg);
196: }
197:
198: public void finishProgress() {
199: // running in the event thread ensures synchronized access to the finished field
200: SwingUtilities.invokeLater(new Runnable() {
201: public void run() {
202: progressHandle.finish();
203: finished = true;
204: }
205: });
206: }
207:
208: //========== property change support needed for progressbar ==========
209: public void addPropertyChangeListener(PropertyChangeListener l) {
210: propertySupport.addPropertyChangeListener(l);
211: }
212:
213: public void removePropertyChangeListener(PropertyChangeListener l) {
214: propertySupport.removePropertyChangeListener(l);
215: }
216: }
|