Statistics
| Revision:

root / branches / v2_0_0_prep / frameworks / _fwAndami / src / org / gvsig / andami / ui / splash / MultiSplashWindow.java @ 29593

History | View | Annotate | Download (6.88 KB)

1

    
2
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
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
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program 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 this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib��ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

    
43
package org.gvsig.andami.ui.splash;
44

    
45
import java.awt.BorderLayout;
46
import java.awt.Color;
47
import java.awt.Dimension;
48
import java.awt.Font;
49
import java.awt.Frame;
50
import java.awt.Graphics;
51
import java.awt.Point;
52
import java.awt.Toolkit;
53
import java.awt.event.MouseEvent;
54
import java.awt.event.MouseListener;
55

    
56
import javax.swing.BorderFactory;
57
import javax.swing.ImageIcon;
58
import javax.swing.JLabel;
59
import javax.swing.JProgressBar;
60
import javax.swing.JWindow;
61

    
62
import org.gvsig.andami.PluginServices;
63
import org.gvsig.andami.messages.Messages;
64
import org.gvsig.andami.ui.theme.Theme;
65

    
66

    
67

    
68
public class MultiSplashWindow extends JWindow implements TimerCallBack,
69
    MouseListener {
70
    private static final long serialVersionUID = 572592158521767258L;
71
    private JProgressBar pb;
72
    private JLabel lblStatus;
73
    private Timer timer;
74
    private int numLogos = 0;
75
    private ImageIcon[] img = null;
76
    private Dimension splashDimension;
77
    private int index = 0;
78
    private int current;
79
    private int lastIndex = -1;
80
    private Theme theme;
81
    private long[] timers;
82

    
83
    private String version="";
84
    private String[] versions=null;
85
    private Point point=new Point(270,240);
86
    private Point[] points=null;
87
    private int fontsize=18;
88
    private int[] fontSizes=null;
89
    private Color fontcolor=new Color(80,170,240);
90
    private Color[] fontColors=null;
91

    
92
    public MultiSplashWindow(Frame f, Theme theme, int progressBarStepCount) {
93
        super(f);
94
        this.theme = theme;
95
        this.timers = theme.getTimers();
96
        lblStatus = new JLabel(Messages.getString("SplashWindow.Iniciando"));
97
        lblStatus.setBorder(BorderFactory.createEtchedBorder());
98
        lblStatus.setBackground(Color.WHITE);
99

    
100
        pack();
101
        pb = new JProgressBar(0, progressBarStepCount);
102
        getContentPane().setLayout(new BorderLayout());
103
        getContentPane().add(lblStatus, BorderLayout.NORTH);
104
        getContentPane().add(pb, BorderLayout.SOUTH);
105

    
106
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
107

    
108
        init();
109
        setLocation((screenSize.width / 2) - (splashDimension.width / 2),
110
            (screenSize.height / 2) - (splashDimension.height / 2));
111
        index = 0;
112
        setVisible(true);
113
        this.addMouseListener(this);
114
    }
115

    
116
    public void init() {
117
        img = theme.getSplashImages();
118
        numLogos = img.length;
119

    
120
        if (numLogos == 0) {
121
            numLogos = 1;
122
            img = new ImageIcon[1];
123
            img[0] = PluginServices.getIconTheme().get("splash"); 
124
            timers = new long[1];
125
            timers[0] = 1000L;
126
        }
127
        versions=theme.getVersions();
128
        points=theme.getPositions();
129
        fontSizes=theme.getFontSizes();
130
        fontColors=theme.getFontColors();
131
        int splashWidth = img[0].getIconWidth();
132
        int splashHeight = img[0].getIconHeight();
133

    
134
        for (int i = 1; i < numLogos; i++) {
135
            splashWidth = Math.max(splashWidth, img[i].getIconWidth());
136
            splashHeight = Math.max(splashHeight, img[i].getIconHeight());
137
        }
138

    
139
        splashDimension = new Dimension(splashWidth, splashHeight);
140
        setSize(splashDimension.width, splashDimension.height + 45);
141

    
142
        start();
143
    }
144

    
145
    public void paint(Graphics g) {
146
        if (lastIndex == current) {
147
            return;
148
        }
149

    
150
        super.paint(g);
151

    
152
        if ((img == null) || (img[current] == null)) {
153
            return;
154
        }
155

    
156
        ImageIcon image = img[current];
157
        g.drawImage(image.getImage(),
158
            (getWidth() / 2) - (image.getIconWidth() / 2),
159
            ((getHeight() / 2) - (image.getIconHeight() / 2)), this);
160

    
161
        Font font=new Font("SansSerif",Font.BOLD,fontsize);
162
        if (fontSizes.length>0 && fontSizes[current]!=0) {
163
                font=new Font("SansSerif",Font.BOLD,fontSizes[current]);
164
        }
165
            g.setFont(font);
166

    
167
            Color color=fontcolor;
168
        if (fontColors.length>0 && fontColors[current]!=null) {
169
                color=fontColors[current];
170
        }
171
        g.setColor(color);
172

    
173
        String ver=version;
174
        if (versions.length>0 && versions[current]!=null) {
175
                ver=versions[current];
176
        }
177

    
178
        Point p=point;
179
        if (points.length>0 && points[current]!=null){
180
                p=points[current];
181
        }
182
        g.drawString(PluginServices.getText(this,ver),(int)p.getX(),(int)p.getY());
183

    
184
        lastIndex = current;
185
    }
186

    
187
    public void tick() {
188
        current = index;
189
        timer.setInterval(timers[current]);
190
        repaint();
191
        index++;
192

    
193
        if (index >= numLogos) {
194
            index = 0;
195
        }
196
    }
197

    
198
    public void start() {
199
        timer = new Timer(this, 1000);
200
        timer.start();
201
    }
202

    
203
    /**
204
     * Cierra la ventana
205
     */
206
    public void close() {
207
        setVisible(false);
208
        stop();
209
        dispose();
210
    }
211

    
212
    public void stop() {
213
        timer.stop();
214
    }
215

    
216
    /**
217
     * DOCUMENT ME!
218
     *
219
     * @param args DOCUMENT ME!
220
     */
221
    public static void main(String[] args) {
222
        Frame frame = new Frame();
223
        Theme theme = new Theme();
224
        MultiSplashWindow ba = new MultiSplashWindow(frame, theme, 5);
225
        ba.setVisible(true);
226
        ba.setSize(500, 500);
227
        ba.init();
228
        ba.start();
229
    }
230

    
231
    /**
232
     * @see com.iver.mdiApp.ui.AppLoadingListener#process(int)
233
     */
234
    public void process(int p, String str) {
235
        lblStatus.setText(str);
236

    
237
        if (pb.getValue() != p) {
238
            pb.setValue(p);
239
        }
240
        doLayout();
241
        repaint();
242
    }
243

    
244
    public void mouseClicked(MouseEvent e) {
245
        this.setVisible(false);
246
    }
247

    
248
        public void mouseEntered(MouseEvent e) { }
249
        public void mouseExited(MouseEvent e) { }
250
        public void mousePressed(MouseEvent e) { }
251
        public void mouseReleased(MouseEvent e) { }
252
    }
253