FileDocCategorySizeDatePackage
SlideInNotification.javaAPI DocExample6134Mon Jan 09 11:02:00 GMT 2006None

SlideInNotification

public class SlideInNotification extends Object

Fields Summary
protected static final int
ANIMATION_TIME
protected static final float
ANIMATION_TIME_F
protected static final int
ANIMATION_DELAY
JWindow
window
JComponent
contents
AnimatingSheet
animatingSheet
Rectangle
desktopBounds
Dimension
tempWindowSize
Timer
animationTimer
int
showX
int
startY
long
animationStart
Constructors Summary
public SlideInNotification()

        
       
        initDesktopBounds();
    
public SlideInNotification(JComponent contents)

        this();
        setContents (contents);
    
Methods Summary
protected voidinitDesktopBounds()

        GraphicsEnvironment env =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        desktopBounds = env.getMaximumWindowBounds();
        System.out.println ("max window bounds = " + desktopBounds);
    
public voidsetContents(javax.swing.JComponent contents)

        this.contents = contents;
        JWindow tempWindow = new JWindow();
        tempWindow.getContentPane().add (contents);
        tempWindow.pack();
        tempWindowSize = tempWindow.getSize();
        tempWindow.getContentPane().removeAll();
        window = new JWindow();
        animatingSheet = new AnimatingSheet ();
        animatingSheet.setSource (contents);
        window.getContentPane().add (animatingSheet);
    
public voidshowAt(int x)

        // create a window with an animating sheet
        // copy over its contents from the temp window
        // animate it
        // when done, remove animating sheet and add real contents

        showX = x;
        startY = desktopBounds.y + desktopBounds.height;

        ActionListener animationLogic = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    long elapsed =
                        System.currentTimeMillis() - animationStart;
                    if (elapsed > ANIMATION_TIME) {
                        // put real contents in window and show
                        window.getContentPane().removeAll();
                        window.getContentPane().add (contents);
                        window.pack();
                        window.setLocation (showX,
                                            startY - window.getSize().height);
                        window.setVisible(true);
                        window.repaint();
                        animationTimer.stop();
                        animationTimer = null;
                    } else {
                        // calculate % done
                        float progress =
                            (float) elapsed / ANIMATION_TIME_F;
                        // get height to show
                        int animatingHeight = 
                            (int) (progress * tempWindowSize.getHeight());
                        //System.out.println ("animatingHeight " + 
                        //                    animatingHeight);
                        animatingHeight = Math.max (animatingHeight, 1);
                        animatingSheet.setAnimatingHeight (animatingHeight);
                        window.pack();
                        window.setLocation (showX,
                                            startY - window.getHeight());
                        window.setVisible(true);
                        window.repaint();
                    }
                }
            };
        animationTimer =
            new Timer (ANIMATION_DELAY, animationLogic);
        animationStart = System.currentTimeMillis();
        animationTimer.start();