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.SoapUI;
18 import com.eviware.soapui.impl.wsdl.AbstractWsdlModelItem;
19 import com.eviware.soapui.support.UISupport;
20
21 /***
22 * Class to animate the icon of a ModelItem
23 *
24 * @author ole.matzura
25 */
26
27 public class ModelItemIconAnimator implements Runnable
28 {
29 private final AbstractWsdlModelItem target;
30 private int index = 0;
31 private boolean stopped = true;
32 private boolean enabled = true;
33 private ImageIcon baseIcon;
34 private ImageIcon [] animateIcons;
35 private Thread iconAnimationThread;
36
37 public ModelItemIconAnimator(AbstractWsdlModelItem target, String baseIcon, String [] icons )
38 {
39 this.target = target;
40 this.baseIcon = UISupport.createImageIcon(baseIcon);
41
42 animateIcons = new ImageIcon[icons.length];
43
44 for( int c = 0; c < icons.length; c++ )
45 animateIcons[c] = UISupport.createImageIcon( icons[c] );
46 }
47
48 public void stop()
49 {
50 stopped = true;
51 }
52
53 public int getIndex()
54 {
55 return index;
56 }
57
58 public boolean isStopped()
59 {
60 return stopped;
61 }
62
63 public void start()
64 {
65 if( !enabled || iconAnimationThread != null )
66 return;
67
68 stopped = false;
69 iconAnimationThread = new Thread( this, target.getName() + " ModelItemIconAnimator" );
70 iconAnimationThread.start();
71 }
72
73 public ImageIcon getBaseIcon()
74 {
75 return baseIcon;
76 }
77
78 public ImageIcon getIcon()
79 {
80 if( !isStopped())
81 {
82 return animateIcons[getIndex()];
83 }
84
85 return baseIcon;
86 }
87
88 public void run()
89 {
90 while( !stopped )
91 {
92 try
93 {
94 if( stopped )
95 break;
96
97 index = index >= animateIcons.length-1 ? 0 : index+1;
98 target.setIcon( getIcon() );
99 Thread.sleep( 500 );
100 }
101 catch (InterruptedException e)
102 {
103 SoapUI.logError( e );
104 }
105 }
106
107 target.setIcon( getIcon() );
108 iconAnimationThread = null;
109 }
110
111 public AbstractWsdlModelItem getTarget()
112 {
113 return target;
114 }
115
116 public boolean isEnabled()
117 {
118 return enabled;
119 }
120
121 public void setEnabled(boolean enabled)
122 {
123 this.enabled = enabled;
124 if( !stopped )
125 stopped = enabled;
126 }
127 }