Dialog shaker: support all type of windows

This commit is contained in:
Konstantin Bulenkov
2016-03-03 11:35:39 +01:00
parent 45e3facefd
commit bd673ac173
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,23 +18,22 @@ package com.intellij.openapi.ui;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.ui.Animator;
import javax.swing.*;
import java.awt.*;
/**
* @author Konstantin Bulenkov
*/
public class DialogEarthquakeShaker {
private JDialog myDialog;
private Window myWindow;
private Point myNaturalLocation;
private long myStartTime;
private DialogEarthquakeShaker(JDialog dialog) {
myDialog = dialog;
private DialogEarthquakeShaker(Window window) {
myWindow = window;
}
public void startShake() {
myNaturalLocation = myDialog.getLocation();
myNaturalLocation = myWindow.getLocation();
myStartTime = System.currentTimeMillis();
new Animator("EarthQuake", 10, 70, true) {
@Override
@@ -43,19 +42,19 @@ public class DialogEarthquakeShaker {
final double waveOffset = (elapsed % 70) / 70d;
final double angle = waveOffset * 2d * Math.PI;
final int shakenX = (int)((Math.sin(angle) * 10) + myNaturalLocation.x);
myDialog.setLocation(shakenX, myNaturalLocation.y);
myDialog.repaint();
myWindow.setLocation(shakenX, myNaturalLocation.y);
myWindow.repaint();
if (elapsed > 150) {
suspend();
myDialog.setLocation(myNaturalLocation);
myDialog.repaint();
myWindow.setLocation(myNaturalLocation);
myWindow.repaint();
Disposer.dispose(this);
}
}
}.resume();
}
public static void shake(JDialog dialog) {
new DialogEarthquakeShaker(dialog).startShake();
public static void shake(Window window) {
new DialogEarthquakeShaker(window).startShake();
}
}