1 /*
2  *  CVS: $Id: Splash.java,v 1.9 2004/07/16 16:22:33 marcus Exp $
3  * 
4  *  This file is part of JZuul.
5  *
6  *  JZuul is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10 *
11 *  JZuul is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with Zuul; if not, write to the Free Software
18 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 * 
20 *  Copyrigth 2004 by marcus, leh
21 * 
22 */
23
24
25package org.jzuul.gdk.swt;
26
27
28import org.eclipse.swt.SWT;
29import org.eclipse.swt.graphics.Image;
30import org.eclipse.swt.layout.GridData;
31import org.eclipse.swt.layout.GridLayout;
32import org.eclipse.swt.widgets.Display;
33import org.eclipse.swt.widgets.Label;
34import org.eclipse.swt.widgets.ProgressBar;
35import org.eclipse.swt.widgets.Shell;
36
37/**
38 * SplashScreen
39 * Der SplashScreen öffnet ein Fenster und stellt die Abarbeitung von Aufgaben grafisch dar.
40 * 
41 * 
42 * @version $Revision: 1.9 $
43 */
44public class Splash {
45    private int percentPerTask;
46    private int numberOfTasks;
47    private int percent;
48    private Display display;
49    private Shell shell;
50    private Label taskName;
51    private ProgressBar bar;
52    private int currentCount = 0;
53
54    public Splash(Display display) {
55        this.percent = 0;
56        this.display = display;
57    }
58
59    /**
60     * öffnet den splashscreen
61     *
62     * @param numberOfTasks anzahl der tasks die abgearbeitet werden sollen
63     * @param firstTask Name des ersten Tasks
64     */
65    public void show(int numberOfTasks, String firstTask) {
66        setNumberOfTasks(numberOfTasks);
67        shell = new Shell(display, SWT.ON_TOP);
68        shell.setText("Jzuul GDK");
69
70        GridLayout layout = new GridLayout();
71        layout.numColumns= 1;
72        layout.horizontalSpacing = 0;
73        layout.verticalSpacing = 0;
74        layout.marginHeight = 0;
75        layout.marginWidth = 0;
76        
77
78        shell.setLayout(layout);
79
80        Label label = new Label(shell, SWT.NONE);
81        Image image =Util.getImagefromResource(display, "etc/artwork/logo-big.png");
82        if (image != null) label.setImage(image);
83
84        this.taskName = new Label(shell, SWT.BORDER);
85        GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
86        this.taskName.setLayoutData(gridData);
87
88        this.bar = new ProgressBar(shell, SWT.HORIZONTAL);
89        this.bar.setMinimum(0);
90        this.bar.setMaximum(100);
91        gridData = new GridData(GridData.FILL_HORIZONTAL);
92        this.bar.setLayoutData(gridData);
93        taskName.setText(firstTask);
94        shell.pack();
95        Util.centerWindow(shell);
96        shell.open();
97
98    }
99    /**
00     * setzt die Anzahl der tasks
01     * @param number anzahl der tasks
02     */
03    private void setNumberOfTasks(int number) {
04        this.numberOfTasks = number;
05        percentPerTask = Math.round(100f / number);
06    }
07
08    /**
09     * nächster task darstellen, also progressbar und tasknamen ändern
10     * @param task Beschreibung des gerade verarbeiteten tasks
11     */
12    public void nextTask(String task) {
13        percent += percentPerTask;
14        taskName.setText(task);
15        this.bar.setSelection(percent);
16        currentCount++;
17
18        taskName.update();
19        this.bar.update();
20        if (numberOfTasks == currentCount) {
21            this.close(); 
22        }
23        
24        }
25        
26    /**
27     * Schliesst den Splashscreen
28     *
29     */
30    public void close() {
31        if(shell != null && !shell.isDisposed())
32          shell.dispose();
33
34    }
35}
36