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-2007 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: /*
043: * ProgressIndicator.java
044: *
045: * Created on April 25, 2001, 7:06 AM
046: */
047:
048: package org.netbeans.modules.uml.integration.ide.dialogs;
049:
050: import java.awt.*;
051: import javax.swing.*;
052: import javax.swing.border.*;
053:
054: import org.netbeans.modules.uml.core.support.umlsupport.Log;
055:
056: /**
057: * A simple dialog that allow the integration to update the user on the
058: * progress of a time consuming process.
059: * @author Trey Spiva
060: * @version 1.0
061: */
062: public class ProgressIndicator extends javax.swing.JDialog implements
063: IProgressIndicator {
064: /**
065: *
066: */
067: private static final long serialVersionUID = 1L;
068:
069: /** The default constructor of ProgressIndicator. */
070: public ProgressIndicator(Frame owner) {
071: super (owner);
072: initComponents();
073:
074: ImageIcon icon = new ImageIcon(ProgressIndicator.class
075: .getResource("ProgressBackground.jpg"));
076: this .getContentPane().add(new ImagePanel(icon.getImage()),
077: BorderLayout.CENTER);
078:
079: Border oldBorder = mProgress.getBorder();
080: Border margin = new EmptyBorder(0, 5, 5, 5);
081: CompoundBorder newBorder = new CompoundBorder(margin, oldBorder);
082: mProgress.setBorder(newBorder);
083:
084: setSize(400, 130);
085:
086: // Center the window.
087: try {
088: setLocationRelativeTo(null);
089: } catch (NoSuchMethodError err) {
090: Log.out("Used only with JDK 1.4");
091: }
092: }
093:
094: /**
095: * Creates a new ProgressIndicator and set the title of the dialog.
096: * @param title The title of the progress indicator.
097: */
098: public ProgressIndicator(String title) {
099: this ((Frame) null);
100:
101: setTitle(title);
102: }
103:
104: public ProgressIndicator(Frame parent, String title) {
105: this (parent);
106:
107: setTitle(title);
108: }
109:
110: /**
111: * Sets the maximum range of the progress bar. The maximum value is used to
112: * detimine the position of the progress.
113: * @param value The maximum value.
114: */
115: public void setMaxRange(int value) {
116: mProgress.setMaximum(value);
117: update(getGraphics());
118: }
119:
120: /**
121: * Returns the maximum range of the progress bar.
122: * @return The maximum value.
123: */
124: public int getMaxRange() {
125: return mProgress.getMaximum();
126: }
127:
128: /**
129: * Sets the minimum range of the progress bar. The minimum value is used to
130: * detimine the position of the progress.
131: * @param value The minimum value.
132: */
133: public void setMinRange(int value) {
134: mProgress.setMinimum(value);
135: }
136:
137: /**
138: * Sets the current progress information.
139: * @param msg A message to be displayed to the user.
140: * @param rangeCompleted The value to indicate the progress.
141: */
142: public void setProgress(String msg, int rangeCompleted) {
143: if (msg != null && msg.length() > 0)
144: mMessage.setText(msg);
145: mProgress.setValue(rangeCompleted);
146:
147: update(getGraphics());
148: }
149:
150: public void incrementProgress(String msg) {
151: if (msg != null && msg.length() > 0)
152: mMessage.setText(msg);
153: mProgress.setValue(mProgress.getValue() + 1);
154: update(getGraphics());
155: }
156:
157: /**
158: * Displays the progress indicator.
159: * @deprecated - use setVisible(boolean)
160: */
161: public void show() {
162: super .show();
163:
164: update(getGraphics());
165: }
166:
167: public void setVisible(boolean val) {
168: super .setVisible(val);
169: update(getGraphics());
170: }
171:
172: /**
173: * Closes the progress dialog.
174: */
175: public void done() {
176: closeDialog(null);
177: }
178:
179: /** This method is called from within the constructor to
180: * initialize the form.
181: * WARNING: Do NOT modify this code. The content of this method is
182: * always regenerated by the FormEditor.
183: */
184: private void initComponents() {//GEN-BEGIN:initComponents
185: mProgressControls = new javax.swing.JPanel();
186: mMessage = new javax.swing.JLabel();
187: mProgress = new javax.swing.JProgressBar();
188: setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
189: setName("GDProgressIndicator");
190: setTitle("Progress Inddicator");
191: setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
192: addWindowListener(new java.awt.event.WindowAdapter() {
193: public void windowClosing(java.awt.event.WindowEvent evt) {
194: closeDialog(evt);
195: }
196: });
197:
198: mProgressControls.setLayout(new java.awt.BorderLayout());
199: mProgressControls.setBorder(new javax.swing.border.BevelBorder(
200: 0));
201:
202: mMessage.setBorder(new javax.swing.border.EmptyBorder(
203: new java.awt.Insets(5, 5, 5, 5)));
204: mMessage.setText("Processing...");
205: mProgressControls.add(mMessage, java.awt.BorderLayout.NORTH);
206:
207: mProgressControls.add(mProgress, java.awt.BorderLayout.SOUTH);
208:
209: getContentPane().add(mProgressControls,
210: java.awt.BorderLayout.SOUTH);
211:
212: }//GEN-END:initComponents
213:
214: /** Closes the dialog */
215: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
216: setVisible(false);
217: dispose();
218: }//GEN-LAST:event_closeDialog
219:
220: // Variables declaration - do not modify//GEN-BEGIN:variables
221: private javax.swing.JPanel mProgressControls;
222: private javax.swing.JLabel mMessage;
223: private javax.swing.JProgressBar mProgress;
224:
225: // End of variables declaration//GEN-END:variables
226:
227: class ImagePanel extends JComponent {
228: Image image;
229:
230: public ImagePanel(Image image) {
231: this .image = image;
232: }
233:
234: public void paintComponent(Graphics g) {
235: super .paintComponent(g); //paint background
236:
237: //Now draw the image scaled.
238: g.drawImage(image, 0, 0, getWidth(), getHeight(), this );
239: }
240:
241: public Dimension getPreferredSize() {
242: return new Dimension(image.getWidth(this), image
243: .getHeight(this));
244: }
245: }
246: }
|