From 1b77d17863216758ff592f2bae5a753dc2b2a759 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Tue, 20 Nov 2018 20:28:24 +0300 Subject: [PATCH] Allow to use AnimatedIcon in TestTree --- .../src/com/intellij/ui/AnimatedIcon.java | 21 ++++++++++++++++++- .../sm/runner/ui/SMPoolOfTestIcons.java | 5 +++++ .../sm/runner/ui/SMTestRunnerResultsForm.java | 10 --------- .../sm/runner/ui/TestsPresentationUtil.java | 4 +--- .../runner/ui/TestsPresentationUtilTest.java | 7 +------ .../execution/testframework/TestTreeView.java | 1 + .../ui/TestsProgressAnimator.java | 1 + .../execution/NodeProgressAnimator.java | 1 + 8 files changed, 30 insertions(+), 20 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/AnimatedIcon.java b/platform/platform-api/src/com/intellij/ui/AnimatedIcon.java index 479ed543909a..33305936ca54 100644 --- a/platform/platform-api/src/com/intellij/ui/AnimatedIcon.java +++ b/platform/platform-api/src/com/intellij/ui/AnimatedIcon.java @@ -2,9 +2,12 @@ package com.intellij.ui; import com.intellij.icons.AllIcons; +import com.intellij.openapi.util.Key; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import javax.swing.CellRendererPane; import javax.swing.Icon; import javax.swing.Timer; import java.awt.Component; @@ -19,6 +22,17 @@ import static java.util.Arrays.asList; * @author Sergey.Malenkov */ public class AnimatedIcon implements Icon { + /** + * This key is used to allow animated icons in lists, tables and trees. + * If the corresponding client property is set to {@code true} the corresponding component + * will be automatically repainted to update an animated icon painted by the renderer of the component. + * Note, that animation may cause a performance problems and should not be used everywhere. + * + * @see UIUtil#putClientProperty + */ + @ApiStatus.Experimental + public static final Key ANIMATION_IN_RENDERER_ALLOWED = Key.create("ANIMATION_IN_RENDERER_ALLOWED"); + public interface Frame { @NotNull Icon getIcon(); @@ -238,7 +252,8 @@ public class AnimatedIcon implements Icon { @Override public final void paintIcon(Component c, Graphics g, int x, int y) { Icon icon = getUpdatedIcon(); - requestRefresh(c); + CellRendererPane pane = UIUtil.getParentOfType(CellRendererPane.class, c); + requestRefresh(pane == null ? c : getRendererOwner(pane.getParent())); icon.paintIcon(c, g, x, y); } @@ -259,4 +274,8 @@ public class AnimatedIcon implements Icon { protected void doRefresh(Component component) { if (component != null) component.repaint(); } + + protected Component getRendererOwner(Component component) { + return UIUtil.isClientPropertyTrue(component, ANIMATION_IN_RENDERER_ALLOWED) ? component : null; + } } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMPoolOfTestIcons.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMPoolOfTestIcons.java index d94b8da8567d..99b68fbdf11e 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMPoolOfTestIcons.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMPoolOfTestIcons.java @@ -18,6 +18,7 @@ package com.intellij.execution.testframework.sm.runner.ui; import com.intellij.execution.testframework.PoolOfTestIcons; import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.icons.AllIcons; +import com.intellij.ui.AnimatedIcon; import com.intellij.ui.LayeredIcon; import org.jetbrains.annotations.NotNull; @@ -36,7 +37,11 @@ public class SMPoolOfTestIcons implements PoolOfTestIcons { public static final Icon IGNORED_E_ICON = addErrorMarkTo(IGNORED_ICON); // Test Progress + public static final Icon RUNNING_ICON = new AnimatedIcon.Default(); + public static final Icon RUNNING_E_ICON = addErrorMarkTo(RUNNING_ICON); public static final Icon PAUSED_E_ICON = addErrorMarkTo(AllIcons.RunConfigurations.TestPaused); + @Deprecated + @SuppressWarnings("DeprecatedIsStillUsed") public static final Icon[] FRAMES_E = new Icon[TestsProgressAnimator.FRAMES.length]; static { for (int i = 0, length = FRAMES_E.length; i < length; i++){ diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java index a64d56d0f7f1..60d8f8066cf3 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java @@ -30,7 +30,6 @@ import com.intellij.execution.testframework.sm.runner.*; import com.intellij.execution.testframework.sm.runner.history.ImportedTestConsoleProperties; import com.intellij.execution.testframework.sm.runner.history.actions.AbstractImportTestsAction; import com.intellij.execution.testframework.ui.TestResultsPanel; -import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.execution.ui.ConsoleView; import com.intellij.ide.DataManager; import com.intellij.ide.util.treeView.IndexComparator; @@ -97,8 +96,6 @@ public class SMTestRunnerResultsForm extends TestResultsPanel private SMTRunnerTestTreeView myTreeView; - private TestsProgressAnimator myAnimator; - /** * Fake parent suite for all tests and suites */ @@ -177,8 +174,6 @@ public class SMTestRunnerResultsForm extends TestResultsPanel Disposer.register(this, myTreeBuilder); Disposer.register(this, asyncTreeModel); - myAnimator = new TestsProgressAnimator(myTreeBuilder); - TrackRunningTestUtil.installStopListeners(myTreeView, myProperties, new Pass() { @Override public void pass(AbstractTestProxy testProxy) { @@ -238,7 +233,6 @@ public class SMTestRunnerResultsForm extends TestResultsPanel myLastSelected = null; myMentionedCategories.clear(); - myAnimator.setCurrentTestCase(myTestsRootNode); if (myEndTime != 0) { // no need to reset when running for the first time resetTreeAndConsoleOnSubsequentTestingStarted(); myEndTime = 0; @@ -291,8 +285,6 @@ public class SMTestRunnerResultsForm extends TestResultsPanel updateStatusLabel(true); updateIconProgress(true); - myAnimator.stopMovie(); - myRequests.clear(); myUpdateTreeRequests.cancelAllRequests(); myTreeBuilder.updateFromRoot(); @@ -612,8 +604,6 @@ public class SMTestRunnerResultsForm extends TestResultsPanel myUpdateTreeRequests.addRequest(update, 50); } - myAnimator.setCurrentTestCase(newTestOrSuite); - if (TestConsoleProperties.TRACK_RUNNING_TEST.value(myProperties)) { if (myLastSelected == null || myLastSelected == newTestOrSuite) { myLastSelected = null; diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtil.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtil.java index 468629252c5e..606919a13c71 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtil.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtil.java @@ -20,7 +20,6 @@ import com.intellij.execution.testframework.TestConsoleProperties; import com.intellij.execution.testframework.sm.SMTestsRunnerBundle; import com.intellij.execution.testframework.sm.runner.SMTestProxy; import com.intellij.execution.testframework.sm.runner.states.TestStateInfo; -import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.icons.AllIcons; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.SimpleTextAttributes; @@ -282,8 +281,7 @@ public class TestsPresentationUtil { return hasErrors ? PAUSED_E_ICON : AllIcons.RunConfigurations.TestPaused; } else { - final int frameIndex = TestsProgressAnimator.getCurrentFrameIndex(); - return hasErrors ? FRAMES_E[frameIndex] : TestsProgressAnimator.FRAMES[frameIndex]; + return hasErrors ? RUNNING_E_ICON : RUNNING_ICON; } case SKIPPED_INDEX: return hasErrors ? SKIPPED_E_ICON : SKIPPED_ICON; diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtilTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtilTest.java index 4987b0e2c8f1..be492214c0d7 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtilTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtilTest.java @@ -22,7 +22,6 @@ import com.intellij.execution.testframework.sm.UITestUtil; import com.intellij.execution.testframework.sm.runner.BaseSMTRunnerTestCase; import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties; import com.intellij.execution.testframework.sm.runner.SMTestProxy; -import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.icons.AllIcons; import com.intellij.ui.SimpleTextAttributes; import org.jetbrains.annotations.Nls; @@ -731,11 +730,7 @@ public class TestsPresentationUtilTest extends BaseSMTRunnerTestCase { } private static void assertIsAnimatorProgressIcon(final Icon icon) { - for (Icon frame : TestsProgressAnimator.FRAMES) { - if (icon == frame) { - return; - } - } + if (icon == SMPoolOfTestIcons.RUNNING_ICON) return; fail("Icon isn't an Animator progress frame"); } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java b/platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java index 230c3e0411f3..8fc41dab6c3b 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java @@ -83,6 +83,7 @@ public abstract class TestTreeView extends Tree implements DataProvider, CopyPro }); installHandlers(); setCellRenderer(getRenderer(myModel.getProperties())); + putClientProperty(AnimatedIcon.ANIMATION_IN_RENDERER_ALLOWED, true); } @Override diff --git a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java index 1b784c6d905d..76a0f15b592e 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; +@Deprecated public class TestsProgressAnimator implements Runnable, Disposable { private static final int FRAMES_COUNT = 8; private static final int MOVIE_TIME = 800; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/NodeProgressAnimator.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/NodeProgressAnimator.java index ecf153a3b4ba..49422ddd2c08 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/NodeProgressAnimator.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/NodeProgressAnimator.java @@ -17,6 +17,7 @@ import javax.swing.tree.DefaultMutableTreeNode; /** * @author Vladislav.Soroka */ +@Deprecated public class NodeProgressAnimator implements Runnable, Disposable { private static final int FRAMES_COUNT = 8; private static final int MOVIE_TIME = 800;