skin: added special keyWindow
authorGiWoong Kim <giwoong.kim@samsung.com>
Thu, 22 Aug 2013 04:26:51 +0000 (13:26 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Thu, 22 Aug 2013 04:26:51 +0000 (13:26 +0900)
Change-Id: Id8a5f048d26be3a80f9b58917e1412ba1c49353e
Signed-off-by: hyunjin816.lee <hyunjin816.lee@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/comm/ICommunicator.java
tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/image/KeyWindowImageRegistry.java [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/menu/KeyWindowKeeper.java
tizen/src/skin/client/src/org/tizen/emulator/skin/util/KeyWindowRotation.java [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/util/SpecialKeyWindowUtil.java [new file with mode: 0644]

index 43e65e285ba4021e385dcb952276356376b85e98..238423066750a9474ea47609a10490e4249c9f35 100644 (file)
@@ -653,7 +653,33 @@ public class EmulatorSkin {
                        @Override
                        public void mouseMove(MouseEvent e) {
                                logger.info("mouse move : " + e);
-                               // TODO:
+                               int eventType = MouseEventType.MOVE.value();
+
+                               if (true == isDisplayDragging) {
+                                       Point canvasSize = lcdCanvas.getSize();
+                                       eventType = MouseEventType.DRAG.value();
+                                       if (e.x < 0) {
+                                               e.x = 0;
+                                               eventType = MouseEventType.RELEASE.value();
+                                               isDisplayDragging = false;
+                                       } else if (e.x >= canvasSize.x) {
+                                               e.x = canvasSize.x - 1;
+                                               eventType = MouseEventType.RELEASE.value();
+                                               isDisplayDragging = false;
+                                       }
+
+                                       if (e.y < 0) {
+                                               e.y = 0;
+                                               eventType = MouseEventType.RELEASE.value();
+                                               isDisplayDragging = false;
+                                       } else if (e.y >= canvasSize.y) {
+                                               e.y = canvasSize.y - 1;
+                                               eventType = MouseEventType.RELEASE.value();
+                                               isDisplayDragging = false;
+                                       }
+                               }
+
+                               mouseMoveDelivery(e, eventType);
                        }
                };
 
@@ -705,13 +731,25 @@ public class EmulatorSkin {
                        @Override
                        public void mouseUp(MouseEvent e) {
                                logger.info("mouse up : " + e);
-                               // TODO:
+                               if (1 == e.button) { /* left button */
+                                       if (true == isDisplayDragging) {
+                                               isDisplayDragging = false;
+                                       }
+                                       mouseUpDelivery(e);
+                               } else if (2 == e.button) { /* wheel button */
+                                       logger.info("wheelUp in display");
+                               }
                        }
 
                        @Override
                        public void mouseDown(MouseEvent e) {
                                logger.info("mouse down : " + e);
-                               // TODO:
+                               if (1 == e.button) { /* left button */
+                                       if (false == isDisplayDragging) {
+                                               isDisplayDragging = true;
+                                       }
+                                       mouseDownDelivery(e);
+                               }
                        }
 
                        @Override
index 20f3ca8b609b46e40f5bb977fa6fa0288a57835f..dc0299e4c05fdce1b9f30e790c4f933a0f4ddf3e 100644 (file)
@@ -96,7 +96,9 @@ public interface ICommunicator extends Runnable {
                RELEASE( (short)2 ),
                DRAG( (short)3 ),
                WHEELUP( (short)4 ),
-               WHEELDOWN( (short)5 );
+               WHEELDOWN( (short)5 ),
+               MOVE( (short)6 ),
+               DOUBLECLICK( (short)7 );
 
                private short value;
                MouseEventType( short value ) {
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java
new file mode 100644 (file)
index 0000000..6cc93b2
--- /dev/null
@@ -0,0 +1,434 @@
+/**
+ *
+ *
+ * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * Hyunjin Lee <hyunjin816.lee@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.custom;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.logging.Level;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.Region;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.skin.EmulatorSkin;
+import org.tizen.emulator.skin.comm.ICommunicator.KeyEventType;
+import org.tizen.emulator.skin.comm.ICommunicator.MouseButtonType;
+import org.tizen.emulator.skin.comm.ICommunicator.MouseEventType;
+import org.tizen.emulator.skin.comm.ICommunicator.SendCommand;
+import org.tizen.emulator.skin.comm.sock.SocketCommunicator;
+import org.tizen.emulator.skin.comm.sock.data.KeyEventData;
+import org.tizen.emulator.skin.comm.sock.data.MouseEventData;
+import org.tizen.emulator.skin.config.EmulatorConfig;
+import org.tizen.emulator.skin.dbi.EmulatorUI;
+import org.tizen.emulator.skin.exception.JaxbException;
+import org.tizen.emulator.skin.image.KeyWindowImageRegistry;
+import org.tizen.emulator.skin.image.KeyWindowImageRegistry.ImageType;
+import org.tizen.emulator.skin.layout.HWKey;
+import org.tizen.emulator.skin.layout.SkinPatches;
+import org.tizen.emulator.skin.util.IOUtil;
+import org.tizen.emulator.skin.util.JaxbUtil;
+import org.tizen.emulator.skin.util.SpecialKeyWindowUtil;
+import org.tizen.emulator.skin.util.SwtUtil;
+
+public class SpecialKeyWindow extends SkinWindow {
+       private static final String PATCH_IMAGES_PATH = "images/key-window/";
+       private static final String KEYWINDOW_LAYOUT = "keywindow-layout";      
+       private static final String DBI_FILE_NAME = "default.dbi";      
+
+       private EmulatorSkin skin;
+       private SkinPatches frameMaker;
+       
+       private HWKey currentPressedHWKey;
+
+       private int widthBase;
+       private int heightBase;
+       
+       private Image imageFrame; /* nine-patch image */
+       private Image keyWindowImage;
+       private Image keyWindowPressedImage;
+
+       private Color colorFrame;
+       private SocketCommunicator communicator;        
+
+       private ShellListener shellListener;
+       private PaintListener shellPaintListener;
+       private MouseMoveListener shellMouseMoveListener;
+       private MouseListener shellMouseListener;
+       
+       private boolean isTouch;
+       private boolean isGrabbedShell;
+       private Point grabPosition;
+
+       public SpecialKeyWindow(EmulatorSkin skin, Shell parent, SocketCommunicator communicator, String path) {
+               super(parent, SWT.RIGHT | SWT.CENTER);
+
+               this.skin = skin;
+               this.shell = new Shell(Display.getDefault(),
+                               SWT.NO_TRIM | SWT.RESIZE | SWT.TOOL);
+               this.frameMaker = new SkinPatches(PATCH_IMAGES_PATH);
+               
+               this.communicator = communicator;       
+               this.grabPosition = new Point(0, 0);
+
+               shell.setText(parent.getText());
+               shell.setImage(parent.getImage());
+               
+               /* load dbi file */
+               String skinPath = skin.skinInfo.getSkinPath();
+               String specialKeyWindowPath = skinPath + File.separator + KEYWINDOW_LAYOUT + File.separator + path;
+               logger.info("special key window path : " + specialKeyWindowPath);
+               EmulatorUI dbiContents = loadXMLForKeyWindow(specialKeyWindowPath);
+
+               /* image init */
+               KeyWindowImageRegistry.getInstance().initialize(dbiContents, specialKeyWindowPath);
+               
+               /* get keywindow image */
+               keyWindowImage = KeyWindowImageRegistry.getInstance().getSpecialKeyWindowImage(EmulatorConfig.DEFAULT_WINDOW_ROTATION, ImageType.IMG_TYPE_MAIN);                
+               keyWindowPressedImage = KeyWindowImageRegistry.getInstance().getSpecialKeyWindowImage(EmulatorConfig.DEFAULT_WINDOW_ROTATION, ImageType.IMG_TYPE_PRESSED);
+               
+               SpecialKeyWindowUtil.trimShell(shell, keyWindowImage);
+               SpecialKeyWindowUtil.trimShell(shell, keyWindowPressedImage);
+               
+               /* calculate the key window size */
+               widthBase = keyWindowImage.getImageData().width;
+               heightBase = keyWindowImage.getImageData().height;
+
+               /* make a frame image */
+               this.imageFrame = frameMaker.getPatchedImage(
+                               widthBase,
+                               heightBase);
+               this.colorFrame = new Color(shell.getDisplay(), new RGB(38, 38, 38));
+
+               shell.setBackground(colorFrame);
+               
+               trimPatchedShell(shell, imageFrame);
+
+               addKeyWindowListener();
+
+               shell.setSize(widthBase, heightBase);
+       }
+
+       private EmulatorUI loadXMLForKeyWindow(String skinPath) {
+               String dbiPath = skinPath + File.separator + DBI_FILE_NAME;
+               logger.info("load dbi file from " + dbiPath);
+
+               FileInputStream fis = null;
+               EmulatorUI emulatorUI = null;
+
+               try {
+                       fis = new FileInputStream(dbiPath);
+                       logger.info("============ dbi contents ============");
+                       byte[] bytes = IOUtil.getBytes(fis);
+                       logger.info(new String(bytes, "UTF-8"));
+                       logger.info("=======================================");
+
+                       emulatorUI = JaxbUtil.unmarshal(bytes, EmulatorUI.class);
+               } catch (IOException e) {
+                       logger.log(Level.SEVERE, e.getMessage(), e);
+               } catch (JaxbException e) {
+                       logger.log(Level.SEVERE, e.getMessage(), e);
+               } finally {
+                       IOUtil.close(fis);
+               }
+
+               return emulatorUI;
+       }
+
+       public static void trimPatchedShell(Shell shell, Image image) {
+               if (null == image) {
+                       return;
+               }
+               ImageData imageData = image.getImageData();
+
+               int width = imageData.width;
+               int height = imageData.height;
+
+               Region region = new Region();
+               region.add(new Rectangle(0, 0, width, height));
+
+               int r = shell.getDisplay().getSystemColor(SWT.COLOR_MAGENTA).getRed();
+               int g = shell.getDisplay().getSystemColor(SWT.COLOR_MAGENTA).getGreen();
+               int b = shell.getDisplay().getSystemColor(SWT.COLOR_MAGENTA).getBlue();
+               int colorKey;
+
+               if (SwtUtil.isWindowsPlatform()) {
+                       colorKey = r << 24 | g << 16 | b << 8;
+               } else {
+                       colorKey = r << 16 | g << 8 | b;
+               }
+
+               for (int i = 0; i < width; i++) {
+                       for (int j = 0; j < height; j++) {
+                               int colorPixel = imageData.getPixel(i, j);
+                               if (colorPixel == colorKey /* magenta */) {
+                                       region.subtract(i, j, 1, 1);
+                               }
+                       }
+               }
+
+               shell.setRegion(region);
+       }
+
+       private void addKeyWindowListener() {
+               shellPaintListener = new PaintListener() {
+                       @Override
+                       public void paintControl(final PaintEvent e) {
+                               if (keyWindowImage != null) {
+                                       e.gc.drawImage(keyWindowImage, 0, 0);
+                               }                               
+                       }
+               };
+
+               shell.addPaintListener(shellPaintListener);
+
+               shellListener = new ShellListener() {
+                       @Override
+                       public void shellClosed(ShellEvent event) {
+                               logger.info("Special Key Window is closed");
+
+                               if (skin.pairTag != null) {
+                                       skin.pairTag.setVisible(false);
+                               }
+
+                               if (null != shellPaintListener) {
+                                       shell.removePaintListener(shellPaintListener);
+                               }
+
+                               if (null != shellListener) {
+                                       shell.removeShellListener(shellListener);
+                               }
+
+                               if (null != shellMouseMoveListener) {
+                                       shell.removeMouseMoveListener(shellMouseMoveListener);
+                               }
+
+                               if (null != shellMouseListener) {
+                                       shell.removeMouseListener(shellMouseListener);
+                               }
+
+                               colorFrame.dispose();
+
+                               frameMaker.freePatches();
+                       }
+
+                       @Override
+                       public void shellActivated(ShellEvent event) {
+                               logger.info("activate");
+
+                               if (SwtUtil.isMacPlatform() == true) {
+                                       parent.moveAbove(shell);
+                               } else {
+                                       shell.getDisplay().asyncExec(new Runnable() {
+                                               @Override
+                                               public void run() {
+                                                       parent.setActive();
+                                               }
+                                       });
+                               }
+                       }
+
+                       @Override
+                       public void shellDeactivated(ShellEvent event) {
+                               logger.info("deactivate");
+
+                               /* do nothing */
+                       }
+
+                       @Override
+                       public void shellIconified(ShellEvent event) {
+                               /* do nothing */
+                       }
+
+                       @Override
+                       public void shellDeiconified(ShellEvent event) {
+                               logger.info("deiconified");
+
+                               shell.getDisplay().asyncExec(new Runnable() {
+                                       @Override
+                                       public void run() {
+                                               if (parent.getMinimized() == true) {
+                                                       parent.setMinimized(false);
+                                               }
+                                       }
+                               });
+                       }
+               };
+
+               shell.addShellListener(shellListener);
+
+               shellMouseMoveListener = new MouseMoveListener() {
+                       @Override
+                       public void mouseMove(MouseEvent e) {
+                               if (isTouch == true) {                                  
+                                       logger.info("MouseMove in SpecialKeyWindow : " + e.x + ", " + e.y);
+                                       HWKey pressedHWKey = currentPressedHWKey;                                       
+                                       int x = pressedHWKey.getRegion().x;
+                                       int y = pressedHWKey.getRegion().y;
+                                       int width = pressedHWKey.getRegion().width;
+                                       int height = pressedHWKey.getRegion().height;
+                                       int eventType;
+                                       
+                                       if (SpecialKeyWindowUtil.isInGeometry(e.x, e.y, x, y, width, height)) {
+                                               eventType = MouseEventType.DRAG.value();
+                                       } else {
+                                               isTouch = false;
+                                               eventType = MouseEventType.RELEASE.value();
+                                               /* rollback a keyPressed image resion */
+                                               shell.redraw(x, y, width, height, false);
+                                       }
+                                       
+                                       MouseEventData mouseEventData = new MouseEventData(
+                                                       MouseButtonType.LEFT.value(), MouseEventType.DRAG.value(), e.x, e.y, e.x, e.y, 0);
+                                       communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData, false);
+                               } else if (isGrabbedShell == true && e.button == 0/* left button */) {
+                                       if (getDockPosition() != SWT.NONE) {
+                                               dock(SWT.NONE, false, false);
+                                               shell.moveAbove(parent);
+                                       }
+
+                                       /* move a window */
+                                       Point previousLocation = shell.getLocation();
+                                       int x = previousLocation.x + (e.x - grabPosition.x);
+                                       int y = previousLocation.y + (e.y - grabPosition.y);
+
+                                       shell.setLocation(x, y);
+                                       return;
+                               }
+                       }
+               };
+
+               shell.addMouseMoveListener(shellMouseMoveListener);
+
+               shellMouseListener = new MouseListener() {
+                       @Override
+                       public void mouseUp(MouseEvent e) {
+                               if (e.button == 1) { /* left button */
+                                       logger.info("MouseUp in SpecialKeyWindow : " + e.x + ", " + e.y);
+                                       isGrabbedShell = false;
+                                       grabPosition.x = grabPosition.y = 0;
+                                       HWKey pressedHWKey = currentPressedHWKey;
+                                       
+                                       if (pressedHWKey != null && pressedHWKey.getKeyCode() != SpecialKeyWindowUtil.UNKNOWN_KEYCODE) {
+                                               /* send event */
+                                               if (isTouch) {
+                                                       isTouch = false;
+                                                       MouseEventData mouseEventData = new MouseEventData(
+                                                                       MouseButtonType.LEFT.value(), MouseEventType.RELEASE.value(), e.x, e.y, e.x, e.y, 0);
+                                                       communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData, false);
+                                               } else {
+                                                       KeyEventData keyEventData = new KeyEventData(KeyEventType.RELEASED.value(), pressedHWKey.getKeyCode(), 0, 0);
+                                                       communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData, false);
+                                               }
+                                               
+                                               currentPressedHWKey = null;
+                                               
+                                               /* rollback a keyPressed image resion */
+                                               shell.redraw(pressedHWKey.getRegion().x, pressedHWKey.getRegion().y, 
+                                                               pressedHWKey.getRegion().width, pressedHWKey.getRegion().height, false);
+                                       }                                               
+                               }
+                       }
+
+                       @Override
+                       public void mouseDown(MouseEvent e) {
+                               if (1 == e.button) { /* left button */
+                                       logger.info("MouseDown in SpecialKeyWindow : " + e.x + ", " + e.y);
+                                               
+                                       /* HW key handling */
+                                       final HWKey hwKey = SpecialKeyWindowUtil.getHWKey(e.x, e.y, EmulatorConfig.DEFAULT_WINDOW_ROTATION);
+                                       if (hwKey == null) {            
+                                               isGrabbedShell = true;
+                                               grabPosition.x = e.x;
+                                               grabPosition.y = e.y;
+                                               return;                                         
+                                       }
+                                       
+                                       if (hwKey.getKeyCode() != SpecialKeyWindowUtil.UNKNOWN_KEYCODE) {
+                                               if (hwKey.getTooltip().equalsIgnoreCase("touch")) {
+                                                       isTouch = true;
+                                                       MouseEventData mouseEventData = new MouseEventData(
+                                                                       MouseButtonType.LEFT.value(), MouseEventType.PRESS.value(), e.x, e.y, e.x, e.y, 0);
+                                                       communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData, false);
+                                               } else {
+                                                       /* send event */
+                                                       KeyEventData keyEventData = new KeyEventData(KeyEventType.PRESSED.value(), hwKey.getKeyCode(), 0, 0);
+                                                       communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData, false);
+                                               }
+                                               
+                                               currentPressedHWKey = hwKey;
+                                               shell.setToolTipText(null);
+                                               
+                                               /* draw the HW key region as the cropped keyPressed image area */
+                                               if(hwKey.getRegion() != null &&
+                                                               hwKey.getRegion().width != 0 && hwKey.getRegion().height != 0) {
+                                                       shell.getDisplay().syncExec(new Runnable() {
+                                                               public void run() {
+                                                                       if(keyWindowPressedImage != null) {
+                                                                               GC gc = new GC(shell);
+                                                                               if(gc != null) {
+                                                                                       gc.drawImage(keyWindowPressedImage, 
+                                                                                                       hwKey.getRegion().x, hwKey.getRegion().y, 
+                                                                                                       hwKey.getRegion().width, hwKey.getRegion().height, 
+                                                                                                       hwKey.getRegion().x, hwKey.getRegion().y, 
+                                                                                                       hwKey.getRegion().width, hwKey.getRegion().height);
+                                                                                       gc.dispose();
+                                                                               }                                                                               
+                                                                       }
+                                                               } /* end of run */
+                                                       });
+                                               }
+                                       }
+                               }
+                       }
+
+                       @Override
+                       public void mouseDoubleClick(MouseEvent e) {
+                               /* do nothing */
+                       }
+               };
+
+               shell.addMouseListener(shellMouseListener);
+       }
+}
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/KeyWindowImageRegistry.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/KeyWindowImageRegistry.java
new file mode 100644 (file)
index 0000000..8567ea8
--- /dev/null
@@ -0,0 +1,282 @@
+/**
+ * image resources management
+ *
+ * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ *
+ * 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.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+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.dbi.EmulatorUI;
+import org.tizen.emulator.skin.dbi.ImageListType;
+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.KeyWindowRotation;
+
+
+/**
+ * 
+ *
+ */
+public class KeyWindowImageRegistry {
+       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(KeyWindowImageRegistry.class).getLogger();
+
+       public enum ImageType {
+               IMG_TYPE_MAIN,
+               IMG_TYPE_PRESSED
+       }
+
+       public enum IconName {
+               DETAIL_INFO("detail_info.png"),
+               ROTATE("rotate.png"),
+               SCALE("scale.png"),
+               SHELL("shell.png"),
+               ADVANCED("advanced.png"),
+               CLOSE("close.png"),
+               SCREENSHOT("screenshot.png"),
+               USB_KEYBOARD("usb_keyboard.png"),
+               HOST_KEYBOARD("host_keyboard.png"),
+               DIAGNOSIS("diagnosis.png"),
+               FORCE_CLOSE("force_close.png"),
+               ABOUT("about.png"),
+
+               COPY_SCREEN_SHOT("copy_screenshot_dialog.png"),
+               REFRESH_SCREEN_SHOT("refresh_screenshot_dialog.png"),
+               INCREASE_SCALE("increase_scale.png"),
+               DECREASE_SCALE("decrease_scale.png"),
+               SAVE_SCREEN_SHOT("save_screenshot_dialog.png"),
+
+               EMULATOR_TITLE("emulator_icon.png"),
+               EMULATOR_TITLE_ICO("emulator_icon.ico");
+               
+               private String name;
+               
+               private IconName(String name) {
+                       this.name = name;
+               }
+               
+               public String getName() {
+                       return this.name;
+               }
+               
+       }
+
+       public enum KeyWindowImageName {
+               KEYBUTTON_NORMAL("keybutton_nml.png"),
+               KEYBUTTON_HOVER("keybutton_hover.png"),
+               KEYBUTTON_PUSHED("keybutton_pushed.png"),
+
+               SCROLL_UPBUTTON_NORMAL("scroll_button_up_nml.png"),
+               SCROLL_UPBUTTON_HOVER("scroll_button_up_hover.png"),
+               SCROLL_UPBUTTON_PUSHED("scroll_button_up_pushed.png"),
+               SCROLL_DOWNBUTTON_NORMAL("scroll_button_down_nml.png"),
+               SCROLL_DOWNBUTTON_HOVER("scroll_button_down_hover.png"),
+               SCROLL_DOWNBUTTON_PUSHED("scroll_button_down_pushed.png"),
+               SCROLL_THUMB("scroll_thumb.png"),
+               SCROLL_SHAFT("scroll_back.png");
+
+               private String name;
+
+               private KeyWindowImageName(String name) {
+                       this.name = name;
+               }
+
+               public String getName() {
+                       return this.name;
+               }
+       }
+
+       private Display display;
+       private EmulatorUI dbiContents;
+
+       private Map<String, Image> skinImageMap;
+       private Map<String, Image> iconMap;
+       private Map<String, Image> keyWindowImageMap;
+
+       private String skinPath;
+
+       private static KeyWindowImageRegistry instance;
+       private static boolean isInitialized;
+
+       private KeyWindowImageRegistry() {
+               /* do nothing */
+       }
+
+       public static KeyWindowImageRegistry getInstance() {
+               if (null == instance) {
+                       instance = new KeyWindowImageRegistry();
+               }
+
+               return instance;
+       }
+
+       public void initialize(EmulatorUI dbiContents, String skinPath) {
+               if (isInitialized) 
+                       KeyWindowRotation.clear();      
+               
+               isInitialized = true;
+
+               this.display = Display.getDefault();
+
+               this.skinPath = skinPath;
+               this.dbiContents = dbiContents;
+               this.skinImageMap = new HashMap<String, Image>();
+               this.iconMap = new HashMap<String, Image>();
+               this.keyWindowImageMap = 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) {
+                       KeyWindowRotation.put(rotation);
+               }
+       }
+
+       public Image getSpecialKeyWindowImage(Short id, ImageType imageType) {
+
+               Image image = skinImageMap.get(makeKey(id, imageType));
+
+               if (null != image) {
+                       return image;
+               } else {
+                       RotationsType rotations = dbiContents.getRotations();
+
+                       if (null == rotations) {
+                               logger.severe("Fail to loading rotations element from dbi.");
+                               return null;
+                       }
+
+                       logger.info("get image data of skin from " + skinPath);
+
+                       RotationType targetRotation = KeyWindowRotation.getRotation(id);
+                       List<RotationType> rotationList = rotations.getRotation();
+
+                       for (RotationType rotation : rotationList) {
+                               ImageListType imageList = rotation.getImageList();
+                               if (imageList == null) {
+                                       continue;
+                               }
+
+                               String mainImage = imageList.getMainImage();
+                               String keyPressedImage = imageList.getKeyPressedImage();
+
+                               if (targetRotation.getName().value().equals(rotation.getName().value())) {
+                                       String mainKey = makeKey(id, ImageType.IMG_TYPE_MAIN);
+                                       skinImageMap.put(mainKey,
+                                                       new Image(display, skinPath + File.separator + mainImage));
+
+                                       String pressedKey = makeKey(id, ImageType.IMG_TYPE_PRESSED);
+                                       skinImageMap.put(pressedKey,
+                                                       new Image(display, skinPath + File.separator + keyPressedImage));
+
+                                       break;
+                               }
+                       }
+
+                       Image registeredImage = skinImageMap.get(makeKey(id, imageType));
+
+                       if (null != registeredImage) {
+                               return registeredImage;
+                       } else {
+                               return null;
+                       }
+
+               }
+       }
+
+       private String makeKey(Short id, ImageType imageType) {
+               return id + ":" + imageType.ordinal();
+       }
+
+       public void dispose() {
+               /* skin image */
+               if (null != skinImageMap) {
+                       Collection<Image> images = skinImageMap.values();
+
+                       Iterator<Image> imageIterator = images.iterator();
+
+                       while (imageIterator.hasNext()) {
+                               Image image = imageIterator.next();
+                               image.dispose();
+                       }
+               }
+
+               /* icon */
+               if (null != iconMap) {
+                       Collection<Image> icons = iconMap.values();
+
+                       Iterator<Image> iconIterator = icons.iterator();
+
+                       while (iconIterator.hasNext()) {
+                               Image image = iconIterator.next();
+                               image.dispose();
+                       }
+               }
+
+               /* key window image */
+               if (null != keyWindowImageMap) {
+                       Collection<Image> images = keyWindowImageMap.values();
+
+                       Iterator<Image> imagesIterator = images.iterator();
+
+                       while (imagesIterator.hasNext()) {
+                               Image image = imagesIterator.next();
+                               image.dispose();
+                       }
+               }
+       }
+}
index 007ef265a735440705f8d583907484b6f3f28e1c..aa7f0f7bb23d4e7b51385cda9a61bebccb6d79b9 100644 (file)
@@ -36,6 +36,7 @@ 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;
+import org.tizen.emulator.skin.custom.SpecialKeyWindow;
 import org.tizen.emulator.skin.dbi.KeyMapType;
 import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.util.SkinUtil;
