menu: added dynamic menu loading for key window layout
authorGiWoong Kim <giwoong.kim@samsung.com>
Wed, 24 Jul 2013 07:18:43 +0000 (16:18 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Wed, 24 Jul 2013 08:47:06 +0000 (17:47 +0900)
Change-Id: Idae9a41162a222f889be8a1177047c02a170cbc4
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/config/EmulatorConfig.java
tizen/src/skin/client/src/org/tizen/emulator/skin/custom/KeyWindow.java
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.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

index 498b92fac0a58f4db361ef454721056e983d8aac..2d6791d1a08757a8b02b1fa0ea5780ce7c2db7af 100644 (file)
@@ -247,10 +247,12 @@ public class EmulatorSkin {
        public long initLayout() {
                imageRegistry = ImageRegistry.getInstance();
 
-               /* attach a menu */
+               /* create and attach a popup menu */
                isOnKbd = false;
                popupMenu = new PopupMenu(config, this, shell, imageRegistry);
 
+               getKeyWindowKeeper().determineLayout();
+
                /* build a skin layout */
                if (skinInfo.isGeneralPurposeSkin() == false) {
                        skinComposer = new ProfileSpecificSkinComposer(config, this,
@@ -1250,8 +1252,30 @@ public class EmulatorSkin {
                SelectionAdapter listener = new SelectionAdapter() {
                        @Override
                        public void widgetSelected(SelectionEvent e) {
+                               /* control the menu */
+                               if (getKeyWindowKeeper().isGeneralKeyWindow() == false) {
+                                       MenuItem layoutSelected = (MenuItem) e.widget;
+
+                                       if (layoutSelected.getSelection() == true) {
+                                               for (MenuItem layout : layoutSelected.getParent().getItems()) {
+                                                       if (layout != layoutSelected) {
+                                                               /* uncheck other menu items */
+                                                               layout.setSelection(false);
+                                                       } else {
+                                                               int layoutIndex = getKeyWindowKeeper().getLayoutIndex();
+                                                               if (getKeyWindowKeeper().determineLayout() != layoutIndex) {
+                                                                       /* switch */
+                                                                       getKeyWindowKeeper().closeKeyWindow();
+                                                                       layoutSelected.setSelection(true);
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+
+                               /* control the window */
                                if (getKeyWindowKeeper().isSelectKeyWindowMenu() == true)
-                               {
+                               { /* checked */
                                        if (getKeyWindowKeeper().getKeyWindow() == null) {
                                                if (getKeyWindowKeeper().getRecentlyDocked() != SWT.NONE) {
                                                        getKeyWindowKeeper().openKeyWindow(
@@ -1269,7 +1293,7 @@ public class EmulatorSkin {
                                        }
                                }
                                else
-                               { /* hide a key window */
+                               { /* unchecked */
                                        if (getKeyWindowKeeper().getDockPosition() != SWT.NONE) {
                                                /* close the Key Window if it is docked to Main Window */
                                                getKeyWindowKeeper().setRecentlyDocked(
@@ -1277,6 +1301,7 @@ public class EmulatorSkin {
 
                                                getKeyWindowKeeper().closeKeyWindow();
                                        } else {
+                                               /* hide a Key Window */
                                                getKeyWindowKeeper().hideKeyWindow();
                                        }
                                }
index a2594720f7f296f0a194e521a81317cb399166f7..dd902b90a5d27466d57b44524bd29071aff1f313 100644 (file)
@@ -139,7 +139,7 @@ public class EmulatorConfig {
 
                                reader.close();
                        } else {
-                               logger.info("cannot find version file" + versionFilePath);
+                               logger.warning("cannot read version from " + versionFilePath);
                        }
                } catch (FileNotFoundException e) {
                        logger.log(Level.SEVERE, e.getMessage(), e);
index 2b248ba463fcdcb412e6588592c35c371883c9f7..f4c63a30dc9b39e946c8d997a798adcccbc2d5eb 100644 (file)
@@ -130,7 +130,9 @@ public class KeyWindow extends SkinWindow {
                int heightTailPart = SHELL_MARGIN_BOTTOM;
 
                /* make a frame image */
-               this.cntHiddenButton = keyMapList.size() - BUTTON_DEFAULT_CNT;
+               if (keyMapList != null) {
+                       this.cntHiddenButton = keyMapList.size() - BUTTON_DEFAULT_CNT;
+               }
 
                this.imageFrame = frameMaker.getPatchedImage(
                                widthBase + ((cntHiddenButton > 0) ? widthScrollbar : 0),
index 34e3efce5b38681007b8c644f87fc07eef036499..59ab257bf8b51589e0aa2e2466f9921a4ac6d5ee 100644 (file)
@@ -324,6 +324,7 @@ public class ProfileSpecificSkinComposer implements ISkinComposer {
                                        e.gc.drawImage(currentState.getCurrentImage(), 0, 0);
                                }
 
+                               skin.getKeyWindowKeeper().redock(false, false);
                        }
                };
 
index 3c9d7b629344c69da5ed022c665dd14d2d5045ff..007ef265a735440705f8d583907484b6f3f28e1c 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.MenuItem;
 import org.tizen.emulator.skin.EmulatorSkin;
 import org.tizen.emulator.skin.custom.KeyWindow;
 import org.tizen.emulator.skin.custom.SkinWindow;
@@ -46,6 +47,7 @@ public class KeyWindowKeeper {
        private EmulatorSkin skin;
        private SkinWindow keyWindow;
        private int recentlyDocked;
+       private int indexLayout;
 
        /**
         *  Constructor
@@ -53,12 +55,13 @@ public class KeyWindowKeeper {
        public KeyWindowKeeper(EmulatorSkin skin) {
                this.skin = skin;
                this.recentlyDocked = SWT.NONE;
+               this.indexLayout = -1;
        }
 
        public void openKeyWindow(int dockValue, boolean recreate) {
                if (keyWindow != null) {
                        if (recreate == false) {
-                               /* show the key window */
+                               /* show the Key Window */
                                selectKeyWindowMenu(skin.isKeyWindow = true);
 
                                if (skin.pairTag != null) {
@@ -75,22 +78,32 @@ public class KeyWindowKeeper {
                        }
                }
 
-               /* create a key window */
-               List<KeyMapType> keyMapList = SkinUtil.getHWKeyMapList(
-                               skin.getEmulatorSkinState().getCurrentRotationId());
-
-               if (keyMapList == null) {
-                       selectKeyWindowMenu(skin.isKeyWindow = false);
-                       logger.info("keyMapList is null");
-                       return;
-               } else if (keyMapList.isEmpty() == true) {
-                       selectKeyWindowMenu(skin.isKeyWindow = false);
-                       logger.info("keyMapList is empty");
-                       return;
-               }
+               /* create a Key Window */
+               if (isGeneralKeyWindow() == true) {
+                       List<KeyMapType> keyMapList = SkinUtil.getHWKeyMapList(
+                                       skin.getEmulatorSkinState().getCurrentRotationId());
 
-               keyWindow = new KeyWindow(
-                               skin, skin.getShell(), skin.communicator, keyMapList);
+                       if (keyMapList == null) {
+                               selectKeyWindowMenu(skin.isKeyWindow = false);
+                               logger.info("keyMapList is null");
+                               return;
+                       } else if (keyMapList.isEmpty() == true) {
+                               selectKeyWindowMenu(skin.isKeyWindow = false);
+                               logger.info("keyMapList is empty");
+                               return;
+                       }
+
+                       keyWindow = new KeyWindow(
+                                       skin, skin.getShell(), skin.communicator, keyMapList);
+               } else {
+                       // TODO:
+                       String layoutName =
+                                       skin.getPopupMenu().keyWindowItem.getMenu().getItem(indexLayout).getText();
+                       logger.info("generate a \'" + layoutName + "\' key window!");
+
+                       keyWindow = new KeyWindow(
+                                       skin, skin.getShell(), skin.communicator, null);
+               }
 
                selectKeyWindowMenu(skin.isKeyWindow = true);
                SkinUtil.setTopMost(keyWindow.getShell(), skin.isOnTop);
@@ -131,18 +144,68 @@ public class KeyWindowKeeper {
                return keyWindow;
        }
 
+       public int getLayoutIndex() {
+               return indexLayout;
+       }
+
+       public boolean isGeneralKeyWindow() {
+               return (getLayoutIndex() < 0);
+       }
+
+       public int determineLayout() {
+               MenuItem keywindowItem = skin.getPopupMenu().keyWindowItem;
+
+               if (keywindowItem != null && keywindowItem.getMenu() != null) {
+                       logger.info("key window has a special layout");
+
+                       MenuItem[] layouts = keywindowItem.getMenu().getItems();
+                       for (int i = 0; i < layouts.length; i++) {
+                               MenuItem layout = layouts[i];
+
+                               if (layout.getSelection() == true) {
+                                       indexLayout = i;
+
+                                       logger.info("the \'" + layout.getText() +
+                                                       "\' layout is selected for key window");
+                                       break;
+                               }
+                       }
+               } else {
+                       logger.info("key window has a general layout");
+                       indexLayout = -1;
+               }
+
+               return indexLayout;
+       }
+
        /* for Menu */
        public boolean isSelectKeyWindowMenu() {
-               if (skin.getPopupMenu().keyWindowItem != null) {
-                       return skin.getPopupMenu().keyWindowItem.getSelection();
+               MenuItem keywindow = skin.getPopupMenu().keyWindowItem;
+
+               if (keywindow != null) {
+                       if (isGeneralKeyWindow() == true) {
+                               return keywindow.getSelection();
+                       } else {
+                               for (MenuItem layout : keywindow.getMenu().getItems()) {
+                                       if (layout.getSelection() == true) {
+                                               return true;
+                                       }
+                               }
+                       }
                }
 
                return false;
        }
 
        public void selectKeyWindowMenu(boolean on) {
-               if (skin.getPopupMenu().keyWindowItem != null) {
-                       skin.getPopupMenu().keyWindowItem.setSelection(on);
+               MenuItem keywindow = skin.getPopupMenu().keyWindowItem;
+
+               if (keywindow != null) {
+                       if (isGeneralKeyWindow() == true) {
+                               keywindow.setSelection(on);
+                       } else {
+                               keywindow.getMenu().getItem(indexLayout).setSelection(on);
+                       }
                }
        }
 
@@ -165,7 +228,7 @@ public class KeyWindowKeeper {
                return recentlyDocked;
        }
 
-       public void setRecentlyDocked(int recentlyDocked) {
-               this.recentlyDocked = recentlyDocked;
+       public void setRecentlyDocked(int dockValue) {
+               recentlyDocked = dockValue;
        }
 }
index 8f51df1781caa7832929d3294cd8fbb13e066c51..28a82c69be1f61793a4e070aba7e4b1d8da86a6f 100644 (file)
@@ -204,7 +204,6 @@ public class PopupMenu {
                        if (layouts != null) {
                                keyWindowItem = new MenuItem(menu, SWT.CASCADE);
                                keyWindowItem.setText(menuName);
-                               //TODO: advancedItem.setImage
 
                                Menu keywindowSubMenu = new Menu(menu.getShell(), SWT.DROP_DOWN);
                                {
@@ -213,15 +212,14 @@ public class PopupMenu {
                                        for (int i = 0; i < layouts.size(); i++) {
                                                File dir = layouts.get(i);
 
-                                               keywindowLayoutItem = new MenuItem(keywindowSubMenu, SWT.RADIO);
+                                               keywindowLayoutItem = new MenuItem(keywindowSubMenu, SWT.CHECK);
                                                keywindowLayoutItem.setText(dir.getName());
                                                if (i == 0) {
                                                        keywindowLayoutItem.setSelection(true);
                                                }
 
-                                               // TODO:
-                                               //SelectionAdapter keywindowLayoutListener =
-                                               //keywindowLayoutItem.addSelectionListener(keywindowLayoutListener);
+                                               SelectionAdapter keywindowLayoutListener = skin.createKeyWindowMenu();
+                                               keywindowLayoutItem.addSelectionListener(keywindowLayoutListener);
                                        }
                                }
                                keyWindowItem.setMenu(keywindowSubMenu);