001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.support;
014:
015: import javax.swing.ImageIcon;
016:
017: import com.eviware.soapui.SoapUI;
018: import com.eviware.soapui.impl.wsdl.AbstractWsdlModelItem;
019: import com.eviware.soapui.support.UISupport;
020:
021: /**
022: * Class to animate the icon of a ModelItem
023: *
024: * @author ole.matzura
025: */
026:
027: public class ModelItemIconAnimator implements Runnable {
028: private final AbstractWsdlModelItem target;
029: private int index = 0;
030: private boolean stopped = true;
031: private boolean enabled = true;
032: private ImageIcon baseIcon;
033: private ImageIcon[] animateIcons;
034: private Thread iconAnimationThread;
035:
036: public ModelItemIconAnimator(AbstractWsdlModelItem target,
037: String baseIcon, String[] icons) {
038: this .target = target;
039: this .baseIcon = UISupport.createImageIcon(baseIcon);
040:
041: animateIcons = new ImageIcon[icons.length];
042:
043: for (int c = 0; c < icons.length; c++)
044: animateIcons[c] = UISupport.createImageIcon(icons[c]);
045: }
046:
047: public void stop() {
048: stopped = true;
049: }
050:
051: public int getIndex() {
052: return index;
053: }
054:
055: public boolean isStopped() {
056: return stopped;
057: }
058:
059: public void start() {
060: if (!enabled || iconAnimationThread != null)
061: return;
062:
063: stopped = false;
064: iconAnimationThread = new Thread(this , target.getName()
065: + " ModelItemIconAnimator");
066: iconAnimationThread.start();
067: }
068:
069: public ImageIcon getBaseIcon() {
070: return baseIcon;
071: }
072:
073: public ImageIcon getIcon() {
074: if (!isStopped()) {
075: return animateIcons[getIndex()];
076: }
077:
078: return baseIcon;
079: }
080:
081: public void run() {
082: while (!stopped) {
083: try {
084: if (stopped)
085: break;
086:
087: index = index >= animateIcons.length - 1 ? 0
088: : index + 1;
089: target.setIcon(getIcon());
090: Thread.sleep(500);
091: } catch (InterruptedException e) {
092: SoapUI.logError(e);
093: }
094: }
095:
096: target.setIcon(getIcon());
097: iconAnimationThread = null;
098: }
099:
100: public AbstractWsdlModelItem getTarget() {
101: return target;
102: }
103:
104: public boolean isEnabled() {
105: return enabled;
106: }
107:
108: public void setEnabled(boolean enabled) {
109: this.enabled = enabled;
110: if (!stopped)
111: stopped = enabled;
112: }
113: }
|