KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > gui > swt > SWTProgressDialog


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.agent.client.gui.swt;
21
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Button;
26 import org.eclipse.swt.widgets.Event;
27 import org.eclipse.swt.widgets.Label;
28 import org.eclipse.swt.widgets.Listener;
29 import org.eclipse.swt.widgets.ProgressBar;
30 import org.eclipse.swt.widgets.Shell;
31
32 import com.sslexplorer.agent.client.TaskProgress;
33
34 /**
35  * SWT Progress Dialog
36  *
37  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
38  */

39 public class SWTProgressDialog implements TaskProgress {
40
41     // Private instace variables
42

43     private Shell shell;
44     private SWTSystemTrayGUI gui;
45     private ProgressBar progressBar;
46     private Label label;
47
48     /**
49      * Constructor.
50      *
51      * @param gui gui
52      * @param note
53      * @param message
54      */

55     public SWTProgressDialog(SWTSystemTrayGUI gui, final int maxValue, final boolean allowCancel, final String JavaDoc message, final String JavaDoc note) {
56         this.gui = gui;
57
58         // Create the shell
59
gui.getDisplay().asyncExec(new Runnable JavaDoc() {
60             public void run() {
61                 doInit(maxValue, allowCancel, message, note);
62             }
63         });
64     }
65     
66     void doInit(int maxValue, boolean allowCancel, String JavaDoc message, String JavaDoc note) {
67         shell = new Shell(gui.getDisplay(), SWT.TITLE | SWT.CLOSE | SWT.BORDER);
68         GridLayout gridLayout = new GridLayout ();
69         gridLayout.marginHeight = 10;
70         gridLayout.verticalSpacing = 10;
71         shell.setLayout (gridLayout);
72         shell.setText(note); //$NON-NLS-1$
73
shell.setImage(gui.loadImage(SWTSystemTrayGUI.class, "/images/frame-agent.png")); //$NON-NLS-1$
74

75         // Label
76
label = new Label(shell, SWT.CENTER);
77         label.setText(message);
78         GridData data = new GridData ();
79         data.horizontalAlignment = GridData.CENTER;
80         label.setLayoutData (data);
81
82         // Progress
83
progressBar = new ProgressBar(shell, SWT.CENTER);
84         progressBar.setMinimum(0);
85         progressBar.setMaximum(maxValue);
86         progressBar.setSelection(0);
87         progressBar.setToolTipText(message);
88         data = new GridData ();
89         data.widthHint = 200;
90         data.horizontalAlignment = GridData.CENTER;
91         progressBar.setLayoutData (data);
92         
93         // Label
94

95         // Clear Button
96
if(allowCancel) {
97             final Button cancel = new Button(shell, SWT.PUSH);
98             cancel.setText(Messages.getString("TaskProgress.cancel")); //$NON-NLS-1$
99
cancel.addListener(SWT.Selection, new Listener() {
100                 public void handleEvent(Event event) {
101                 }
102             });
103             data = new GridData ();
104             data.horizontalAlignment = GridData.CENTER;
105             cancel.setLayoutData (data);
106         }
107
108         shell.pack();
109         SWTUtil.center(shell);
110         shell.open();
111     }
112
113     public void dispose() {
114         gui.getDisplay().syncExec(new Runnable JavaDoc() {
115             public void run() {
116                 shell.setVisible(false);
117             }
118         });
119     }
120
121     public void setMessage(final String JavaDoc text) {
122         gui.getDisplay().syncExec(new Runnable JavaDoc() {
123             public void run() {
124                 label.setText(text);
125             }
126         });
127     }
128
129     public void updateValue(final long value) {
130         gui.getDisplay().syncExec(new Runnable JavaDoc() {
131             public void run() {
132                 progressBar.setSelection((int)value);
133             }
134         });
135     }
136 }
Popular Tags