KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > ProgressInternalDialog


1 package net.suberic.pooka.gui;
2
3 import javax.swing.*;
4
5 /**
6  * A simple implementation of ProgressDialog. This creates and shows a
7  * JInternalFramewith a JProgressBar and a cancel button.
8  */

9 public class ProgressInternalDialog extends ProgressDialogImpl {
10   
11   JInternalFrame dialogFrame = null;
12   JDesktopPane desktop = null;
13
14   /**
15    * Creates a ProgressDialogImpl with the given minimum, maximum, and
16    * current values.
17    */

18   public ProgressInternalDialog(int min, int max, int current, String JavaDoc title, String JavaDoc message, JDesktopPane desktopPane) {
19     initDialog(min, max, current, title, message);
20     desktop = desktopPane;
21   }
22
23   /**
24    * Creates the Dialog in which the ProgressBar will be shown.
25    */

26   protected void createDialog() {
27     dialogFrame = new JInternalFrame(nameLabel.getText(), true, false, false, true);
28     dialogFrame.getContentPane().setLayout(new BoxLayout(dialogFrame.getContentPane(), BoxLayout.Y_AXIS));
29
30     dialogFrame.getContentPane().add(nameLabel);
31     dialogFrame.getContentPane().add(progressBar);
32     dialogFrame.getContentPane().add(buttonPanel);
33     
34     dialogFrame.pack();
35     
36   }
37
38   /**
39    * Shows the dialog.
40    */

41   public void show() {
42     Runnable JavaDoc runMe = new Runnable JavaDoc() {
43     public void run() {
44       desktop.add(dialogFrame);
45       if (desktop instanceof MessagePanel) {
46         dialogFrame.setLocation(((MessagePanel) desktop).getNewWindowLocation(dialogFrame, true));
47       }
48       dialogFrame.setVisible(true);
49     }
50       };
51     if (SwingUtilities.isEventDispatchThread())
52       runMe.run();
53     else
54       SwingUtilities.invokeLater(runMe);
55   }
56
57   /**
58    * Disposes of the dialog.
59    */

60   public void dispose() {
61     Runnable JavaDoc runMe = new Runnable JavaDoc() {
62     public void run() {
63       try {
64         dialogFrame.setClosed(true);
65       } catch (java.beans.PropertyVetoException JavaDoc e) {
66       }
67     }
68       };
69     
70     if (SwingUtilities.isEventDispatchThread())
71       runMe.run();
72     else
73       SwingUtilities.invokeLater(runMe);
74   }
75
76 }
77
Popular Tags