1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.support;
14
15 import javax.swing.ImageIcon;
16
17 import com.eviware.soapui.impl.wsdl.AbstractWsdlModelItem;
18 import com.eviware.soapui.support.UISupport;
19
20 public class ModelItemIconAnimator implements Runnable
21 {
22 private final AbstractWsdlModelItem target;
23 private int index = 0;
24 private boolean stopped = true;
25 private boolean enabled = true;
26 private ImageIcon baseIcon;
27 private ImageIcon [] animateIcons;
28 private Thread iconAnimationThread;
29
30 public ModelItemIconAnimator(AbstractWsdlModelItem target, String baseIcon, String [] icons )
31 {
32 this.target = target;
33 this.baseIcon = UISupport.createImageIcon(baseIcon);
34
35 animateIcons = new ImageIcon[icons.length];
36
37 for( int c = 0; c < icons.length; c++ )
38 animateIcons[c] = UISupport.createImageIcon( icons[c] );
39 }
40
41 public void stop()
42 {
43 stopped = true;
44 }
45
46 public int getIndex()
47 {
48 return index;
49 }
50
51 public boolean isStopped()
52 {
53 return stopped;
54 }
55
56 public void start()
57 {
58 if( !enabled || iconAnimationThread != null )
59 return;
60
61 stopped = false;
62 iconAnimationThread = new Thread( this );
63 iconAnimationThread.start();
64 }
65
66 public ImageIcon getBaseIcon()
67 {
68 return baseIcon;
69 }
70
71 public ImageIcon getIcon()
72 {
73 if( !isStopped())
74 {
75 return animateIcons[getIndex()];
76 }
77
78 return baseIcon;
79 }
80
81 public void run()
82 {
83 while( !stopped )
84 {
85 try
86 {
87 if( stopped )
88 break;
89
90 index = index >= animateIcons.length-1 ? 0 : index+1;
91 target.setIcon( getIcon() );
92 Thread.sleep( 500 );
93 }
94 catch (InterruptedException e)
95 {
96 e.printStackTrace();
97 }
98 }
99
100 target.setIcon( getIcon() );
101 iconAnimationThread = null;
102 }
103
104 public AbstractWsdlModelItem getTarget()
105 {
106 return target;
107 }
108
109 public boolean isEnabled()
110 {
111 return enabled;
112 }
113
114 public void setEnabled(boolean enabled)
115 {
116 this.enabled = enabled;
117 if( !stopped )
118 stopped = enabled;
119 }
120 }