From c78bb338233651da83e3118e38724c431b1dace8 Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Tue, 1 Oct 2013 13:23:20 +0900 Subject: [PATCH] skin: added GeneralSkinImageRegistry Change-Id: I1c0c72d9bc117eb79ea09b663d292d579a807ec8 Signed-off-by: GiWoong Kim --- .../tizen/emulator/skin/EmulatorSkinMain.java | 16 +++ .../skin/custom/GeneralKeyWindow.java | 22 ++-- .../skin/custom/SpecialKeyWindow.java | 4 +- .../image/GeneralKeyWindowImageRegistry.java | 7 +- .../skin/image/GeneralSkinImageRegistry.java | 120 ++++++++++++++++++ .../emulator/skin/image/ImageRegistry.java | 30 ----- .../skin/image/ProfileSkinImageRegistry.java | 17 --- .../image/SpecialKeyWindowImageRegistry.java | 2 +- .../layout/GeneralPurposeSkinComposer.java | 74 ++--------- 9 files changed, 167 insertions(+), 125 deletions(-) create mode 100644 tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralSkinImageRegistry.java diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java index ab111fc059..ed815b2bbe 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java @@ -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 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) { 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 a9c196a8b4..7c15bf0100 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 @@ -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)); 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 88db58851f..2325fb001b 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 @@ -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); 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 e1c841c01a..cf2872c1d4 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 @@ -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(); } - 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 index 0000000000..2559bbabff --- /dev/null +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/GeneralSkinImageRegistry.java @@ -0,0 +1,120 @@ +/** + * Image Resource Management For General-Purpose Skin + * + * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * YeongKyoon Lee + * + * 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 skinImageMap; + + /** + * Constructor + */ + public GeneralSkinImageRegistry(Display display) { + this.display = display; + this.skinImageMap = new HashMap(); + } + + 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 images = skinImageMap.values(); + Iterator imageIterator = images.iterator(); + + while (imageIterator.hasNext()) { + image = imageIterator.next(); + image.dispose(); + } + } + } +} diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java index dc6b8ed5ef..62a1058b3d 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java @@ -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 resourceImageMap; private Map 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(); this.iconImageMap = new HashMap(); - - 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 rotationList = rotations.getRotation(); - - for (RotationType rotation : rotationList) { - SkinRotation.put(rotation); - } } public Image getResourceImage(ResourceImageName name) { 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 cd720da24f..35e3e57449 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 @@ -68,23 +68,6 @@ public class ProfileSkinImageRegistry { this.skinPath = skinPath; this.dbiContents = dbiContents; this.skinImageMap = new HashMap(); - - 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 rotationList = rotations.getRotation(); - - for (RotationType rotation : rotationList) { - SkinRotation.put(rotation); - } } private String makeKey(Short id, SkinImageType imageType) { diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/SpecialKeyWindowImageRegistry.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/SpecialKeyWindowImageRegistry.java index 9e413c3d4d..f55c792043 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/SpecialKeyWindowImageRegistry.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/SpecialKeyWindowImageRegistry.java @@ -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) { diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java index 98fdf6c951..5f37efdae6 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java @@ -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 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(); } } -- 2.34.1