From: GiWoong Kim Date: Tue, 1 Oct 2013 02:35:32 +0000 (+0900) Subject: skin: KeyWindow code refactoring X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~710^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8dca5479924ede4b69e3c1aff34c64b4f2187a1e;p=sdk%2Femulator%2Fqemu.git skin: KeyWindow code refactoring Change-Id: I666ac48e5dd26a802eecb44720f582e5af2b9281 Signed-off-by: GiWoong Kim --- diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/GeneralKeyWindow.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/GeneralKeyWindow.java index b8f0911960..5a1084e98e 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/GeneralKeyWindow.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/GeneralKeyWindow.java @@ -56,7 +56,7 @@ import org.tizen.emulator.skin.comm.ICommunicator.SendCommand; import org.tizen.emulator.skin.comm.sock.data.KeyEventData; import org.tizen.emulator.skin.dbi.KeyMapType; import org.tizen.emulator.skin.image.GeneralKeyWindowImageRegistry; -import org.tizen.emulator.skin.image.GeneralKeyWindowImageRegistry.KeyWindowImageName; +import org.tizen.emulator.skin.image.GeneralKeyWindowImageRegistry.GeneralKeyWindowImageName; import org.tizen.emulator.skin.layout.SkinPatches; import org.tizen.emulator.skin.util.SwtUtil; @@ -118,12 +118,12 @@ public class GeneralKeyWindow extends SkinWindow { shell.setImage(parent.getImage()); /* load image for HW key button */ - imageNormal = imageRegistry.getKeyWindowImageData( - KeyWindowImageName.KEYBUTTON_NORMAL); - imageHover = imageRegistry.getKeyWindowImageData( - KeyWindowImageName.KEYBUTTON_HOVER); - imagePushed = imageRegistry.getKeyWindowImageData( - KeyWindowImageName.KEYBUTTON_PUSHED); + imageNormal = imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.KEYBUTTON_NORMAL); + imageHover = imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.KEYBUTTON_HOVER); + imagePushed = imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.KEYBUTTON_PUSHED); /* calculate the key window size */ widthBase = imageNormal.getImageData().width; @@ -176,27 +176,27 @@ public class GeneralKeyWindow extends SkinWindow { Image imagesScrollArrowUp[] = new Image[3]; Image imagesScrollArrowDown[] = new Image[3]; - imagesScrollArrowUp[0] = imageRegistry.getKeyWindowImageData( - KeyWindowImageName.SCROLL_UPBUTTON_NORMAL); - imagesScrollArrowUp[1] = imageRegistry.getKeyWindowImageData( - KeyWindowImageName.SCROLL_UPBUTTON_HOVER); - imagesScrollArrowUp[2] = imageRegistry.getKeyWindowImageData( - KeyWindowImageName.SCROLL_UPBUTTON_PUSHED); + imagesScrollArrowUp[0] = imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.SCROLL_UPBUTTON_NORMAL); + imagesScrollArrowUp[1] = imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.SCROLL_UPBUTTON_HOVER); + imagesScrollArrowUp[2] = imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.SCROLL_UPBUTTON_PUSHED); - imagesScrollArrowDown[0] = imageRegistry.getKeyWindowImageData( - KeyWindowImageName.SCROLL_DOWNBUTTON_NORMAL); - imagesScrollArrowDown[1] = imageRegistry.getKeyWindowImageData( - KeyWindowImageName.SCROLL_DOWNBUTTON_HOVER); - imagesScrollArrowDown[2] = imageRegistry.getKeyWindowImageData( - KeyWindowImageName.SCROLL_DOWNBUTTON_PUSHED); + imagesScrollArrowDown[0] = imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_NORMAL); + imagesScrollArrowDown[1] = imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_HOVER); + imagesScrollArrowDown[2] = imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_PUSHED); CustomScrolledComposite compositeScroll = new CustomScrolledComposite(shell, SWT.NONE, imagesScrollArrowUp, imagesScrollArrowDown, - imageRegistry.getKeyWindowImageData( - KeyWindowImageName.SCROLL_THUMB), - imageRegistry.getKeyWindowImageData( - KeyWindowImageName.SCROLL_SHAFT)); + imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.SCROLL_THUMB), + imageRegistry.getGeneralKeyWindowImageData( + GeneralKeyWindowImageName.SCROLL_SHAFT)); compositeScroll.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1)); Composite compositeBase = new Composite(compositeScroll, SWT.NONE); @@ -331,7 +331,7 @@ public class GeneralKeyWindow extends SkinWindow { shellListener = new ShellListener() { @Override public void shellClosed(ShellEvent event) { - logger.info("Key Window is closed"); + logger.info("General Key Window is closed"); dispose(); } 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 index 6cc93b27f7..0663f8c08c 100644 --- 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 @@ -1,7 +1,7 @@ /** + * Special Key Window * - * - * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * GiWoong Kim @@ -45,12 +45,8 @@ 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; @@ -64,32 +60,29 @@ 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.image.KeyWindowImageRegistry.SpecailKeyWindowImageType; 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 KeyWindowImageRegistry imageRegistry; private SocketCommunicator communicator; private ShellListener shellListener; @@ -101,32 +94,37 @@ public class SpecialKeyWindow extends SkinWindow { private boolean isGrabbedShell; private Point grabPosition; - public SpecialKeyWindow(EmulatorSkin skin, Shell parent, SocketCommunicator communicator, String path) { - super(parent, SWT.RIGHT | SWT.CENTER); + public SpecialKeyWindow(EmulatorSkin skin, String layoutName) { + super(skin.getShell(), 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.parent = skin.getShell(); + if (SwtUtil.isMacPlatform() == false) { + this.shell = new Shell(parent, + SWT.NO_TRIM | SWT.RESIZE | SWT.TOOL); + } else { + this.shell = new Shell(parent.getDisplay(), + SWT.NO_TRIM | SWT.RESIZE | SWT.TOOL); + } + + this.communicator = skin.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; + String specialKeyWindowPath = skinPath + File.separator + KEYWINDOW_LAYOUT + File.separator + layoutName; logger.info("special key window path : " + specialKeyWindowPath); EmulatorUI dbiContents = loadXMLForKeyWindow(specialKeyWindowPath); /* image init */ - KeyWindowImageRegistry.getInstance().initialize(dbiContents, specialKeyWindowPath); + this.imageRegistry = new KeyWindowImageRegistry(shell.getDisplay(), 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); + keyWindowImage = imageRegistry.getSpecialKeyWindowImage(EmulatorConfig.DEFAULT_WINDOW_ROTATION, SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL); + keyWindowPressedImage = imageRegistry.getSpecialKeyWindowImage(EmulatorConfig.DEFAULT_WINDOW_ROTATION, SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED); SpecialKeyWindowUtil.trimShell(shell, keyWindowImage); SpecialKeyWindowUtil.trimShell(shell, keyWindowPressedImage); @@ -136,14 +134,9 @@ public class SpecialKeyWindow extends SkinWindow { 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(); @@ -176,41 +169,6 @@ public class SpecialKeyWindow extends SkinWindow { 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 @@ -228,29 +186,7 @@ public class SpecialKeyWindow extends SkinWindow { 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(); + dispose(); } @Override @@ -309,7 +245,7 @@ public class SpecialKeyWindow extends SkinWindow { 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 { @@ -318,7 +254,7 @@ public class SpecialKeyWindow extends SkinWindow { /* 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); @@ -349,7 +285,7 @@ public class SpecialKeyWindow extends SkinWindow { isGrabbedShell = false; grabPosition.x = grabPosition.y = 0; HWKey pressedHWKey = currentPressedHWKey; - + if (pressedHWKey != null && pressedHWKey.getKeyCode() != SpecialKeyWindowUtil.UNKNOWN_KEYCODE) { /* send event */ if (isTouch) { @@ -361,9 +297,9 @@ public class SpecialKeyWindow extends SkinWindow { 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); @@ -375,7 +311,7 @@ public class SpecialKeyWindow extends SkinWindow { 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) { @@ -384,7 +320,7 @@ public class SpecialKeyWindow extends SkinWindow { grabPosition.y = e.y; return; } - + if (hwKey.getKeyCode() != SpecialKeyWindowUtil.UNKNOWN_KEYCODE) { if (hwKey.getTooltip().equalsIgnoreCase("touch")) { isTouch = true; @@ -396,10 +332,10 @@ public class SpecialKeyWindow extends SkinWindow { 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) { @@ -431,4 +367,29 @@ public class SpecialKeyWindow extends SkinWindow { shell.addMouseListener(shellMouseListener); } + + private void dispose() { + 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(); + imageRegistry.dispose(); + } } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralKeyWindowImageRegistry.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralKeyWindowImageRegistry.java index 1ed1e27eed..4505d3a27d 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralKeyWindowImageRegistry.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralKeyWindowImageRegistry.java @@ -46,7 +46,7 @@ public class GeneralKeyWindowImageRegistry { private static Logger logger = SkinLogger.getSkinLogger( GeneralKeyWindowImageRegistry.class).getLogger(); - public enum KeyWindowImageName { + public enum GeneralKeyWindowImageName { KEYBUTTON_NORMAL("keybutton_nml.png"), KEYBUTTON_HOVER("keybutton_hover.png"), KEYBUTTON_PUSHED("keybutton_pushed.png"), @@ -62,7 +62,7 @@ public class GeneralKeyWindowImageRegistry { private String name; - private KeyWindowImageName(String name) { + private GeneralKeyWindowImageName(String name) { this.name = name; } @@ -82,15 +82,15 @@ public class GeneralKeyWindowImageRegistry { this.keyWindowImageMap = new HashMap(); } - public Image getKeyWindowImageData(KeyWindowImageName name) { + public Image getGeneralKeyWindowImageData(GeneralKeyWindowImageName name) { if (keyWindowImageMap.size() == 0) { /* load all of the images at once */ ClassLoader classLoader = this.getClass().getClassLoader(); InputStream is = null; String imageName, imagePath; - KeyWindowImageName[] values = KeyWindowImageName.values(); - for (KeyWindowImageName value : values) { + GeneralKeyWindowImageName[] values = GeneralKeyWindowImageName.values(); + for (GeneralKeyWindowImageName value : values) { imageName = value.getName(); imagePath = ImageRegistry.IMAGES_FOLDER + "/" + KEYWINDOW_FOLDER + "/" + imageName; 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 index 8567ea81fa..2b0d9dd78d 100644 --- 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 @@ -1,12 +1,11 @@ /** - * image resources management + * Image Resource Management For Special Key Window * - * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * GiWoong Kim * YeongKyoon Lee - * HyunJun Son * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,7 +29,6 @@ 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; @@ -39,16 +37,14 @@ 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; +import org.tizen.emulator.skin.util.SkinRotation; /** @@ -56,126 +52,37 @@ 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; - } + public enum SpecailKeyWindowImageType { + SPECIAL_IMAGE_TYPE_NORMAL, + SPECIAL_IMAGE_TYPE_PRESSED } private Display display; + private String skinPath; private EmulatorUI dbiContents; - - private Map skinImageMap; - private Map iconMap; private Map 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(); - + /** + * Constructor + */ + public KeyWindowImageRegistry( + Display display, EmulatorUI dbiContents, String skinPath) { + this.display = display; this.skinPath = skinPath; this.dbiContents = dbiContents; - this.skinImageMap = new HashMap(); - this.iconMap = new HashMap(); this.keyWindowImageMap = new HashMap(); - init(this.skinPath); + initialize(skinPath); } - private void init(String argSkinPath) { - + private void initialize(String argSkinPath) { RotationsType rotations = dbiContents.getRotations(); if (null == rotations) { - logger.severe("Fail to loading rotations element from dbi."); + logger.severe("Fail to loading rotations element from XML"); return; } @@ -186,23 +93,24 @@ public class KeyWindowImageRegistry { } } - public Image getSpecialKeyWindowImage(Short id, ImageType imageType) { + private String makeKey(Short id, SpecailKeyWindowImageType imageType) { + return id + ":" + imageType.ordinal(); + } - Image image = skinImageMap.get(makeKey(id, imageType)); + public Image getSpecialKeyWindowImage(Short id, SpecailKeyWindowImageType imageType) { + Image image = keyWindowImageMap.get(makeKey(id, imageType)); - if (null != image) { - return image; - } else { + if (image == null) { RotationsType rotations = dbiContents.getRotations(); if (null == rotations) { - logger.severe("Fail to loading rotations element from dbi."); + logger.severe("Fail to loading rotations element from XML"); return null; } - logger.info("get image data of skin from " + skinPath); + logger.info("get skin image from " + skinPath); - RotationType targetRotation = KeyWindowRotation.getRotation(id); + RotationType targetRotation = SkinRotation.getRotation(id); List rotationList = rotations.getRotation(); for (RotationType rotation : rotationList) { @@ -215,66 +123,35 @@ public class KeyWindowImageRegistry { String keyPressedImage = imageList.getKeyPressedImage(); if (targetRotation.getName().value().equals(rotation.getName().value())) { - String mainKey = makeKey(id, ImageType.IMG_TYPE_MAIN); - skinImageMap.put(mainKey, + String mainKey = makeKey(id, + SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL); + keyWindowImageMap.put(mainKey, new Image(display, skinPath + File.separator + mainImage)); - String pressedKey = makeKey(id, ImageType.IMG_TYPE_PRESSED); - skinImageMap.put(pressedKey, + String pressedKey = makeKey(id, + SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED); + keyWindowImageMap.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; - } - + image = keyWindowImageMap.get(makeKey(id, imageType)); } - } - private String makeKey(Short id, ImageType imageType) { - return id + ":" + imageType.ordinal(); + return image; } public void dispose() { - /* skin image */ - if (null != skinImageMap) { - Collection images = skinImageMap.values(); + if (null != keyWindowImageMap) { + Image image = null; + Collection images = keyWindowImageMap.values(); Iterator imageIterator = images.iterator(); while (imageIterator.hasNext()) { - Image image = imageIterator.next(); - image.dispose(); - } - } - - /* icon */ - if (null != iconMap) { - Collection icons = iconMap.values(); - - Iterator iconIterator = icons.iterator(); - - while (iconIterator.hasNext()) { - Image image = iconIterator.next(); - image.dispose(); - } - } - - /* key window image */ - if (null != keyWindowImageMap) { - Collection images = keyWindowImageMap.values(); - - Iterator imagesIterator = images.iterator(); - - while (imagesIterator.hasNext()) { - Image image = imagesIterator.next(); + image = imageIterator.next(); image.dispose(); } } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ProfileSkinImageRegistry.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ProfileSkinImageRegistry.java index 2a81e5866f..cd720da24f 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ProfileSkinImageRegistry.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ProfileSkinImageRegistry.java @@ -38,7 +38,6 @@ 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.ImageListType; import org.tizen.emulator.skin.dbi.RotationType; @@ -63,11 +62,11 @@ public class ProfileSkinImageRegistry { /** * Constructor */ - public ProfileSkinImageRegistry(EmulatorConfig config, - Display display, String skinPath) { + public ProfileSkinImageRegistry( + Display display, EmulatorUI dbiContents, String skinPath) { this.display = display; this.skinPath = skinPath; - this.dbiContents = config.getDbiContents(); + this.dbiContents = dbiContents; this.skinImageMap = new HashMap(); initialize(skinPath); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.java index 51afcc3b81..4d2c90ca03 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.java @@ -101,7 +101,7 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { this.grabPosition = new Point(0, 0); this.imageRegistry = new ProfileSkinImageRegistry( - config, shell.getDisplay(), skin.skinInfo.getSkinPath()); + shell.getDisplay(), config.getDbiContents(), skin.skinInfo.getSkinPath()); } @Override diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/KeyWindowKeeper.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/KeyWindowKeeper.java index 7ca7c88d7d..5f7bfeca48 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/KeyWindowKeeper.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/KeyWindowKeeper.java @@ -101,8 +101,7 @@ public class KeyWindowKeeper { skin.getPopupMenu().keyWindowItem.getMenu().getItem(indexLayout).getText(); logger.info("generate a \'" + layoutName + "\' key window!"); - keyWindow = new SpecialKeyWindow( - skin, skin.getShell(), skin.communicator, layoutName); + keyWindow = new SpecialKeyWindow(skin, layoutName); } selectKeyWindowMenu(skin.isKeyWindow = true);