KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > base > TransparentWindow


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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 JavaDoc;
21 import java.awt.AWTException JavaDoc;
22 import java.awt.Graphics JavaDoc;
23 import java.awt.Graphics2D JavaDoc;
24 import java.awt.Point JavaDoc;
25 import java.awt.Rectangle JavaDoc;
26 import java.awt.Robot JavaDoc;
27 import java.awt.Shape JavaDoc;
28 import java.awt.Toolkit JavaDoc;
29 import java.awt.event.FocusEvent JavaDoc;
30 import java.awt.image.BufferedImage JavaDoc;
31
32 import javax.swing.ImageIcon JavaDoc;
33 import javax.swing.JWindow JavaDoc;
34
35
36 public class TransparentWindow extends JWindow JavaDoc {
37     Robot JavaDoc robot;
38     BufferedImage JavaDoc screen;
39     Shape JavaDoc shape;
40     BufferedImage JavaDoc buffer;
41     ImageIcon JavaDoc splashimg;
42
43     public TransparentWindow(ImageIcon JavaDoc splashimg) throws AWTException JavaDoc {
44         this.splashimg = splashimg;
45
46         robot = new Robot JavaDoc(getGraphicsConfiguration().getDevice());
47         requestFocus();
48         setSize(splashimg.getIconWidth(), splashimg.getIconHeight());
49         buffer = new BufferedImage JavaDoc(getWidth(), getHeight(),
50                 BufferedImage.TYPE_INT_ARGB);
51         updateScreen();
52
53         enableEvents(AWTEvent.FOCUS_EVENT_MASK);
54
55     }
56
57     protected void updateScreen() {
58         screen = robot.createScreenCapture(new Rectangle JavaDoc(new Point JavaDoc(0, 0),
59                     Toolkit.getDefaultToolkit().getScreenSize()));
60     }
61
62     protected void processFocusEvent(FocusEvent JavaDoc 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 JavaDoc _g) {
72         Graphics2D JavaDoc g = buffer.createGraphics();
73
74         if (screen != null) {
75             Point JavaDoc 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 }
84
Popular Tags