
Slide Notes Out from the Taskbar #46
Chapter 6, Transparent and Animated Windows
|
245
HACK
Running the Hack
The SlideInNotification will take any JComponent as its contents. To make
things a little interesting, the
TestSlideInNotification class, shown in
Example 6-13, grabs an icon from the
JOptionPane class and makes a JLabel
of that and a little nonsense text.
public void setAnimatingHeight (int height) {
animatingSize.height = height;
setSize (animatingSize);
}
private void makeOffscreenImage(JComponent source) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment( );
GraphicsConfiguration gfxConfig =
ge.getDefaultScreenDevice().getDefaultConfiguration( );
offscreenImage =
gfxConfig.createCompatibleImage(source.getWidth( ),
source.getHeight( ));
Graphics2D offscreenGraphics =
(Graphics2D) offscreenImage.getGraphics( );
// windows workaround
offscreenGraphics.setColor (source.getBackground( ));
offscreenGraphics.fillRect (0, 0,
source.getWidth(), source.getHeight( ));
// paint from source to offscreen buffer
source.paint (offscreenGraphics);
}
public Dimension getPreferredSize( ) { return animatingSize; }
public Dimension getMinimumSize( ) { return animatingSize; }
public Dimension getMaximumSize( ) { return animatingSize; }
public void update (Graphics g) {
// override to eliminate flicker from
// unnecessary clear
paint (g);
}
public void paint (Graphics g) {
// ...