@@ -101,8 +102,8 @@ public class KeyWindowKeeper {
                                        skin.getPopupMenu().keyWindowItem.getMenu().getItem(indexLayout).getText();
                        logger.info("generate a \'" + layoutName + "\' key window!");
 
-                       keyWindow = new KeyWindow(
-                                       skin, skin.getShell(), skin.communicator, null);
+                       keyWindow = new SpecialKeyWindow(
+                                       skin, skin.getShell(), skin.communicator, layoutName);
                }
 
                selectKeyWindowMenu(skin.isKeyWindow = true);
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/KeyWindowRotation.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/KeyWindowRotation.java
new file mode 100644 (file)
index 0000000..d66c0a4
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ * 
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ * Hyunjin Lee <hyunjin816.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.util;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
+import org.tizen.emulator.skin.dbi.RotationType;
+
+
+/**
+ * 
+ *
+ */
+public class KeyWindowRotation {
+       
+       private static Map<Short, RotationType> rotationMap;
+       private static Map<Short, RotationInfo> angleMap;
+       
+       private KeyWindowRotation(){}
+       
+       static {
+               rotationMap = new LinkedHashMap<Short, RotationType>();
+               angleMap = new HashMap<Short, RotationInfo>();
+       }
+       
+       public static void clear() {
+               if (!rotationMap.isEmpty())
+                       rotationMap.clear();
+               if (!angleMap.isEmpty())
+                       angleMap.clear();
+       }
+       
+       public static void put(RotationType rotation ) {
+
+               if ( RotationInfo.PORTRAIT.value().equalsIgnoreCase( rotation.getName().value() ) ) {
+                       rotationMap.put( RotationInfo.PORTRAIT.id(), rotation );
+                       angleMap.put( RotationInfo.PORTRAIT.id(), RotationInfo.PORTRAIT );
+               } else if ( RotationInfo.LANDSCAPE.value().equalsIgnoreCase( rotation.getName().value() ) ) {
+                       rotationMap.put( RotationInfo.LANDSCAPE.id(), rotation );
+                       angleMap.put( RotationInfo.LANDSCAPE.id(), RotationInfo.LANDSCAPE );
+               } else if ( RotationInfo.REVERSE_PORTRAIT.value().equalsIgnoreCase( rotation.getName().value() ) ) {
+                       rotationMap.put( RotationInfo.REVERSE_PORTRAIT.id(), rotation );
+                       angleMap.put( RotationInfo.REVERSE_PORTRAIT.id(), RotationInfo.REVERSE_PORTRAIT );
+               } else if ( RotationInfo.REVERSE_LANDSCAPE.value().equalsIgnoreCase( rotation.getName().value() ) ) {
+                       rotationMap.put( RotationInfo.REVERSE_LANDSCAPE.id(), rotation );
+                       angleMap.put( RotationInfo.REVERSE_LANDSCAPE.id(), RotationInfo.REVERSE_LANDSCAPE );
+               }
+
+       }
+
+       public static int getAngle( Short rotationId ) {
+               RotationInfo rotationInfo = angleMap.get(rotationId);
+               if( null != rotationInfo ) {
+                       return rotationInfo.angle();
+               }else {
+                       return 0;
+               }
+       }
+
+       public static RotationType getRotation( Short rotationId ) {
+               return rotationMap.get(rotationId);
+       }
+
+       public static Iterator<Entry<Short, RotationType>>getRotationIterator() {
+               return rotationMap.entrySet().iterator();
+       }
+       
+}
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SpecialKeyWindowUtil.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SpecialKeyWindowUtil.java
new file mode 100644 (file)
index 0000000..9c5bfa9
--- /dev/null
@@ -0,0 +1,161 @@
+/**
+ * 
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ * Hyunjin Lee <hyunjin816.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.util;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.Region;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
+import org.tizen.emulator.skin.dbi.EventInfoType;
+import org.tizen.emulator.skin.dbi.KeyMapListType;
+import org.tizen.emulator.skin.dbi.KeyMapType;
+import org.tizen.emulator.skin.dbi.RegionType;
+import org.tizen.emulator.skin.dbi.RotationType;
+import org.tizen.emulator.skin.layout.HWKey;
+import org.tizen.emulator.skin.log.SkinLogger;
+
+
+/**
+ * 
+ *
+ */
+public class SpecialKeyWindowUtil {
+       public static final int UNKNOWN_KEYCODE = -1;
+       public static final int TOUCH_KEYCODE = -2;
+       
+       private static Logger logger =
+                       SkinLogger.getSkinLogger(SkinUtil.class).getLogger();
+
+       private SpecialKeyWindowUtil() {
+               /* do nothing */
+       }
+
+       public static List<KeyMapType> getHWKeyMapList(short rotationId) {
+               RotationType rotation = KeyWindowRotation.getRotation(rotationId);
+               if (rotation == null) {
+                       return null;
+               }
+
+               KeyMapListType list = rotation.getKeyMapList();
+               if (list == null) {
+                       /* try to using a KeyMapList of portrait */
+                       rotation = KeyWindowRotation.getRotation(RotationInfo.PORTRAIT.id());
+                       if (rotation == null) {
+                               return null;
+                       }
+
+                       list = rotation.getKeyMapList();
+                       if (list == null) {
+                               return null;
+                       }
+               }
+
+               return list.getKeyMap();
+       }
+
+       public static HWKey getHWKey(
+                       int currentX, int currentY, short rotationId) {         
+
+               List<KeyMapType> keyMapList = getHWKeyMapList(rotationId);
+               if (keyMapList == null) {
+                       return null;
+               }
+
+               for (KeyMapType keyMap : keyMapList) {
+                       RegionType region = keyMap.getRegion();
+
+                       int scaledX = (int) region.getLeft();
+                       int scaledY = (int) region.getTop();
+                       int scaledWidth = (int) region.getWidth();
+                       int scaledHeight = (int) region.getHeight();
+
+                       if (isInGeometry(currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight)) {
+                               EventInfoType eventInfo = keyMap.getEventInfo();
+
+                               HWKey hwKey = new HWKey();
+                               hwKey.setKeyCode(eventInfo.getKeyCode());
+                               hwKey.setRegion(new SkinRegion(scaledX, scaledY, scaledWidth, scaledHeight));
+                               hwKey.setTooltip(keyMap.getTooltip());
+
+                               return hwKey;
+                       }
+               }
+
+               return null;
+       }
+
+       public static boolean isInGeometry(int currentX, int currentY,
+                       int targetX, int targetY, int targetWidth, int targetHeight) {
+
+               if ((currentX >= targetX) && (currentY >= targetY)) {
+                       if ((currentX <= (targetX + targetWidth)) &&
+                                       (currentY <= (targetY + targetHeight))) {
+                               return true;
+                       }
+               }
+
+               return false;
+       }       
+       
+       public static void trimShell( Shell shell, Image image ) {
+
+               // trim transparent pixels in image. especially, corner round areas.
+
+               if ( null == image ) {
+                       return;
+               }
+
+               ImageData imageData = image.getImageData();
+
+               int width = imageData.width;
+               int height = imageData.height;
+
+               Region region = new Region();
+               region.add( new Rectangle( 0, 0, width, height ) );
+
+               for ( int i = 0; i < width; i++ ) {
+                       for ( int j = 0; j < height; j++ ) {
+                               int alpha = imageData.getAlpha( i, j );
+                               if ( 0 == alpha ) {
+                                       region.subtract( i, j, 1, 1 );
+                               }
+                       }
+               }
+
+               shell.setRegion( region );
+
+       }
+}