KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > connection > ProgressDialog


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.connection;
18
19 import javax.swing.*;
20 import java.awt.*;
21
22 /**
23  * A Dialog for displaying the progress on the initial MBean load.
24  *
25  * @author Greg Hinkle (ghinkle@users.sourceforge.net), January 2002
26  * @version $Revision: 480 $($Author: ghinkl $ / $Date: 2004-10-05 01:17:41 -0400 (Tue, 05 Oct 2004) $)
27  */

28 public class ProgressDialog extends JDialog {
29
30     private JProgressBar progressBar;
31
32     private int max;
33
34     public ProgressDialog(int max) {
35         this.max = max;
36
37         init();
38     }
39
40     private void init() {
41         JLabel title = new JLabel("Loading " + max + " MBeans.");
42         progressBar = new JProgressBar(0, max);
43
44         setTitle("Loading " + max + " MBeans.");
45
46         getContentPane().setLayout(new GridBagLayout());
47         GridBagConstraints c1 = new GridBagConstraints();
48         c1.gridx = 0;
49         c1.gridy = 0;
50         c1.insets = new Insets(10,10,10,10);
51         c1.anchor = GridBagConstraints.NORTHWEST;
52
53         getContentPane().add(title, c1);
54
55         GridBagConstraints c2 = new GridBagConstraints();
56         c2.gridx = 0;
57         c2.gridy = 1;
58         c2.fill = GridBagConstraints.HORIZONTAL;
59         c2.insets = new Insets(10,10,10,10);
60
61         progressBar.setMinimumSize(new Dimension(240,25));
62         getContentPane().add(progressBar, c2);
63
64         GridBagConstraints c3 = new GridBagConstraints();
65         c3.fill = GridBagConstraints.HORIZONTAL;
66         c3.gridwidth = GridBagConstraints.REMAINDER;
67         c3.anchor = GridBagConstraints.EAST;
68         JButton cancelButton = new JButton("Cancel");
69         getContentPane().add(cancelButton, c3);
70
71         setSize(340,120);
72         Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
73
74         setLocation(
75                 dim.width/2 - getWidth()/2,
76                 dim.height/2 - getHeight()/2
77         );
78
79         //setModal(true);
80
setVisible(true);
81     }
82
83     public void setValue(int value) {
84         progressBar.setValue(value);
85     }
86
87     public void close() {
88         setVisible(false);
89         dispose();
90     }
91
92     public static void main(String JavaDoc[] args) {
93         ProgressDialog dialog = new ProgressDialog(100);
94         dialog.setVisible(true);
95     }
96 }
97
Popular Tags