1 /********************************************************************************
2 * InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 package ui.panel;
21
22 import java.awt.Graphics;
23 import java.awt.Image;
24 import java.awt.MediaTracker;
25 import java.awt.event.ComponentEvent;
26 import java.awt.event.ComponentListener;
27 import java.io.File;
28
29 import javax.imageio.ImageIO;
30 import javax.swing.JPanel;
31
32 import org.apache.log4j.Logger;
33
34 import ui.Messages;
35 import base.ConfigurationManager;
36 import base.InternetCafe;
37
38 @SuppressWarnings("serial")
39 public class ICInfoPanel extends JPanel {
40
41 private static final transient Logger logger = Logger
42 .getLogger(ICInfoPanel.class.getName());
43
44 private volatile Image backgroundImage = null;
45
46 private boolean scaled = false;
47
48 public ICInfoPanel() {
49 try {
50 final MediaTracker tracker = new MediaTracker(this);
51 new Thread() {
52 public void run() {
53 InternetCafe.setStatusBarMessage(Messages.getString("common.loading")
54 + ConfigurationManager.getInstance()
55 .getInternetCafeName() + " logo...");
56 InternetCafe.getStatusBar().getTimer().start();
57
58 Image originalImage = null;
59 try {
60 File logoFile = new File(ConfigurationManager
61 .getInstance().getInternetCafeLogoPath());
62 if (logoFile.exists()) {
63 tracker.addImage(originalImage = ImageIO
64 .read(logoFile), 0);
65 tracker.waitForID(0);
66 tracker.addImage(backgroundImage = originalImage
67 .getScaledInstance(
68 getParent().getWidth() - 20,
69 getParent().getHeight() - 20,
70 Image.SCALE_FAST), 1);
71 tracker.waitForID(1);
72 scaled = true;
73 updateUI();
74 InternetCafe.setStatusBarMessage(Messages.getString("common.ready"));
75 InternetCafe.getStatusBar().setTaskDone(true);
76 }
77 } catch (Exception e) {
78
79 logger.error(e.getMessage());
80 e.printStackTrace();
81 }
82 }
83 }.start();
84 } catch (Exception ex) {
85 ex.printStackTrace();
86 }
87
88 this.addComponentListener(new ComponentListener() {
89
90 public void componentResized(ComponentEvent arg0) {
91 if (backgroundImage != null && getParent() != null) {
92
93 backgroundImage = backgroundImage.getScaledInstance(
94 getParent().getWidth() - 20, getParent()
95 .getHeight() - 20, Image.SCALE_FAST);
96 }
97
98 }
99
100 public void componentMoved(ComponentEvent arg0) {
101
102
103 }
104
105 public void componentShown(ComponentEvent arg0) {
106
107
108 }
109
110 public void componentHidden(ComponentEvent arg0) {
111
112
113 }
114
115 });
116
117 }
118
119 public void paintComponent(Graphics graphics) {
120 super.paintComponent(graphics);
121 if (backgroundImage != null && scaled)
122 graphics.drawImage(backgroundImage, 0, 0, this);
123 }
124 }