FileDocCategorySizeDatePackage
SWTSkinObjectBasic.javaAPI DocAzureus 3.0.3.410988Mon Oct 01 14:37:54 BST 2007com.aelitis.azureus.ui.swt.skin

SWTSkinObjectBasic

public class SWTSkinObjectBasic extends Object implements SWTSkinObject
author
TuxPaper
created
Jun 12, 2006

Fields Summary
protected org.eclipse.swt.widgets.Control
control
protected String
type
protected String
sConfigID
protected SWTBGImagePainter
painter
protected SWTSkinProperties
properties
protected String
sID
protected SWTSkinObject
parent
protected SWTSkin
skin
protected String[]
suffixes
protected ArrayList
listeners
protected AEMonitor
listeners_mon
private String
sViewID
Constructors Summary
public SWTSkinObjectBasic(SWTSkin skin, SWTSkinProperties properties, org.eclipse.swt.widgets.Control control, String sID, String sConfigID, String type, SWTSkinObject parent)

param
properties TODO


	    	 
	    
			       
			  
		this(skin, properties, sID, sConfigID, type, parent);
		setControl(control);
	
public SWTSkinObjectBasic(SWTSkin skin, SWTSkinProperties properties, String sID, String sConfigID, String type, SWTSkinObject parent)

		this.skin = skin;
		this.properties = properties;
		this.sConfigID = sConfigID;
		this.sID = sID;
		this.type = type;
		this.parent = parent;
	
Methods Summary
public voidaddListener(SWTSkinObjectListener listener)

		listeners_mon.enter();
		try {
			listeners.add(listener);
		} finally {
			listeners_mon.exit();
		}
	
public voiddispose()

		if (control != null && !control.isDisposed()) {
			control.dispose();
		}
	
public booleanequals(java.lang.Object obj)

		if (obj instanceof SWTSkinObject) {
			SWTSkinObject skinObject = (SWTSkinObject) obj;
			boolean bEquals = skinObject.getSkinObjectID().equals(sID);
			if (parent != null) {
				return bEquals && parent.equals(skinObject.getParent());
			}
			return bEquals;
		}

		return super.equals(obj);
	
public java.lang.StringgetConfigID()

		return sConfigID;
	
public org.eclipse.swt.widgets.ControlgetControl()

		return control;
	
public SWTSkinObjectListener[]getListeners()

		return (SWTSkinObjectListener[]) listeners.toArray(new SWTSkinObjectListener[0]);
	
public SWTSkinObjectgetParent()

		return parent;
	
public SWTSkinPropertiesgetProperties()

return
the properties

		return properties;
	
public SWTSkingetSkin()

		return skin;
	
public java.lang.StringgetSkinObjectID()

		return sID;
	
public java.lang.StringgetSuffix()

		String suffix = "";
		for (int i = 0; i < suffixes.length; i++) {
			suffix += suffixes[i];
		}
		return suffix;
	
public java.lang.StringgetType()

		return type;
	
public java.lang.StringgetViewID()

		return sViewID;
	
public booleanisDisposed()

		if (control == null) {
			return false;
		}

		return Utils.execSWTThreadWithBool("isDisposed", new AERunnableBoolean() {
			public boolean runSupport() {
				return control == null || control.isDisposed();
			}
		}, 30000);
	
public booleanisVisible()

		return Utils.execSWTThreadWithBool("isVisible", new AERunnableBoolean() {
		
			public boolean runSupport() {
				return control != null && !control.isDisposed() && control.isVisible();
			}
		
		}, 30000);
	
public voidremoveListener(SWTSkinObjectListener listener)

		listeners_mon.enter();
		try {
			listeners.remove(listener);
		} finally {
			listeners_mon.exit();
		}
	
public voidsetBackground(java.lang.String sConfigID, java.lang.String sSuffix)

		Image imageBG;
		Image imageBGLeft;
		Image imageBGRight;

		if (sConfigID == null) {
			return;
		}

		ImageLoader imageLoader = skin.getImageLoader(properties);
		Image[] images = imageLoader.getImages(sConfigID + sSuffix);
		if (images.length == 1 && ImageLoader.isRealImage(images[0])) {
			imageBG = images[0];
			imageBGLeft = imageLoader.getImage(sConfigID + sSuffix + "-left");
			imageBGRight = imageLoader.getImage(sConfigID + sSuffix + "-right");
		} else if (images.length == 3 && ImageLoader.isRealImage(images[2])) {
			imageBGLeft = images[0];
			imageBG = images[1];
			imageBGRight = images[2];
		} else {
			return;
		}

		if (painter == null) {
			//control.setBackgroundImage doesn't handle transparency!
			//control.setBackgroundImage(image);

			// Workaround: create our own image with shell's background
			// for "transparent" area.  Doesn't allow control's image to show
			// through.  To do that, we'd have to walk up the tree until we 
			// found a composite with an image
			//control.setBackgroundMode(SWT.INHERIT_NONE);
			//control.setBackgroundImage(imageBG);

			String sTileMode = properties.getStringValue(sConfigID + ".drawmode");
			int tileMode = SWTSkinUtils.getTileMode(sTileMode);
			painter = new SWTBGImagePainter(control, imageBGLeft, imageBGRight,
					imageBG, tileMode);
		} else {
			//System.out.println("setImage " + sConfigID + "  " + sSuffix);
			painter.setImage(imageBGLeft, imageBGRight, imageBG);
		}

		// XXX Is this needed?  It causes flicker and slows things down.
		//     Maybe a redraw instead (if anything at all)?
		//control.update();
	
