From 6a700ff040dad96e6407d68629f09a1bfd817373 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 6 Apr 2015 18:58:19 +0200 Subject: [PATCH] tests: simplified animation --- .../sm/runner/ui/SMTestRunnerResultsForm.java | 9 +-- .../ui/TestsProgressAnimator.java | 7 ++- .../execution/junit2/ui/Animator.java | 56 ------------------- .../execution/junit2/ui/TestRenderer.java | 3 +- .../junit2/ui/model/JUnitRunningModel.java | 30 ++++++++-- .../theoryinpractice/testng/ui/Animator.java | 27 --------- .../testng/ui/ResultTreeRenderer.java | 7 ++- .../testng/ui/TestNGResults.java | 5 +- 8 files changed, 40 insertions(+), 104 deletions(-) delete mode 100644 plugins/junit/src/com/intellij/execution/junit2/ui/Animator.java delete mode 100644 plugins/testng/src/com/theoryinpractice/testng/ui/Animator.java 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 19ae13b3fa29..44cad56a144e 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 @@ -163,7 +163,7 @@ public class SMTestRunnerResultsForm extends TestResultsPanel myTreeBuilder.setTestsComparator(TestConsoleProperties.SORT_ALPHABETICALLY.value(myProperties)); Disposer.register(this, myTreeBuilder); - myAnimator = new MyAnimator(this, myTreeBuilder); + myAnimator = new TestsProgressAnimator(myTreeBuilder); //TODO always hide root node //myTreeView.setRootVisible(false); @@ -570,13 +570,6 @@ public class SMTestRunnerResultsForm extends TestResultsPanel } - private static class MyAnimator extends TestsProgressAnimator { - public MyAnimator(final Disposable parentDisposable, final AbstractTestTreeBuilder builder) { - super(parentDisposable); - init(builder); - } - } - private void updateCountersAndProgressOnTestCount(final int count, final boolean isCustomMessage) { if (!isModeConsistent(isCustomMessage)) return; 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 1375168ad913..751ad333234c 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java @@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; -public abstract class TestsProgressAnimator implements Runnable, Disposable { +public class TestsProgressAnimator implements Runnable, Disposable { private static final int FRAMES_COUNT = 8; private static final int MOVIE_TIME = 800; private static final int FRAME_TIME = MOVIE_TIME / FRAMES_COUNT; @@ -37,8 +37,9 @@ public abstract class TestsProgressAnimator implements Runnable, Disposable { private AbstractTestProxy myCurrentTestCase; private AbstractTestTreeBuilder myTreeBuilder; - protected TestsProgressAnimator(Disposable parentDisposable) { - Disposer.register(parentDisposable, this); + public TestsProgressAnimator(AbstractTestTreeBuilder builder) { + Disposer.register(builder, this); + init(builder); } static { diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/Animator.java b/plugins/junit/src/com/intellij/execution/junit2/ui/Animator.java deleted file mode 100644 index 88a66a17eeb3..000000000000 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/Animator.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.execution.junit2.ui; - -import com.intellij.execution.junit2.events.StateChangedEvent; -import com.intellij.execution.junit2.events.TestEvent; -import com.intellij.execution.junit2.TestProxy; -import com.intellij.execution.junit2.ui.model.JUnitAdapter; -import com.intellij.execution.junit2.ui.model.JUnitRunningModel; -import com.intellij.execution.junit2.ui.model.StateEvent; -import com.intellij.execution.testframework.ui.TestsProgressAnimator; -import com.intellij.openapi.Disposable; -import com.intellij.rt.execution.junit.states.PoolOfTestStates; - -public class Animator extends TestsProgressAnimator { - public Animator(Disposable parentDisposable) { - super(parentDisposable); - } - - public void setModel(final JUnitRunningModel model) { - init(model.getTreeBuilder()); - - model.addListener(new JUnitAdapter() { - public void onTestChanged(final TestEvent event) { - if (event instanceof StateChangedEvent) { - final TestProxy test = event.getSource(); - if (test.isLeaf() && test.getState().getMagnitude() == PoolOfTestStates.RUNNING_INDEX) - setCurrentTestCase(test); - } - } - - public void onRunnerStateChanged(final StateEvent event) { - if (!event.isRunning()) - stopMovie(); - } - - public void doDispose() { - dispose(); - } - }); - } -} diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/TestRenderer.java b/plugins/junit/src/com/intellij/execution/junit2/ui/TestRenderer.java index 0a7836648588..4124d8528da9 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/TestRenderer.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/TestRenderer.java @@ -21,6 +21,7 @@ import com.intellij.execution.junit2.info.TestInfo; import com.intellij.execution.junit2.ui.model.SpecialNode; import com.intellij.execution.testframework.PoolOfTestIcons; import com.intellij.execution.testframework.TestsUIUtil; +import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.icons.AllIcons; import com.intellij.rt.execution.junit.states.PoolOfTestStates; import com.intellij.ui.SimpleColoredComponent; @@ -36,7 +37,7 @@ class TestRenderer { public static Icon getIconFor(final TestProxy testProxy, final boolean isPaused) { final int magnitude = testProxy.getState().getMagnitude(); if (magnitude == PoolOfTestStates.RUNNING_INDEX) - return isPaused ? AllIcons.RunConfigurations.TestPaused : Animator.getCurrentFrame(); + return isPaused ? AllIcons.RunConfigurations.TestPaused : TestsProgressAnimator.getCurrentFrame(); else return ourIcons.get(new Integer(magnitude)); } diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitRunningModel.java b/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitRunningModel.java index 5e1049c7c856..4d53bb8cbaa7 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitRunningModel.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitRunningModel.java @@ -18,7 +18,8 @@ package com.intellij.execution.junit2.ui.model; import com.intellij.execution.junit.JUnitConfiguration; import com.intellij.execution.junit2.TestProxy; -import com.intellij.execution.junit2.ui.Animator; +import com.intellij.execution.junit2.events.StateChangedEvent; +import com.intellij.execution.junit2.events.TestEvent; import com.intellij.execution.junit2.ui.TestProgress; import com.intellij.execution.junit2.ui.TestProxyClient; import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties; @@ -26,10 +27,12 @@ import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.execution.testframework.Filter; import com.intellij.execution.testframework.TestFrameworkRunningModel; import com.intellij.execution.testframework.TestTreeView; +import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; +import com.intellij.rt.execution.junit.states.PoolOfTestStates; import com.intellij.util.ui.tree.TreeUtil; import javax.swing.*; @@ -50,7 +53,7 @@ public class JUnitRunningModel implements TestFrameworkRunningModel { private TestTreeBuilder myTreeBuilder; private final JUnitListenersNotifier myNotifier = new JUnitListenersNotifier(); - private final Animator myAnimator; + private TestsProgressAnimator myAnimator; public JUnitRunningModel(final TestProxy root, final JUnitConsoleProperties properties) { myRoot = root; @@ -64,7 +67,6 @@ public class JUnitRunningModel implements TestFrameworkRunningModel { myNotifier.fireDisposed(JUnitRunningModel.this); } }); - myAnimator = new Animator(this); } public TestTreeBuilder getTreeBuilder() { @@ -74,7 +76,27 @@ public class JUnitRunningModel implements TestFrameworkRunningModel { public void attachToTree(final TestTreeView treeView) { myTreeBuilder = new TestTreeBuilder(treeView, this, myProperties); Disposer.register(this, myTreeBuilder); - myAnimator.setModel(this); + myAnimator = new TestsProgressAnimator(myTreeBuilder); + addListener(new JUnitAdapter() { + public void onTestChanged(final TestEvent event) { + if (event instanceof StateChangedEvent) { + final TestProxy test = event.getSource(); + if (test.isLeaf() && test.getState().getMagnitude() == PoolOfTestStates.RUNNING_INDEX) { + myAnimator.setCurrentTestCase(test); + } + } + } + + public void onRunnerStateChanged(final StateEvent event) { + if (!event.isRunning()) { + myAnimator.stopMovie(); + } + } + + public void doDispose() { + dispose(); + } + }); myTreeView = treeView; selectTest(getRoot()); myTreeListener.install(); diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/Animator.java b/plugins/testng/src/com/theoryinpractice/testng/ui/Animator.java deleted file mode 100644 index bedb51de01ea..000000000000 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/Animator.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.theoryinpractice.testng.ui; - -import com.intellij.execution.testframework.ui.TestsProgressAnimator; -import com.intellij.openapi.Disposable; -import com.theoryinpractice.testng.model.TestTreeBuilder; - -public class Animator extends TestsProgressAnimator { - public Animator(final Disposable parentDisposable, final TestTreeBuilder builder) { - super(parentDisposable); - init(builder); - } -} diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java b/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java index 9ea4429447fe..b85a5e2ca164 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java @@ -17,6 +17,7 @@ package com.theoryinpractice.testng.ui; import com.intellij.execution.testframework.PoolOfTestIcons; import com.intellij.execution.testframework.TestFrameworkRunningModel; +import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.icons.AllIcons; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; @@ -62,7 +63,7 @@ public class ResultTreeRenderer extends ColoredTreeCellRenderer } } else { - setIcon(root.isInProgress() ? Animator.getCurrentFrame() : getIcon(proxy)); + setIcon(root.isInProgress() ? TestsProgressAnimator.getCurrentFrame() : getIcon(proxy)); append(root.isInProgress() ? "Running tests..." : "Test Results", SimpleTextAttributes.REGULAR_ATTRIBUTES); } @@ -77,10 +78,10 @@ public class ResultTreeRenderer extends ColoredTreeCellRenderer } else { append(proxy.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } - setIcon(proxy.isInProgress() ? Animator.getCurrentFrame() : proxy.isInterrupted() ? PoolOfTestIcons.NOT_RAN : getIcon(proxy)); + setIcon(proxy.isInProgress() ? TestsProgressAnimator.getCurrentFrame() : proxy.isInterrupted() ? PoolOfTestIcons.NOT_RAN : getIcon(proxy)); } } else { - setIcon(Animator.getCurrentFrame()); + setIcon(TestsProgressAnimator.getCurrentFrame()); append(node.getUserObject() != null ? node.getUserObject().toString() : "null", SimpleTextAttributes.REGULAR_ATTRIBUTES); } } diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java index 6519bc571f77..04d8d1b0ec6e 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java @@ -28,6 +28,7 @@ import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.execution.testframework.*; import com.intellij.execution.testframework.actions.ScrollToTestSourceAction; import com.intellij.execution.testframework.ui.TestResultsPanel; +import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.application.ApplicationManager; @@ -80,7 +81,6 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn private long start; private long end; private TestTreeBuilder treeBuilder; - private Animator animator; private final TreeRootNode rootNode; private static final String NO_PACKAGE = "No Package"; @@ -88,6 +88,7 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn private int myStatus = MessageHelper.PASSED_TEST; private Set startedMethods = new HashSet(); private TestProxy myLastSelected; + private TestsProgressAnimator animator; public TestNGResults(final JComponent component, final TestNGConfiguration configuration, @@ -135,7 +136,7 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn treeBuilder = new TestTreeBuilder(tree, structure); Disposer.register(this, treeBuilder); - animator = new Animator(this, treeBuilder); + animator = new TestsProgressAnimator(treeBuilder); openSourceListener = new OpenSourceSelectionListener(); tree.getSelectionModel().addTreeSelectionListener(openSourceListener);