Revision 7484
trunk/frameworks/_fwAndami/src/com/iver/andami/ui/splash/MultiSplashWindow.java | ||
---|---|---|
1 | 1 |
package com.iver.andami.ui.splash; |
2 | 2 |
|
3 |
import java.awt.AlphaComposite; |
|
4 | 3 |
import java.awt.BorderLayout; |
5 | 4 |
import java.awt.Color; |
6 |
import java.awt.Composite; |
|
7 | 5 |
import java.awt.Dimension; |
8 | 6 |
import java.awt.Frame; |
9 | 7 |
import java.awt.Graphics; |
10 |
import java.awt.Graphics2D; |
|
11 |
import java.awt.GraphicsConfiguration; |
|
12 |
import java.awt.Image; |
|
13 | 8 |
import java.awt.Toolkit; |
14 |
import java.awt.Transparency; |
|
15 |
import java.awt.image.BufferedImage; |
|
16 | 9 |
import java.io.File; |
17 | 10 |
import java.io.FileFilter; |
18 | 11 |
import java.net.MalformedURLException; |
... | ... | |
25 | 18 |
|
26 | 19 |
import com.iver.andami.messages.Messages; |
27 | 20 |
|
21 |
public class MultiSplashWindow extends JWindow implements TimerCallBack { |
|
28 | 22 |
|
29 |
public class MultiSplashWindow extends JWindow implements TimerCallBack{
|
|
23 |
private static final long serialVersionUID = 572592158521767258L;
|
|
30 | 24 |
|
31 |
private Timer timer; |
|
32 |
private int numLogos =0; |
|
25 |
private Timer timer; |
|
26 |
private int numLogos = 0; |
|
27 |
private ImageIcon[] img = null; |
|
28 |
private static JProgressBar pb; |
|
29 |
private static JLabel lblStatus; |
|
30 |
private Dimension splashDimension; |
|
31 |
private int index = 0; |
|
32 |
private int current; |
|
33 | 33 |
|
34 |
private Image offscreenImage; |
|
35 |
private ImageIcon[] img =null; |
|
36 |
private static JProgressBar pb; |
|
37 |
private static JLabel lblStatus; |
|
38 |
private Dimension splashDimension; |
|
39 |
float f=0.9f; |
|
40 |
int i=0; |
|
34 |
public MultiSplashWindow(Frame f) { |
|
35 |
super(f); |
|
41 | 36 |
|
42 |
public MultiSplashWindow(Frame f) { |
|
43 |
super(f); |
|
37 |
if (splashDimension == null) { |
|
38 |
splashDimension = new Dimension(400, 400); |
|
39 |
} |
|
40 |
lblStatus = new JLabel(Messages.getString("SplashWindow.Iniciando")); |
|
41 |
lblStatus.setBorder(BorderFactory.createEtchedBorder()); |
|
42 |
lblStatus.setBackground(Color.WHITE); |
|
44 | 43 |
|
45 |
if (splashDimension==null){ |
|
46 |
splashDimension=new Dimension(400,400); |
|
47 |
} |
|
48 |
lblStatus = new JLabel(Messages.getString("SplashWindow.Iniciando")); |
|
49 |
lblStatus.setBorder(BorderFactory.createEtchedBorder()); |
|
50 |
lblStatus.setBackground(Color.WHITE); |
|
44 |
pack(); |
|
45 |
pb = new JProgressBar(); |
|
46 |
getContentPane().setLayout(new BorderLayout()); |
|
47 |
getContentPane().add(lblStatus, BorderLayout.NORTH); |
|
48 |
getContentPane().add(pb, BorderLayout.SOUTH); |
|
51 | 49 |
|
52 |
pack(); |
|
53 |
pb = new JProgressBar(); |
|
54 |
getContentPane().setLayout(new BorderLayout()); |
|
55 |
getContentPane().add(lblStatus, BorderLayout.NORTH); |
|
56 |
getContentPane().add(pb, BorderLayout.SOUTH); |
|
50 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
|
57 | 51 |
|
58 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
|
52 |
setLocation((screenSize.width / 2) - (splashDimension.width / 2), |
|
53 |
(screenSize.height / 2) - (splashDimension.height / 2)); |
|
59 | 54 |
|
60 |
setLocation((screenSize.width / 2) - (splashDimension.width / 2), |
|
61 |
(screenSize.height / 2) - (splashDimension.height / 2)); |
|
55 |
index = 0; |
|
56 |
setVisible(true); |
|
57 |
setSize(splashDimension.width, splashDimension.height + 20); |
|
58 |
show(true); |
|
62 | 59 |
|
63 |
setVisible(true);
|
|
64 |
setSize(splashDimension.width, splashDimension.height+20);
|
|
60 |
init();
|
|
61 |
}
|
|
65 | 62 |
|
66 |
init();
|
|
67 |
show(true);
|
|
68 |
}
|
|
63 |
public void init(){
|
|
64 |
File dirLogos=new File("./logos");
|
|
65 |
File[] fileLogos=dirLogos.listFiles(new FileFilter() {
|
|
69 | 66 |
|
70 |
|
|
71 |
|
|
72 |
public void init(){ |
|
73 |
offscreenImage = createCompatibleImage(splashDimension.width, splashDimension.height+20,Transparency.TRANSLUCENT); |
|
74 |
File dirLogos=new File("./logos"); |
|
75 |
File[] fileLogos=dirLogos.listFiles(new FileFilter() { |
|
76 |
|
|
77 | 67 |
public boolean accept(File arg0) { |
78 | 68 |
if (arg0.isDirectory()) |
79 | 69 |
return false; |
... | ... | |
85 | 75 |
return false; |
86 | 76 |
return true; |
87 | 77 |
}}); |
88 |
numLogos=fileLogos.length+1;
|
|
89 |
img=new ImageIcon[numLogos];
|
|
90 |
img[0]=new ImageIcon(this.getClass().getClassLoader().getResource("images/logo_es.png"));
|
|
91 |
for (int i=0;i<numLogos-1;i++){
|
|
92 |
try {
|
|
78 |
numLogos=fileLogos.length+1; |
|
79 |
img=new ImageIcon[numLogos]; |
|
80 |
img[0]=new ImageIcon(this.getClass().getClassLoader().getResource("images/logo_es.png")); |
|
81 |
for (int i=0;i<numLogos-1;i++){ |
|
82 |
try { |
|
93 | 83 |
img[i+1]=new ImageIcon(fileLogos[i].toURL()); |
94 |
} catch (MalformedURLException e) { |
|
95 |
} |
|
96 |
} |
|
97 |
start(); |
|
98 |
} |
|
99 |
private BufferedImage createCompatibleImage(int w, int h, int transparancy){ |
|
100 |
GraphicsConfiguration gc = getGraphicsConfiguration(); |
|
101 |
return gc.createCompatibleImage(w, h, transparancy); |
|
102 |
} |
|
103 |
public void update(Graphics g){ |
|
104 |
if (offscreenImage == null) { |
|
105 |
// no images were loaded yet (for computers with slow disks) |
|
106 |
super.update(g); |
|
107 |
} else { |
|
108 |
Graphics offscreenG = offscreenImage.getGraphics(); |
|
109 |
offscreenG.setColor(getBackground()); |
|
110 |
offscreenG.fillRect(0, 0, splashDimension.width, splashDimension.height+20); |
|
111 |
paint(offscreenG); |
|
112 |
g.drawImage(offscreenImage, 0, 0, this); |
|
113 |
} |
|
114 |
} |
|
84 |
} catch (MalformedURLException e) { |
|
85 |
} |
|
86 |
} |
|
87 |
start(); |
|
88 |
} |
|
115 | 89 |
|
116 |
public void paint(Graphics g){ |
|
117 |
super.paint(g); |
|
118 |
if (img==null || img[i]==null) |
|
119 |
return; |
|
120 |
Composite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,f); |
|
121 |
((Graphics2D)g).setComposite(alpha); |
|
122 |
g.drawImage(img[i].getImage(),0,20,null); |
|
123 |
i++; |
|
124 |
if (i>=numLogos) |
|
125 |
i=0; |
|
126 |
} |
|
90 |
public void paint(Graphics g) { |
|
91 |
super.paint(g); |
|
92 |
if (img == null || img[current] == null) |
|
93 |
return; |
|
94 |
g.drawImage(img[current].getImage(), 0, 20, null); |
|
95 |
} |
|
127 | 96 |
|
128 |
public void tick(){ |
|
129 |
repaint(); |
|
130 |
} |
|
97 |
public void tick() { |
|
98 |
current = index; |
|
99 |
repaint(); |
|
100 |
index++; |
|
101 |
if (index >= numLogos) |
|
102 |
index = 0; |
|
103 |
} |
|
131 | 104 |
|
132 |
public void start(){
|
|
133 |
timer = new Timer(this, 1000);
|
|
134 |
timer.start();
|
|
135 |
}
|
|
105 |
public void start() {
|
|
106 |
timer = new Timer(this, 1000);
|
|
107 |
timer.start();
|
|
108 |
}
|
|
136 | 109 |
|
137 |
/** |
|
138 |
* cierra la ventana |
|
139 |
*/ |
|
140 |
public void close() { |
|
141 |
setVisible(false); |
|
142 |
stop(); |
|
143 |
dispose(); |
|
144 |
} |
|
145 |
public void stop(){ |
|
146 |
timer.stop(); |
|
147 |
timer = null; |
|
148 |
} |
|
149 |
public static void main(String[] args) { |
|
150 |
Frame frame=new Frame(); |
|
151 |
MultiSplashWindow ba=new MultiSplashWindow(frame); |
|
110 |
/** |
|
111 |
* cierra la ventana |
|
112 |
*/ |
|
113 |
public void close() { |
|
114 |
setVisible(false); |
|
115 |
stop(); |
|
116 |
dispose(); |
|
117 |
} |
|
118 |
|
|
119 |
public void stop() { |
|
120 |
timer.stop(); |
|
121 |
timer = null; |
|
122 |
} |
|
123 |
|
|
124 |
public static void main(String[] args) { |
|
125 |
Frame frame = new Frame(); |
|
126 |
MultiSplashWindow ba = new MultiSplashWindow(frame); |
|
152 | 127 |
ba.show(true); |
153 |
ba.setSize(500,500); |
|
128 |
ba.setSize(500, 500);
|
|
154 | 129 |
ba.init(); |
155 | 130 |
ba.start(); |
156 | 131 |
} |
157 |
/** |
|
158 |
* @see com.iver.mdiApp.ui.AppLoadingListener#process(int) |
|
159 |
*/ |
|
160 |
public static void process(int p, String str) { |
|
161 | 132 |
|
162 |
lblStatus.setText(str); |
|
163 |
// System.out.println("Porcentaje :" + p); |
|
164 |
if (pb.getValue() != p) |
|
165 |
{ |
|
166 |
pb.setValue(p); |
|
167 |
pb.repaint(); |
|
168 |
// pb.paint(pb.getGraphics()); |
|
169 |
} |
|
170 |
} |
|
171 |
} |
|
133 |
/** |
|
134 |
* @see com.iver.mdiApp.ui.AppLoadingListener#process(int) |
|
135 |
*/ |
|
136 |
public static void process(int p, String str) { |
|
172 | 137 |
|
173 |
|
|
138 |
lblStatus.setText(str); |
|
139 |
// System.out.println("Porcentaje :" + p); |
|
140 |
if (pb.getValue() != p) { |
|
141 |
pb.setValue(p); |
|
142 |
pb.repaint(); |
|
143 |
// pb.paint(pb.getGraphics()); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
Also available in: Unified diff