01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.core.gui.base;
19:
20: import java.awt.AWTEvent;
21: import java.awt.AWTException;
22: import java.awt.Graphics;
23: import java.awt.Graphics2D;
24: import java.awt.Point;
25: import java.awt.Rectangle;
26: import java.awt.Robot;
27: import java.awt.Shape;
28: import java.awt.Toolkit;
29: import java.awt.event.FocusEvent;
30: import java.awt.image.BufferedImage;
31:
32: import javax.swing.ImageIcon;
33: import javax.swing.JWindow;
34:
35: public class TransparentWindow extends JWindow {
36: Robot robot;
37: BufferedImage screen;
38: Shape shape;
39: BufferedImage buffer;
40: ImageIcon splashimg;
41:
42: public TransparentWindow(ImageIcon splashimg) throws AWTException {
43: this .splashimg = splashimg;
44:
45: robot = new Robot(getGraphicsConfiguration().getDevice());
46: requestFocus();
47: setSize(splashimg.getIconWidth(), splashimg.getIconHeight());
48: buffer = new BufferedImage(getWidth(), getHeight(),
49: BufferedImage.TYPE_INT_ARGB);
50: updateScreen();
51:
52: enableEvents(AWTEvent.FOCUS_EVENT_MASK);
53:
54: }
55:
56: protected void updateScreen() {
57: screen = robot.createScreenCapture(new Rectangle(
58: new Point(0, 0), Toolkit.getDefaultToolkit()
59: .getScreenSize()));
60: }
61:
62: protected void processFocusEvent(FocusEvent e) {
63: super .processFocusEvent(e);
64:
65: if (e.getID() == FocusEvent.FOCUS_GAINED) {
66: updateScreen();
67: repaint();
68: }
69: }
70:
71: public void paint(Graphics _g) {
72: Graphics2D g = buffer.createGraphics();
73:
74: if (screen != null) {
75: Point location = getLocationOnScreen();
76: g.drawImage(screen, -location.x, -location.y, this );
77: }
78:
79: g.drawImage(splashimg.getImage(), 0, 0, this );
80:
81: _g.drawImage(buffer, 0, 0, this);
82: }
83: }
|