svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / splash / MultiSplashWindow.java @ 45098
History | View | Annotate | Download (8.5 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.andami.ui.splash; |
26 |
|
27 |
import java.awt.BorderLayout; |
28 |
import java.awt.Color; |
29 |
import java.awt.Dimension; |
30 |
import java.awt.Font; |
31 |
import java.awt.Frame; |
32 |
import java.awt.Graphics; |
33 |
import java.awt.Graphics2D; |
34 |
import java.awt.Point; |
35 |
import java.awt.RenderingHints; |
36 |
import java.awt.Toolkit; |
37 |
import java.awt.event.ActionEvent; |
38 |
import java.awt.event.ActionListener; |
39 |
import java.awt.event.MouseEvent; |
40 |
import java.awt.event.MouseListener; |
41 |
|
42 |
import javax.swing.BorderFactory; |
43 |
import javax.swing.ImageIcon; |
44 |
import javax.swing.JLabel; |
45 |
import javax.swing.JProgressBar; |
46 |
import javax.swing.JWindow; |
47 |
import javax.swing.SwingUtilities; |
48 |
import javax.swing.Timer; |
49 |
import org.gvsig.andami.Launcher; |
50 |
|
51 |
import org.gvsig.andami.PluginServices; |
52 |
import org.gvsig.andami.messages.Messages; |
53 |
import org.gvsig.andami.ui.theme.Theme; |
54 |
import org.slf4j.Logger; |
55 |
import org.slf4j.LoggerFactory; |
56 |
|
57 |
|
58 |
|
59 |
public class MultiSplashWindow extends JWindow implements |
60 |
MouseListener {
|
61 |
private static final Logger logger = LoggerFactory.getLogger(MultiSplashWindow.class); |
62 |
|
63 |
private static final long serialVersionUID = 572592158521767258L; |
64 |
private JProgressBar pb; |
65 |
private int progress = 0; |
66 |
private JLabel lblStatus; |
67 |
private Timer timer; |
68 |
private int numLogos = 0; |
69 |
private ImageIcon[] img = null; |
70 |
private Dimension splashDimension; |
71 |
private int index = 0; |
72 |
private int current; |
73 |
private int lastIndex = -1; |
74 |
private Theme theme;
|
75 |
private int[] timers; |
76 |
|
77 |
private String version=""; |
78 |
private String[] versions=null; |
79 |
private Point point=new Point(270,240); |
80 |
private Point[] points=null; |
81 |
private int fontsize=18; |
82 |
private int[] fontSizes=null; |
83 |
private Color fontcolor=new Color(80,170,240); |
84 |
private Color[] fontColors=null; |
85 |
private final boolean showsplash; |
86 |
|
87 |
public MultiSplashWindow(Frame f, Theme theme, int progressBarStepCount) { |
88 |
super(f);
|
89 |
this.showsplash = (boolean) Launcher.getArguments().get("splash",true); |
90 |
this.theme = theme;
|
91 |
this.timers = theme.getTimers();
|
92 |
lblStatus = new JLabel(Messages.getString("SplashWindow.Iniciando")); |
93 |
lblStatus.setBorder(BorderFactory.createEtchedBorder());
|
94 |
lblStatus.setBackground(Color.WHITE);
|
95 |
|
96 |
pack(); |
97 |
pb = new JProgressBar(0, progressBarStepCount); |
98 |
getContentPane().setLayout(new BorderLayout()); |
99 |
getContentPane().add(lblStatus, BorderLayout.NORTH);
|
100 |
getContentPane().add(pb, BorderLayout.SOUTH);
|
101 |
|
102 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
103 |
|
104 |
init(); |
105 |
setLocation((screenSize.width / 2) - (splashDimension.width / 2), |
106 |
(screenSize.height / 2) - (splashDimension.height / 2)); |
107 |
index = 0;
|
108 |
setVisible(this.showsplash);
|
109 |
this.addMouseListener(this); |
110 |
} |
111 |
|
112 |
public void init() { |
113 |
img = theme.getSplashImages(); |
114 |
numLogos = img.length; |
115 |
|
116 |
if (numLogos == 0) { |
117 |
numLogos = 1;
|
118 |
img = new ImageIcon[1]; |
119 |
img[0] = PluginServices.getIconTheme().get("splash-default"); |
120 |
timers = new int[1]; |
121 |
timers[0] = 1000; |
122 |
} |
123 |
versions=theme.getVersions(); |
124 |
points=theme.getPositions(); |
125 |
fontSizes=theme.getFontSizes(); |
126 |
fontColors=theme.getFontColors(); |
127 |
int splashWidth = img[0].getIconWidth(); |
128 |
int splashHeight = img[0].getIconHeight(); |
129 |
|
130 |
for (int i = 1; i < numLogos; i++) { |
131 |
splashWidth = Math.max(splashWidth, img[i].getIconWidth());
|
132 |
splashHeight = Math.max(splashHeight, img[i].getIconHeight());
|
133 |
} |
134 |
|
135 |
splashDimension = new Dimension(splashWidth, splashHeight); |
136 |
setSize(splashDimension.width, splashDimension.height + 45);
|
137 |
|
138 |
start(); |
139 |
} |
140 |
|
141 |
public void paint(Graphics g) { |
142 |
if (lastIndex == current) {
|
143 |
return;
|
144 |
} |
145 |
|
146 |
super.paint(g);
|
147 |
|
148 |
if ((img == null) || (img[current] == null)) { |
149 |
return;
|
150 |
} |
151 |
|
152 |
ImageIcon image = img[current];
|
153 |
g.drawImage(image.getImage(), |
154 |
(getWidth() / 2) - (image.getIconWidth() / 2), |
155 |
((getHeight() / 2) - (image.getIconHeight() / 2)), this); |
156 |
|
157 |
// Activate antialias for text
|
158 |
if (g instanceof Graphics2D) { |
159 |
((Graphics2D) g).setRenderingHint(
|
160 |
RenderingHints.KEY_TEXT_ANTIALIASING,
|
161 |
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
162 |
} |
163 |
|
164 |
Font font = new Font("SansSerif", Font.BOLD, fontsize); |
165 |
if (fontSizes.length>0 && fontSizes[current]!=0) { |
166 |
font = new Font("SansSerif", Font.BOLD, fontSizes[current]); |
167 |
} |
168 |
g.setFont(font); |
169 |
|
170 |
Color color=fontcolor;
|
171 |
if (fontColors.length>0 && fontColors[current]!=null) { |
172 |
color=fontColors[current]; |
173 |
} |
174 |
g.setColor(color); |
175 |
|
176 |
String ver=version;
|
177 |
if (versions.length>0 && versions[current]!=null) { |
178 |
ver=versions[current]; |
179 |
} |
180 |
|
181 |
Point p=point;
|
182 |
if (points.length>0 && points[current]!=null){ |
183 |
p=points[current]; |
184 |
} |
185 |
|
186 |
g.drawString(PluginServices.getText(this,ver),(int)p.getX(),(int)p.getY()); |
187 |
|
188 |
lastIndex = current; |
189 |
} |
190 |
|
191 |
public void tick() { |
192 |
current = index; |
193 |
timer.setDelay(timers[current]); |
194 |
repaint(); |
195 |
index++; |
196 |
|
197 |
if (index >= numLogos) {
|
198 |
index = 0;
|
199 |
} |
200 |
} |
201 |
|
202 |
public void start() { |
203 |
timer = new Timer(1000,new ActionListener() { |
204 |
|
205 |
@Override
|
206 |
public void actionPerformed(ActionEvent e) { |
207 |
tick(); |
208 |
} |
209 |
}); |
210 |
timer.start(); |
211 |
} |
212 |
|
213 |
/**
|
214 |
* Cierra la ventana
|
215 |
*/
|
216 |
public void close() { |
217 |
if( this.progress != this.pb.getMaximum() ) { |
218 |
logger.warn("Max value of launch progress can be set to "+this.progress); |
219 |
} |
220 |
setVisible(false);
|
221 |
stop(); |
222 |
dispose(); |
223 |
} |
224 |
|
225 |
public void stop() { |
226 |
timer.stop(); |
227 |
timer = null;
|
228 |
} |
229 |
|
230 |
/**
|
231 |
* DOCUMENT ME!
|
232 |
*
|
233 |
* @param args DOCUMENT ME!
|
234 |
*/
|
235 |
public static void main(String[] args) { |
236 |
Frame frame = new Frame(); |
237 |
Theme theme = new Theme();
|
238 |
MultiSplashWindow ba = new MultiSplashWindow(frame, theme, 5); |
239 |
ba.setVisible(true);
|
240 |
ba.setSize(500, 500); |
241 |
ba.init(); |
242 |
ba.start(); |
243 |
} |
244 |
|
245 |
/**
|
246 |
* @see com.iver.mdiApp.ui.AppLoadingListener#process(int)
|
247 |
*/
|
248 |
public void process(int p, String str) { |
249 |
lblStatus.setText(str); |
250 |
if( this.progress < p ) { |
251 |
this.progress = p;
|
252 |
} |
253 |
if (pb.getValue() != this.progress && this.progress <= pb.getMaximum() ) { |
254 |
pb.setValue(this.progress);
|
255 |
} |
256 |
doLayout(); |
257 |
repaint(); |
258 |
} |
259 |
|
260 |
public void process(final String str) { |
261 |
if( !SwingUtilities.isEventDispatchThread() ) { |
262 |
try {
|
263 |
SwingUtilities.invokeAndWait(new Runnable() { |
264 |
@Override
|
265 |
public void run() { |
266 |
process(str); |
267 |
} |
268 |
}); |
269 |
} catch (Exception ex) { |
270 |
} |
271 |
return;
|
272 |
} |
273 |
lblStatus.setText(str); |
274 |
lblStatus.paintImmediately(lblStatus.getVisibleRect()); |
275 |
|
276 |
this.progress++;
|
277 |
if( this.progress <= pb.getMaximum() ) { |
278 |
pb.setValue(this.progress);
|
279 |
pb.paintImmediately(pb.getVisibleRect()); |
280 |
} |
281 |
} |
282 |
|
283 |
public void mouseClicked(MouseEvent e) { |
284 |
this.setVisible(false); |
285 |
} |
286 |
|
287 |
public void mouseEntered(MouseEvent e) { } |
288 |
public void mouseExited(MouseEvent e) { } |
289 |
public void mousePressed(MouseEvent e) { } |
290 |
public void mouseReleased(MouseEvent e) { } |
291 |
} |
292 |
|