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