FileDocCategorySizeDatePackage
SWTSkinButtonUtility.javaAPI DocAzureus 3.0.3.43849Mon Sep 17 18:42:30 BST 2007com.aelitis.azureus.ui.swt.skin

SWTSkinButtonUtility

public class SWTSkinButtonUtility extends Object
Simple encapsulation of SWTSkinObjectContainer that provides typical button funtionality

Fields Summary
ArrayList
listeners
private final SWTSkinObject
skinObject
Constructors Summary
public SWTSkinButtonUtility(SWTSkinObject skinObject)

		this.skinObject = skinObject;
		Listener l = new Listener() {
			boolean bDownPressed;

			public void handleEvent(Event event) {
				if (event.type == SWT.MouseDown) {
					bDownPressed = true;
					return;
				} else if (!bDownPressed) {
					return;
				}

				bDownPressed = false;

				if (isDisabled()) {
					return;
				}

				for (Iterator iter = listeners.iterator(); iter.hasNext();) {
					ButtonListenerAdapter l = (ButtonListenerAdapter) iter.next();
					l.pressed(SWTSkinButtonUtility.this);
				}
			}
		};
		if (skinObject instanceof SWTSkinObjectContainer) {
			Utils.addListenerAndChildren((Composite) skinObject.getControl(),
					SWT.MouseUp, l);
			Utils.addListenerAndChildren((Composite) skinObject.getControl(),
					SWT.MouseDown, l);
		} else {
			skinObject.getControl().addListener(SWT.MouseUp, l);
			skinObject.getControl().addListener(SWT.MouseDown, l);
		}
	
Methods Summary
public voidaddSelectionListener(com.aelitis.azureus.ui.swt.skin.SWTSkinButtonUtility$ButtonListenerAdapter listener)

		if (listeners.contains(listener)) {
			return;
		}
		listeners.add(listener);
	
public SWTSkinObjectgetSkinObject()

		return skinObject;
	
public booleanisDisabled()

		return skinObject.getSuffix().equals("-disabled");
	
public voidsetDisabled(boolean disabled)

		String suffix = disabled ? "-disabled" : "";
		if (skinObject.getSuffix().equals(suffix)) {
			return;
		}
		skinObject.switchSuffix(suffix, 1, true);

		for (Iterator iter = listeners.iterator(); iter.hasNext();) {
			ButtonListenerAdapter l = (ButtonListenerAdapter) iter.next();
			l.disabledStateChanged(SWTSkinButtonUtility.this, disabled);
		}
	
public voidsetImage(java.lang.String id)

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				if (skinObject instanceof SWTSkinObjectImage) {
					SWTSkinObjectImage skinImageObject = (SWTSkinObjectImage) skinObject;
					skinImageObject.setImageByID(id);
				} else if (skinObject instanceof SWTSkinObjectContainer) {
					SWTSkinObject[] children = ((SWTSkinObjectContainer) skinObject).getChildren();
					if (children.length > 0 && children[0] instanceof SWTSkinObjectImage) {
						SWTSkinObjectImage skinImageObject = (SWTSkinObjectImage) children[0];
						skinImageObject.setImageByID(id);
					}
				}
				if (skinObject.isVisible()) {
					Utils.relayout(skinObject.getControl());
				}
			}
		});
	
public voidsetTextID(java.lang.String id)

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				if (skinObject instanceof SWTSkinObjectText) {
					SWTSkinObjectText skinTextObject = (SWTSkinObjectText) skinObject;
					skinTextObject.setTextID(id);
				} else if (skinObject instanceof SWTSkinObjectContainer) {
					SWTSkinObject[] children = ((SWTSkinObjectContainer) skinObject).getChildren();
					if (children.length > 0 && children[0] instanceof SWTSkinObjectText) {
						SWTSkinObjectText skinTextObject = (SWTSkinObjectText) children[0];
						skinTextObject.setTextID(id);
					}
				}
				Utils.relayout(skinObject.getControl());
			}
		});