svn-gvsig-desktop / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / splash / MultiSplashWindow.java @ 7858
History | View | Annotate | Download (3.51 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.Toolkit; |
9 |
import java.io.File; |
10 |
import java.io.FileFilter; |
11 |
import java.net.MalformedURLException; |
12 |
|
13 |
import javax.swing.BorderFactory; |
14 |
import javax.swing.ImageIcon; |
15 |
import javax.swing.JLabel; |
16 |
import javax.swing.JProgressBar; |
17 |
import javax.swing.JWindow; |
18 |
|
19 |
import com.iver.andami.messages.Messages; |
20 |
|
21 |
public class MultiSplashWindow extends JWindow implements TimerCallBack { |
22 |
|
23 |
private static final long serialVersionUID = 572592158521767258L; |
24 |
|
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 |
|
34 |
public MultiSplashWindow(Frame f) { |
35 |
super(f);
|
36 |
|
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);
|
43 |
|
44 |
pack(); |
45 |
pb = new JProgressBar(); |
46 |
getContentPane().setLayout(new BorderLayout()); |
47 |
getContentPane().add(lblStatus, BorderLayout.NORTH);
|
48 |
getContentPane().add(pb, BorderLayout.SOUTH);
|
49 |
|
50 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
51 |
|
52 |
setLocation((screenSize.width / 2) - (splashDimension.width / 2), |
53 |
(screenSize.height / 2) - (splashDimension.height / 2)); |
54 |
|
55 |
index = 0;
|
56 |
|
57 |
setSize(splashDimension.width, splashDimension.height + 20);
|
58 |
setVisible(true);
|
59 |
|
60 |
init(); |
61 |
} |
62 |
|
63 |
public void init(){ |
64 |
File dirLogos=new File("./logos"); |
65 |
File[] fileLogos=dirLogos.listFiles(new FileFilter() { |
66 |
|
67 |
public boolean accept(File arg0) { |
68 |
if (arg0.isDirectory())
|
69 |
return false; |
70 |
if (!(arg0.getName().toUpperCase().endsWith(".PNG")|| |
71 |
arg0.getName().toUpperCase().endsWith(".BMP")||
|
72 |
arg0.getName().toUpperCase().endsWith(".GIF")||
|
73 |
arg0.getName().toUpperCase().endsWith(".JPG")||
|
74 |
arg0.getName().toUpperCase().endsWith(".JPEG")))
|
75 |
return false; |
76 |
return true; |
77 |
}}); |
78 |
if (fileLogos!=null) { |
79 |
numLogos=fileLogos.length+1;
|
80 |
}else {
|
81 |
numLogos=1;
|
82 |
} |
83 |
img=new ImageIcon[numLogos]; |
84 |
img[0]=new ImageIcon(this.getClass().getClassLoader().getResource("images/logo_es.png")); |
85 |
for (int i=0;i<numLogos-1;i++){ |
86 |
try {
|
87 |
img[i+1]=new ImageIcon(fileLogos[i].toURL()); |
88 |
} catch (MalformedURLException e) { |
89 |
} |
90 |
} |
91 |
start(); |
92 |
} |
93 |
|
94 |
public void paint(Graphics g) { |
95 |
super.paint(g);
|
96 |
if (img == null || img[current] == null) |
97 |
return;
|
98 |
g.drawImage(img[current].getImage(), 0, 20, null); |
99 |
} |
100 |
|
101 |
public void tick() { |
102 |
current = index; |
103 |
repaint(); |
104 |
index++; |
105 |
if (index >= numLogos)
|
106 |
index = 0;
|
107 |
} |
108 |
|
109 |
public void start() { |
110 |
timer = new Timer(this, 1000); |
111 |
timer.start(); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* cierra la ventana
|
116 |
*/
|
117 |
public void close() { |
118 |
setVisible(false);
|
119 |
stop(); |
120 |
dispose(); |
121 |
} |
122 |
|
123 |
public void stop() { |
124 |
timer.stop(); |
125 |
timer = null;
|
126 |
} |
127 |
|
128 |
public static void main(String[] args) { |
129 |
Frame frame = new Frame(); |
130 |
MultiSplashWindow ba = new MultiSplashWindow(frame);
|
131 |
ba.setVisible(true);
|
132 |
ba.setSize(500, 500); |
133 |
ba.init(); |
134 |
ba.start(); |
135 |
} |
136 |
|
137 |
/**
|
138 |
* @see com.iver.mdiApp.ui.AppLoadingListener#process(int)
|
139 |
*/
|
140 |
public static void process(int p, String str) { |
141 |
|
142 |
lblStatus.setText(str); |
143 |
// System.out.println("Porcentaje :" + p);
|
144 |
if (pb.getValue() != p) {
|
145 |
pb.setValue(p); |
146 |
pb.repaint(); |
147 |
// pb.paint(pb.getGraphics());
|
148 |
} |
149 |
} |
150 |
} |