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 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
3 |
*
|
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 |
* Av. Blasco Ib��ez, 50
|
25 |
* 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 |
package org.gvsig.andami.ui.splash; |
44 |
|
45 |
import java.awt.BorderLayout; |
46 |
import java.awt.Color; |
47 |
import java.awt.Dimension; |
48 |
import java.awt.Font; |
49 |
import java.awt.Frame; |
50 |
import java.awt.Graphics; |
51 |
import java.awt.Graphics2D; |
52 |
import java.awt.Point; |
53 |
import java.awt.RenderingHints; |
54 |
import java.awt.Toolkit; |
55 |
import java.awt.event.MouseEvent; |
56 |
import java.awt.event.MouseListener; |
57 |
|
58 |
import javax.swing.BorderFactory; |
59 |
import javax.swing.ImageIcon; |
60 |
import javax.swing.JLabel; |
61 |
import javax.swing.JProgressBar; |
62 |
import javax.swing.JWindow; |
63 |
|
64 |
import org.gvsig.andami.PluginServices; |
65 |
import org.gvsig.andami.messages.Messages; |
66 |
import org.gvsig.andami.ui.theme.Theme; |
67 |
|
68 |
|
69 |
|
70 |
public class MultiSplashWindow extends JWindow implements TimerCallBack, |
71 |
MouseListener {
|
72 |
private static final long serialVersionUID = 572592158521767258L; |
73 |
private JProgressBar pb; |
74 |
private JLabel lblStatus; |
75 |
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 |
|
85 |
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 |
|
94 |
public MultiSplashWindow(Frame f, Theme theme, int progressBarStepCount) { |
95 |
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 |
|
102 |
pack(); |
103 |
pb = new JProgressBar(0, progressBarStepCount); |
104 |
getContentPane().setLayout(new BorderLayout()); |
105 |
getContentPane().add(lblStatus, BorderLayout.NORTH);
|
106 |
getContentPane().add(pb, BorderLayout.SOUTH);
|
107 |
|
108 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
109 |
|
110 |
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 |
|
118 |
public void init() { |
119 |
img = theme.getSplashImages(); |
120 |
numLogos = img.length; |
121 |
|
122 |
if (numLogos == 0) { |
123 |
numLogos = 1;
|
124 |
img = new ImageIcon[1]; |
125 |
img[0] = PluginServices.getIconTheme().get("splash-default"); |
126 |
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 |
|
136 |
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 |
|
141 |
splashDimension = new Dimension(splashWidth, splashHeight); |
142 |
setSize(splashDimension.width, splashDimension.height + 45);
|
143 |
|
144 |
start(); |
145 |
} |
146 |
|
147 |
public void paint(Graphics g) { |
148 |
if (lastIndex == current) {
|
149 |
return;
|
150 |
} |
151 |
|
152 |
super.paint(g);
|
153 |
|
154 |
if ((img == null) || (img[current] == null)) { |
155 |
return;
|
156 |
} |
157 |
|
158 |
ImageIcon image = img[current];
|
159 |
g.drawImage(image.getImage(), |
160 |
(getWidth() / 2) - (image.getIconWidth() / 2), |
161 |
((getHeight() / 2) - (image.getIconHeight() / 2)), this); |
162 |
|
163 |
// 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 |
if (fontSizes.length>0 && fontSizes[current]!=0) { |
172 |
font = new Font("SansSerif", Font.BOLD, fontSizes[current]); |
173 |
} |
174 |
g.setFont(font); |
175 |
|
176 |
Color color=fontcolor;
|
177 |
if (fontColors.length>0 && fontColors[current]!=null) { |
178 |
color=fontColors[current]; |
179 |
} |
180 |
g.setColor(color); |
181 |
|
182 |
String ver=version;
|
183 |
if (versions.length>0 && versions[current]!=null) { |
184 |
ver=versions[current]; |
185 |
} |
186 |
|
187 |
Point p=point;
|
188 |
if (points.length>0 && points[current]!=null){ |
189 |
p=points[current]; |
190 |
} |
191 |
|
192 |
g.drawString(PluginServices.getText(this,ver),(int)p.getX(),(int)p.getY()); |
193 |
|
194 |
lastIndex = current; |
195 |
} |
196 |
|
197 |
public void tick() { |
198 |
current = index; |
199 |
timer.setInterval(timers[current]); |
200 |
repaint(); |
201 |
index++; |
202 |
|
203 |
if (index >= numLogos) {
|
204 |
index = 0;
|
205 |
} |
206 |
} |
207 |
|
208 |
public void start() { |
209 |
timer = new Timer(this, 1000); |
210 |
timer.start(); |
211 |
} |
212 |
|
213 |
/**
|
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 |
MultiSplashWindow ba = new MultiSplashWindow(frame, theme, 5); |
235 |
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 |
public void process(int p, String str) { |
245 |
lblStatus.setText(str); |
246 |
|
247 |
if (pb.getValue() != p) {
|
248 |
pb.setValue(p); |
249 |
} |
250 |
doLayout(); |
251 |
repaint(); |
252 |
} |
253 |
|
254 |
public void mouseClicked(MouseEvent e) { |
255 |
this.setVisible(false); |
256 |
} |
257 |
|
258 |
public void mouseEntered(MouseEvent e) { } |
259 |
public void mouseExited(MouseEvent e) { } |
260 |
public void mousePressed(MouseEvent e) { } |
261 |
public void mouseReleased(MouseEvent e) { } |
262 |
} |
263 |
|