FileDocCategorySizeDatePackage
UISwitcherUtil.javaAPI DocAzureus 3.0.3.44926Fri Sep 07 12:52:16 BST 2007org.gudy.azureus2.ui.swt

UISwitcherUtil

public class UISwitcherUtil extends Object
author
TuxPaper
created
Mar 21, 2007

Fields Summary
private static boolean
NOT_GOOD_ENOUGH_FOR_AZ2_USERS_YET
public static ArrayList
listeners
public static String
lastUI
Constructors Summary
Methods Summary
public static java.lang.String_openSwitcherWindow(boolean bForceAsk)

		Class uiswClass = null;
		try {
			uiswClass = Class.forName("com.aelitis.azureus.ui.swt.shells.uiswitcher.UISwitcherWindow");
		} catch (ClassNotFoundException e1) {
		}
		if (uiswClass == null) {
			return "az2";
		}

		if (!bForceAsk) {
			String forceUI = System.getProperty("force.ui");
			if (forceUI != null) {
				COConfigurationManager.setParameter("ui", forceUI);
				return forceUI;
			}

			boolean asked = COConfigurationManager.getBooleanParameter("ui.asked",
					false);

			if (asked || COConfigurationManager.hasParameter("ui", true)) {
				return COConfigurationManager.getStringParameter("ui", "az3");
			}

			// Never auto-ask people who never have had 2.x, because they'd be scared
			// and cry at the advanced coolness of the az2 ui
			String sFirstVersion = COConfigurationManager.getStringParameter("First Recorded Version");
			if (Constants.compareVersions(sFirstVersion, "3.0.0.0") >= 0) {
				COConfigurationManager.setParameter("ui", "az3");
				return "az3";
			}

			// Short Circuit: We don't want to ask az2 users yet
			if (NOT_GOOD_ENOUGH_FOR_AZ2_USERS_YET) {
				COConfigurationManager.setParameter("ui", "az2");
				return "az2";
			}
		}

		// either !asked or forceAsked at this point

		try {

			final int[] result = {
				-1
			};

			final Class fuiswClass = uiswClass;

			Utils.execSWTThread(new AERunnable() {
				public void runSupport() {
					try {
						final Constructor constructor = fuiswClass.getConstructor(new Class[] {});

						Object object = constructor.newInstance(new Object[] {});

						Method method = fuiswClass.getMethod("open", new Class[] {});

						Object resultObj = method.invoke(object, new Object[] {});

						if (resultObj instanceof Number) {
							result[0] = ((Number) resultObj).intValue();
						}
					} catch (Exception e) {
						Debug.printStackTrace(e);
					}
				}
			}, false);

			if (result[0] == 0) {
				// Full AZ3UI
				COConfigurationManager.setParameter("ui", "az3");
				COConfigurationManager.setParameter("v3.Start Advanced", false);
			} else if (result[0] == 1) {
				// AZ3UI w/Advanced view default
				COConfigurationManager.setParameter("ui", "az3");
				COConfigurationManager.setParameter("v3.Start Advanced", true);
			} else if (result[0] == 2) {
				COConfigurationManager.setParameter("ui", "az2");
			}

			if (result[0] != -1) {
				COConfigurationManager.setParameter("ui.asked", true);
			}
		} catch (Exception e) {
			Debug.printStackTrace(e);
		}

		return COConfigurationManager.getStringParameter("ui");
	
public static voidaddListener(UISwitcherListener l)

	
	     
		listeners.add(l);
		if (lastUI != null) {
			triggerListeners(lastUI);
		}
	
public static booleanisAZ3Avail()

		Class uiswClass = null;
		try {
			uiswClass = Class.forName("com.aelitis.azureus.ui.swt.shells.uiswitcher.UISwitcherWindow");
			return true;
		} catch (ClassNotFoundException e1) {
		}
		return false;
	
public static java.lang.StringopenSwitcherWindow(boolean bForceAsk)

		lastUI = _openSwitcherWindow(bForceAsk);
		triggerListeners(lastUI);
		return lastUI;
	
public static voidremoveListener(UISwitcherListener l)

		listeners.remove(l);
	
private static voidtriggerListeners(java.lang.String ui)

		Object[] array = listeners.toArray();
		for (int i = 0; i < array.length; i++) {
			UISwitcherListener l = (UISwitcherListener) array[i];
			l.uiSwitched(ui);
		}