menu: try to detect layouts for Key Window
authorGiWoong Kim <giwoong.kim@samsung.com>
Tue, 23 Jul 2013 05:53:12 +0000 (14:53 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Tue, 23 Jul 2013 06:01:00 +0000 (15:01 +0900)
try to detect layouts from skin path

Change-Id: I3df0a337573d9b07d74dd8671f108975a4e2cc87
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/menu/PopupMenu.java

index 045675d..8f51df1 100644 (file)
@@ -28,6 +28,9 @@
 
 package org.tizen.emulator.skin.menu;
 
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
 import java.util.logging.Logger;
 
 import org.eclipse.swt.SWT;
@@ -60,6 +63,8 @@ public class PopupMenu {
        public static final String SDBSHELL_MENUITEM_NAME = "S&hell";
        public static final String CLOSE_MENUITEM_NAME = "&Close";
 
+       public static final String KEYWINDOW_LAYOUT_ROOT = "keywindow-layout";
+
        private static Logger logger =
                        SkinLogger.getSkinLogger(PopupMenu.class).getLogger();
 
@@ -192,12 +197,42 @@ public class PopupMenu {
 
                if (keywindowMenuType == null ||
                                (keywindowMenuType != null && keywindowMenuType.isVisible() == true)) {
-                       keyWindowItem = new MenuItem(menu, SWT.CHECK);
-                       keyWindowItem.setText(menuName);
-                       keyWindowItem.setSelection(skin.isKeyWindow);
+                       String pathLayoutRoot = skin.skinInfo.getSkinPath() +
+                                       File.separator + KEYWINDOW_LAYOUT_ROOT;
+                       ArrayList<File> layouts = getKeyWindowLayoutList(pathLayoutRoot);
+
+                       if (layouts != null) {
+                               keyWindowItem = new MenuItem(menu, SWT.CASCADE);
+                               keyWindowItem.setText(menuName);
+                               //TODO: advancedItem.setImage
+
+                               Menu keywindowSubMenu = new Menu(menu.getShell(), SWT.DROP_DOWN);
+                               {
+                                       MenuItem keywindowLayoutItem = null;
+
+                                       for (int i = 0; i < layouts.size(); i++) {
+                                               File dir = layouts.get(i);
+
+                                               keywindowLayoutItem = new MenuItem(keywindowSubMenu, SWT.RADIO);
+                                               keywindowLayoutItem.setText(dir.getName());
+                                               if (i == 0) {
+                                                       keywindowLayoutItem.setSelection(true);
+                                               }
 
-                       SelectionAdapter keyWindowListener = skin.createKeyWindowMenu();
-                       keyWindowItem.addSelectionListener(keyWindowListener);
+                                               // TODO:
+                                               //SelectionAdapter keywindowLayoutListener =
+                                               //keywindowLayoutItem.addSelectionListener(keywindowLayoutListener);
+                                       }
+                               }
+                               keyWindowItem.setMenu(keywindowSubMenu);
+                       } else {
+                               keyWindowItem = new MenuItem(menu, SWT.CHECK);
+                               keyWindowItem.setText(menuName);
+                               keyWindowItem.setSelection(skin.isKeyWindow);
+
+                               SelectionAdapter keyWindowListener = skin.createKeyWindowMenu();
+                               keyWindowItem.addSelectionListener(keyWindowListener);
+                       }
                }
 
                /* Advanced menu */
@@ -307,4 +342,38 @@ public class PopupMenu {
        public Menu getMenuRoot() {
                return contextMenu;
        }
+
+       private ArrayList<File> getKeyWindowLayoutList(String path) {
+               File pathRoot = new File(path);
+
+               if (pathRoot.exists() == true) {
+                       FileFilter filter = new FileFilter() {
+                               @Override
+                               public boolean accept(File pathname) {
+                                       if (!pathname.isDirectory()) {
+                                               return false;
+                                       }
+
+                                       return true;
+                               }
+                       };
+
+                       File[] layoutPaths = pathRoot.listFiles(filter);
+                       if (layoutPaths.length <= 0) {
+                               logger.info("the layout of key window not found");
+                               return null;
+                       }
+
+                       ArrayList<File> layoutList = new ArrayList<File>();
+                       for (File layout : layoutPaths) {
+                               logger.info("the layout of key window detected : " + layout.getName());
+
+                               layoutList.add(layout);
+                       }
+
+                       return layoutList;
+               }
+
+               return null;
+       }
 }