View Javadoc

1   package com.explosion.utilities.dialog;
2   
3   /*
4    * =============================================================================
5    * 
6    * Copyright 2004 Stephen Cowx
7    * 
8    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
9    * use this file except in compliance with the License. You may obtain a copy of
10   * the License at
11   * 
12   * http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   * 
20   * =============================================================================
21   */
22  
23  import java.awt.BorderLayout;
24  import java.awt.Image;
25  
26  import javax.swing.JFrame;
27  import javax.swing.JProgressBar;
28  import javax.swing.SwingUtilities;
29  
30  import com.explosion.utilities.process.threads.ProcessThread;
31  
32  /***
33   * @author Stephen Cowx Date created:@12-Feb-2003
34   */
35  public class ProgressDialog extends BusyDialog
36  {
37  
38      private JProgressBar progressBar;
39  
40      public ProgressDialog(JFrame owner, String title, ProcessThread workerThread, Image[] images)
41      {
42          super(owner, title, workerThread, images);
43          progressBar = new JProgressBar(0, 100);
44          progressBar.setValue(0);
45          progressBar.setStringPainted(true);
46          this.getContentPane().add(progressBar, BorderLayout.CENTER);
47          pack();
48      }
49  
50      /***
51       * @see com.explosion.utilities.process.threads.UnitisedProcess#processUnit()
52       */
53      public void processUnit() throws Exception
54      {
55          /* Initialise double buffer */
56          if (screenImage == null)
57          {
58              screenImage = canvas.createVolatileImage(width, height);
59              screenGraphics = screenImage.getGraphics();
60          }
61  
62          /* Wipe canvas */
63          screenGraphics.setColor(controlPanel.getBackground());
64          screenGraphics.fillRect(0, 0, width, height);
65  
66          /* Draw frame */
67          image.draw(screenGraphics);
68          image.cycle();
69  
70          /* Render buffer to canvas */
71          canvas.getGraphics().drawImage(screenImage, 0, 0, null);
72  
73          canvas.getGraphics().drawImage(screenImage, 0, 0, null);
74  
75          Runnable updateProgress = new Runnable()
76          {
77  
78              public void run()
79              {
80                  progressBar.setValue(workerThread.getProcess().getPercentComplete());
81              }
82          };
83          SwingUtilities.invokeLater(updateProgress);
84  
85          /* Sleep */
86          try
87          {
88              Thread.sleep(100);
89          } catch (InterruptedException e)
90          {}
91      }
92  
93  }