1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.idea;
18
19 import com.intellij.util.ui.AsyncProcessIcon;
20 import com.intellij.openapi.util.IconLoader;
21
22 import javax.swing.*;
23 import java.awt.*;
24
25
26
27
28
29
30
31
32 public class ProgressAnimationProvider extends JPanel {
33
34 private AnimatedProgressIcon progressIcon = new AnimatedProgressIcon("Progress Indicator");
35 private JComponent replacedComponent;
36 private Object addConstraint;
37 private JComponent parentComponent;
38
39
40
41
42
43
44
45 public void configure(JComponent rootComponent, JComponent replaceComponent, Object constraint) {
46 this.parentComponent = rootComponent;
47 this.replacedComponent = replaceComponent;
48 this.addConstraint = constraint;
49 }
50
51 public void startProgressAnimation() {
52 EventQueue.invokeLater(new ProgressAnimation(true));
53 }
54
55 public void stopProgressAnimation() {
56 EventQueue.invokeLater(new ProgressAnimation(false));
57 }
58
59 private class ProgressAnimation implements Runnable {
60 private boolean start;
61
62 public ProgressAnimation(boolean start) {
63 this.start = start;
64 }
65
66 public void run() {
67 if (start) {
68 if (replacedComponent != null) {
69 parentComponent.remove(replacedComponent);
70 }
71 parentComponent.add(progressIcon, addConstraint);
72 progressIcon.resume();
73 parentComponent.repaint();
74 parentComponent.validate();
75 parentComponent.requestFocus();
76 } else {
77
78 progressIcon.suspend();
79 parentComponent.remove(progressIcon);
80 if (replacedComponent != null) {
81 parentComponent.add(replacedComponent, addConstraint);
82 }
83 parentComponent.repaint();
84 parentComponent.validate();
85 parentComponent.requestFocus();
86 }
87
88 }
89 }
90
91 private static class AnimatedProgressIcon extends AsyncProcessIcon {
92 private Icon[] icons;
93 private Icon passiveIcon;
94 private static final int CYCLE_LENGTH = 640;
95 private static final int CYCLE_GAP = 80;
96
97 public AnimatedProgressIcon(@org.jetbrains.annotations.NonNls String name) {
98 super(name);
99
100
101 initCustomLook();
102 }
103
104 private void initCustomLook() {
105 loadIcons();
106 init(icons, passiveIcon, CYCLE_LENGTH, CYCLE_GAP, -1);
107 }
108
109 private void loadIcons() {
110 icons = new Icon[]{
111 IconLoader.getIcon("/icons/progress/roller_1.png"),
112 IconLoader.getIcon("/icons/progress/roller_2.png"),
113 IconLoader.getIcon("/icons/progress/roller_3.png"),
114 IconLoader.getIcon("/icons/progress/roller_4.png"),
115 IconLoader.getIcon("/icons/progress/roller_5.png"),
116 IconLoader.getIcon("/icons/progress/roller_6.png"),
117 IconLoader.getIcon("/icons/progress/roller_7.png"),
118 IconLoader.getIcon("/icons/progress/roller_8.png"),
119 };
120
121 passiveIcon = IconLoader.getIcon("/icons/progress/roller_0.png");
122
123 }
124 }
125 }