skin: save a skin path information to SkinInfomation
authorGiWoong Kim <giwoong.kim@samsung.com>
Tue, 16 Jul 2013 08:36:57 +0000 (17:36 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Tue, 16 Jul 2013 11:21:46 +0000 (20:21 +0900)
save a skin path information to SkinInfomation

Change-Id: If0cc832f9d622b5a3dc1710df4f439925d193115
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java
tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java
tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java
tizen/src/skin/client/src/org/tizen/emulator/skin/info/SkinInformation.java

index fe13555..a43d25e 100644 (file)
 
 package org.tizen.emulator.skin;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.net.Socket;
 import java.util.HashMap;
@@ -59,7 +57,6 @@ import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.log.SkinLogger.SkinLogLevel;
 import org.tizen.emulator.skin.util.IOUtil;
 import org.tizen.emulator.skin.util.JaxbUtil;
-import org.tizen.emulator.skin.util.SkinUtil;
 import org.tizen.emulator.skin.util.StringUtil;
 import org.tizen.emulator.skin.util.SwtUtil;
 
@@ -68,6 +65,9 @@ import org.tizen.emulator.skin.util.SwtUtil;
  *
  */
 public class EmulatorSkinMain {
+       public static final String SKINS_FOLDER = "skins";
+       public static final String DEFAULT_SKIN_FOLDER = "emul-general-3btn";
+
        public static final String SKIN_INFO_FILE_NAME = "info.ini";
        public static final String SKIN_PROPERTIES_FILE_NAME = ".skin.properties";
        public static final String CONFIG_PROPERTIES_FILE_NAME = ".skinconfig.properties";
@@ -136,15 +136,20 @@ public class EmulatorSkinMain {
                        /* startup arguments parsing */
                        Map<String, String> argsMap = parseArgs(args);
 
-                       /* emulator resolution */
-                       /*int resolutionW = Integer.parseInt(
-                                       argsMap.get(ArgsConstants.RESOLUTION_WIDTH));
-                       int resolutionH = Integer.parseInt(
-                                       argsMap.get(ArgsConstants.RESOLUTION_HEIGHT));*/
-
                        /* get skin path from startup argument */
-                       String skinPath = ImageRegistry.getSkinPath(
-                                       (String) argsMap.get(ArgsConstants.SKIN_PATH));
+                       String argSkinPath = (String) argsMap.get(ArgsConstants.SKIN_PATH);
+                       String skinPath = ".." +
+                                       File.separator + SKINS_FOLDER + File.separator + DEFAULT_SKIN_FOLDER;
+
+                       File f = new File(argSkinPath);
+                       if (f.isDirectory() == false) {
+                               /* When emulator receive a invalid skin path,
+                                emulator uses default skin path instead of it */
+                               logger.info("Emulator uses default skin path (" + skinPath +
+                                               ") instead of invalid skin path (" + argSkinPath + ").");
+                       } else {
+                               skinPath = argSkinPath;
+                       }
 
                        /* set skin information */
                        String skinInfoFilePath = skinPath + File.separator + SKIN_INFO_FILE_NAME;
@@ -166,6 +171,7 @@ public class EmulatorSkinMain {
                                logger.info("skin info:" + skinInfoProperties); //TODO:
                        }
 
+                       /* determine the layout */
                        String skinInfoResolutionW =
                                        skinInfoProperties.getProperty(SkinInfoConstants.RESOLUTION_WIDTH);
                        String skinInfoResolutionH =
@@ -177,7 +183,8 @@ public class EmulatorSkinMain {
                                isGeneralSkin = true;
                        }
                        SkinInformation skinInfo = new SkinInformation(
-                                       skinInfoProperties.getProperty(SkinInfoConstants.SKIN_NAME), isGeneralSkin);
+                                       skinInfoProperties.getProperty(SkinInfoConstants.SKIN_NAME),
+                                       skinPath, isGeneralSkin);
 
                        /* set emulator window skin property */
                        String skinPropFilePath = vmPath + File.separator + SKIN_PROPERTIES_FILE_NAME;
@@ -221,28 +228,8 @@ public class EmulatorSkinMain {
                        EmulatorConfig config = new EmulatorConfig(argsMap,
                                        dbiContents, skinProperties, skinPropFilePath, configProperties);
 
-                       /* load SDK version */
-                       String strVersion = "Undefined";
-                       String versionFilePath = SkinUtil.getSdkVersionFilePath();
-
-                       File file = new File(versionFilePath);
-                       if (file.exists() && file.isFile()) {
-                               BufferedReader reader = new BufferedReader(
-                                               new FileReader(versionFilePath));
-
-                               strVersion = reader.readLine();
-
-                               reader.close();
-                       } else {
-                               logger.info("cannot find version file" + versionFilePath);
-                       }
-
-                       logger.info("SDK version : " + strVersion);
-                       config.setSkinProperty(
-                                       EmulatorConfig.SkinInfoConstants.SDK_VERSION_NAME, strVersion);
-
                        /* load image resource */
-                       ImageRegistry.getInstance().initialize(config);
+                       ImageRegistry.getInstance().initialize(config, skinPath);
 
                        /* load Always on Top value */
                        String onTopVal = config.getSkinProperty(
index 8bcd8ab..a259472 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * 
  *
- * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact:
  * GiWoong Kim <giwoong.kim@samsung.com>
 
 package org.tizen.emulator.skin.config;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.FileReader;
 import java.io.IOException;
 import java.util.Map;
 import java.util.Properties;
@@ -46,6 +49,7 @@ import org.tizen.emulator.skin.exception.ConfigException;
 import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.log.SkinLogger.SkinLogLevel;
 import org.tizen.emulator.skin.util.IOUtil;
+import org.tizen.emulator.skin.util.SkinUtil;
 import org.tizen.emulator.skin.util.StringUtil;
 
 
@@ -104,6 +108,9 @@ public class EmulatorConfig {
        private Properties configProperties;
        private String skinPropertiesFilePath;
 
+       /**
+        *  Constructor
+        */
        public EmulatorConfig(Map<String, String> args,
                        EmulatorUI dbiContents, Properties skinProperties,
                        String skinPropertiesFilePath, Properties configProperties) {
@@ -116,6 +123,33 @@ public class EmulatorConfig {
                if (null == configProperties) {
                        this.configProperties = new Properties();
                }
+
+               /* load SDK version */
+               String strVersion = "Undefined";
+               String versionFilePath = SkinUtil.getSdkVersionFilePath();
+
+               File file = new File(versionFilePath);
+
+               try {
+                       if (file.exists() && file.isFile()) {
+                               BufferedReader reader = new BufferedReader(
+                                               new FileReader(versionFilePath));
+
+                               strVersion = reader.readLine();
+
+                               reader.close();
+                       } else {
+                               logger.info("cannot find version file" + versionFilePath);
+                       }
+               } catch (FileNotFoundException e) {
+                       logger.log(Level.SEVERE, e.getMessage(), e);
+               } catch (IOException e) {
+                       logger.log(Level.SEVERE, e.getMessage(), e);
+               }
+
+               logger.info("SDK version : " + strVersion);
+               setSkinProperty(
+                               EmulatorConfig.SkinInfoConstants.SDK_VERSION_NAME, strVersion);
        }
 
        public static void validateArgs(Map<String, String> args) throws ConfigException {
@@ -208,14 +242,15 @@ public class EmulatorConfig {
                        skinProperties.setProperty(SkinPropertiesConstants.WINDOW_X, "" + xx);
                }
 
-               if( skinProperties.containsKey( SkinPropertiesConstants.WINDOW_Y ) ) {
+               if ( skinProperties.containsKey( SkinPropertiesConstants.WINDOW_Y ) ) {
                        String y = skinProperties.getProperty( SkinPropertiesConstants.WINDOW_Y );
                        int yy = 0;
 
                        try {
                                yy = Integer.parseInt( y );
                        } catch ( NumberFormatException e ) {
-                               String msg = SkinPropertiesConstants.WINDOW_Y + " in .skin.properties is not numeric. : " + y;
+                               String msg = SkinPropertiesConstants.WINDOW_Y +
+                                               " in .skin.properties is not numeric. : " + y;
                                throw new ConfigException( msg );
                        }
 
@@ -240,7 +275,8 @@ public class EmulatorConfig {
                        try {
                                Integer.parseInt( rotation );
                        } catch ( NumberFormatException e ) {
-                               String msg = SkinPropertiesConstants.WINDOW_ROTATION + " in .skin.properties is not numeric. : " + rotation;
+                               String msg = SkinPropertiesConstants.WINDOW_ROTATION +
+                                               " in .skin.properties is not numeric. : " + rotation;
                                throw new ConfigException( msg );
                        }
                }
@@ -250,7 +286,8 @@ public class EmulatorConfig {
                        try {
                                Integer.parseInt( scale );
                        } catch ( NumberFormatException e ) {
-                               String msg = SkinPropertiesConstants.WINDOW_SCALE + " in .skin.properties is not numeric. : " + scale;
+                               String msg = SkinPropertiesConstants.WINDOW_SCALE +
+                                               " in .skin.properties is not numeric. : " + scale;
                                throw new ConfigException( msg );
                        }
                }
index be9149b..5d93293 100644 (file)
@@ -42,7 +42,6 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.ImageData;
 import org.eclipse.swt.widgets.Display;
 import org.tizen.emulator.skin.config.EmulatorConfig;
-import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
 import org.tizen.emulator.skin.dbi.EmulatorUI;
 import org.tizen.emulator.skin.dbi.ImageListType;
 import org.tizen.emulator.skin.dbi.RotationType;
@@ -57,15 +56,14 @@ import org.tizen.emulator.skin.util.SkinRotation;
  *
  */
 public class ImageRegistry {
-       private static Logger logger =
-                       SkinLogger.getSkinLogger(ImageRegistry.class).getLogger();
-
-       public static final String SKINS_FOLDER = "skins";
        public static final String GENERAL_FOLDER = "emul-general-3btn";
        public static final String ICON_FOLDER = "icons";
        public static final String IMAGES_FOLDER = "images";
        public static final String KEYWINDOW_FOLDER = "key-window";
 
+       private static Logger logger =
+                       SkinLogger.getSkinLogger(ImageRegistry.class).getLogger();
+
        public enum ImageType {
                IMG_TYPE_MAIN,
                IMG_TYPE_PRESSED
@@ -138,7 +136,7 @@ public class ImageRegistry {
        private Map<String, Image> iconMap;
        private Map<String, Image> keyWindowImageMap;
 
-       private String argSkinPath;
+       private String skinPath;
 
        private static ImageRegistry instance;
        private static boolean isInitialized;
@@ -155,7 +153,7 @@ public class ImageRegistry {
                return instance;
        }
 
-       public void initialize(EmulatorConfig config) {
+       public void initialize(EmulatorConfig config, String skinPath) {
                if (isInitialized) {
                        return;
                }
@@ -163,38 +161,13 @@ public class ImageRegistry {
 
                this.display = Display.getDefault();
 
-               this.argSkinPath = config.getArg(ArgsConstants.SKIN_PATH);
+               this.skinPath = skinPath;
                this.dbiContents = config.getDbiContents();
                this.skinImageMap = new HashMap<String, Image>();
                this.iconMap = new HashMap<String, Image>();
                this.keyWindowImageMap = new HashMap<String, Image>();
 
-               init(this.argSkinPath);
-
-       }
-
-       public static String getSkinPath(String argSkinPath) {
-               /* When emulator receive a invalid skin path,
-                emulator uses default skin path instead of it */
-               String defaultSkinPath = ".." + //TODO:
-                               File.separator + SKINS_FOLDER + File.separator + GENERAL_FOLDER;
-
-               if (argSkinPath == null) {
-                       logger.info("Emulator uses default skin path (" + defaultSkinPath +
-                                       ") instead of invalid skin path (null).");
-
-                       return defaultSkinPath;
-               }
-
-               File f = new File(argSkinPath);
-               if (f.isDirectory() == false) {
-                       logger.info("Emulator uses default skin path (" + defaultSkinPath +
-                                       ") instead of invalid skin path (" + argSkinPath + ").");
-
-                       return defaultSkinPath;
-               }
-
-               return argSkinPath;
+               init(this.skinPath);
        }
 
        private void init(String argSkinPath) {
@@ -228,7 +201,6 @@ public class ImageRegistry {
                                return null;
                        }
 
-                       String skinPath = getSkinPath(argSkinPath);
                        logger.info("get image data of skin from " + skinPath);
 
                        RotationType targetRotation = SkinRotation.getRotation(id);
index 09dc1ab..7f2d932 100644 (file)
@@ -33,11 +33,13 @@ package org.tizen.emulator.skin.info;
  */
 public class SkinInformation {
        private String skinName;
+       private String skinPath;
        private boolean isGeneralSkin;
        private int skinOption;
 
-       public SkinInformation(String skinName, boolean isGeneralSkin) {
+       public SkinInformation(String skinName, String skinPath, boolean isGeneralSkin) {
                this.skinName = skinName;
+               this.skinPath = skinPath;
                this.isGeneralSkin = isGeneralSkin;
                this.skinOption = 0;
        }
@@ -46,6 +48,10 @@ public class SkinInformation {
                return skinName;
        }
 
+       public String getSkinPath() {
+               return skinPath;
+       }
+
        public boolean isGeneralPurposeSkin() {
                return isGeneralSkin;
        }