From f2eac4fc75945b259e26cb9fcaf57c3ddc7d52a2 Mon Sep 17 00:00:00 2001 From: "munkyu.im" Date: Tue, 3 Dec 2013 15:59:37 +0900 Subject: [PATCH] menu: remove preferences and about menu They are default swt menu and do not have handler. They are unnecessary. so remove them. Change-Id: I765e8feb3c235bb898a5f48b59090995a5b8560d Signed-off-by: munkyu.im --- .../tizen/emulator/skin/EmulatorSkinMain.java | 12 +- .../tizen/emulator/skin/util/CocoaUtil.java | 106 ++++++++++++++++++ 2 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 tizen/src/skin/client/src/org/tizen/emulator/skin/util/CocoaUtil.java diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java index 78d5ddcbb0..1062e353aa 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java @@ -59,6 +59,7 @@ import org.tizen.emulator.skin.image.ImageRegistry; import org.tizen.emulator.skin.info.SkinInformation; import org.tizen.emulator.skin.log.SkinLogger; import org.tizen.emulator.skin.log.SkinLogger.SkinLogLevel; +import org.tizen.emulator.skin.util.CocoaUtil; import org.tizen.emulator.skin.util.IOUtil; import org.tizen.emulator.skin.util.JaxbUtil; import org.tizen.emulator.skin.util.SkinRotation; @@ -84,10 +85,17 @@ public class EmulatorSkinMain { * @param args */ public static void main(String[] args) { + /* make vm name and remove unused menu for macos-x */ if (SwtUtil.isMacPlatform()) { - //TODO: event handling of about dialog System.setProperty("apple.laf.useScreenMenuBar", "true"); - System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Emulator"); + System.setProperty("com.apple.mrj.application.apple.menu.about.name", + "Emulator"); + Display display = Display.getDefault(); + display.syncExec(new Runnable() { + public void run() { + new CocoaUtil().removeTopMenuItems(); + } + }); } String simpleMsg = getSimpleMsg(args); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/CocoaUtil.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/CocoaUtil.java new file mode 100644 index 0000000000..430df17a0d --- /dev/null +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/CocoaUtil.java @@ -0,0 +1,106 @@ +/** + * + * + * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Munkyu Im + * YeongKyoon Lee + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.emulator.skin.util; + +import java.lang.reflect.InvocationTargetException; + +public class CocoaUtil { + + private static final long aboutMenuValue = 0; + private static final long prefMenuValue = 2; + public static final String NSApplication_CLASS = "org.eclipse.swt.internal.cocoa.NSApplication"; + public static final String NSMenu_CLASS = "org.eclipse.swt.internal.cocoa.NSMenu"; + public static final String NSMenuItem_CLASS = "org.eclipse.swt.internal.cocoa.NSMenuItem"; + + public static Object invokeMethod(Class clazz, Object object, String method, Object[] args) + throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, + SecurityException, NoSuchMethodException { + Class[] signature = new Class[args.length]; + for (int i = 0; i < args.length; i++) { + Class thisClass = args[i].getClass(); + if (thisClass == Integer.class) + signature[i] = int.class; + else if (thisClass == Long.class) + signature[i] = long.class; + else if (thisClass == Byte.class) + signature[i] = byte.class; + else if ( thisClass == Boolean.class ) + signature[i] = boolean.class; + else + signature[i] = thisClass; + } + return clazz.getDeclaredMethod(method, signature).invoke(object, args); + } + + // remove about and preference menu item + public void removeTopMenuItems() { + try { + Class nsmenuClass = Class.forName(NSMenu_CLASS); + Class nsmenuitemClass = Class.forName(NSMenuItem_CLASS); + Class nsapplicationClass = Class.forName(NSApplication_CLASS); + + Object sharedApplication = nsapplicationClass.getDeclaredMethod( + "sharedApplication", (Class[]) null).invoke(null, + (Object[]) null); + Object mainMenu = sharedApplication.getClass() + .getDeclaredMethod("mainMenu", (Class[]) null) + .invoke(sharedApplication, (Object[]) null); + + Object mainMenuItem = invokeMethod(nsmenuClass, mainMenu, + "itemAtIndex", new Object[] { new Long(0) }); + Object appMenu = mainMenuItem.getClass() + .getDeclaredMethod("submenu", (Class[]) null) + .invoke(mainMenuItem, (Object[]) null); + + Object aboutMenuItem = invokeMethod(nsmenuClass, appMenu, + "itemAtIndex", new Object[] { new Long(aboutMenuValue) }); + Object prefMenuItem = invokeMethod(nsmenuClass, appMenu, + "itemAtIndex", new Object[] { new Long(prefMenuValue) }); + + //set hidden + invokeMethod(nsmenuitemClass, aboutMenuItem, "setHidden", + new Object[] { new Boolean(true) }); + invokeMethod(nsmenuitemClass, prefMenuItem, "setHidden", + new Object[] { new Boolean(true) }); + + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } +} -- 2.34.1