1 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 36 public class TransparentWindow extends JWindow { 37 Robot robot; 38 BufferedImage screen; 39 Shape shape; 40 BufferedImage buffer; 41 ImageIcon splashimg; 42 43 public TransparentWindow(ImageIcon splashimg) throws AWTException { 44 this.splashimg = splashimg; 45 46 robot = new Robot (getGraphicsConfiguration().getDevice()); 47 requestFocus(); 48 setSize(splashimg.getIconWidth(), splashimg.getIconHeight()); 49 buffer = new BufferedImage (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 (new Point (0, 0), 59 Toolkit.getDefaultToolkit().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 } 84 | Popular Tags |