Search in sources :

Example 1 with Animator

use of com.intellij.util.ui.Animator in project intellij-community by JetBrains.

the class SheetMessage method startAnimation.

void startAnimation(final boolean enlarge) {
    staticImage = myController.getStaticImage();
    JPanel staticPanel = new JPanel() {

        @Override
        public void paint(@NotNull Graphics g) {
            super.paint(g);
            if (staticImage != null) {
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.setBackground(new JBColor(new Color(255, 255, 255, 0), new Color(110, 110, 110, 0)));
                g2d.clearRect(0, 0, myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT);
                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.95f));
                int multiplyFactor = staticImage.getWidth(null) / myController.SHEET_NC_WIDTH;
                g.drawImage(staticImage, 0, 0, myController.SHEET_NC_WIDTH, imageHeight, 0, staticImage.getHeight(null) - imageHeight * multiplyFactor, staticImage.getWidth(null), staticImage.getHeight(null), null);
            }
        }
    };
    staticPanel.setOpaque(false);
    staticPanel.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT);
    myWindow.setContentPane(staticPanel);
    Animator myAnimator = new Animator("Roll Down Sheet Animator", myController.SHEET_NC_HEIGHT, TIME_TO_SHOW_SHEET, false) {

        @Override
        public void paintNow(int frame, int totalFrames, int cycle) {
            setPositionRelativeToParent();
            float percentage = (float) frame / (float) totalFrames;
            imageHeight = enlarge ? (int) (((float) myController.SHEET_NC_HEIGHT) * percentage) : (int) (myController.SHEET_NC_HEIGHT - percentage * myController.SHEET_HEIGHT);
            myWindow.repaint();
        }

        @Override
        protected void paintCycleEnd() {
            setPositionRelativeToParent();
            if (enlarge) {
                imageHeight = myController.SHEET_NC_HEIGHT;
                staticImage = null;
                myWindow.setContentPane(myController.getPanel(myWindow));
                IJSwingUtilities.moveMousePointerOn(myWindow.getRootPane().getDefaultButton());
                myController.requestFocus();
            } else {
                if (restoreFullScreenButton) {
                    FullScreenUtilities.setWindowCanFullScreen(myParent, true);
                }
                myParent.removeComponentListener(myPositionListener);
                myController.dispose();
                myWindow.dispose();
                DialogWrapper.cleanupRootPane(myWindow.getRootPane());
            }
        }
    };
    myAnimator.resume();
}
Also used : Animator(com.intellij.util.ui.Animator) JBColor(com.intellij.ui.JBColor) JBColor(com.intellij.ui.JBColor) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Animator

use of com.intellij.util.ui.Animator in project intellij-community by JetBrains.

the class DialogEarthquakeShaker method startShake.

public void startShake() {
    myNaturalLocation = myWindow.getLocation();
    myStartTime = System.currentTimeMillis();
    new Animator("EarthQuake", 10, 70, true) {

        @Override
        public void paintNow(int frame, int totalFrames, int cycle) {
            final long elapsed = System.currentTimeMillis() - myStartTime;
            final double waveOffset = (elapsed % 70) / 70d;
            final double angle = waveOffset * 2d * Math.PI;
            final int shakenX = (int) ((Math.sin(angle) * 10) + myNaturalLocation.x);
            myWindow.setLocation(shakenX, myNaturalLocation.y);
            myWindow.repaint();
            if (elapsed > 150) {
                suspend();
                myWindow.setLocation(myNaturalLocation);
                myWindow.repaint();
                Disposer.dispose(this);
            }
        }
    }.resume();
}
Also used : Animator(com.intellij.util.ui.Animator)

Aggregations

Animator (com.intellij.util.ui.Animator)2 JBColor (com.intellij.ui.JBColor)1 NotNull (org.jetbrains.annotations.NotNull)1