import org.tizen.emulator.skin.dialog.DetailInfoDialog;
import org.tizen.emulator.skin.dialog.RamdumpDialog;
import org.tizen.emulator.skin.image.ImageRegistry;
-import org.tizen.emulator.skin.image.ImageRegistry.IconName;
import org.tizen.emulator.skin.info.SkinInformation;
import org.tizen.emulator.skin.layout.GeneralPurposeSkinComposer;
import org.tizen.emulator.skin.layout.ISkinComposer;
import org.tizen.emulator.skin.layout.PhoneShapeSkinComposer;
import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.menu.PopupMenu;
import org.tizen.emulator.skin.screenshot.ScreenShotDialog;
import org.tizen.emulator.skin.util.SkinRotation;
import org.tizen.emulator.skin.util.SkinUtil;
protected ImageRegistry imageRegistry;
protected Canvas lcdCanvas;
private int displayCanvasStyle;
- protected SkinInformation skinInfo;
+ public SkinInformation skinInfo;
protected ISkinComposer skinComposer;
protected EmulatorSkinState currentState;
private boolean isDisplayDragging;
private boolean isShutdownRequested;
private boolean isAboutToReopen;
- private boolean isOnTop;
- private boolean isKeyWindow;
- private boolean isOnKbd;
+ public boolean isOnTop;
+ public boolean isKeyWindow;
+ public boolean isOnKbd;
+ private PopupMenu popupMenu;
- private Menu contextMenu;
public Color colorVM;
- private MenuItem keyWindowItem; /* key window menu */
public KeyWindow keyWindow;
public int recentlyDocked;
public ColorTag pairTag;
this.recentlyDocked = SWT.NONE;
int style = SWT.NO_TRIM | SWT.DOUBLE_BUFFERED;
-// if (skinInfo.isPhoneShape() == false) {
-// style = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.BORDER;
-// }
this.shell = new Shell(Display.getDefault(), style);
+
if (isOnTop == true) {
SkinUtil.setTopMost(shell, true);
}
setFocus();
/* attach a menu */
- this.isOnKbd = false;
- setMenu();
+ isOnKbd = false;
+ popupMenu = new PopupMenu(config, this, shell, imageRegistry);
return 0;
}
- private void setMenu() {
- contextMenu = new Menu(shell);
-
- addMenuItems(shell, contextMenu);
-
- shell.setMenu(contextMenu);
- }
-
// private void readyToReopen( EmulatorSkin sourceSkin, boolean isOnTop ) {
//
// logger.info( "Start Changing AlwaysOnTop status" );
shellMenuDetectListener = new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent e) {
- Menu menu = EmulatorSkin.this.contextMenu;
+ Menu menu = popupMenu.getMenu();
if (menu != null) {
shell.setMenu(menu);
canvasMenuDetectListener = new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent e) {
- Menu menu = EmulatorSkin.this.contextMenu;
+ Menu menu = popupMenu.getMenu();
keyForceRelease(true);
if (menu != null && isDisplayDragging == false) {
}
public boolean isSelectKeyWindow() {
- return keyWindowItem.getSelection();
+ return popupMenu.keyWindowItem.getSelection();
}
public void openKeyWindow(int dockValue, boolean recreate) {
if (keyWindow != null) {
if (recreate == false) {
/* show the key window */
- keyWindowItem.setSelection(isKeyWindow = true);
+ popupMenu.keyWindowItem.setSelection(isKeyWindow = true);
pairTag.setVisible(true);
keyWindow.getShell().setVisible(true);
SkinUtil.getHWKeyMapList(currentState.getCurrentRotationId());
if (keyMapList == null) {
- keyWindowItem.setSelection(isKeyWindow = false);
+ popupMenu.keyWindowItem.setSelection(isKeyWindow = false);
logger.info("keyMapList is null");
return;
} else if (keyMapList.isEmpty() == true) {
- keyWindowItem.setSelection(isKeyWindow = false);
+ popupMenu.keyWindowItem.setSelection(isKeyWindow = false);
logger.info("keyMapList is empty");
return;
}
keyWindow = new KeyWindow(this, shell, communicator, keyMapList);
- keyWindowItem.setSelection(isKeyWindow = true);
+ popupMenu.keyWindowItem.setSelection(isKeyWindow = true);
SkinUtil.setTopMost(keyWindow.getShell(), isOnTop);
pairTag.setVisible(true);
}
public void hideKeyWindow() {
- keyWindowItem.setSelection(isKeyWindow = false);
+ popupMenu.keyWindowItem.setSelection(isKeyWindow = false);
pairTag.setVisible(false);
if (keyWindow != null) {
}
public void closeKeyWindow() {
- keyWindowItem.setSelection(isKeyWindow = false);
+ popupMenu.keyWindowItem.setSelection(isKeyWindow = false);
pairTag.setVisible(false);
if (keyWindow != null) {
}
}
- private void addMenuItems(final Shell shell, final Menu menu) {
-
- /* Emulator detail info menu */
- final MenuItem detailInfoItem = new MenuItem(menu, SWT.PUSH);
-
- String emulatorName = SkinUtil.makeEmulatorName(config);
- detailInfoItem.setText(emulatorName);
- detailInfoItem.setImage(imageRegistry.getIcon(IconName.DETAIL_INFO));
- detailInfoItem.addSelectionListener(new SelectionAdapter() {
+ /* for popup menu */
+ public SelectionAdapter createDetailInfoMenu() {
+ SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (logger.isLoggable(Level.FINE)) {
shell, emulatorName, communicator, config);
detailInfoDialog.open();
}
- } );
-
- new MenuItem(menu, SWT.SEPARATOR);
-
- /* Always on top menu */
- if (!SwtUtil.isMacPlatform()) { /* not supported on mac */
- final MenuItem onTopItem = new MenuItem(menu, SWT.CHECK);
- onTopItem.setText("&Always On Top");
- onTopItem.setSelection(isOnTop);
-
- onTopItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- isOnTop = onTopItem.getSelection();
-
- logger.info("Select Always On Top : " + isOnTop);
- // readyToReopen(EmulatorSkin.this, isOnTop);
-
- if (SkinUtil.setTopMost(shell, isOnTop) == false) {
- logger.info("failed to Always On Top");
+ };
- onTopItem.setSelection(isOnTop = false);
- } else {
- if (keyWindow != null) {
- SkinUtil.setTopMost(keyWindow.getShell(), isOnTop);
- }
- }
- }
- } );
- }
+ return listener;
+ }
- /* Rotate menu */
- final MenuItem rotateItem = new MenuItem(menu, SWT.CASCADE);
- rotateItem.setText("&Rotate");
- rotateItem.setImage(imageRegistry.getIcon(IconName.ROTATE));
- Menu rotateMenu = createRotateMenu(menu.getShell());
- rotateItem.setMenu(rotateMenu);
-
- /* Scale menu */
- final MenuItem scaleItem = new MenuItem(menu, SWT.CASCADE);
- scaleItem.setText("&Scale");
- scaleItem.setImage(imageRegistry.getIcon(IconName.SCALE));
- Menu scaleMenu = createScaleMenu(menu.getShell());
- scaleItem.setMenu(scaleMenu);
-
- new MenuItem(menu, SWT.SEPARATOR);
-
- /* Key Window menu */
- if (skinInfo.isPhoneShape() == false) { //TODO:
- keyWindowItem = new MenuItem(menu, SWT.CHECK);
- keyWindowItem.setText("&Key Window");
- keyWindowItem.setSelection(isKeyWindow);
-
- keyWindowItem.addSelectionListener(new SelectionAdapter() {
+ public SelectionAdapter createTopMostMenu() {
+ SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- final boolean selectKeyWindow = keyWindowItem.getSelection();
-
- if (selectKeyWindow == true) {
- if (keyWindow == null) {
- openKeyWindow(recentlyDocked, false);
- recentlyDocked = SWT.NONE;
- } else {
- openKeyWindow(keyWindow.getDockPosition(), false);
- }
- } else { /* hide a key window */
- if (keyWindow != null &&
- keyWindow.getDockPosition() != SWT.NONE) {
- /* close the Key Window if it is docked to Main Window */
- recentlyDocked = keyWindow.getDockPosition();
- closeKeyWindow();
- } else {
- hideKeyWindow();
- }
- }
- }
- } );
- }
+ isOnTop = popupMenu.onTopItem.getSelection();
- /* Advanced menu */
- final MenuItem advancedItem = new MenuItem(menu, SWT.CASCADE);
- advancedItem.setText("Ad&vanced");
- advancedItem.setImage(imageRegistry.getIcon(IconName.ADVANCED));
- Menu advancedMenu = createAdvancedMenu(menu.getShell());
- advancedItem.setMenu(advancedMenu);
+ logger.info("Select Always On Top : " + isOnTop);
+ // readyToReopen(EmulatorSkin.this, isOnTop);
- /* Shell menu */
- final MenuItem shellItem = new MenuItem(menu, SWT.PUSH);
- shellItem.setText("S&hell");
- shellItem.setImage(imageRegistry.getIcon(IconName.SHELL));
+ if (SkinUtil.setTopMost(shell, isOnTop) == false) {
+ logger.info("failed to Always On Top");
- shellItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- if (!communicator.isSdbDaemonStarted()) {
- SkinUtil.openMessage(shell, null, "SDB is not ready.\n" +
- "Please wait until the emulator is completely boot up.",
- SWT.ICON_WARNING, config);
- return;
- }
-
- String sdbPath = SkinUtil.getSdbPath();
-
- File sdbFile = new File(sdbPath);
- if (!sdbFile.exists()) {
- logger.log(Level.INFO, "SDB file is not exist : " + sdbFile.getAbsolutePath());
- try {
- SkinUtil.openMessage(shell, null,
- "SDB file is not exist in the following path.\n" + sdbFile.getCanonicalPath()
- , SWT.ICON_ERROR, config);
- } catch (IOException ee) {
- logger.log(Level.SEVERE, ee.getMessage(), ee);
+ popupMenu.onTopItem.setSelection(isOnTop = false);
+ } else {
+ if (keyWindow != null) {
+ SkinUtil.setTopMost(keyWindow.getShell(), isOnTop);
}
- return;
}
-
- int portSdb = config.getArgInt(ArgsConstants.NET_BASE_PORT);
-
- ProcessBuilder procSdb = new ProcessBuilder();
-
- if (SwtUtil.isLinuxPlatform()) {
- procSdb.command("/usr/bin/gnome-terminal", "--disable-factory",
- "--title=" + SkinUtil.makeEmulatorName( config ), "-x", sdbPath,
- "-s", "emulator-" + portSdb, "shell");
- } else if (SwtUtil.isWindowsPlatform()) {
- procSdb.command("cmd.exe", "/c", "start", sdbPath, "sdb",
- "-s", "emulator-" + portSdb, "shell");
- } else if (SwtUtil.isMacPlatform()) {
- procSdb.command("./sdbscript", "emulator-" + portSdb);
- //procSdb.command("/usr/X11/bin/uxterm", "-T", "emulator-" + portSdb, "-e", sdbPath,"shell");
- }
-
- logger.log(Level.INFO, procSdb.command().toString());
-
- try {
- procSdb.start(); /* open the sdb shell */
- } catch (Exception ee) {
- logger.log(Level.SEVERE, ee.getMessage(), ee);
- SkinUtil.openMessage(shell, null, "Fail to open Shell: \n" +
- ee.getMessage(), SWT.ICON_ERROR, config);
- }
-
- communicator.sendToQEMU(
- SendCommand.OPEN_SHELL, null, false);
- }
- } );
-
- new MenuItem(menu, SWT.SEPARATOR);
-
- /* Close menu */
- MenuItem closeItem = new MenuItem(menu, SWT.PUSH);
- closeItem.setText("&Close");
- closeItem.setImage(imageRegistry.getIcon(IconName.CLOSE));
-
- closeItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- logger.info("Close Menu is selected");
- communicator.sendToQEMU(
- SendCommand.CLOSE, null, false);
}
- } );
+ };
+ return listener;
}
- private Menu createRotateMenu(final Shell shell) {
-
- Menu menu = new Menu( shell, SWT.DROP_DOWN );
+ public Menu createRotateMenu() {
+ Menu menu = new Menu(shell, SWT.DROP_DOWN);
final List<MenuItem> rotationList = new ArrayList<MenuItem>();
return menu;
}
- private Menu createScaleMenu(final Shell shell) {
-
+ public Menu createScaleMenu() {
Menu menu = new Menu(shell, SWT.DROP_DOWN);
final List<MenuItem> scaleList = new ArrayList<MenuItem>();
return menu;
}
- private Menu createDiagnosisMenu(Shell shell) {
+ public SelectionAdapter createKeyWindowMenu() {
+ SelectionAdapter listener = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ final boolean selectKeyWindow =
+ popupMenu.keyWindowItem.getSelection();
+
+ if (selectKeyWindow == true) {
+ if (keyWindow == null) {
+ openKeyWindow(recentlyDocked, false);
+ recentlyDocked = SWT.NONE;
+ } else {
+ openKeyWindow(keyWindow.getDockPosition(), false);
+ }
+ } else { /* hide a key window */
+ if (keyWindow != null &&
+ keyWindow.getDockPosition() != SWT.NONE) {
+ /* close the Key Window if it is docked to Main Window */
+ recentlyDocked = keyWindow.getDockPosition();
+ closeKeyWindow();
+ } else {
+ hideKeyWindow();
+ }
+ }
+ }
+ };
+
+ return listener;
+ };
+
+ public Menu createDiagnosisMenu() {
Menu menu = new Menu(shell, SWT.DROP_DOWN);
final MenuItem ramdumpItem = new MenuItem(menu, SWT.PUSH);
return menu;
}
- private Menu createAdvancedMenu(final Shell shell) {
-
- final Menu menu = new Menu(shell, SWT.DROP_DOWN);
-
- /* Screen shot menu */
- final MenuItem screenshotItem = new MenuItem(menu, SWT.PUSH);
- screenshotItem.setText("&Screen Shot");
- screenshotItem.setImage(imageRegistry.getIcon(IconName.SCREENSHOT));
- screenshotItem.addSelectionListener(new SelectionAdapter() {
+ public SelectionAdapter createScreenshotMenu() {
+ SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
logger.info("ScreenShot Menu is selected");
openScreenShotWindow();
}
- } );
-
- /* VirtIO Keyboard Menu */
- final MenuItem hostKeyboardItem = new MenuItem(menu, SWT.CASCADE);
- hostKeyboardItem.setText("&Host Keyboard");
- hostKeyboardItem.setImage(imageRegistry.getIcon(IconName.HOST_KEYBOARD));
-
- Menu hostKeyboardMenu = new Menu(shell, SWT.DROP_DOWN);
-
- final MenuItem kbdOnItem = new MenuItem(hostKeyboardMenu, SWT.RADIO);
- kbdOnItem.setText("On");
- kbdOnItem.setSelection( isOnKbd );
+ };
- final MenuItem kbdOffItem = new MenuItem(hostKeyboardMenu, SWT.RADIO);
- kbdOffItem.setText("Off");
- kbdOffItem.setSelection(!isOnKbd);
+ return listener;
+ }
- SelectionAdapter kbdSelectionAdaptor = new SelectionAdapter() {
+ public SelectionAdapter createHostKeyboardMenu() {
+ SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (!communicator.isSensorDaemonStarted()) {
SkinUtil.openMessage(shell, null,
- "Host Keyboard is not ready.\nPlease wait until the emulator is completely boot up.",
+ "Host Keyboard is not ready.\n" +
+ "Please wait until the emulator is completely boot up.",
SWT.ICON_WARNING, config);
- kbdOnItem.setSelection(isOnKbd);
- kbdOffItem.setSelection(!isOnKbd);
+ popupMenu.kbdOnItem.setSelection(isOnKbd);
+ popupMenu.kbdOffItem.setSelection(!isOnKbd);
return;
}
MenuItem item = (MenuItem) e.getSource();
if (item.getSelection()) {
- boolean on = item.equals(kbdOnItem);
+ boolean on = item.equals(popupMenu.kbdOnItem);
isOnKbd = on;
logger.info("Host Keyboard " + isOnKbd);
communicator.sendToQEMU(SendCommand.HOST_KBD,
new BooleanData(on, SendCommand.HOST_KBD.toString()), false);
}
-
}
};
- kbdOnItem.addSelectionListener(kbdSelectionAdaptor);
- kbdOffItem.addSelectionListener(kbdSelectionAdaptor);
-
- hostKeyboardItem.setMenu(hostKeyboardMenu);
-
- /* Diagnosis menu */
- if (SwtUtil.isLinuxPlatform()) { //TODO: windows
- final MenuItem diagnosisItem = new MenuItem(menu, SWT.CASCADE);
- diagnosisItem.setText("&Diagnosis");
- diagnosisItem.setImage(imageRegistry.getIcon(IconName.DIAGNOSIS));
- Menu diagnosisMenu = createDiagnosisMenu(menu.getShell());
- diagnosisItem.setMenu(diagnosisMenu);
- }
-
- new MenuItem(menu, SWT.SEPARATOR);
-
- /* About menu */
- final MenuItem aboutItem = new MenuItem(menu, SWT.PUSH);
- aboutItem.setText("&About");
- aboutItem.setImage(imageRegistry.getIcon(IconName.ABOUT));
-
- aboutItem.addSelectionListener(new SelectionAdapter() {
- private boolean isOpen;
+ return listener;
+ }
+ public SelectionAdapter createAboutMenu() {
+ SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (!isOpen) {
- isOpen = true;
+ logger.info("Open the about dialog");
- logger.info("Open the about dialog");
- AboutDialog dialog = new AboutDialog(shell, config);
- dialog.open();
- isOpen = false;
- }
+ AboutDialog dialog = new AboutDialog(shell, config);
+ dialog.open();
}
- } );
-
- new MenuItem(menu, SWT.SEPARATOR);
+ };
- /* Force close menu */
- final MenuItem forceCloseItem = new MenuItem(menu, SWT.PUSH);
- forceCloseItem.setText("&Force Close");
- forceCloseItem.setImage(imageRegistry.getIcon(IconName.FORCE_CLOSE));
+ return listener;
+ }
- forceCloseItem.addSelectionListener(new SelectionAdapter() {
+ public SelectionAdapter createForceCloseMenu() {
+ SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
logger.info("Force close is selected");
});
}
}
- });
+ };
- return menu;
+ return listener;
+ }
+
+ public SelectionAdapter createShellMenu() {
+ SelectionAdapter listener = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (!communicator.isSdbDaemonStarted()) {
+ SkinUtil.openMessage(shell, null, "SDB is not ready.\n" +
+ "Please wait until the emulator is completely boot up.",
+ SWT.ICON_WARNING, config);
+ return;
+ }
+
+ String sdbPath = SkinUtil.getSdbPath();
+
+ File sdbFile = new File(sdbPath);
+ if (!sdbFile.exists()) {
+ logger.log(Level.INFO, "SDB file is not exist : " + sdbFile.getAbsolutePath());
+ try {
+ SkinUtil.openMessage(shell, null,
+ "SDB file is not exist in the following path.\n" +
+ sdbFile.getCanonicalPath(),
+ SWT.ICON_ERROR, config);
+ } catch (IOException ee) {
+ logger.log(Level.SEVERE, ee.getMessage(), ee);
+ }
+ return;
+ }
+
+ int portSdb = config.getArgInt(ArgsConstants.NET_BASE_PORT);
+
+ ProcessBuilder procSdb = new ProcessBuilder();
+
+ if (SwtUtil.isLinuxPlatform()) {
+ procSdb.command("/usr/bin/gnome-terminal", "--disable-factory",
+ "--title=" + SkinUtil.makeEmulatorName( config ), "-x", sdbPath,
+ "-s", "emulator-" + portSdb, "shell");
+ } else if (SwtUtil.isWindowsPlatform()) {
+ procSdb.command("cmd.exe", "/c", "start", sdbPath, "sdb",
+ "-s", "emulator-" + portSdb, "shell");
+ } else if (SwtUtil.isMacPlatform()) {
+ procSdb.command("./sdbscript", "emulator-" + portSdb);
+ /* procSdb.command(
+ "/usr/X11/bin/uxterm", "-T", "emulator-" + portSdb, "-e", sdbPath,"shell"); */
+ }
+
+ logger.log(Level.INFO, procSdb.command().toString());
+
+ try {
+ procSdb.start(); /* open the sdb shell */
+ } catch (Exception ee) {
+ logger.log(Level.SEVERE, ee.getMessage(), ee);
+ SkinUtil.openMessage(shell, null, "Fail to open Shell: \n" +
+ ee.getMessage(), SWT.ICON_ERROR, config);
+ }
+
+ communicator.sendToQEMU(
+ SendCommand.OPEN_SHELL, null, false);
+ }
+ };
+
+ return listener;
+ }
+
+ public SelectionAdapter createCloseMenu() {
+ SelectionAdapter listener = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ logger.info("Close Menu is selected");
+
+ communicator.sendToQEMU(
+ SendCommand.CLOSE, null, false);
+ }
+ };
+ return listener;
}
public void shutdown() {
--- /dev/null
+/**
+ * Pop-up Menu
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * 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.menu;
+
+import java.util.logging.Logger;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.skin.EmulatorSkin;
+import org.tizen.emulator.skin.config.EmulatorConfig;
+import org.tizen.emulator.skin.image.ImageRegistry;
+import org.tizen.emulator.skin.image.ImageRegistry.IconName;
+import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.util.SkinUtil;
+import org.tizen.emulator.skin.util.SwtUtil;
+
+public class PopupMenu {
+ private static Logger logger =
+ SkinLogger.getSkinLogger(PopupMenu.class).getLogger();
+
+ private EmulatorConfig config;
+ private EmulatorSkin skin;
+ private Shell shell;
+ private ImageRegistry imageRegistry;
+ private Menu contextMenu;
+
+ /* default menu items */
+ public MenuItem detailInfoItem;
+ public MenuItem onTopItem;
+ public MenuItem rotateItem;
+ public MenuItem scaleItem;
+ public MenuItem keyWindowItem; /* key window menu */
+ public MenuItem advancedItem;
+ public MenuItem screenshotItem;
+ public MenuItem hostKeyboardItem;
+ public MenuItem kbdOnItem;
+ public MenuItem kbdOffItem;
+ public MenuItem diagnosisItem;
+ public MenuItem shellItem;
+ public MenuItem closeItem;
+ public MenuItem aboutItem;
+ public MenuItem forceCloseItem;
+
+ public PopupMenu(EmulatorConfig config, EmulatorSkin skin,
+ Shell shell, ImageRegistry imageRegistry) {
+ this.config = config;
+ this.skin = skin;
+ this.shell = shell;
+ this.imageRegistry = imageRegistry;
+
+ createMenu();
+ }
+
+ private void createMenu() {
+ logger.info("create a popup menu");
+
+ contextMenu = new Menu(shell);
+
+ addMenuItems(contextMenu);
+ shell.setMenu(contextMenu);
+ }
+
+ private void addMenuItems(final Menu menu) {
+ /* Emulator detail info menu */
+ detailInfoItem = new MenuItem(menu, SWT.PUSH);
+ String emulatorName = SkinUtil.makeEmulatorName(config);
+ detailInfoItem.setText(emulatorName);
+ detailInfoItem.setImage(imageRegistry.getIcon(IconName.DETAIL_INFO));
+
+ SelectionAdapter detailInfoListener = skin.createDetailInfoMenu();
+ detailInfoItem.addSelectionListener(detailInfoListener);
+
+ new MenuItem(menu, SWT.SEPARATOR);
+
+ /* Always on top menu */
+ if (SwtUtil.isMacPlatform() == false) { /* not supported on mac */
+ onTopItem = new MenuItem(menu, SWT.CHECK);
+ onTopItem.setText("&Always On Top");
+ onTopItem.setSelection(skin.isOnTop);
+
+ SelectionAdapter topMostListener = skin.createTopMostMenu();
+ onTopItem.addSelectionListener(topMostListener);
+ }
+
+ /* Rotate menu */
+ rotateItem = new MenuItem(menu, SWT.CASCADE);
+ rotateItem.setText("&Rotate");
+ rotateItem.setImage(imageRegistry.getIcon(IconName.ROTATE));
+
+ Menu rotateMenu = skin.createRotateMenu();
+ rotateItem.setMenu(rotateMenu);
+
+ /* Scale menu */
+ scaleItem = new MenuItem(menu, SWT.CASCADE);
+ scaleItem.setText("&Scale");
+ scaleItem.setImage(imageRegistry.getIcon(IconName.SCALE));
+
+ Menu scaleMenu = skin.createScaleMenu();
+ scaleItem.setMenu(scaleMenu);
+
+ new MenuItem(menu, SWT.SEPARATOR);
+
+ /* Key Window menu */
+ if (skin.skinInfo.isPhoneShape() == false) { //TODO:
+ keyWindowItem = new MenuItem(menu, SWT.CHECK);
+ keyWindowItem.setText("&Key Window");
+ keyWindowItem.setSelection(skin.isKeyWindow);
+
+ SelectionAdapter keyWindowListener = skin.createKeyWindowMenu();
+ keyWindowItem.addSelectionListener(keyWindowListener);
+ }
+
+ /* Advanced menu */
+ advancedItem = new MenuItem(menu, SWT.CASCADE);
+ advancedItem.setText("Ad&vanced");
+ advancedItem.setImage(imageRegistry.getIcon(IconName.ADVANCED));
+
+ Menu advancedMenu = new Menu(shell, SWT.DROP_DOWN);
+ {
+ /* Screen shot menu */
+ screenshotItem = new MenuItem(advancedMenu, SWT.PUSH);
+ screenshotItem.setText("&Screen Shot");
+ screenshotItem.setImage(imageRegistry.getIcon(IconName.SCREENSHOT));
+
+ SelectionAdapter screenshotListener = skin.createScreenshotMenu();
+ screenshotItem.addSelectionListener(screenshotListener);
+
+ /* VirtIO Keyboard Menu */
+ hostKeyboardItem = new MenuItem(advancedMenu, SWT.CASCADE);
+ hostKeyboardItem.setText("&Host Keyboard");
+ hostKeyboardItem.setImage(imageRegistry.getIcon(IconName.HOST_KEYBOARD));
+
+ Menu hostKeyboardMenu = new Menu(shell, SWT.DROP_DOWN);
+
+ kbdOnItem = new MenuItem(hostKeyboardMenu, SWT.RADIO);
+ kbdOnItem.setText("On");
+ kbdOnItem.setSelection(skin.isOnKbd);
+
+ kbdOffItem = new MenuItem(hostKeyboardMenu, SWT.RADIO);
+ kbdOffItem.setText("Off");
+ kbdOffItem.setSelection(!skin.isOnKbd);
+
+ SelectionAdapter hostKeyboardListener = skin.createHostKeyboardMenu();
+ kbdOnItem.addSelectionListener(hostKeyboardListener);
+ kbdOffItem.addSelectionListener(hostKeyboardListener);
+
+ hostKeyboardItem.setMenu(hostKeyboardMenu);
+
+ /* Diagnosis menu */
+ if (SwtUtil.isLinuxPlatform()) { //TODO: windows
+ diagnosisItem = new MenuItem(advancedMenu, SWT.CASCADE);
+ diagnosisItem.setText("&Diagnosis");
+ diagnosisItem.setImage(imageRegistry.getIcon(IconName.DIAGNOSIS));
+
+ Menu diagnosisMenu = skin.createDiagnosisMenu();
+ diagnosisItem.setMenu(diagnosisMenu);
+ }
+
+ new MenuItem(advancedMenu, SWT.SEPARATOR);
+
+ /* About menu */
+ aboutItem = new MenuItem(advancedMenu, SWT.PUSH);
+ aboutItem.setText("&About");
+ aboutItem.setImage(imageRegistry.getIcon(IconName.ABOUT));
+
+ SelectionAdapter aboutListener = skin.createAboutMenu();
+ aboutItem.addSelectionListener(aboutListener);
+
+ new MenuItem(advancedMenu, SWT.SEPARATOR);
+
+ /* Force close menu */
+ forceCloseItem = new MenuItem(advancedMenu, SWT.PUSH);
+ forceCloseItem.setText("&Force Close");
+ forceCloseItem.setImage(imageRegistry.getIcon(IconName.FORCE_CLOSE));
+
+ SelectionAdapter forceCloseListener = skin.createForceCloseMenu();
+ forceCloseItem.addSelectionListener(forceCloseListener);
+ }
+ advancedItem.setMenu(advancedMenu);
+
+ /* Shell menu */
+ shellItem = new MenuItem(menu, SWT.PUSH);
+ shellItem.setText("S&hell");
+ shellItem.setImage(imageRegistry.getIcon(IconName.SHELL));
+
+ SelectionAdapter shellListener = skin.createShellMenu();
+ shellItem.addSelectionListener(shellListener);
+
+ new MenuItem(menu, SWT.SEPARATOR);
+
+ /* Close menu */
+ closeItem = new MenuItem(menu, SWT.PUSH);
+ closeItem.setText("&Close");
+ closeItem.setImage(imageRegistry.getIcon(IconName.CLOSE));
+
+ SelectionAdapter closeListener = skin.createCloseMenu();
+ closeItem.addSelectionListener(closeListener);
+ }
+
+ public Menu getMenu() {
+ return contextMenu;
+ }
+}