public voidsetControl(org.eclipse.swt.widgets.Control control)

		this.control = control;
		control.setData("ConfigID", sConfigID);
		control.setData("SkinObject", this);

		SWTSkinUtils.addMouseImageChangeListeners(control);
		switchSuffix("", 1, false);

		// setvisible is one time only
		if (properties.getStringValue(sConfigID + ".visible", "true").equalsIgnoreCase(
				"false")) {
			setVisible(false);
		}
	
public voidsetDefaultVisibility()

		if (sConfigID == null) {
			return;
		}

		setVisible(properties.getStringValue(sConfigID + ".visible", "true").equalsIgnoreCase(
				"true"));
	
public voidsetProperties(SWTSkinProperties skinProperties)

		this.properties = skinProperties;
	
public voidsetTooltipAndChildren(org.eclipse.swt.widgets.Control c, java.lang.String sToolTip)

		c.setToolTipText(sToolTip);
		if (c instanceof Composite) {
			Control[] children = ((Composite) c).getChildren();
			for (int i = 0; i < children.length; i++) {
				Control control = children[i];
				setTooltipAndChildren(control, sToolTip);
			}
		}
	
protected voidsetViewID(java.lang.String viewID)

		sViewID = viewID;
	
public voidsetVisible(boolean visible)

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				if (control != null && !control.isDisposed()) {
					control.setVisible(visible);
				}
				triggerListeners(visible ? SWTSkinObjectListener.EVENT_SHOW
						: SWTSkinObjectListener.EVENT_HIDE);
			}
		});
	
public java.lang.StringswitchSuffix(java.lang.String suffix, int level, boolean walkUp)

		if (walkUp) {
			SWTSkinObject parentSkinObject = parent;
			SWTSkinObject skinObject = this;

			// Move up the tree until propogation stops
			while ((parentSkinObject instanceof SWTSkinObjectContainer)
					&& ((SWTSkinObjectContainer) parentSkinObject).getPropogation()) {
				skinObject = parentSkinObject;
				parentSkinObject = parentSkinObject.getParent();
			}

			if (skinObject != this) {
				//System.out.println(sConfigID + suffix + "; walkup");

				skinObject.switchSuffix(suffix, level, false);
				return null;
			}
		}

		//System.out.println(SystemTime.getCurrentTime() + ": " + this + suffix + "; switchy");
		if (suffixes == null) {
			suffixes = new String[level];
		} else if (suffixes.length < level) {
			String[] newSuffixes = new String[level];
			System.arraycopy(suffixes, 0, newSuffixes, 0, suffixes.length);
			suffixes = newSuffixes;
		}
		suffixes[level - 1] = suffix;

		suffix = getSuffix();

		if (sConfigID == null || control == null || control.isDisposed()) {
			return suffix;
		}

		final String sSuffix = suffix;

		Utils.execSWTThread(new AERunnable() {

			public void runSupport() {
				if (control == null || control.isDisposed()) {
					return;
				}

				Color color = properties.getColor(sConfigID + ".color" + sSuffix);
				if (color != null) {
					control.setBackground(color);
				}

				Color fg = properties.getColor(sConfigID + ".fgcolor" + sSuffix);
				if (fg != null) {
					control.setForeground(fg);
				}

				setBackground(sConfigID + ".background", sSuffix);

				String sCursor = properties.getStringValue(sConfigID + ".cursor");
				if (sCursor != null && sCursor.length() > 0) {
					if (sCursor.equalsIgnoreCase("hand")) {
						control.addListener(SWT.MouseEnter,
								skin.getHandCursorListener(control.getDisplay()));
						control.addListener(SWT.MouseExit,
								skin.getHandCursorListener(control.getDisplay()));
					}
				}

				String sTooltip = properties.getStringValue(sConfigID + ".tooltip"
						+ sSuffix);
				if (sTooltip != null) {
					setTooltipAndChildren(control, sTooltip);
				}

			}

		});
		return suffix;
	
public java.lang.StringtoString()

		String s = "SWTSkinObjectBasic {" + sID;

		if (!sID.equals(sConfigID)) {
			s += "/" + sConfigID;
		}

		s += ", " + type + "; parent="
				+ ((parent == null) ? null : parent.getSkinObjectID() + "}");

		return s;
	
public voidtriggerListeners(int eventType)

		triggerListeners(eventType, null);
	
public voidtriggerListeners(int eventType, java.lang.Object params)

		// process listeners added locally
		listeners_mon.enter();
		try {
			for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
				try {
					SWTSkinObjectListener l = (SWTSkinObjectListener) iterator.next();
					l.eventOccured(this, eventType, params);
				} catch (Exception e) {
					Debug.out("Skin Event " + SWTSkinObjectListener.NAMES[eventType]
							+ " caused an error for listener added locally", e);
				}
			}
		} finally {
			listeners_mon.exit();
		}

		// process listeners added to skin
		SWTSkinObjectListener[] listeners = skin.getSkinObjectListeners(sViewID);
		for (int i = 0; i < listeners.length; i++) {
			try {
				SWTSkinObjectListener l = listeners[i];
				l.eventOccured(this, eventType, params);
			} catch (Exception e) {
				Debug.out("Skin Event " + SWTSkinObjectListener.NAMES[eventType]
						+ " caused an error for listener added to skin", e);
			}
		}