menu: method for initial scale factor value determining 18/12918/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Mon, 25 Nov 2013 10:19:07 +0000 (19:19 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Tue, 26 Nov 2013 02:40:45 +0000 (11:40 +0900)
Emulator does not use fixed value(1/2x) for initial scale
factor anymore. It depend on arrange of Scale menu.
The first sub menu item of Scale menu will be choosen as
initial scale for emulator window. (except when there is
already 1/2x factor as sub menu item)

Change-Id: I1750269035d4324139adf343a76246597e2066a1
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/menu/PopupMenu.java
tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java

index cf7917b..b2f137a 100755 (executable)
@@ -247,13 +247,10 @@ public class EmulatorSkin {
                imageRegistry = ImageRegistry.getInstance();
 
                /* set emulator states */
-               currentState.setCurrentResolutionWidth(
-                               config.getArgInt(ArgsConstants.RESOLUTION_WIDTH));
-               currentState.setCurrentResolutionHeight(
-                               config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT));
+               currentState.setCurrentResolutionWidth(config.getValidResolutionWidth());
+               currentState.setCurrentResolutionHeight(config.getValidResolutionHeight());
 
-               int scale = SkinUtil.getValidScale(config);
-               currentState.setCurrentScale(scale);
+               currentState.setCurrentScale(config.getValidScale());
 
                short rotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
                currentState.setCurrentRotationId(rotationId);
index 3f20dcc..3f9c7e1 100644 (file)
@@ -60,15 +60,17 @@ public class EmulatorConfig {
        public static final String INVALID_OPTION_MESSAGE =
                        "An invalid option have caused the error.\n";
 
-       private static Logger logger =
-                       SkinLogger.getSkinLogger(EmulatorConfig.class).getLogger();
-
        public static final int DEFAULT_WINDOW_SCALE = 50;
+       public static final int MIN_SCALE_FACTOR = 25;
+       public static final int MAX_SCALE_FACTOR = 200;
        public static final short DEFAULT_WINDOW_ROTATION = RotationInfo.PORTRAIT.id();
        public static final int DEFAULT_WINDOW_X = 50;
        public static final int DEFAULT_WINDOW_Y = 50;
        public static final SkinLogLevel DEFAULT_LOG_LEVEL = SkinLogLevel.DEBUG;
 
+       private static Logger logger =
+                       SkinLogger.getSkinLogger(EmulatorConfig.class).getLogger();
+
        public interface ArgsConstants {
                public static final String SIMPLE_MESSAGE = "simple.msg";
                public static final String UID = "uid";
@@ -244,14 +246,14 @@ public class EmulatorConfig {
 
                if (skinProperties.containsKey(
                                SkinPropertiesConstants.WINDOW_X) == true) {
-                       String x = skinProperties.getProperty(SkinPropertiesConstants.WINDOW_X);
+                       String window_x = skinProperties.getProperty(SkinPropertiesConstants.WINDOW_X);
                        int xx = 0;
 
                        try {
-                               xx = Integer.parseInt(x);
+                               xx = Integer.parseInt(window_x);
                        } catch (NumberFormatException e) {
                                String msg = SkinPropertiesConstants.WINDOW_X +
-                                               " in .skin.properties is not numeric : " + x;
+                                               " in .skin.properties is not numeric : " + window_x;
                                logger.warning(msg);
 
                                xx = DEFAULT_WINDOW_X;
@@ -275,14 +277,14 @@ public class EmulatorConfig {
 
                if (skinProperties.containsKey(
                                SkinPropertiesConstants.WINDOW_Y) == true) {
-                       String y = skinProperties.getProperty(SkinPropertiesConstants.WINDOW_Y);
+                       String window_y = skinProperties.getProperty(SkinPropertiesConstants.WINDOW_Y);
                        int yy = 0;
 
                        try {
-                               yy = Integer.parseInt(y);
+                               yy = Integer.parseInt(window_y);
                        } catch (NumberFormatException e) {
                                String msg = SkinPropertiesConstants.WINDOW_Y +
-                                               " in .skin.properties is not numeric. : " + y;
+                                               " in .skin.properties is not numeric. : " + window_y;
                                logger.warning(msg);
 
                                yy = DEFAULT_WINDOW_Y;
@@ -336,6 +338,8 @@ public class EmulatorConfig {
 
                        skinProperties.setProperty(SkinPropertiesConstants.WINDOW_SCALE, "" + percent);
                }
+
+               // TODO: WINDOW_ONTOP, KEYWINDOW_POSITION
        }
 
        public static void validateSkinConfigProperties(
@@ -344,7 +348,7 @@ public class EmulatorConfig {
                        return;
                }
 
-               // TODO:
+               // TODO: HEART_BEAT_IGNORE, LOG_LEVEL
        }
 
        public void saveSkinProperties() {
@@ -421,6 +425,14 @@ public class EmulatorConfig {
                return Boolean.parseBoolean(arg);
        }
 
+       public int getValidResolutionWidth() {
+               return getArgInt(ArgsConstants.RESOLUTION_WIDTH);
+       }
+
+       public int getValidResolutionHeight() {
+               return getArgInt(ArgsConstants.RESOLUTION_HEIGHT);
+       }
+
        /* java properties */
        private void setProperty(Properties properties, String key, String value) {
                properties.put(key, value);
@@ -502,6 +514,18 @@ public class EmulatorConfig {
                setProperty(skinProperties, key, value);
        }
 
+       public int getValidScale() {
+               int storedScale = getSkinPropertyInt(
+                               SkinPropertiesConstants.WINDOW_SCALE, DEFAULT_WINDOW_SCALE);
+
+               if (storedScale >= MIN_SCALE_FACTOR &&
+                               storedScale <= MAX_SCALE_FACTOR) { /* percentage */
+                       return storedScale;
+               } else {
+                       return DEFAULT_WINDOW_SCALE;
+               }
+       }
+
        /* config properties */
        public String getConfigProperty(String key) {
                return getProperty(configProperties, key);
index 0b37902..57335a4 100644 (file)
@@ -288,30 +288,32 @@ public class PopupMenu {
                scaleItem.setText(name);
                scaleItem.setImage(imageRegistry.getIcon(IconName.SCALE));
 
-               SelectionAdapter scaleListener = skin.createScaleMenuListener();
+               if (factors == null) {
+                       /* use default factor array */
+                       ScaleItemType.FactorItem actual = new ScaleItemType.FactorItem();
+                       actual.setItemName("1x");
+                       actual.setValue(100);
 
-               Menu scaleSubMenu = new Menu(menu.getShell(), SWT.DROP_DOWN);
-               {
-                       if (factors == null) {
-                               /* use default factor array */
-                               ScaleItemType.FactorItem actual = new ScaleItemType.FactorItem();
-                               actual.setItemName("1x");
-                               actual.setValue(100);
+                       ScaleItemType.FactorItem threeQuater = new ScaleItemType.FactorItem();
+                       threeQuater.setItemName("3/4x");
+                       threeQuater.setValue(75);
 
-                               ScaleItemType.FactorItem threeQuater = new ScaleItemType.FactorItem();
-                               threeQuater.setItemName("3/4x");
-                               threeQuater.setValue(75);
+                       ScaleItemType.FactorItem half = new ScaleItemType.FactorItem();
+                       half.setItemName("1/2x");
+                       half.setValue(50);
 
-                               ScaleItemType.FactorItem half = new ScaleItemType.FactorItem();
-                               half.setItemName("1/2x");
-                               half.setValue(50);
+                       ScaleItemType.FactorItem quater = new ScaleItemType.FactorItem();
+                       quater.setItemName("1/4x");
+                       quater.setValue(25);
 
-                               ScaleItemType.FactorItem quater = new ScaleItemType.FactorItem();
-                               quater.setItemName("1/4x");
-                               quater.setValue(25);
+                       factors = Arrays.asList(actual, threeQuater, half, quater);
+               }
 
-                               factors = Arrays.asList(actual, threeQuater, half, quater);
-                       }
+               SelectionAdapter scaleListener = skin.createScaleMenuListener();
+
+               Menu scaleSubMenu = new Menu(menu.getShell(), SWT.DROP_DOWN);
+               {
+                       MenuItem matchedItem = null;
 
                        for (ScaleItemType.FactorItem factor : factors) {
                                final MenuItem menuItem = new MenuItem(scaleSubMenu, SWT.RADIO);
@@ -320,11 +322,19 @@ public class PopupMenu {
 
                                if (skin.getEmulatorSkinState().getCurrentScale()
                                                == (Integer) menuItem.getData()) {
-                                       menuItem.setSelection(true);
+                                       matchedItem = menuItem;
                                }
 
                                menuItem.addSelectionListener(scaleListener);
                        }
+
+                       if (matchedItem == null) {
+                               matchedItem = scaleSubMenu.getItem(0);
+                               skin.getEmulatorSkinState().setCurrentScale(
+                                               (Integer) matchedItem.getData());
+                       }
+
+                       matchedItem.setSelection(true);
                }
 
                scaleItem.setMenu(scaleSubMenu);
index 28c505a..40bcffb 100644 (file)
@@ -49,7 +49,6 @@ import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
 import org.tizen.emulator.skin.config.EmulatorConfig;
 import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
-import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
 import org.tizen.emulator.skin.dbi.EventInfoType;
 import org.tizen.emulator.skin.dbi.KeyMapListType;
 import org.tizen.emulator.skin.dbi.KeyMapType;
@@ -69,9 +68,6 @@ public class SkinUtil {
        public static final String COCOA_OS_CLASS = "org.eclipse.swt.internal.cocoa.OS";
 
        public static final int UNKNOWN_KEYCODE = -1;
-
-       public static final int MIN_SCALE_FACTOR = 25;
-       public static final int MAX_SCALE_FACTOR = 200;
        public static final int SCALE_CONVERTER = 100;
 
        public static final String EMULATOR_PREFIX = "Emulator";
@@ -302,26 +298,6 @@ public class SkinUtil {
                return (float) scale / SCALE_CONVERTER;
        }
 
-       public static int getValidScale(EmulatorConfig config) {
-               int storedScale = config.getSkinPropertyInt(
-                               SkinPropertiesConstants.WINDOW_SCALE, EmulatorConfig.DEFAULT_WINDOW_SCALE);
-
-               if (!SkinUtil.isValidScale(storedScale)) {
-                       return EmulatorConfig.DEFAULT_WINDOW_SCALE;
-               } else {
-                       return storedScale;
-               }
-       }
-
-       public static boolean isValidScale(int scale) {
-               if (scale >= MIN_SCALE_FACTOR &&
-                               scale <= MAX_SCALE_FACTOR) { /* percentage */
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-
        public static <T> int openMessage(Shell shell,
                        String title, String message, int style, EmulatorConfig config) {
                MessageBox messageBox = new MessageBox(shell, style);