menu: source code clean-up 93/13093/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Thu, 28 Nov 2013 06:47:45 +0000 (15:47 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Thu, 28 Nov 2013 09:44:10 +0000 (18:44 +0900)
Added some null check.
And define DEFAULT_DOCK_POSITION value for Key Window.

Change-Id: Ifdd8895e5a41508e842eab0c8e9515320436adb4
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.java
tizen/src/skin/client/src/org/tizen/emulator/skin/menu/GeneralKeyWindow.java
tizen/src/skin/client/src/org/tizen/emulator/skin/menu/KeyWindowKeeper.java
tizen/src/skin/client/src/org/tizen/emulator/skin/menu/PopupMenu.java
tizen/src/skin/client/src/org/tizen/emulator/skin/menu/SpecialKeyWindow.java

index f8babf4b8c104d0640813828ddb67be0d1af4ee9..04a2be3aeca712166f8d9f7a03b77c7125a99b9f 100755 (executable)
@@ -1541,14 +1541,13 @@ public class EmulatorSkin {
                                        if (getKeyWindowKeeper().getKeyWindow() == null) {
                                                if (getKeyWindowKeeper().getRecentlyDocked() != SWT.NONE) {
                                                        getKeyWindowKeeper().openKeyWindow(
-                                                                       getKeyWindowKeeper().getRecentlyDocked(),
-                                                                       false);
+                                                                       getKeyWindowKeeper().getRecentlyDocked(), false);
 
                                                        getKeyWindowKeeper().setRecentlyDocked(SWT.NONE);
                                                } else {
                                                        /* opening for first time */
                                                        getKeyWindowKeeper().openKeyWindow(
-                                                                       SWT.RIGHT | SWT.CENTER, false);
+                                                                       KeyWindowKeeper.DEFAULT_DOCK_POSITION, false);
                                                }
                                        } else {
                                                getKeyWindowKeeper().openKeyWindow(
index 4581ec9e9bc65c9c610faa07f58c89e6c3fd0ffd..1f8f9703048cb24ff3b63f33ff92694ec9acf07e 100644 (file)
@@ -60,6 +60,7 @@ import org.tizen.emulator.skin.image.GeneralSkinImageRegistry.GeneralSkinImageNa
 import org.tizen.emulator.skin.image.ImageRegistry.IconName;
 import org.tizen.emulator.skin.info.EmulatorSkinState;
 import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.menu.KeyWindowKeeper;
 import org.tizen.emulator.skin.menu.PopupMenu;
 import org.tizen.emulator.skin.util.SkinUtil;
 import org.tizen.emulator.skin.util.SwtUtil;
@@ -167,10 +168,11 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                        public void mouseDown(MouseEvent e) {
                                if (skin.isKeyWindow == true) {
                                        skin.getKeyWindowKeeper().closeKeyWindow();
-                                       skin.getKeyWindowKeeper().setRecentlyDocked(SWT.RIGHT | SWT.CENTER);
+                                       skin.getKeyWindowKeeper().setRecentlyDocked(
+                                                       KeyWindowKeeper.DEFAULT_DOCK_POSITION);
                                } else {
                                        skin.getKeyWindowKeeper().openKeyWindow(
-                                                       SWT.RIGHT | SWT.CENTER, true);
+                                                       KeyWindowKeeper.DEFAULT_DOCK_POSITION, true);
                                }
                        }
 
@@ -200,14 +202,14 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
 
                if (popupMenu != null && popupMenu.keyWindowItem != null) {
                        final int dockValue = config.getSkinPropertyInt(
-                                       SkinPropertiesConstants.KEYWINDOW_POSITION, 0);
+                                       SkinPropertiesConstants.KEYWINDOW_POSITION, SWT.NONE);
 
                        shell.getDisplay().asyncExec(new Runnable() {
                                @Override
                                public void run() {
                                        if (dockValue == SWT.NONE) {
                                                skin.getKeyWindowKeeper().openKeyWindow(
-                                                               SWT.RIGHT | SWT.CENTER, false);
+                                                               KeyWindowKeeper.DEFAULT_DOCK_POSITION, false);
                                        } else {
                                                skin.getKeyWindowKeeper().openKeyWindow(dockValue, false);
                                        }
index b71aad660d01cebb3a0bbe4404eb83e0e1fe9f57..34e5b246e154dbc60f4f9a851b6c1246d1f606a1 100644 (file)
@@ -65,6 +65,7 @@ import org.tizen.emulator.skin.image.ProfileSkinImageRegistry;
 import org.tizen.emulator.skin.image.ProfileSkinImageRegistry.SkinImageType;
 import org.tizen.emulator.skin.info.EmulatorSkinState;
 import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.menu.KeyWindowKeeper;
 import org.tizen.emulator.skin.menu.PopupMenu;
 import org.tizen.emulator.skin.util.HWKeyRegion;
 import org.tizen.emulator.skin.util.SkinRotation;
@@ -162,14 +163,14 @@ public class ProfileSpecificSkinComposer implements ISkinComposer {
 
                if (popupMenu != null && popupMenu.keyWindowItem != null) {
                        final int dockValue = config.getSkinPropertyInt(
-                                       SkinPropertiesConstants.KEYWINDOW_POSITION, 0);
+                                       SkinPropertiesConstants.KEYWINDOW_POSITION, SWT.NONE);
 
                        shell.getDisplay().asyncExec(new Runnable() {
                                @Override
                                public void run() {
                                        if (dockValue == SWT.NONE) {
                                                skin.getKeyWindowKeeper().openKeyWindow(
-                                                               SWT.RIGHT | SWT.CENTER, false);
+                                                               KeyWindowKeeper.DEFAULT_DOCK_POSITION, false);
                                        } else {
                                                skin.getKeyWindowKeeper().openKeyWindow(
                                                                dockValue, false);
index 672c4dabc593412ef88fbf925e85adac318836f6..2c44ec587a6c4380d2a6e4a32b5bdf569027c017 100644 (file)
@@ -100,7 +100,7 @@ public class GeneralKeyWindow extends SkinWindow {
 
        public GeneralKeyWindow(EmulatorSkin skin,
                        GeneralKeyWindowImageRegistry imageRegstry, List<KeyMapType> keyMapList) {
-               super(skin.getShell(), SWT.RIGHT | SWT.CENTER);
+               super(skin.getShell(), KeyWindowKeeper.DEFAULT_DOCK_POSITION);
 
                this.skin = skin;
                this.parent = skin.getShell();
index 7e5e28b733bc364c86d6cc0bf880d7fa8952ef87..37cf4b9c6e3811e6b6afadf5c60a9d9be05497be 100644 (file)
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.logging.Logger;
 
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.MenuItem;
 import org.tizen.emulator.skin.EmulatorSkin;
 import org.tizen.emulator.skin.custom.SkinWindow;
@@ -41,6 +42,8 @@ import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.util.SkinUtil;
 
 public class KeyWindowKeeper {
+       public static final int DEFAULT_DOCK_POSITION = (SWT.RIGHT | SWT.CENTER);
+
        private static Logger logger =
                        SkinLogger.getSkinLogger(KeyWindowKeeper.class).getLogger();
 
@@ -82,8 +85,7 @@ public class KeyWindowKeeper {
                /* create a Key Window */
                determineLayout();
 
-               if (isGeneralKeyWindow() == true
-                               || skin.getPopupMenu().keyWindowItem.getMenu() == null) {
+               if (isGeneralKeyWindow() == true) {
                        if (imageRegstry == null) {
                                logger.warning("GeneralKeyWindowImageRegistry is null");
                                return;
@@ -106,9 +108,14 @@ public class KeyWindowKeeper {
 
                        keyWindow = new GeneralKeyWindow(skin, imageRegstry, keyMapList);
                } else {
-                       // TODO:
-                       String layoutName =
-                                       skin.getPopupMenu().keyWindowItem.getMenu().getItem(indexLayout).getText();
+                       Menu keywindowMenu = skin.getPopupMenu().keyWindowItem.getMenu();
+                       MenuItem layout = keywindowMenu.getItem(indexLayout);
+                       if (layout == null) {
+                               layout = keywindowMenu.getItem(0);
+                               layout.setSelection(true);
+                       }
+
+                       String layoutName = layout.getText();
                        logger.info("generate a \'" + layoutName + "\' key window!");
 
                        keyWindow = new SpecialKeyWindow(skin, layoutName);
@@ -161,6 +168,8 @@ public class KeyWindowKeeper {
                if (keywindowItem != null && keywindowItem.getMenu() != null) {
                        logger.info("key window has a special layout");
 
+                       indexLayout = 0;
+
                        MenuItem[] layouts = keywindowItem.getMenu().getItems();
                        for (int i = 0; i < layouts.length; i++) {
                                MenuItem layout = layouts[i];
@@ -195,13 +204,9 @@ public class KeyWindowKeeper {
                        if (isGeneralKeyWindow() == true) {
                                return keywindowMenu.getSelection();
                        } else {
-                               if (keywindowMenu.getMenu() == null) {
-                                       logger.info("Special KeyWindow menu item is null");
-                               } else {
-                                       for (MenuItem layout : keywindowMenu.getMenu().getItems()) {
-                                               if (layout.getSelection() == true) {
-                                                       return true;
-                                               }
+                               for (MenuItem layout : keywindowMenu.getMenu().getItems()) {
+                                       if (layout.getSelection() == true) {
+                                               return true;
                                        }
                                }
                        }
@@ -217,10 +222,9 @@ public class KeyWindowKeeper {
                        if (isGeneralKeyWindow() == true) {
                                keywindowMenu.setSelection(on);
                        } else {
-                               if (keywindowMenu.getMenu() == null) {
-                                       logger.info("Special KeyWindow menu item is null");
-                               } else {
-                                       keywindowMenu.getMenu().getItem(indexLayout).setSelection(on);
+                               MenuItem layout = keywindowMenu.getMenu().getItem(indexLayout);
+                               if (layout != null) {
+                                       layout.setSelection(on);
                                }
                        }
                }
index 70bbbe7cfb7349cdad153af7bf0a40a15c79178d..85ddcdf3b00a39b0e69bae7c862f2ee4da53f700 100644 (file)
@@ -334,6 +334,9 @@ public class PopupMenu {
 
                        if (matchedItem == null) {
                                matchedItem = scaleSubMenu.getItem(0);
+                               if (matchedItem == null) {
+                                       return;
+                               }
                                skin.getEmulatorSkinState().setCurrentScale(
                                                (Integer) matchedItem.getData());
                        }
index 4a26946441d277fbef7fc7ffd4f77ea171f93825..d53430c860170663a30ffe98bd93d50aa83ab9a7 100644 (file)
@@ -96,7 +96,7 @@ public class SpecialKeyWindow extends SkinWindow {
        private boolean isTouch;
 
        public SpecialKeyWindow(EmulatorSkin skin, String layoutName) {
-               super(skin.getShell(), SWT.RIGHT | SWT.CENTER);
+               super(skin.getShell(), KeyWindowKeeper.DEFAULT_DOCK_POSITION);
 
                this.parent = skin.getShell();
                this.shell = new Shell(parent.getDisplay() /* for Mac & Always on Top */,