KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > shutdown > ShutdownDialog


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.shutdown;
17
18 import java.awt.BorderLayout JavaDoc;
19 import java.awt.Dimension JavaDoc;
20 import java.awt.Font JavaDoc;
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.awt.event.ActionListener JavaDoc;
23
24 import javax.swing.BorderFactory JavaDoc;
25 import javax.swing.JFrame JavaDoc;
26 import javax.swing.JLabel JavaDoc;
27 import javax.swing.JPanel JavaDoc;
28 import javax.swing.JProgressBar JavaDoc;
29 import javax.swing.Timer JavaDoc;
30
31 import org.columba.core.resourceloader.GlobalResourceLoader;
32 import org.columba.core.resourceloader.ImageLoader;
33
34
35 /**
36  * Dialog shown while closing Columba.
37  * <p>
38  * Waits two seconds until it is visible.
39  *
40  * @author fdietz
41  */

42 public class ShutdownDialog extends JFrame JavaDoc implements ActionListener JavaDoc {
43     protected static final String JavaDoc RESOURCE_PATH = "org.columba.core.i18n.dialog";
44     private JProgressBar JavaDoc progressBar;
45     private Timer JavaDoc timer;
46
47     public ShutdownDialog() throws Exception JavaDoc{
48         super(GlobalResourceLoader.getString(RESOURCE_PATH, "session",
49                 "exit_title"));
50
51         JLabel JavaDoc icon = new JLabel JavaDoc();
52         icon.setIcon(ImageLoader.getMiscIcon("out-of-office-48.png"));
53
54         JLabel JavaDoc text = new JLabel JavaDoc(GlobalResourceLoader.getString(RESOURCE_PATH,
55                     "session", "exit_msg"));
56         text.setFont(text.getFont().deriveFont(Font.BOLD));
57
58         JPanel JavaDoc panel = new JPanel JavaDoc();
59
60         panel.setLayout(new BorderLayout JavaDoc());
61
62         icon.setBorder(BorderFactory.createEmptyBorder(12, 12, 6, 12));
63         text.setBorder(BorderFactory.createEmptyBorder(0, 6, 12, 12));
64
65         progressBar = new JProgressBar JavaDoc();
66         progressBar.setIndeterminate(true);
67         progressBar.setPreferredSize(new Dimension JavaDoc(250, 20));
68
69         JPanel JavaDoc bottomPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
70         bottomPanel.setBorder(BorderFactory.createEmptyBorder(0, 12, 12, 12));
71         bottomPanel.add(progressBar, BorderLayout.CENTER);
72
73         getContentPane().setLayout(new BorderLayout JavaDoc());
74
75         getContentPane().add(panel, BorderLayout.CENTER);
76
77         getContentPane().add(icon, BorderLayout.WEST);
78
79         getContentPane().add(bottomPanel, BorderLayout.SOUTH);
80
81         panel.add(text, BorderLayout.SOUTH);
82
83         pack();
84
85         setLocationRelativeTo(null);
86
87         // wait for 2 seconds until the dialog is openened
88
timer = new Timer JavaDoc(2 * 1000, this);
89         timer.start();
90     }
91
92     /**
93  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
94  */

95     public void actionPerformed(ActionEvent JavaDoc arg0) {
96         setVisible(true);
97         timer.stop();
98     }
99
100     public void close() {
101         timer.stop();
102
103         if (isVisible()) {
104             setVisible(false);
105         }
106     }
107 }
108
Popular Tags