Statistics
| Revision:

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

History | View | Annotate | Download (7.2 KB)

1 13742 caballero
2 14819 jmvivo
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
3 13742 caballero
 *
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 14819 jmvivo
 *   Av. Blasco Ib��ez, 50
25 13742 caballero
 *   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 29593 jpiera
package org.gvsig.andami.ui.splash;
44 7302 caballero
45
import java.awt.BorderLayout;
46
import java.awt.Color;
47
import java.awt.Dimension;
48 13742 caballero
import java.awt.Font;
49 7302 caballero
import java.awt.Frame;
50
import java.awt.Graphics;
51 35000 cordinyana
import java.awt.Graphics2D;
52 13742 caballero
import java.awt.Point;
53 35000 cordinyana
import java.awt.RenderingHints;
54 7302 caballero
import java.awt.Toolkit;
55 13261 cesar
import java.awt.event.MouseEvent;
56
import java.awt.event.MouseListener;
57 7302 caballero
58
import javax.swing.BorderFactory;
59
import javax.swing.ImageIcon;
60
import javax.swing.JLabel;
61
import javax.swing.JProgressBar;
62 14168 jdominguez
import javax.swing.JWindow;
63 7302 caballero
64 29593 jpiera
import org.gvsig.andami.PluginServices;
65
import org.gvsig.andami.messages.Messages;
66
import org.gvsig.andami.ui.theme.Theme;
67 7302 caballero
68 13827 cesar
69 29593 jpiera
70 14168 jdominguez
public class MultiSplashWindow extends JWindow implements TimerCallBack,
71 13742 caballero
    MouseListener {
72
    private static final long serialVersionUID = 572592158521767258L;
73 14168 jdominguez
    private JProgressBar pb;
74
    private JLabel lblStatus;
75 13742 caballero
    private Timer timer;
76
    private int numLogos = 0;
77
    private ImageIcon[] img = null;
78
    private Dimension splashDimension;
79
    private int index = 0;
80
    private int current;
81
    private int lastIndex = -1;
82
    private Theme theme;
83
    private long[] timers;
84 7302 caballero
85 13742 caballero
    private String version="";
86
    private String[] versions=null;
87
    private Point point=new Point(270,240);
88
    private Point[] points=null;
89
    private int fontsize=18;
90
    private int[] fontSizes=null;
91
    private Color fontcolor=new Color(80,170,240);
92
    private Color[] fontColors=null;
93 7302 caballero
94 14168 jdominguez
    public MultiSplashWindow(Frame f, Theme theme, int progressBarStepCount) {
95 13742 caballero
        super(f);
96
        this.theme = theme;
97
        this.timers = theme.getTimers();
98
        lblStatus = new JLabel(Messages.getString("SplashWindow.Iniciando"));
99
        lblStatus.setBorder(BorderFactory.createEtchedBorder());
100
        lblStatus.setBackground(Color.WHITE);
101 7302 caballero
102 13742 caballero
        pack();
103 14168 jdominguez
        pb = new JProgressBar(0, progressBarStepCount);
104 13742 caballero
        getContentPane().setLayout(new BorderLayout());
105
        getContentPane().add(lblStatus, BorderLayout.NORTH);
106
        getContentPane().add(pb, BorderLayout.SOUTH);
107 7302 caballero
108 13742 caballero
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
109 7302 caballero
110 13742 caballero
        init();
111
        setLocation((screenSize.width / 2) - (splashDimension.width / 2),
112
            (screenSize.height / 2) - (splashDimension.height / 2));
113
        index = 0;
114
        setVisible(true);
115
        this.addMouseListener(this);
116
    }
117 7302 caballero
118 13742 caballero
    public void init() {
119
        img = theme.getSplashImages();
120
        numLogos = img.length;
121 7435 caballero
122 13742 caballero
        if (numLogos == 0) {
123
            numLogos = 1;
124
            img = new ImageIcon[1];
125 38564 jjdelcerro
            img[0] = PluginServices.getIconTheme().get("splash-default");
126 13742 caballero
            timers = new long[1];
127
            timers[0] = 1000L;
128
        }
129
        versions=theme.getVersions();
130
        points=theme.getPositions();
131
        fontSizes=theme.getFontSizes();
132
        fontColors=theme.getFontColors();
133
        int splashWidth = img[0].getIconWidth();
134
        int splashHeight = img[0].getIconHeight();
135 8507 jaume
136 13742 caballero
        for (int i = 1; i < numLogos; i++) {
137
            splashWidth = Math.max(splashWidth, img[i].getIconWidth());
138
            splashHeight = Math.max(splashHeight, img[i].getIconHeight());
139
        }
140 8507 jaume
141 13742 caballero
        splashDimension = new Dimension(splashWidth, splashHeight);
142
        setSize(splashDimension.width, splashDimension.height + 45);
143 8507 jaume
144 13742 caballero
        start();
145 7484 caballero
    }
146 7302 caballero
147 13742 caballero
    public void paint(Graphics g) {
148
        if (lastIndex == current) {
149
            return;
150
        }
151 8252 caballero
152 13742 caballero
        super.paint(g);
153 7302 caballero
154 13742 caballero
        if ((img == null) || (img[current] == null)) {
155
            return;
156
        }
157 7302 caballero
158 13742 caballero
        ImageIcon image = img[current];
159
        g.drawImage(image.getImage(),
160
            (getWidth() / 2) - (image.getIconWidth() / 2),
161
            ((getHeight() / 2) - (image.getIconHeight() / 2)), this);
162 7302 caballero
163 35000 cordinyana
        // Activate antialias for text
164
        if (g instanceof Graphics2D) {
165
            ((Graphics2D) g).setRenderingHint(
166
                RenderingHints.KEY_TEXT_ANTIALIASING,
167
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
168
        }
169
170
        Font font = new Font("SansSerif", Font.BOLD, fontsize);
171 13742 caballero
        if (fontSizes.length>0 && fontSizes[current]!=0) {
172 35000 cordinyana
            font = new Font("SansSerif", Font.BOLD, fontSizes[current]);
173 13742 caballero
        }
174
            g.setFont(font);
175 7484 caballero
176 13742 caballero
            Color color=fontcolor;
177
        if (fontColors.length>0 && fontColors[current]!=null) {
178
                color=fontColors[current];
179
        }
180
        g.setColor(color);
181 7484 caballero
182 13742 caballero
        String ver=version;
183
        if (versions.length>0 && versions[current]!=null) {
184
                ver=versions[current];
185
        }
186 7302 caballero
187 13742 caballero
        Point p=point;
188
        if (points.length>0 && points[current]!=null){
189
                p=points[current];
190
        }
191 35000 cordinyana
192 13742 caballero
        g.drawString(PluginServices.getText(this,ver),(int)p.getX(),(int)p.getY());
193 13261 cesar
194 13742 caballero
        lastIndex = current;
195
    }
196 13261 cesar
197 13742 caballero
    public void tick() {
198
        current = index;
199
        timer.setInterval(timers[current]);
200
        repaint();
201
        index++;
202 13261 cesar
203 13742 caballero
        if (index >= numLogos) {
204
            index = 0;
205
        }
206
    }
207 13261 cesar
208 13742 caballero
    public void start() {
209
        timer = new Timer(this, 1000);
210
        timer.start();
211
    }
212 13261 cesar
213 13742 caballero
    /**
214
     * Cierra la ventana
215
     */
216
    public void close() {
217
        setVisible(false);
218
        stop();
219
        dispose();
220
    }
221
222
    public void stop() {
223
        timer.stop();
224
    }
225
226
    /**
227
     * DOCUMENT ME!
228
     *
229
     * @param args DOCUMENT ME!
230
     */
231
    public static void main(String[] args) {
232
        Frame frame = new Frame();
233
        Theme theme = new Theme();
234 14168 jdominguez
        MultiSplashWindow ba = new MultiSplashWindow(frame, theme, 5);
235 13742 caballero
        ba.setVisible(true);
236
        ba.setSize(500, 500);
237
        ba.init();
238
        ba.start();
239
    }
240
241
    /**
242
     * @see com.iver.mdiApp.ui.AppLoadingListener#process(int)
243
     */
244 14168 jdominguez
    public void process(int p, String str) {
245 13742 caballero
        lblStatus.setText(str);
246
247
        if (pb.getValue() != p) {
248
            pb.setValue(p);
249
        }
250 14168 jdominguez
        doLayout();
251
        repaint();
252 13742 caballero
    }
253
254
    public void mouseClicked(MouseEvent e) {
255
        this.setVisible(false);
256
    }
257
258 14168 jdominguez
        public void mouseEntered(MouseEvent e) { }
259
        public void mouseExited(MouseEvent e) { }
260
        public void mousePressed(MouseEvent e) { }
261
        public void mouseReleased(MouseEvent e) { }
262 14819 jmvivo
    }