Statistics
| Revision:

root / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / splash / MultiSplashWindow.java @ 8924

History | View | Annotate | Download (3.5 KB)

1
package com.iver.andami.ui.splash;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Dimension;
6
import java.awt.Frame;
7
import java.awt.Graphics;
8
import java.awt.Image;
9
import java.awt.Toolkit;
10

    
11
import javax.swing.BorderFactory;
12
import javax.swing.ImageIcon;
13
import javax.swing.JLabel;
14
import javax.swing.JProgressBar;
15
import javax.swing.JWindow;
16

    
17
import com.iver.andami.messages.Messages;
18
import com.iver.andami.ui.theme.Theme;
19

    
20
public class MultiSplashWindow extends JWindow implements TimerCallBack {
21

    
22
        private static final long serialVersionUID = 572592158521767258L;
23

    
24
        private Timer timer;
25
        private int numLogos = 0;
26
        private ImageIcon[] img = null;
27
        private static JProgressBar pb;
28
        private static JLabel lblStatus;
29
        private Dimension splashDimension;
30
        private int index = 0;
31
        private int current;
32
        private int lastIndex=-1;
33
        private Theme theme;
34
        private long[] timers;
35
        public MultiSplashWindow(Frame f, Theme theme) {
36
                super(f);
37
                this.theme=theme;
38
                this.timers=theme.getTimers();
39
                lblStatus = new JLabel(Messages.getString("SplashWindow.Iniciando"));
40
                lblStatus.setBorder(BorderFactory.createEtchedBorder());
41
                lblStatus.setBackground(Color.WHITE);
42

    
43
                pack();
44
                pb = new JProgressBar();
45
                getContentPane().setLayout(new BorderLayout());
46
                getContentPane().add(lblStatus, BorderLayout.NORTH);
47
                getContentPane().add(pb, BorderLayout.SOUTH);
48

    
49
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
50

    
51
                init();
52
                setLocation((screenSize.width / 2) - (splashDimension.width / 2),
53
                                (screenSize.height / 2) - (splashDimension.height / 2));
54
                index = 0;
55
                setVisible(true);
56

    
57
        }
58

    
59
        public void init(){
60
            img=theme.getSplashImages();
61
            numLogos=img.length;
62
            if (numLogos==0) {
63
                    numLogos=1;
64
                    img=new ImageIcon[1];
65
                    img[0]=new ImageIcon(this.getClass().getClassLoader().getResource("images/logo_es.png"));
66
                    timers=new long[1];
67
                    timers[0]=1000l;
68
            }
69

    
70
            int splashWidth = img[0].getIconWidth();
71
            int splashHeight = img[0].getIconHeight();
72

    
73
            for (int i=1;i<numLogos;i++){
74
                   splashWidth = Math.max(splashWidth, img[i].getIconWidth());
75
                splashHeight = Math.max(splashHeight, img[i].getIconHeight());
76
            }
77
            splashDimension = new Dimension(splashWidth, splashHeight);
78
            setSize(splashDimension.width, splashDimension.height + 20);
79

    
80
            start();
81
    }
82

    
83
        public void paint(Graphics g) {
84
                if (lastIndex==current)
85
                        return;
86
                super.paint(g);
87

    
88
                if (img == null || img[current] == null)
89
                        return;
90
                ImageIcon image=img[current];
91
                g.drawImage(image.getImage(), (getWidth()/2)-(image.getIconWidth()/2),(getHeight()/2-image.getIconHeight()/2), this);
92
                lastIndex=current;
93
        }
94

    
95
        public void tick() {
96
                current = index;
97
                timer.setInterval(timers[current]);
98
                repaint();
99
                index++;
100
                if (index >= numLogos)
101
                        index = 0;
102
        }
103

    
104
        public void start() {
105
                timer = new Timer(this, 1000);
106
                timer.start();
107
        }
108

    
109
        /**
110
         * cierra la ventana
111
         */
112
        public void close() {
113
                setVisible(false);
114
                stop();
115
                dispose();
116
        }
117

    
118
        public void stop() {
119
                timer.stop();
120
                //timer = null;
121
        }
122

    
123
        public static void main(String[] args) {
124
                Frame frame = new Frame();
125
                Theme theme=new Theme();
126
                MultiSplashWindow ba = new MultiSplashWindow(frame,theme);
127
                ba.setVisible(true);
128
                ba.setSize(500, 500);
129
                ba.init();
130
                ba.start();
131
        }
132

    
133
        /**
134
         * @see com.iver.mdiApp.ui.AppLoadingListener#process(int)
135
         */
136
        public static void process(int p, String str) {
137
                lblStatus.setText(str);
138
                // System.out.println("Porcentaje :" + p);
139
                if (pb.getValue() != p) {
140
                        pb.setValue(p);
141
                        pb.repaint();
142
                        // pb.paint(pb.getGraphics());
143
                }
144
        }
145
}