KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > server > SwingBootProgressMonitor


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.server;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Color JavaDoc;
24 import java.net.URL JavaDoc;
25
26 import javax.swing.BorderFactory JavaDoc;
27 import javax.swing.ImageIcon JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.JProgressBar JavaDoc;
30
31 import com.sslexplorer.boot.BootProgressMonitor;
32 import com.sslexplorer.boot.Util;
33
34
35 /**
36  * Swing implementation of the boot progress monitor.
37  *
38  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
39  */

40 public class SwingBootProgressMonitor implements BootProgressMonitor {
41     
42     private SplashWindow monitor;
43     private JProgressBar JavaDoc progress;
44     private String JavaDoc message;
45     
46     /**
47      * Constructor.
48      *
49      */

50     public SwingBootProgressMonitor() {
51         URL JavaDoc u = getClass().getResource("/images/enterprise.png");
52         if(u == null) {
53             u = getClass().getResource("/images/community.png");
54         }
55         if(u != null) {
56                 ImageIcon JavaDoc icon = new ImageIcon JavaDoc(u);
57             
58             // Create progress bar
59
progress = new JProgressBar JavaDoc(0, 100);
60             progress.setBackground(Color.white);
61             progress.setForeground(Color.black);
62             progress.setStringPainted(true);
63             JPanel JavaDoc pp = new JPanel JavaDoc(new BorderLayout JavaDoc());
64             pp.setBorder(BorderFactory.createEmptyBorder(2, 5, 5, 5));
65             pp.setOpaque(true);
66             pp.setBackground(Color.white);
67             pp.setForeground(Color.black);
68             pp.add(progress, BorderLayout.CENTER);
69             
70             // Create the monitor / splash window
71
monitor = new SplashWindow(null, icon == null ? null : icon.getImage(), 100000, pp);
72             monitor.setBackground(Color.white);
73             monitor.setForeground(Color.black);
74             monitor.setVisible(true);
75             monitor.setBorder(BorderFactory.createLineBorder(Color.black));
76         }
77     }
78
79     /* (non-Javadoc)
80      * @see com.sslexplorer.boot.BootProgressMonitor#updateMessage(java.lang.String)
81      */

82     public void updateMessage(String JavaDoc message) {
83         if(monitor != null) {
84             this.message = message;
85             progress.setString(message + " - " + progress.getValue() + "%");
86         }
87     }
88
89     /* (non-Javadoc)
90      * @see com.sslexplorer.boot.BootProgressMonitor#updateProgress(int)
91      */

92     public void updateProgress(int percent) {
93         if(monitor != null) {
94             progress.setString(message == null ? percent + "%" : ( message + " - " + percent + "%") );
95             progress.setValue(percent);
96         }
97     }
98
99     /* (non-Javadoc)
100      * @see com.sslexplorer.boot.BootProgressMonitor#dispose()
101      */

102     public void dispose() {
103         if(monitor != null) {
104             monitor.hide();
105         }
106     }
107
108 }
109
Popular Tags