diff options
author | Raphael Moll <ralf@android.com> | 2011-04-29 09:29:40 -0700 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-04-29 09:29:40 -0700 |
commit | 2944133dbae6cbcd17408b38838070c18e0865e1 (patch) | |
tree | 15019002ad2e8a132121385fa8da605d6083c042 | |
parent | b16a1e4b68be419320148379e120f24bea76c9c6 (diff) | |
parent | 9e1748f533f9d25dcedb50f9464b36588eec686b (diff) | |
download | sdk-2944133dbae6cbcd17408b38838070c18e0865e1.zip sdk-2944133dbae6cbcd17408b38838070c18e0865e1.tar.gz sdk-2944133dbae6cbcd17408b38838070c18e0865e1.tar.bz2 |
Merge "Use SwtMenuBar in HierarchyViewer application."
-rw-r--r-- | ddms/app/README | 8 | ||||
-rwxr-xr-x | eclipse/scripts/create_hierarchyviewer_symlinks.sh | 7 | ||||
-rw-r--r-- | hierarchyviewer2/app/.classpath | 1 | ||||
-rw-r--r-- | hierarchyviewer2/app/Android.mk | 3 | ||||
-rwxr-xr-x | hierarchyviewer2/app/README | 69 | ||||
-rw-r--r-- | hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplication.java | 73 | ||||
-rw-r--r-- | swtmenubar/Android.mk | 5 | ||||
-rwxr-xr-x | swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCarbon.java | 3 | ||||
-rw-r--r-- | swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCocoa.java | 5 | ||||
-rw-r--r-- | swtmenubar/src/com/android/menubar/IMenuBarEnhancer.java | 6 | ||||
-rw-r--r-- | swtmenubar/src/com/android/menubar/MenuBarEnhancer.java | 139 |
11 files changed, 241 insertions, 78 deletions
diff --git a/ddms/app/README b/ddms/app/README index be0403c..3b7df9c 100644 --- a/ddms/app/README +++ b/ddms/app/README @@ -34,6 +34,14 @@ SWT depends on OSGI, so we'll also create an ANDROID_OSGI library for that. In order to compile the project: - Open Preferences > Java > Build Path > User Libraries +- Create a new user library named ANDROID_SWT +- Add the following 4 JAR files: + + - prebuild/<platform>/swt/swt.jar + - prebuilt/common/eclipse/org.eclipse.core.commands_3.*.jar + - prebuilt/common/eclipse/org.eclipse.equinox.common_3.*.jar + - prebuilt/common/eclipse/org.eclipse.jface_3.*.jar + - Create a new user library named ANDROID_OSGI - Add the following JAR file: diff --git a/eclipse/scripts/create_hierarchyviewer_symlinks.sh b/eclipse/scripts/create_hierarchyviewer_symlinks.sh index e0439ef..47dbe7f 100755 --- a/eclipse/scripts/create_hierarchyviewer_symlinks.sh +++ b/eclipse/scripts/create_hierarchyviewer_symlinks.sh @@ -60,10 +60,11 @@ DEST=$BASE/libs mkdir -p $DEST -LIBS="hierarchyviewerlib " +COPY_LIBS="hierarchyviewerlib" +ALL_LIBS="$COPY_LIBS swtmenubar" echo "make java libs ..." -make -j3 showcommands $LIBS || die "Hierarchy Viewer: Fail to build one of $LIBS." +make -j3 showcommands $ALL_LIBS || die "Hierarchy Viewer: Fail to build one of $ALL_LIBS." -for LIB in $LIBS; do +for LIB in $COPY_LIBS; do cpfile $DEST out/host/$PLATFORM/framework/$LIB.jar done diff --git a/hierarchyviewer2/app/.classpath b/hierarchyviewer2/app/.classpath index d75889a..c5a657c 100644 --- a/hierarchyviewer2/app/.classpath +++ b/hierarchyviewer2/app/.classpath @@ -7,5 +7,6 @@ <classpathentry combineaccessrules="false" kind="src" path="/ddmlib"/> <classpathentry combineaccessrules="false" kind="src" path="/ddmuilib"/> <classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/> + <classpathentry kind="var" path="ANDROID_OUT_FRAMEWORK/swtmenubar.jar" sourcepath="/ANDROID_SRC/sdk/swtmenubar/src"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/hierarchyviewer2/app/Android.mk b/hierarchyviewer2/app/Android.mk index d940403..0e00273 100644 --- a/hierarchyviewer2/app/Android.mk +++ b/hierarchyviewer2/app/Android.mk @@ -27,7 +27,8 @@ LOCAL_JAVA_LIBRARIES := \ swt \ org.eclipse.jface_3.4.2.M20090107-0800 \ org.eclipse.core.commands_3.4.0.I20080509-2000 \ - sdklib + sdklib \ + swtmenubar LOCAL_MODULE := hierarchyviewer2 diff --git a/hierarchyviewer2/app/README b/hierarchyviewer2/app/README new file mode 100755 index 0000000..5d33255 --- /dev/null +++ b/hierarchyviewer2/app/README @@ -0,0 +1,69 @@ +Using the Eclipse project HierarchyViewer +----------------------------------------- + +HierarchyViewer requires some external libraries to compile. +If you build HierarchyViewer using the makefile, you have nothing +to configure. However if you want to develop on HierarchyViewer +using Eclipse, you need to perform the following configuration. + + +------- +1- Projects required in Eclipse +------- + +To run HierarchyViewer from Eclipse, you need to import the following 5 projects: + + - sdk/hierarchyviewer2/app + - sdk/hierarchyviewer2/libs/hierarchyviewerlib/ + - sdk/ddms/libs/ddmlib + - sdk/ddms/libs/ddmuilib + - sdk/sdkmanager/libs/sdklib + + +------- +2- HierarchyViewer requires some SWT JARs to compile. +------- + +SWT is available in the tree under prebuild/<platform>/swt + +Because the build path cannot contain relative path that are not inside +the project directory, the .classpath file references a user library +called ANDROID_SWT. + +In order to compile the project: +- Open Preferences > Java > Build Path > User Libraries + +- Create a new user library named ANDROID_SWT +- Add the following 4 JAR files: + + - prebuild/<platform>/swt/swt.jar + - prebuilt/common/eclipse/org.eclipse.core.commands_3.*.jar + - prebuilt/common/eclipse/org.eclipse.equinox.common_3.*.jar + - prebuilt/common/eclipse/org.eclipse.jface_3.*.jar + + +------- +3- HierarchyViewer also requires the compiled SwtMenuBar library. +------- + +Build the swtmenubar library: +$ cd $TOP (top of Android tree) +$ . build/envsetup.sh && lunch sdk-eng +$ sdk/eclipse/scripts/create_sdkman_symlinks.sh + +Define a classpath variable in Eclipse: +- Open Preferences > Java > Build Path > Classpath Variables +- Create a new classpath variable named ANDROID_OUT_FRAMEWORK +- Set its folder value to <Android tree>/out/host/<platform>/framework +- Create a new classpath variable named ANDROID_SRC +- Set its folder value to <Android tree> + +You might need to clean the ddms project (Project > Clean...) after +you add the new classpath variable, otherwise previous errors might not +go away automatically. + +The ANDROID_SRC part should be optional. It allows you to have access to +the SwtMenuBar generic parts from the Java editor. + +-- +EOF diff --git a/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplication.java b/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplication.java index 3a0a0e9..54a5fd6 100644 --- a/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplication.java +++ b/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplication.java @@ -53,11 +53,15 @@ import com.android.hierarchyviewerlib.ui.PropertyViewer; import com.android.hierarchyviewerlib.ui.TreeView; import com.android.hierarchyviewerlib.ui.TreeViewControls; import com.android.hierarchyviewerlib.ui.TreeViewOverview; +import com.android.menubar.IMenuBarEnhancer; +import com.android.menubar.MenuBarEnhancer; +import com.android.menubar.IMenuBarEnhancer.MenuBarMode; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTException; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.events.SelectionEvent; @@ -81,6 +85,7 @@ import org.eclipse.swt.widgets.Shell; public class HierarchyViewerApplication extends ApplicationWindow { + private static final String APP_NAME = "Hierarchy Viewer"; private static final int INITIAL_WIDTH = 1024; private static final int INITIAL_HEIGHT = 768; @@ -148,7 +153,7 @@ public class HierarchyViewerApplication extends ApplicationWindow { @Override protected void configureShell(Shell shell) { super.configureShell(shell); - shell.setText("Hierarchy Viewer"); + shell.setText(APP_NAME); ImageLoader imageLoader = ImageLoader.getLoader(HierarchyViewerDirector.class); Image image = imageLoader.loadImage("sdk-hierarchyviewer-128.png", Display.getDefault()); //$NON-NLS-1$ shell.setImage(image); @@ -162,7 +167,14 @@ public class HierarchyViewerApplication extends ApplicationWindow { public void run() { setBlockOnOpen(true); - open(); + try { + open(); + } catch (SWTException e) { + // Ignore "widget disposed" errors after we closed. + if (!getShell().isDisposed()) { + throw e; + } + } TreeViewModel.getModel().removeTreeChangeListener(mTreeChangeListener); PixelPerfectModel.getModel().removeImageChangeListener(mImageChangeListener); @@ -581,12 +593,16 @@ public class HierarchyViewerApplication extends ApplicationWindow { MenuManager mm = getMenuBarManager(); mm.removeAll(); - String os = System.getProperty("os.name"); //$NON-NLS-1$ - if (os.startsWith("Mac OS") == false) { //$NON-NLS-1$ - MenuManager file = new MenuManager("&File"); + MenuManager file = new MenuManager("&File"); + IMenuBarEnhancer enhancer = MenuBarEnhancer.setupMenuManager( + APP_NAME, + getShell().getDisplay(), + file, + AboutAction.getAction(getShell()), + null /*preferencesAction*/, + QuitAction.getAction()); + if (enhancer.getMenuBarMode() == MenuBarMode.GENERIC) { mm.add(file); - - file.add(QuitAction.getAction()); } MenuManager device = new MenuManager("&Devices"); @@ -596,11 +612,6 @@ public class HierarchyViewerApplication extends ApplicationWindow { device.add(LoadViewHierarchyAction.getAction()); device.add(InspectScreenshotAction.getAction()); - MenuManager help = new MenuManager("&Help"); - mm.add(help); - - help.add(AboutAction.getAction(getShell())); - mm.updateAll(true); mDeviceViewButton.setSelection(true); @@ -626,12 +637,16 @@ public class HierarchyViewerApplication extends ApplicationWindow { MenuManager mm = getMenuBarManager(); mm.removeAll(); - String os = System.getProperty("os.name"); //$NON-NLS-1$ - if (os.startsWith("Mac OS") == false) { //$NON-NLS-1$ - MenuManager file = new MenuManager("&File"); + MenuManager file = new MenuManager("&File"); + IMenuBarEnhancer enhancer = MenuBarEnhancer.setupMenuManager( + APP_NAME, + getShell().getDisplay(), + file, + AboutAction.getAction(getShell()), + null /*preferencesAction*/, + QuitAction.getAction()); + if (enhancer.getMenuBarMode() == MenuBarMode.GENERIC) { mm.add(file); - - file.add(QuitAction.getAction()); } MenuManager treeViewMenu = new MenuManager("&Tree View"); @@ -646,11 +661,6 @@ public class HierarchyViewerApplication extends ApplicationWindow { treeViewMenu.add(InvalidateAction.getAction()); treeViewMenu.add(RequestLayoutAction.getAction()); - MenuManager help = new MenuManager("&Help"); - mm.add(help); - - help.add(AboutAction.getAction(getShell())); - mm.updateAll(true); mDeviceViewButton.setSelection(false); @@ -676,12 +686,16 @@ public class HierarchyViewerApplication extends ApplicationWindow { MenuManager mm = getMenuBarManager(); mm.removeAll(); - String os = System.getProperty("os.name"); //$NON-NLS-1$ - if (os.startsWith("Mac OS") == false) { //$NON-NLS-1$ - MenuManager file = new MenuManager("&File"); + MenuManager file = new MenuManager("&File"); + IMenuBarEnhancer enhancer = MenuBarEnhancer.setupMenuManager( + APP_NAME, + getShell().getDisplay(), + file, + AboutAction.getAction(getShell()), + null /*preferencesAction*/, + QuitAction.getAction()); + if (enhancer.getMenuBarMode() == MenuBarMode.GENERIC) { mm.add(file); - - file.add(QuitAction.getAction()); } MenuManager pixelPerfect = new MenuManager("&Pixel Perfect"); @@ -695,11 +709,6 @@ public class HierarchyViewerApplication extends ApplicationWindow { mm.add(pixelPerfect); - MenuManager help = new MenuManager("&Help"); - mm.add(help); - - help.add(AboutAction.getAction(getShell())); - mm.updateAll(true); mDeviceViewButton.setSelection(false); diff --git a/swtmenubar/Android.mk b/swtmenubar/Android.mk index 333684f..8167755 100644 --- a/swtmenubar/Android.mk +++ b/swtmenubar/Android.mk @@ -27,7 +27,10 @@ endif LOCAL_MODULE := swtmenubar LOCAL_MODULE_TAGS := optional -LOCAL_JAVA_LIBRARIES := swt +LOCAL_JAVA_LIBRARIES := \ + swt \ + org.eclipse.jface_3.4.2.M20090107-0800 + include $(BUILD_HOST_JAVA_LIBRARY) diff --git a/swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCarbon.java b/swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCarbon.java index eac3f30..45dacfb 100755 --- a/swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCarbon.java +++ b/swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCarbon.java @@ -44,9 +44,8 @@ public final class MenuBarEnhancerCarbon implements IMenuBarEnhancer { public void setupMenu( String appName, - Menu swtMenu, + Display display, final IMenuBarCallback callbacks) { - final Display display = swtMenu.getDisplay(); // Callback target Object target = new Object() { diff --git a/swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCocoa.java b/swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCocoa.java index cba2878..170603a 100644 --- a/swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCocoa.java +++ b/swtmenubar/src-darwin/com/android/menubar/internal/MenuBarEnhancerCocoa.java @@ -109,16 +109,15 @@ public class MenuBarEnhancerCocoa implements IMenuBarEnhancer { * given application name and links them to the callback. * * @param appName The application name. - * @param swtMenu The tools menu. Not used here. + * @param display The SWT display. Must not be null. * @param callbacks The callbacks invoked by the menus. */ public void setupMenu( String appName, - Menu swtMenu, + Display display, IMenuBarCallback callbacks) { mAppName = appName; - final Display display = swtMenu.getDisplay(); // This is our callback object whose 'actionProc' method will be called // when the About or Preferences menuItem is invoked. diff --git a/swtmenubar/src/com/android/menubar/IMenuBarEnhancer.java b/swtmenubar/src/com/android/menubar/IMenuBarEnhancer.java index 560701b..d835bd6 100644 --- a/swtmenubar/src/com/android/menubar/IMenuBarEnhancer.java +++ b/swtmenubar/src/com/android/menubar/IMenuBarEnhancer.java @@ -16,6 +16,7 @@ package com.android.menubar; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Menu; @@ -61,13 +62,12 @@ public interface IMenuBarEnhancer { * {@link MenuBarEnhancer#setupMenu} should be used instead. * * @param appName Name used for the About menu item and similar. Must not be null. - * @param swtMenu For non-mac platform this is the menu where the "About" and - * the "Preferences" menu items are created. Must not be null. + * @param display The SWT display. Must not be null. * @param callbacks Callbacks called when "About" and "Preferences" menu items are invoked. * Must not be null. */ public void setupMenu( String appName, - Menu swtMenu, + Display display, IMenuBarCallback callbacks); } diff --git a/swtmenubar/src/com/android/menubar/MenuBarEnhancer.java b/swtmenubar/src/com/android/menubar/MenuBarEnhancer.java index 04fcab0..eb3e817 100644 --- a/swtmenubar/src/com/android/menubar/MenuBarEnhancer.java +++ b/swtmenubar/src/com/android/menubar/MenuBarEnhancer.java @@ -16,9 +16,13 @@ package com.android.menubar; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.Separator; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; @@ -57,36 +61,12 @@ public final class MenuBarEnhancer { */ public static IMenuBarEnhancer setupMenu( String appName, - Menu swtMenu, + final Menu swtMenu, IMenuBarCallback callbacks) { - IMenuBarEnhancer enhancer = null; - String p = SWT.getPlatform(); - String className = null; - if ("carbon".equals(p)) { //$NON-NLS-1$ - className = "com.android.menubar.internal.MenuBarEnhancerCarbon"; //$NON-NLS-1$ - } else if ("cocoa".equals(p)) { //$NON-NLS-1$ - className = "com.android.menubar.internal.MenuBarEnhancerCocoa"; //$NON-NLS-1$ - } - - if (System.getenv("DEBUG_SWTMENUBAR") != null) { - callbacks.printError("DEBUG SwtMenuBar: SWT=%1$s, class=%2$s", p, className); - } + IMenuBarEnhancer enhancer = getEnhancer(callbacks); - if (className != null) { - try { - Class<?> clazz = Class.forName(className); - enhancer = (IMenuBarEnhancer) clazz.newInstance(); - } catch (Exception e) { - // Log an error and fallback on the default implementation. - callbacks.printError( - "Failed to instantiate %1$s: %2$s", //$NON-NLS-1$ - className, - e.toString()); - } - } - - // Default implementation for other platforms + // Default implementation for generic platforms if (enhancer == null) { enhancer = new IMenuBarEnhancer() { @@ -96,17 +76,17 @@ public final class MenuBarEnhancer { public void setupMenu( String appName, - Menu menu, + Display display, final IMenuBarCallback callbacks) { - if (menu.getItemCount() > 0) { - new MenuItem(menu, SWT.SEPARATOR); + if (swtMenu.getItemCount() > 0) { + new MenuItem(swtMenu, SWT.SEPARATOR); } // Note: we use "Preferences" on Mac and "Options" on Windows/Linux. - final MenuItem pref = new MenuItem(menu, SWT.NONE); + final MenuItem pref = new MenuItem(swtMenu, SWT.NONE); pref.setText("&Options..."); - final MenuItem about = new MenuItem(menu, SWT.NONE); + final MenuItem about = new MenuItem(swtMenu, SWT.NONE); about.setText("&About..."); pref.addSelectionListener(new SelectionAdapter() { @@ -138,8 +118,101 @@ public final class MenuBarEnhancer { }; } - enhancer.setupMenu(appName, swtMenu, callbacks); + enhancer.setupMenu(appName, swtMenu.getDisplay(), callbacks); + return enhancer; + } + + + public static IMenuBarEnhancer setupMenuManager( + String appName, + Display display, + final IMenuManager menuManager, + final IAction aboutAction, + final IAction preferencesAction, + final IAction quitAction) { + + IMenuBarCallback callbacks = new IMenuBarCallback() { + public void printError(String format, Object... args) { + System.err.println(String.format(format, args)); + } + + public void onPreferencesMenuSelected() { + if (preferencesAction != null) { + preferencesAction.run(); + } + } + + public void onAboutMenuSelected() { + if (aboutAction != null) { + aboutAction.run(); + } + } + }; + + IMenuBarEnhancer enhancer = getEnhancer(callbacks); + + // Default implementation for generic platforms + if (enhancer == null) { + enhancer = new IMenuBarEnhancer() { + + public MenuBarMode getMenuBarMode() { + return MenuBarMode.GENERIC; + } + + public void setupMenu( + String appName, + Display display, + final IMenuBarCallback callbacks) { + if (!menuManager.isEmpty()) { + menuManager.add(new Separator()); + } + + if (aboutAction != null) { + menuManager.add(aboutAction); + } + if (preferencesAction != null) { + menuManager.add(preferencesAction); + } + if (quitAction != null) { + if (aboutAction != null || preferencesAction != null) { + menuManager.add(new Separator()); + } + menuManager.add(quitAction); + } + } + }; + } + + enhancer.setupMenu(appName, display, callbacks); return enhancer; } + private static IMenuBarEnhancer getEnhancer(IMenuBarCallback callbacks) { + IMenuBarEnhancer enhancer = null; + String p = SWT.getPlatform(); + String className = null; + if ("carbon".equals(p)) { //$NON-NLS-1$ + className = "com.android.menubar.internal.MenuBarEnhancerCarbon"; //$NON-NLS-1$ + } else if ("cocoa".equals(p)) { //$NON-NLS-1$ + className = "com.android.menubar.internal.MenuBarEnhancerCocoa"; //$NON-NLS-1$ + } + + if (System.getenv("DEBUG_SWTMENUBAR") != null) { + callbacks.printError("DEBUG SwtMenuBar: SWT=%1$s, class=%2$s", p, className); + } + + if (className != null) { + try { + Class<?> clazz = Class.forName(className); + enhancer = (IMenuBarEnhancer) clazz.newInstance(); + } catch (Exception e) { + // Log an error and fallback on the default implementation. + callbacks.printError( + "Failed to instantiate %1$s: %2$s", //$NON-NLS-1$ + className, + e.toString()); + } + } + return enhancer; + } } |