001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.summary.load;
053:
054: import java.awt.Frame;
055: import java.awt.Color;
056: import java.awt.Dimension;
057: import java.awt.GridLayout;
058: import javax.swing.JFrame;
059: import javax.swing.JDialog;
060: import javax.swing.JProgressBar;
061: import javax.swing.JLabel;
062: import org.acm.seguin.tools.RefactoryStorage;
063:
064: /**
065: * Reports to the user the status of the loading using stdout
066: *
067: *@author Chris Seguin
068: *@created September 12, 2001
069: */
070: public class SwingLoadStatus extends JDialog implements LoadStatus {
071: private JLabel label;
072: private JProgressBar progress;
073: private int count;
074: private int max;
075: private int fivePercent;
076: private String oldName;
077: private RefactoryStorage lengths;
078: private boolean inPanel = false;
079:
080: /**
081: * Constructor for the SwingLoadStatus object
082: */
083: public SwingLoadStatus(Frame owner) {
084: super (owner, "Loading source files", false);
085: initialise();
086: }
087:
088: /**
089: * Constructor for the SwingLoadStatus object
090: */
091: public SwingLoadStatus() {
092: super (new JFrame(), "Loading source files", false);
093: initialise();
094: }
095:
096: private void initialise() {
097: getContentPane().setLayout(new GridLayout(2, 1));
098:
099: label = new JLabel(
100: "Loading: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
101: Dimension size = label.getPreferredSize();
102: label.setSize(size);
103: getContentPane().add(label);
104:
105: progress = new JProgressBar();
106: progress.setSize(size);
107: getContentPane().add(progress);
108:
109: //setSize(230, 70);
110: pack();
111: setVisible(true);
112:
113: oldName = null;
114: lengths = new RefactoryStorage();
115: try {
116: setAlwaysOnTop(true);
117: } catch (Error e) {
118: } catch (Exception e) {
119: }
120: }
121:
122: public java.awt.Container getPanel() {
123: return getContentPane();
124: }
125:
126: /**
127: * Sets the Root attribute of the LoadStatus object
128: *
129: *@param name The new Root value
130: */
131: public void setLength(String name, int count) {
132: lengths.addKey(name + ".count", count);
133: oldName = name;
134: }
135:
136: /**
137: * Sets the Root attribute of the LoadStatus object
138: *
139: *@param name The new Root value
140: */
141: public void setRoot(String name) {
142: if (oldName != null) {
143: lengths.addKey(oldName + ".count", count);
144: }
145:
146: if (name.endsWith(".stub")) {
147: name = name.substring(0, name.length() - 5);
148: progress.setForeground(Color.red);
149: } else if (name.toLowerCase().indexOf("j2sdk") >= 0) {
150: progress.setForeground(Color.green);
151: } else {
152: progress.setForeground(Color.blue);
153: }
154: label.setText("Loading: " + name);
155: label.setSize(label.getPreferredSize());
156: count = 0;
157: progress.setValue(count);
158: max = lengths.getValue(name + ".count");
159: progress.setMaximum(max);
160: fivePercent = max / 20;
161:
162: oldName = name;
163: }
164:
165: public void completedLoading() {
166: progress.setValue(0);
167: label.setText("Loaded");
168: }
169:
170: public void setLabel(String name) {
171: label.setText(name);
172: }
173:
174: /**
175: * Sets the CurrentFile attribute of the LoadStatus object
176: *
177: *@param name The new CurrentFile value
178: */
179: public void setCurrentFile(String name) {
180: count++;
181: if (fivePercent < 1) {
182: progress.setValue(count);
183: } else if (count % fivePercent == 0) {
184: progress.setValue(count);
185: }
186: }
187:
188: /**
189: * Completed the loading
190: */
191: public void done() {
192: completedLoading();
193: dispose();
194: if (oldName != null) {
195: lengths.addKey(oldName + ".count", count);
196: }
197: lengths.store();
198: }
199: }
|