root / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / splash / MultiSplashWindow.java @ 8924
History | View | Annotate | Download (3.5 KB)
1 | 7302 | caballero | 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 | 8924 | caballero | import java.awt.Image; |
9 | 7302 | caballero | 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 | 8924 | caballero | import com.iver.andami.ui.theme.Theme; |
19 | 7302 | caballero | |
20 | 7484 | caballero | public class MultiSplashWindow extends JWindow implements TimerCallBack { |
21 | 7302 | caballero | |
22 | 7484 | caballero | private static final long serialVersionUID = 572592158521767258L; |
23 | 7302 | caballero | |
24 | 7484 | caballero | 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 | 8252 | caballero | private int lastIndex=-1; |
33 | 8924 | caballero | private Theme theme;
|
34 | private long[] timers; |
||
35 | public MultiSplashWindow(Frame f, Theme theme) { |
||
36 | 7484 | caballero | super(f);
|
37 | 8924 | caballero | this.theme=theme;
|
38 | this.timers=theme.getTimers();
|
||
39 | 7484 | caballero | lblStatus = new JLabel(Messages.getString("SplashWindow.Iniciando")); |
40 | lblStatus.setBorder(BorderFactory.createEtchedBorder());
|
||
41 | lblStatus.setBackground(Color.WHITE);
|
||
42 | 7302 | caballero | |
43 | 7484 | caballero | pack(); |
44 | pb = new JProgressBar(); |
||
45 | getContentPane().setLayout(new BorderLayout()); |
||
46 | getContentPane().add(lblStatus, BorderLayout.NORTH);
|
||
47 | getContentPane().add(pb, BorderLayout.SOUTH);
|
||
48 | 7302 | caballero | |
49 | 7484 | caballero | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
50 | 7302 | caballero | |
51 | 8507 | jaume | init(); |
52 | 7484 | caballero | setLocation((screenSize.width / 2) - (splashDimension.width / 2), |
53 | (screenSize.height / 2) - (splashDimension.height / 2)); |
||
54 | index = 0;
|
||
55 | setVisible(true);
|
||
56 | 7302 | caballero | |
57 | 7484 | caballero | } |
58 | 7435 | caballero | |
59 | 7484 | caballero | public void init(){ |
60 | 8924 | caballero | 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 | 7611 | caballero | } |
69 | 8507 | jaume | |
70 | int splashWidth = img[0].getIconWidth(); |
||
71 | int splashHeight = img[0].getIconHeight(); |
||
72 | |||
73 | 8924 | caballero | for (int i=1;i<numLogos;i++){ |
74 | splashWidth = Math.max(splashWidth, img[i].getIconWidth());
|
||
75 | splashHeight = Math.max(splashHeight, img[i].getIconHeight());
|
||
76 | 7484 | caballero | } |
77 | 8507 | jaume | splashDimension = new Dimension(splashWidth, splashHeight); |
78 | setSize(splashDimension.width, splashDimension.height + 20);
|
||
79 | |||
80 | 7484 | caballero | start(); |
81 | } |
||
82 | 7302 | caballero | |
83 | 7484 | caballero | public void paint(Graphics g) { |
84 | 8252 | caballero | if (lastIndex==current)
|
85 | return;
|
||
86 | 7484 | caballero | super.paint(g);
|
87 | 8252 | caballero | |
88 | 7484 | caballero | if (img == null || img[current] == null) |
89 | return;
|
||
90 | 8924 | caballero | ImageIcon image=img[current];
|
91 | g.drawImage(image.getImage(), (getWidth()/2)-(image.getIconWidth()/2),(getHeight()/2-image.getIconHeight()/2), this); |
||
92 | 8252 | caballero | lastIndex=current; |
93 | 7484 | caballero | } |
94 | 7302 | caballero | |
95 | 7484 | caballero | public void tick() { |
96 | current = index; |
||
97 | 8924 | caballero | timer.setInterval(timers[current]); |
98 | 7484 | caballero | repaint(); |
99 | index++; |
||
100 | if (index >= numLogos)
|
||
101 | index = 0;
|
||
102 | } |
||
103 | 7302 | caballero | |
104 | 7484 | caballero | public void start() { |
105 | timer = new Timer(this, 1000); |
||
106 | timer.start(); |
||
107 | } |
||
108 | 7302 | caballero | |
109 | 7484 | caballero | /**
|
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 | 8924 | caballero | //timer = null;
|
121 | 7484 | caballero | } |
122 | |||
123 | public static void main(String[] args) { |
||
124 | Frame frame = new Frame(); |
||
125 | 8924 | caballero | Theme theme=new Theme();
|
126 | MultiSplashWindow ba = new MultiSplashWindow(frame,theme);
|
||
127 | 7858 | caballero | ba.setVisible(true);
|
128 | 7484 | caballero | ba.setSize(500, 500); |
129 | 7302 | caballero | ba.init(); |
130 | ba.start(); |
||
131 | } |
||
132 | |||
133 | 7484 | caballero | /**
|
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 | } |