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