FileDocCategorySizeDatePackage
SWTSkinTabSet.javaAPI DocAzureus 3.0.3.47858Fri Jun 08 16:36:44 BST 2007com.aelitis.azureus.ui.swt.skin

SWTSkinTabSet

public class SWTSkinTabSet extends Object
author
TuxPaper
created
Jun 8, 2006

Fields Summary
private Listener
tabMouseListener
private final SWTSkin
skin
private final SWTSkinProperties
skinProperties
private final String
sID
private SWTSkinObjectTab
activeTab
private List
tabs
List of SWTSKinObjectTab
private ArrayList
listeners
Constructors Summary
public SWTSkinTabSet(SWTSkin skin, String sID)


	// XXX Do we need to pass in SkinProperties in case of cloning?
	     
		this.sID = sID;
		this.skin = skin;
		skinProperties = skin.getSkinProperties();
		tabs = new ArrayList();
	
Methods Summary
public voidaddListener(SWTSkinTabSetListener listener)

		listeners.add(listener);
	
private voidaddMouseListener(SWTSkinObject tab, Control control)

		if (tabMouseListener == null) {
			tabMouseListener = new Listener() {
				boolean bDownPressed = false;

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

					bDownPressed = false;

					Control control = (Control) event.widget;
					setActiveTab((SWTSkinObjectTab) control.getData("Tab"), true);
				}
			};
		}

		control.setData("Tab", tab);
		control.addListener(SWT.MouseUp, tabMouseListener);
		control.addListener(SWT.MouseDown, tabMouseListener);

		if (control instanceof Composite) {
			Control[] children = ((Composite) control).getChildren();
			for (int i = 0; i < children.length; i++) {
				addMouseListener(tab, children[i]);
			}
		}
	
public voidaddTab(SWTSkinObjectTab tab)

		tabs.add(tab);
		tab.setTabset(this);

		//System.out.println("AddTab for " + sID + ": " + tab.getSkinObjectID());
		addMouseListener(tab, tab.getControl());
		if (tabs.size() == 1) {
			//			activeTab = tab;
			//			setTabVisible(tab, true, null);
			setTabVisible(tab, false, tab.getActiveWidgets());
		} else {
			setTabVisible(tab, false, tab.getActiveWidgets());
		}
	
public voidclean()

		if (tabs.size() > 0) {
			for (int i = tabs.size() - 1; i >= 0; i--) {
				SWTSkinObjectTab tab = (SWTSkinObjectTab) tabs.get(i);
				setTabVisible(tab, false, null);
				if (i == 0) {
					setActiveTab(tab);
				}
			}
		}
	
public SWTSkinObjectTabgetActiveTab()

		return activeTab;
	
public java.lang.StringgetID()

		return sID;
	
public SWTSkinObjectTabgetTab(java.lang.String sID)

		for (int i = 0; i < tabs.size(); i++) {
			SWTSkinObjectTab tab = (SWTSkinObjectTab) tabs.get(i);
			String sTabID = tab.getSkinObjectID();

			if (sTabID.equals(sID)) {
				return tab;
			}
		}

		return null;
	
public static java.lang.StringgetTabSetID(SWTSkin skin, SWTSkinObject skinObject, java.lang.String sTemplateKey)

		String[] templateInfo = getTemplateInfo(skin, skinObject, sTemplateKey);
		if (templateInfo != null && templateInfo.length > 1) {
			return templateInfo[1];
		}
		return null;
	
public SWTSkinObjectTab[]getTabs()

		return (SWTSkinObjectTab[]) tabs.toArray(new SWTSkinObjectTab[0]);
	
protected static java.lang.StringgetTemplateID(SWTSkin skin, SWTSkinObject skinObject, java.lang.String sTemplateKey)

		String[] templateInfo = getTemplateInfo(skin, skinObject, sTemplateKey);
		if (templateInfo != null) {
			return templateInfo[0];
		}
		return null;
	
protected static java.lang.String[]getTemplateInfo(SWTSkin skin, SWTSkinObject skinObject, java.lang.String sTemplateKey)

		SWTSkinProperties skinProperties = skin.getSkinProperties();
		String sID = skinObject.getConfigID() + ".view.template." + sTemplateKey;
		return skinProperties.getStringArray(sID);
	
