FileDocCategorySizeDatePackage
UIUpdaterImpl.javaAPI DocAzureus 3.0.3.44137Thu Mar 01 23:47:32 GMT 2007com.aelitis.azureus.ui.swt.utils

UIUpdaterImpl

public class UIUpdaterImpl extends AEThread implements org.gudy.azureus2.core3.config.ParameterListener, UIUpdater
author
TuxPaper

Fields Summary
private static final org.gudy.azureus2.core3.logging.LogIDs
LOGID
private static String
CFG_REFRESH_INTERVAL
private int
iWaitTime
private boolean
finished
private boolean
refreshed
private ArrayList
updateables
private AEMonitor
updateables_mon
Constructors Summary
public UIUpdaterImpl()


	  
		super("UI Updater");
		setDaemon(true);

		COConfigurationManager.addAndFireParameterListener(CFG_REFRESH_INTERVAL,
				this);
	
Methods Summary
public voidaddUpdater(UIUpdatable updateable)

		updateables_mon.enter();
		try {
			if (!updateables.contains(updateable)) {
				updateables.add(updateable);
			}
		} finally {
			updateables_mon.exit();
		}
	
public voidparameterChanged(java.lang.String parameterName)

		iWaitTime = COConfigurationManager.getIntParameter(CFG_REFRESH_INTERVAL);
	
public voidremoveUpdater(UIUpdatable updateable)

		updateables_mon.enter();
		try {
			updateables.remove(updateable);
		} finally {
			updateables_mon.exit();
		}
	
public voidrunSupport()

		while (!finished) {
			if (refreshed) {
				refreshed = false;
				if (!Utils.execSWTThread(new AERunnable() {
					public void runSupport() {
						try {
							update();
						} catch (Exception e) {
							Logger.log(new LogEvent(LOGID,
									"Error while trying to update GUI", e));
						}

						refreshed = true;
					}
				})) {
					refreshed = true;
				}
			}

			try {
				Thread.sleep(iWaitTime);
			} catch (Exception e) {
				Debug.printStackTrace(e);
			}
		}
	
public voidstopIt()

		finished = true;
		COConfigurationManager.removeParameterListener(CFG_REFRESH_INTERVAL, this);
	
private voidupdate()

		Object[] updateablesArray = updateables.toArray();
		for (int i = 0; i < updateablesArray.length; i++) {
			if (!(updateablesArray[i] instanceof UIUpdatable)) {
				continue;
			}

			if (SWTThread.getInstance().getDisplay().isDisposed()) {
				return;
			}

			UIUpdatable updateable = (UIUpdatable) updateablesArray[i];
			try {
				updateable.updateUI();
			} catch (Exception e) {
				Logger.log(new LogEvent(LOGID, "Error while trying to update GUI "
						+ updateable.getUpdateUIName(), e));
			}
		}