From aaf77dbc64017c19c7a0450d4b293691b6cc8c31 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 10 Nov 2024 21:55:18 +0800 Subject: [PATCH] Fix a class cast exception in `BalloonImpl` --- .../translate/ui/balloon/BalloonImpl.java | 78 +++++++++++-------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/src/main/java/cn/yiiguxing/plugin/translate/ui/balloon/BalloonImpl.java b/src/main/java/cn/yiiguxing/plugin/translate/ui/balloon/BalloonImpl.java index 85c73920b..a68b0e50b 100644 --- a/src/main/java/cn/yiiguxing/plugin/translate/ui/balloon/BalloonImpl.java +++ b/src/main/java/cn/yiiguxing/plugin/translate/ui/balloon/BalloonImpl.java @@ -10,6 +10,7 @@ import com.intellij.ide.RemoteDesktopService; import com.intellij.ide.ui.PopupLocationTracker; import com.intellij.ide.ui.ScreenAreaConsumer; +import com.intellij.openapi.Disposable; import com.intellij.openapi.MnemonicHelper; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -634,7 +635,7 @@ public void run() { if (ApplicationManager.getApplication() != null) { ApplicationManager.getApplication().getMessageBus().connect(this) - .subscribe(AnActionListener.TOPIC,new AnActionListener(){ + .subscribe(AnActionListener.TOPIC, new AnActionListener() { @Override public void beforeActionPerformed(@NotNull AnAction action, @NotNull AnActionEvent event) { if (myHideOnAction && !(action instanceof HintManagerImpl.ActionToIgnore)) { @@ -892,49 +893,60 @@ public void show(JLayeredPane pane, @Nullable Rectangle bounds) { } - private void runAnimation(boolean forward, final JLayeredPane layeredPane, @Nullable final Runnable onDone) { - if (myAnimator != null) { - Disposer.dispose(myAnimator); + private class MyAnimator extends Animator implements Disposable { + + final JLayeredPane layeredPane; + final Runnable onDone; + + MyAnimator(boolean forward, JLayeredPane layeredPane, Runnable onDone) { + super("Balloon", 8, isAnimationEnabled() ? myAnimationCycle : 0, false, forward); + this.layeredPane = layeredPane; + this.onDone = onDone; } - myAnimator = new Animator("Balloon", 8, isAnimationEnabled() ? myAnimationCycle : 0, false, forward) { - @Override - public void paintNow(final int frame, final int totalFrames, final int cycle) { - if (myComp == null || myComp.getParent() == null || !isAnimationEnabled()) return; - myComp.setAlpha((float) frame / totalFrames); - } + @Override + public void paintNow(final int frame, final int totalFrames, final int cycle) { + if (myComp == null || myComp.getParent() == null || !isAnimationEnabled()) return; + myComp.setAlpha((float) frame / totalFrames); + } - @Override - protected void paintCycleEnd() { - if (myComp == null || myComp.getParent() == null) return; + @Override + protected void paintCycleEnd() { + if (myComp == null || myComp.getParent() == null) return; - if (isForward()) { - myComp.clear(); - myComp.repaint(); + if (isForward()) { + myComp.clear(); + myComp.repaint(); - myFadedIn = true; + myFadedIn = true; - if (!myFadeoutAlarm.isDisposed()) { - startFadeoutTimer((int) myFadeoutTime); - } - } else { - layeredPane.remove(myComp); - layeredPane.revalidate(); - layeredPane.repaint(); + if (!myFadeoutAlarm.isDisposed()) { + startFadeoutTimer((int) myFadeoutTime); } - Disposer.dispose(this); + } else { + layeredPane.remove(myComp); + layeredPane.revalidate(); + layeredPane.repaint(); } + Disposer.dispose(this); + } - @Override - public void dispose() { - super.dispose(); - myAnimator = null; - if (onDone != null) { - onDone.run(); - } + @Override + public void dispose() { + super.dispose(); + myAnimator = null; + if (onDone != null) { + onDone.run(); } - }; + } + } + + private void runAnimation(boolean forward, final JLayeredPane layeredPane, @Nullable final Runnable onDone) { + if (myAnimator != null) { + Disposer.dispose(myAnimator); + } + myAnimator = new MyAnimator(forward, layeredPane, onDone); myAnimator.resume(); }