skin: added GeneralSkinImageRegistry 42/10642/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Tue, 1 Oct 2013 04:23:20 +0000 (13:23 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Tue, 8 Oct 2013 06:13:28 +0000 (15:13 +0900)
Change-Id: I1c0c72d9bc117eb79ea09b663d292d579a807ec8
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/custom/GeneralKeyWindow.java
tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java
tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralKeyWindowImageRegistry.java
tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralSkinImageRegistry.java [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java
tizen/src/skin/client/src/org/tizen/emulator/skin/image/ProfileSkinImageRegistry.java
tizen/src/skin/client/src/org/tizen/emulator/skin/image/SpecialKeyWindowImageRegistry.java
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java

index ab111fc0590c6bfbf7afb71fdb210aabf1f09645..ed815b2bbef297ac47c930e264b3e3e36b5e63fb 100644 (file)
@@ -34,6 +34,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.Socket;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.logging.Level;
@@ -50,6 +51,8 @@ import org.tizen.emulator.skin.config.EmulatorConfig.ConfigPropertiesConstants;
 import org.tizen.emulator.skin.config.EmulatorConfig.SkinInfoConstants;
 import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
 import org.tizen.emulator.skin.dbi.EmulatorUI;
+import org.tizen.emulator.skin.dbi.RotationType;
+import org.tizen.emulator.skin.dbi.RotationsType;
 import org.tizen.emulator.skin.exception.JaxbException;
 import org.tizen.emulator.skin.image.ImageRegistry;
 import org.tizen.emulator.skin.info.SkinInformation;
@@ -57,6 +60,7 @@ 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.SkinRotation;
 import org.tizen.emulator.skin.util.StringUtil;
 import org.tizen.emulator.skin.util.SwtUtil;
 
@@ -411,6 +415,18 @@ public class EmulatorSkinMain {
                        logger.info("=======================================");
 
                        emulatorUI = JaxbUtil.unmarshal(bytes, EmulatorUI.class);
+
+                       /* register rotation info */
+                       RotationsType rotations = emulatorUI.getRotations();
+                       if (rotations != null) {
+                               List<RotationType> rotationList = rotations.getRotation();
+
+                               for (RotationType rotation : rotationList) {
+                                       SkinRotation.put(rotation);
+                               }
+                       } else {
+                               logger.severe("Fail to loading rotations element from XML");
+                       }
                } catch (IOException e) {
                        logger.log(Level.SEVERE, e.getMessage(), e);
                } catch (JaxbException e) {
index a9c196a8b4bb2fa95cfbaf365b4780c593530f87..7c15bf01009358f889128bcdba02ca32c36a7b27 100644 (file)
@@ -118,11 +118,11 @@ public class GeneralKeyWindow extends SkinWindow {
                shell.setImage(parent.getImage());
 
                /* load image for HW key button */
-               imageNormal = imageRegistry.getGeneralKeyWindowImageData(
+               imageNormal = imageRegistry.getKeyWindowImage(
                                GeneralKeyWindowImageName.KEYBUTTON_NORMAL);
-               imageHover = imageRegistry.getGeneralKeyWindowImageData(
+               imageHover = imageRegistry.getKeyWindowImage(
                                GeneralKeyWindowImageName.KEYBUTTON_HOVER);
-               imagePushed = imageRegistry.getGeneralKeyWindowImageData(
+               imagePushed = imageRegistry.getKeyWindowImage(
                                GeneralKeyWindowImageName.KEYBUTTON_PUSHED);
 
                /* calculate the key window size */
@@ -176,26 +176,26 @@ public class GeneralKeyWindow extends SkinWindow {
                        Image imagesScrollArrowUp[] = new Image[3];
                        Image imagesScrollArrowDown[] = new Image[3];
 
-                       imagesScrollArrowUp[0] = imageRegistry.getGeneralKeyWindowImageData(
+                       imagesScrollArrowUp[0] = imageRegistry.getKeyWindowImage(
                                        GeneralKeyWindowImageName.SCROLL_UPBUTTON_NORMAL);
-                       imagesScrollArrowUp[1] = imageRegistry.getGeneralKeyWindowImageData(
+                       imagesScrollArrowUp[1] = imageRegistry.getKeyWindowImage(
                                        GeneralKeyWindowImageName.SCROLL_UPBUTTON_HOVER);
-                       imagesScrollArrowUp[2] = imageRegistry.getGeneralKeyWindowImageData(
+                       imagesScrollArrowUp[2] = imageRegistry.getKeyWindowImage(
                                        GeneralKeyWindowImageName.SCROLL_UPBUTTON_PUSHED);
 
-                       imagesScrollArrowDown[0] = imageRegistry.getGeneralKeyWindowImageData(
+                       imagesScrollArrowDown[0] = imageRegistry.getKeyWindowImage(
                                        GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_NORMAL);
-                       imagesScrollArrowDown[1] = imageRegistry.getGeneralKeyWindowImageData(
+                       imagesScrollArrowDown[1] = imageRegistry.getKeyWindowImage(
                                        GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_HOVER);
-                       imagesScrollArrowDown[2] = imageRegistry.getGeneralKeyWindowImageData(
+                       imagesScrollArrowDown[2] = imageRegistry.getKeyWindowImage(
                                        GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_PUSHED);
 
                        CustomScrolledComposite compositeScroll =
                                        new CustomScrolledComposite(shell, SWT.NONE,
                                                        imagesScrollArrowUp, imagesScrollArrowDown,
-                                                       imageRegistry.getGeneralKeyWindowImageData(
+                                                       imageRegistry.getKeyWindowImage(
                                                                        GeneralKeyWindowImageName.SCROLL_THUMB),
-                                                       imageRegistry.getGeneralKeyWindowImageData(
+                                                       imageRegistry.getKeyWindowImage(
                                                                        GeneralKeyWindowImageName.SCROLL_SHAFT));
                        compositeScroll.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));
 
index 88db58851f1ef20f611f70213a369624edc2dd92..2325fb001b9012ed88f940ddbc0c8a33100276dd 100644 (file)
@@ -123,8 +123,8 @@ public class SpecialKeyWindow extends SkinWindow {
                this.imageRegistry = new SpecialKeyWindowImageRegistry(shell.getDisplay(), dbiContents, specialKeyWindowPath);
                
                /* get keywindow image */
-               keyWindowImage = imageRegistry.getSpecialKeyWindowImage(EmulatorConfig.DEFAULT_WINDOW_ROTATION, SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL);           
-               keyWindowPressedImage = imageRegistry.getSpecialKeyWindowImage(EmulatorConfig.DEFAULT_WINDOW_ROTATION, SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED);
+               keyWindowImage = imageRegistry.getKeyWindowImage(EmulatorConfig.DEFAULT_WINDOW_ROTATION, SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL);          
+               keyWindowPressedImage = imageRegistry.getKeyWindowImage(EmulatorConfig.DEFAULT_WINDOW_ROTATION, SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED);
                
                SpecialKeyWindowUtil.trimShell(shell, keyWindowImage);
                SpecialKeyWindowUtil.trimShell(shell, keyWindowPressedImage);
index e1c841c01ab2475afb93c5a5a31355d7d5d62e1d..cf2872c1d48dbbdd0e162680e5e4eff18eb1c431 100644 (file)
@@ -28,6 +28,7 @@
 
 package org.tizen.emulator.skin.image;
 
+import java.io.File;
 import java.io.InputStream;
 import java.util.Collection;
 import java.util.HashMap;
@@ -82,7 +83,7 @@ public class GeneralKeyWindowImageRegistry {
                this.keyWindowImageMap = new HashMap<String, Image>();
        }
 
-       public Image getGeneralKeyWindowImageData(GeneralKeyWindowImageName name) {
+       public Image getKeyWindowImage(GeneralKeyWindowImageName name) {
                if (keyWindowImageMap.size() == 0) {
                        /* load all of the images at once */
                        ClassLoader classLoader = this.getClass().getClassLoader();
@@ -92,8 +93,8 @@ public class GeneralKeyWindowImageRegistry {
                        GeneralKeyWindowImageName[] values = GeneralKeyWindowImageName.values();
                        for (GeneralKeyWindowImageName value : values) {
                                imageName = value.getName();
-                               imagePath = ImageRegistry.IMAGES_FOLDER + "/" +
-                                               KEYWINDOW_FOLDER + "/" + imageName;
+                               imagePath = ImageRegistry.IMAGES_FOLDER + File.separator
+                                               + KEYWINDOW_FOLDER + File.separator + imageName;
 
                                try {
                                        is = classLoader.getResourceAsStream(imagePath);
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralSkinImageRegistry.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralSkinImageRegistry.java
new file mode 100644 (file)
index 0000000..2559bba
--- /dev/null
@@ -0,0 +1,120 @@
+/**
+ * Image Resource Management For General-Purpose Skin
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.skin.image;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.util.IOUtil;
+
+public class GeneralSkinImageRegistry {
+       private static final String PATCH_IMAGES_PATH = "emul-window";
+
+       private static Logger logger = SkinLogger.getSkinLogger(
+                       GeneralSkinImageRegistry.class).getLogger();
+
+       public enum GeneralSkinImageName {
+               TOGGLE_BUTTON_NORMAL("arrow_nml.png"),
+               TOGGLE_BUTTON_HOVER("arrow_hover.png"),
+               TOGGLE_BUTTON_PUSHED("arrow_pushed.png");
+
+               private String name;
+
+               private GeneralSkinImageName(String name) {
+                       this.name = name;
+               }
+
+               public String getName() {
+                       return this.name;
+               }
+       }
+
+       private Display display;
+       private Map<String, Image> skinImageMap;
+
+       /**
+        *  Constructor
+        */
+       public GeneralSkinImageRegistry(Display display) {
+               this.display = display;
+               this.skinImageMap = new HashMap<String, Image>();
+       }
+
+       public Image getSkinImage(GeneralSkinImageName name) {
+               if (skinImageMap.size() == 0) {
+                       /* load all of the images at once */
+                       ClassLoader classLoader = this.getClass().getClassLoader();
+                       InputStream is = null;
+                       String imageName, imagePath;
+
+                       GeneralSkinImageName[] values = GeneralSkinImageName.values();
+                       for (GeneralSkinImageName value : values) {
+                               imageName = value.getName();
+                               imagePath = ImageRegistry.IMAGES_FOLDER + File.separator
+                                               + PATCH_IMAGES_PATH + File.separator + imageName;
+
+                               try {
+                                       is = classLoader.getResourceAsStream(imagePath);
+                                       if (null != is) {
+                                               logger.fine("KeyWindow image is loaded : " + imagePath);
+                                               skinImageMap.put(imageName, new Image(display, is));
+                                       } else {
+                                               logger.severe("missing image : " + imagePath);
+                                       }
+                               } finally {
+                                       IOUtil.close(is);
+                               }
+                       }
+               }
+
+               return skinImageMap.get(name.getName());
+       }
+
+       public void dispose() {
+               if (null != skinImageMap) {
+                       Image image = null;
+
+                       Collection<Image>  images = skinImageMap.values();
+                       Iterator<Image> imageIterator = images.iterator();
+
+                       while (imageIterator.hasNext()) {
+                               image = imageIterator.next();
+                               image.dispose();
+                       }
+               }
+       }
+}
index dc6b8ed5ef189a5937791edc69051875f434eb46..62a1058b3df1506e3f47bebe70ef1106b39eee2f 100644 (file)
@@ -33,19 +33,14 @@ import java.io.InputStream;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
 
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
 import org.tizen.emulator.skin.config.EmulatorConfig;
-import org.tizen.emulator.skin.dbi.EmulatorUI;
-import org.tizen.emulator.skin.dbi.RotationType;
-import org.tizen.emulator.skin.dbi.RotationsType;
 import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.util.IOUtil;
-import org.tizen.emulator.skin.util.SkinRotation;
 
 
 /**
@@ -110,13 +105,9 @@ public class ImageRegistry {
        }
 
        private Display display;
-       private EmulatorUI dbiContents;
-
        private Map<String, Image> resourceImageMap;
        private Map<String, Image> iconImageMap;
 
-       private String skinPath;
-
        private static ImageRegistry instance;
        private static boolean isInitialized;
 
@@ -142,29 +133,8 @@ public class ImageRegistry {
                isInitialized = true;
 
                this.display = Display.getDefault();
-
-               this.skinPath = skinPath;
-               this.dbiContents = config.getDbiContents();
-
                this.resourceImageMap = new HashMap<String, Image>();
                this.iconImageMap = new HashMap<String, Image>();
-
-               init(this.skinPath);
-       }
-
-       private void init(String argSkinPath) {
-               RotationsType rotations = dbiContents.getRotations();
-
-               if (null == rotations) {
-                       logger.severe("Fail to loading rotations element from dbi.");
-                       return;
-               }
-
-               List<RotationType> rotationList = rotations.getRotation();
-
-               for (RotationType rotation : rotationList) {
-                       SkinRotation.put(rotation);
-               }
        }
 
        public Image getResourceImage(ResourceImageName name) {
index cd720da24f14f0ac307fa65c8ac3ac0dc7d933f0..35e3e57449ef8b4dda7cbf6978cefbb7b339d56f 100644 (file)
@@ -68,23 +68,6 @@ public class ProfileSkinImageRegistry {
                this.skinPath = skinPath;
                this.dbiContents = dbiContents;
                this.skinImageMap = new HashMap<String, Image>();
-
-               initialize(skinPath);
-       }
-
-       private void initialize(String argSkinPath) {
-               RotationsType rotations = dbiContents.getRotations();
-
-               if (null == rotations) {
-                       logger.severe("Fail to loading rotations element from XML");
-                       return;
-               }
-
-               List<RotationType> rotationList = rotations.getRotation();
-
-               for (RotationType rotation : rotationList) {
-                       SkinRotation.put(rotation);
-               }
        }
 
        private String makeKey(Short id, SkinImageType imageType) {
index 9e413c3d4d3504a5427036965f72d23f1b747eff..f55c7920434733b49a64021257e723deb31a8173 100644 (file)
@@ -97,7 +97,7 @@ public class SpecialKeyWindowImageRegistry {
                return id + ":" + imageType.ordinal();
        }
 
-       public Image getSpecialKeyWindowImage(Short id, SpecailKeyWindowImageType imageType) {
+       public Image getKeyWindowImage(Short id, SpecailKeyWindowImageType imageType) {
                Image image = keyWindowImageMap.get(makeKey(id, imageType));
 
                if (image == null) {
index 98fdf6c951885c3992ead8d91bdec11499b3f004..5f37efdae66cb5cdb903f1634016bdda1839d239 100644 (file)
@@ -54,6 +54,8 @@ import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
 import org.tizen.emulator.skin.custom.ColorTag;
 import org.tizen.emulator.skin.custom.CustomButton;
 import org.tizen.emulator.skin.custom.CustomProgressBar;
+import org.tizen.emulator.skin.image.GeneralSkinImageRegistry;
+import org.tizen.emulator.skin.image.GeneralSkinImageRegistry.GeneralSkinImageName;
 import org.tizen.emulator.skin.image.ImageRegistry.IconName;
 import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.menu.PopupMenu;
@@ -63,10 +65,6 @@ import org.tizen.emulator.skin.util.SwtUtil;
 
 public class GeneralPurposeSkinComposer implements ISkinComposer {
        private static final String PATCH_IMAGES_PATH = "images/emul-window/";
-       private static final String TOGGLE_BUTTON_NORMAL_IMG = "arrow_nml.png";
-       private static final String TOGGLE_BUTTON_HOVER_IMG = "arrow_hover.png";
-       private static final String TOGGLE_BUTTON_PUSHED_IMG = "arrow_pushed.png";
-
        private static final int PAIR_TAG_POSITION_X = 26;
        private static final int PAIR_TAG_POSITION_Y = 13;
 
@@ -87,6 +85,7 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
        private MouseMoveListener shellMouseMoveListener;
        private MouseListener shellMouseListener;
 
+       private GeneralSkinImageRegistry imageRegistry;
        private boolean isGrabbedShell;
        private Point grabPosition;
 
@@ -100,6 +99,9 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                this.isGrabbedShell= false;
                this.grabPosition = new Point(0, 0);
 
+               this.imageRegistry =
+                               new GeneralSkinImageRegistry(shell.getDisplay());
+
                this.frameMaker = new SkinPatches(PATCH_IMAGES_PATH);
                this.backgroundColor = new Color(shell.getDisplay(), new RGB(38, 38, 38));
        }
@@ -148,13 +150,12 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                }
 
                /* load image for toggle button of key window */
-               ClassLoader loader = this.getClass().getClassLoader();
-               Image imageNormal = new Image(shell.getDisplay(),
-                               loader.getResourceAsStream(PATCH_IMAGES_PATH + TOGGLE_BUTTON_NORMAL_IMG));
-               Image imageHover = new Image(shell.getDisplay(),
-                               loader.getResourceAsStream(PATCH_IMAGES_PATH + TOGGLE_BUTTON_HOVER_IMG));
-               Image imagePushed = new Image(shell.getDisplay(),
-                               loader.getResourceAsStream(PATCH_IMAGES_PATH + TOGGLE_BUTTON_PUSHED_IMG));
+               Image imageNormal = imageRegistry.getSkinImage(
+                               GeneralSkinImageName.TOGGLE_BUTTON_NORMAL);
+               Image imageHover = imageRegistry.getSkinImage(
+                               GeneralSkinImageName.TOGGLE_BUTTON_HOVER);
+               Image imagePushed = imageRegistry.getSkinImage(
+                               GeneralSkinImageName.TOGGLE_BUTTON_PUSHED);
 
                /* create a toggle button of key window */
                toggleButton = new CustomButton(shell, SWT.DRAW_TRANSPARENT | SWT.NO_FOCUS,
@@ -438,56 +439,6 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                shell.addMouseListener(shellMouseListener);
        }
 
-//     private void createHWKeyRegion() {
-//             if (compositeBase != null) {
-//                     compositeBase.dispose();
-//                     compositeBase = null;
-//             }
-//
-//             List<KeyMapType> keyMapList =
-//                             SkinUtil.getHWKeyMapList(currentState.getCurrentRotationId());
-//
-//             if (keyMapList != null && keyMapList.isEmpty() == false) {
-//                     compositeBase = new Composite(shell, SWT.NONE);
-//                     compositeBase.setLayout(new GridLayout(1, true));
-//
-//                     for (KeyMapType keyEntry : keyMapList) {
-//                             Button hardKeyButton = new Button(compositeBase, SWT.FLAT);
-//                             hardKeyButton.setText(keyEntry.getEventInfo().getKeyName());
-//                             hardKeyButton.setToolTipText(keyEntry.getTooltip());
-//
-//                             hardKeyButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-//
-//                             final int keycode = keyEntry.getEventInfo().getKeyCode();
-//                             hardKeyButton.addMouseListener(new MouseListener() {
-//                                     @Override
-//                                     public void mouseDown(MouseEvent e) {
-//                                             KeyEventData keyEventData = new KeyEventData(
-//                                                             KeyEventType.PRESSED.value(), keycode, 0, 0);
-//                                             communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
-//                                     }
-//
-//                                     @Override
-//                                     public void mouseUp(MouseEvent e) {
-//                                             KeyEventData keyEventData = new KeyEventData(
-//                                                             KeyEventType.RELEASED.value(), keycode, 0, 0);
-//                                             communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
-//                                     }
-//
-//                                     @Override
-//                                     public void mouseDoubleClick(MouseEvent e) {
-//                                             /* do nothing */
-//                                     }
-//                             });
-//                     }
-//
-//                     FormData dataComposite = new FormData();
-//                     dataComposite.left = new FormAttachment(displayCanvas, 0);
-//                     dataComposite.top = new FormAttachment(0, 0);
-//                     compositeBase.setLayoutData(dataComposite);
-//             }
-//     }
-
        @Override
        public void composerFinalize() {
                if (null != shellPaintListener) {
@@ -515,5 +466,6 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                }
 
                frameMaker.freePatches();
+               imageRegistry.dispose();
        }
 }