private booleanhasSkinBrowser(SWTSkinObject skinObject)

		if (skinObject instanceof SWTSkinObjectContainer) {
			SWTSkinObject[] children = ((SWTSkinObjectContainer) skinObject).getChildren();
			for (int i = 0; i < children.length; i++) {
				SWTSkinObject object = children[i];
				if (hasSkinBrowser(object)) {
					return true;
				}
			}
		}
		return (skinObject instanceof SWTSkinObjectBrowser);
	
public booleansetActiveTab(java.lang.String sID)

		for (int i = 0; i < tabs.size(); i++) {
			SWTSkinObject tab = (SWTSkinObject) tabs.get(i);
			if (tab instanceof SWTSkinObjectTab) {
				String sTabID = tab.getSkinObjectID();

				if (sTabID.equals(sID)) {
					setActiveTab((SWTSkinObjectTab) tab);
					return true;
				}
			}
		}

		return false;
	
public voidsetActiveTab(SWTSkinObjectTab newTab)

		setActiveTab(newTab, false);
	
private voidsetActiveTab(SWTSkinObjectTab newTab, boolean bEvenIfSame)

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				// Don't exit early if we are already on tab.  We want to be notified if
				// the user clicks on the tab again (for example, for page refreshing)
				if (!tabs.contains(newTab)) {
					System.err.println("No contain in " + sID + ": " + newTab);
					return;
				}

				String sOldID = activeTab == null ? "" : activeTab.getSkinObjectID();

				SWTSkinObject[] objects = setTabVisible(newTab, true, null);
				if (newTab != activeTab) {
					if (activeTab != null) {
						setTabVisible(activeTab, false, objects);
					}

					activeTab = newTab;
				} else if (!bEvenIfSame) {
					return;
				}

				String sConfigID = activeTab.getConfigID();
				String sNewID = activeTab.getSkinObjectID();

				SWTSkinObject parent = skin.getSkinObject(skinProperties.getStringValue(sConfigID
						+ ".activate"));
				if (parent != null) {
					parent.getControl().setFocus();
				}

				if (org.gudy.azureus2.core3.util.Constants.isOSX) {
					boolean bHasSkinBrowser = false;
					SWTSkinObject[] activeWidgets = activeTab.getActiveWidgets();
					for (int i = 0; i < activeWidgets.length; i++) {
						SWTSkinObject skinObject = activeWidgets[i];
						if (hasSkinBrowser(skinObject)) {
							bHasSkinBrowser = true;
							break;
						}
					}

					if (bHasSkinBrowser) {
						Shell shell = activeTab.getControl().getShell();
						Point size = shell.getSize();
						size.x -= 1;
						shell.setSize(size);
						size.x += 1;
						shell.setSize(size);
					}
				}

				triggerChangeListener(sOldID, sNewID);
			}
		});
	
private SWTSkinObject[]setTabVisible(SWTSkinObjectTab tab, boolean visible, SWTSkinObject[] skipObjects)

		String sSkinID = tab.getSkinObjectID();

		SWTSkinObject swtObject = skin.getSkinObjectByID(sSkinID);
		if (swtObject == null) {
			return null;
		}

		String suffix = visible ? "-selected" : "";

		swtObject.switchSuffix(suffix, 1, true);

		tab.triggerListeners(SWTSkinObjectListener.EVENT_SELECT);

		SWTSkinObject[] activeWidgets = tab.getActiveWidgets();
		for (int i = 0; i < activeWidgets.length; i++) {
			SWTSkinObject skinObject = activeWidgets[i];
			boolean ok = true;
			if (skipObjects != null) {
				for (int j = 0; j < skipObjects.length; j++) {
					if (skinObject.equals(skipObjects[j])) {
						ok = false;
						break;
					}
				}
			}

			if (ok) {
				if (visible) {
  				skinObject.setDefaultVisibility();
				} else {
					skinObject.setVisible(visible);
				}
				//System.out.println(((visible ? "show" : "hide") + " " + skinObject) + Debug.getCompressedStackTrace());
			}
		}

		return activeWidgets;
	
private voidtriggerChangeListener(java.lang.String oldID, java.lang.String newID)

param
oldID
param
newID

		for (Iterator iter = listeners.iterator(); iter.hasNext();) {
			try {
				SWTSkinTabSetListener l = (SWTSkinTabSetListener) iter.next();
				l.tabChanged(this, oldID, newID);
			} catch (Exception e) {
				Debug.printStackTrace(e);
			}
		}