KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JWaitDialog


1 import java.awt.*;
2 import java.awt.event.*;
3 import java.awt.image.ImageObserver JavaDoc;
4 import java.io.Serializable JavaDoc;
5 import java.util.*;
6 import javax.swing.*;
7 import javax.accessibility.Accessible JavaDoc;
8
9
10 /** Waiting modal dialog.*/
11 public final class JWaitDialog extends JDialog implements Accessible JavaDoc, ImageObserver JavaDoc, MenuContainer, RootPaneContainer, Serializable JavaDoc, SwingConstants,WindowConstants{
12     
13     private final JProgressBar pbar=new JProgressBar(1,20);
14     private JDialog owner;
15     private JFrame frameOwner;
16     private boolean ownerIsFrame=false;
17         
18     public JWaitDialog(JFrame owner, String JavaDoc msg){
19         super(owner,Lang.gs("wait"),false); //create dialog
20
setResizable(false);
21         setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
22         Container cp=getContentPane();
23         cp.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
24         cp.add(pbar);
25         
26         pbar.setStringPainted(true);
27         pbar.setString(Lang.gs(msg));
28         cp.add(pbar);
29         this.frameOwner=owner;
30         ownerIsFrame=true;
31         this.setCursor(GUI.WAIT);
32         pbar.setBorderPainted(false);
33         pack();
34     }
35     
36     public JWaitDialog(JDialog owner, String JavaDoc msg){
37         super(owner,Lang.gs("wait"),false); //create dialog
38
setResizable(false);
39         setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
40         Container cp=getContentPane();
41         cp.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
42         cp.add(pbar);
43         
44         pbar.setStringPainted(true);
45         pbar.setString(Lang.gs(msg));
46         cp.add(pbar);
47         this.owner=owner;
48         this.setCursor(GUI.WAIT);
49         pbar.setBorderPainted(false);
50         pack();
51     }
52     
53     public void show(){
54         pbar.setIndeterminate(true);
55         if(ownerIsFrame){
56             if(frameOwner!=null){
57                 setLocationRelativeTo(frameOwner);
58                 frameOwner.getGlassPane().setVisible(true);
59                 frameOwner.setCursor(GUI.WAIT);
60                 frameOwner.setEnabled(false);
61             }
62             else{
63                 setLocationRelativeTo(null);
64             }
65         }
66         else{
67             if(owner!=null){
68                 setLocationRelativeTo(owner);
69                 owner.getGlassPane().setVisible(true);
70                 owner.setCursor(GUI.WAIT);
71                 owner.setEnabled(false);
72             }
73             else{
74                 setLocationRelativeTo(null);
75             }
76         }
77         super.show();
78     }
79     
80     public void dispose(){
81         pbar.setIndeterminate(false);
82         if(ownerIsFrame){
83             if(frameOwner!=null){
84                 frameOwner.setEnabled(true);
85                 frameOwner.setCursor(GUI.NORMAL);
86                 frameOwner.getGlassPane().setVisible(false);
87             }
88         }
89         else{
90             if(owner!=null){
91                 owner.setEnabled(true);
92                 owner.setCursor(GUI.NORMAL);
93                 owner.getGlassPane().setVisible(false);
94             }
95         }
96         super.dispose();
97     }
98 }
Popular Tags