import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.util.List;
import java.util.logging.Level;
import org.eclipse.swt.SWT;
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.Point;
-import org.eclipse.swt.graphics.RGB;
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.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.SpecialKeyWindowImageRegistry;
import org.tizen.emulator.skin.image.SpecialKeyWindowImageRegistry.SpecailKeyWindowImageType;
+import org.tizen.emulator.skin.keywindow.dbi.EventInfoType;
+import org.tizen.emulator.skin.keywindow.dbi.KeyMapType;
+import org.tizen.emulator.skin.keywindow.dbi.KeyWindowUI;
+import org.tizen.emulator.skin.keywindow.dbi.RegionType;
import org.tizen.emulator.skin.layout.HWKey;
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.SkinRegion;
+import org.tizen.emulator.skin.util.SkinUtil;
import org.tizen.emulator.skin.util.SwtUtil;
public class SpecialKeyWindow extends SkinWindow {
- private static final String KEYWINDOW_LAYOUT = "keywindow-layout";
- private static final String DBI_FILE_NAME = "default.dbi";
+ public static final String KEYWINDOW_LAYOUT_ROOT = "keywindow-layout";
+ public static final String DBI_FILE_NAME = "default.dbi";
private EmulatorSkin skin;
-
- private HWKey currentPressedHWKey;
-
- private int widthBase;
- private int heightBase;
+ private SpecialKeyWindowImageRegistry imageRegistry;
+ private SocketCommunicator communicator;
+ private KeyWindowUI dbiContents;
private Image keyWindowImage;
private Image keyWindowPressedImage;
- private Color colorFrame;
- private SpecialKeyWindowImageRegistry imageRegistry;
- private SocketCommunicator communicator;
-
private ShellListener shellListener;
private PaintListener shellPaintListener;
private MouseMoveListener shellMouseMoveListener;
private MouseListener shellMouseListener;
-
- private boolean isTouch;
+
private boolean isGrabbedShell;
private Point grabPosition;
+ private HWKey currentPressedHWKey;
+ private boolean isTouch;
public SpecialKeyWindow(EmulatorSkin skin, String layoutName) {
super(skin.getShell(), SWT.RIGHT | SWT.CENTER);
this.skin = skin;
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.shell = new Shell(parent.getDisplay() /* for Mac & Always on Top */,
+ SWT.NO_TRIM | SWT.RESIZE | SWT.TOOL | SWT.NO_FOCUS);
this.communicator = skin.communicator;
+
+ this.isGrabbedShell= false;
this.grabPosition = new Point(0, 0);
shell.setText(parent.getText());
+ shell.setBackground(parent.getBackground());
shell.setImage(parent.getImage());
/* load dbi file */
String skinPath = skin.skinInfo.getSkinPath();
- String specialKeyWindowPath = skinPath + File.separator + KEYWINDOW_LAYOUT + File.separator + layoutName;
+ String specialKeyWindowPath = skinPath + File.separator
+ + KEYWINDOW_LAYOUT_ROOT + File.separator + layoutName;
logger.info("special key window path : " + specialKeyWindowPath);
- EmulatorUI dbiContents = loadXMLForKeyWindow(specialKeyWindowPath);
- /* image init */
- this.imageRegistry = new SpecialKeyWindowImageRegistry(shell.getDisplay(), dbiContents, specialKeyWindowPath);
-
- /* get keywindow image */
- 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);
-
- /* calculate the key window size */
- widthBase = keyWindowImage.getImageData().width;
- heightBase = keyWindowImage.getImageData().height;
+ this.dbiContents = loadXMLForKeyWindow(specialKeyWindowPath);
- /* make a frame image */
- this.colorFrame = new Color(shell.getDisplay(), new RGB(38, 38, 38));
+ /* image init */
+ this.imageRegistry = new SpecialKeyWindowImageRegistry(
+ shell.getDisplay(), dbiContents, specialKeyWindowPath);
- shell.setBackground(colorFrame);
+ /* get keywindow image */
+ //TODO: null
+ keyWindowImage = imageRegistry.getKeyWindowImage(
+ EmulatorConfig.DEFAULT_WINDOW_ROTATION,
+ SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL);
+ keyWindowPressedImage = imageRegistry.getKeyWindowImage(
+ EmulatorConfig.DEFAULT_WINDOW_ROTATION,
+ SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED);
+
+ /* set window size */
+ shell.setSize(
+ keyWindowImage.getImageData().width,
+ keyWindowImage.getImageData().height);
+
+ /* custom window shape */
+ SkinUtil.trimShell(shell, keyWindowImage);
addKeyWindowListener();
-
- shell.setSize(widthBase, heightBase);
}
- private EmulatorUI loadXMLForKeyWindow(String skinPath) {
+ private KeyWindowUI loadXMLForKeyWindow(String skinPath) {
String dbiPath = skinPath + File.separator + DBI_FILE_NAME;
logger.info("load dbi file from " + dbiPath);
FileInputStream fis = null;
- EmulatorUI emulatorUI = null;
+ KeyWindowUI keyWindowUI = null;
try {
fis = new FileInputStream(dbiPath);
logger.info(new String(bytes, "UTF-8"));
logger.info("=======================================");
- emulatorUI = JaxbUtil.unmarshal(bytes, EmulatorUI.class);
+ keyWindowUI = JaxbUtil.unmarshal(bytes, KeyWindowUI.class);
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
} catch (JaxbException e) {
IOUtil.close(fis);
}
- return emulatorUI;
+ return keyWindowUI;
+ }
+
+ private HWKey getHWKey(int currentX, int currentY) {
+ List<KeyMapType> keyMapList = dbiContents.getKeyMapList().getKeyMap();
+ if (keyMapList == null) {
+ return null;
+ }
+
+ for (KeyMapType keyEntry : keyMapList) {
+ RegionType region = keyEntry.getRegion();
+
+ int scaledX = (int) region.getLeft();
+ int scaledY = (int) region.getTop();
+ int scaledWidth = (int) region.getWidth();
+ int scaledHeight = (int) region.getHeight();
+
+ if (SkinUtil.isInGeometry(currentX, currentY,
+ scaledX, scaledY, scaledWidth, scaledHeight)) {
+ EventInfoType eventInfo = keyEntry.getEventInfo();
+
+ HWKey hwKey = new HWKey(
+ eventInfo.getKeyName(),
+ eventInfo.getKeyCode(),
+ new SkinRegion(scaledX, scaledY, scaledWidth, scaledHeight),
+ keyEntry.getTooltip());
+
+ return hwKey;
+ }
+ }
+
+ return null;
}
private void addKeyWindowListener() {
@Override
public void mouseMove(MouseEvent e) {
if (isTouch == true) {
- logger.info("MouseMove in SpecialKeyWindow : " + e.x + ", " + e.y);
+ logger.info("mouseMove in KeyWindow : " + e.x + ", " + e.y);
+
HWKey pressedHWKey = currentPressedHWKey;
int x = pressedHWKey.getRegion().x;
int y = pressedHWKey.getRegion().y;
int height = pressedHWKey.getRegion().height;
int eventType;
- if (SpecialKeyWindowUtil.isInGeometry(e.x, e.y, x, y, width, height)) {
+ if (SkinUtil.isInGeometry(e.x, e.y, x, y, width, height)) {
eventType = MouseEventType.DRAG.value();
} else {
isTouch = 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);
+ 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);
@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;
+
+ /* HW key handling */
HWKey pressedHWKey = currentPressedHWKey;
+ if (pressedHWKey == null) {
+ logger.info("mouseUp in KeyWindow : " + e.x + ", " + e.y);
+ return;
+ }
+
+ if (pressedHWKey.getKeyCode() != SkinUtil.UNKNOWN_KEYCODE) {
+ logger.info(pressedHWKey.getName() + " key is released");
- 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);
+ 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);
+ KeyEventData keyEventData = new KeyEventData(
+ KeyEventType.RELEASED.value(), pressedHWKey.getKeyCode(), 0, 0);
+ communicator.sendToQEMU(
+ SendCommand.SEND_HARD_KEY_EVENT, keyEventData, false);
}
currentPressedHWKey = null;
@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) {
+ final HWKey hwKey = getHWKey(e.x, e.y);
+ if (hwKey == null) {
+ logger.info("mouseDown in KeyWindow : " + e.x + ", " + e.y);
+
isGrabbedShell = true;
grabPosition.x = e.x;
grabPosition.y = e.y;
+
return;
}
- if (hwKey.getKeyCode() != SpecialKeyWindowUtil.UNKNOWN_KEYCODE) {
+ if (hwKey.getKeyCode() != SkinUtil.UNKNOWN_KEYCODE) {
+ logger.info(hwKey.getName() + " key is pressed");
+
+ /* send event */
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);
+ 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);
+ 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 &&
+ if (hwKey.getRegion() != null &&
hwKey.getRegion().width != 0 && hwKey.getRegion().height != 0) {
shell.getDisplay().syncExec(new Runnable() {
public void run() {
- if(keyWindowPressedImage != null) {
+ if (keyWindowPressedImage != null) {
GC gc = new GC(shell);
- if(gc != null) {
+ if (gc != null) {
gc.drawImage(keyWindowPressedImage,
hwKey.getRegion().x, hwKey.getRegion().y,
hwKey.getRegion().width, hwKey.getRegion().height,
shell.removeMouseListener(shellMouseListener);
}
- colorFrame.dispose();
imageRegistry.dispose();
}
}
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.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.keywindow.dbi.ImageListType;
+import org.tizen.emulator.skin.keywindow.dbi.KeyWindowUI;
import org.tizen.emulator.skin.log.SkinLogger;
-import org.tizen.emulator.skin.util.KeyWindowRotation;
-import org.tizen.emulator.skin.util.SkinRotation;
/**
}
private Display display;
- private String skinPath;
- private EmulatorUI dbiContents;
+ private String imagePath;
+ private KeyWindowUI dbiContents;
private Map<String, Image> keyWindowImageMap;
/**
* Constructor
*/
public SpecialKeyWindowImageRegistry(
- Display display, EmulatorUI dbiContents, String skinPath) {
+ Display display, KeyWindowUI dbiContents, String imagePath) {
this.display = display;
- this.skinPath = skinPath;
+ this.imagePath = imagePath;
this.dbiContents = dbiContents;
this.keyWindowImageMap = new HashMap<String, Image>();
-
- initialize(skinPath);
- }
-
- private void initialize(String argSkinPath) {
- RotationsType rotations = dbiContents.getRotations();
-
- if (null == rotations) {
- logger.severe("Fail to loading rotations element from XML");
- return;
- }
-
- List<RotationType> rotationList = rotations.getRotation();
-
- for (RotationType rotation : rotationList) {
- KeyWindowRotation.put(rotation);
- }
}
private String makeKey(Short id, SpecailKeyWindowImageType imageType) {
Image image = keyWindowImageMap.get(makeKey(id, imageType));
if (image == null) {
- RotationsType rotations = dbiContents.getRotations();
-
- if (null == rotations) {
- logger.severe("Fail to loading rotations element from XML");
+ ImageListType imageList = dbiContents.getImageList();
+ if (imageList == null) {
return null;
}
- logger.info("get skin image from " + skinPath);
-
- RotationType targetRotation = SkinRotation.getRotation(id);
- List<RotationType> rotationList = rotations.getRotation();
+ logger.info("get Key Window image from " + imagePath);
- for (RotationType rotation : rotationList) {
- ImageListType imageList = rotation.getImageList();
- if (imageList == null) {
- continue;
- }
+ String mainImage = imageList.getMainImage();
+ String keyPressedImage = imageList.getKeyPressedImage();
- String mainImage = imageList.getMainImage();
- String keyPressedImage = imageList.getKeyPressedImage();
+ String mainKey = makeKey(id,
+ SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL);
+ keyWindowImageMap.put(mainKey,
+ new Image(display, imagePath + File.separator + mainImage));
- if (targetRotation.getName().value().equals(rotation.getName().value())) {
- String mainKey = makeKey(id,
- SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL);
- keyWindowImageMap.put(mainKey,
- new Image(display, skinPath + File.separator + mainImage));
-
- String pressedKey = makeKey(id,
- SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED);
- keyWindowImageMap.put(pressedKey,
- new Image(display, skinPath + File.separator + keyPressedImage));
-
- break;
- }
- }
+ String pressedKey = makeKey(id,
+ SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED);
+ keyWindowImageMap.put(pressedKey,
+ new Image(display, imagePath + File.separator + keyPressedImage));
image = keyWindowImageMap.get(makeKey(id, imageType));
}
+++ /dev/null
-/**
- *
- *
- * 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 );
-
- }
-}