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