From: GiWoong Kim Date: Tue, 12 Nov 2013 01:55:38 +0000 (+0900) Subject: skin: move to the proper java package X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~607^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe2377d7ad49bf0b8e08ee081d7728267f804501;p=sdk%2Femulator%2Fqemu.git skin: move to the proper java package EmulatorSkinState: skin -> skin.info GeneralKeyWindow, SpecialKeyWindow: custom -> menu Change-Id: I14ea94539a0ad44edeb35bb0be6cd226f6467f1c Signed-off-by: GiWoong Kim --- diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java index 05b21c083d..3bc23c11c3 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java @@ -44,6 +44,7 @@ import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo; import org.tizen.emulator.skin.comm.ICommunicator.SendCommand; import org.tizen.emulator.skin.comm.sock.SocketCommunicator; import org.tizen.emulator.skin.comm.sock.data.MouseEventData; +import org.tizen.emulator.skin.info.EmulatorSkinState; import org.tizen.emulator.skin.log.SkinLogger; public class EmulatorFingers { diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java index 83b173db62..7cee18b994 100755 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java @@ -90,6 +90,7 @@ import org.tizen.emulator.skin.dialog.AboutDialog; import org.tizen.emulator.skin.dialog.DetailInfoDialog; import org.tizen.emulator.skin.dialog.RamdumpDialog; import org.tizen.emulator.skin.image.ImageRegistry; +import org.tizen.emulator.skin.info.EmulatorSkinState; import org.tizen.emulator.skin.info.SkinInformation; import org.tizen.emulator.skin.layout.GeneralPurposeSkinComposer; import org.tizen.emulator.skin.layout.ISkinComposer; diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinState.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinState.java deleted file mode 100644 index 1011207651..0000000000 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinState.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Emulator Skin Process - * - * Copyright (C) 2011 - 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; - -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.tizen.emulator.skin.config.EmulatorConfig; -import org.tizen.emulator.skin.util.SkinRotation; - -public class EmulatorSkinState { - private Point currentResolution; - private int currentScale; - private short currentRotationId; - - private Rectangle displayBounds; - private boolean updateDisplayBounds; - - private Image currentImage; - private Image currentKeyPressedImage; - private Color hoverColor; - - /** - * Constructor - */ - public EmulatorSkinState() { - this.currentResolution = new Point(720, 1280); - this.currentScale = EmulatorConfig.DEFAULT_WINDOW_SCALE; - this.currentRotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION; - - this.displayBounds = null; - this.updateDisplayBounds = false; - } - - /* resolution */ - public synchronized Point getCurrentResolution() { - return currentResolution; - } - - public synchronized int getCurrentResolutionWidth() { - return currentResolution.x; - } - - public synchronized int getCurrentResolutionHeight() { - return currentResolution.y; - } - - public synchronized void setCurrentResolution(Point resolution) { - setCurrentResolutionWidth(resolution.x); - setCurrentResolutionHeight(resolution.y); - } - - public synchronized void setCurrentResolutionWidth(int width) { - if (width < 0) { - width = 0; - } - this.currentResolution.x = width; - } - - public synchronized void setCurrentResolutionHeight(int height) { - if (height < 0) { - height = 0; - } - this.currentResolution.y = height; - } - - /* scale */ - public synchronized int getCurrentScale() { - return currentScale; - } - - public synchronized void setCurrentScale(int scale) { - this.currentScale = scale; - } - - /* rotation */ - public synchronized short getCurrentRotationId() { - return currentRotationId; - } - - public synchronized int getCurrentAngle() { - return SkinRotation.getAngle(currentRotationId); - } - - public synchronized void setCurrentRotationId(short rotationId) { - this.currentRotationId = rotationId; - } - - /* display bounds */ - public synchronized Rectangle getDisplayBounds() { - if (displayBounds == null) { - return new Rectangle(0, 0, 10, 10); - } - - return displayBounds; - } - - public synchronized void setDisplayBounds(Rectangle bounds) { - this.displayBounds = bounds; - } - - public synchronized boolean isNeedToUpdateDisplay() { - return updateDisplayBounds; - } - - public synchronized void setNeedToUpdateDisplay(boolean needUpdate) { - this.updateDisplayBounds = needUpdate; - } - - /* skin image */ - public synchronized Image getCurrentImage() { - return currentImage; - } - - public synchronized void setCurrentImage(Image image) { - this.currentImage = image; - } - - public synchronized Image getCurrentKeyPressedImage() { - return currentKeyPressedImage; - } - - public synchronized void setCurrentKeyPressedImage(Image keyPressedImage) { - this.currentKeyPressedImage = keyPressedImage; - } - - /* color of hover */ - public synchronized Color getHoverColor() { - return hoverColor; - } - - public synchronized void setHoverColor(Color color) { - this.hoverColor = color; - } -} 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 deleted file mode 100644 index 3ee83a8fd9..0000000000 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/GeneralKeyWindow.java +++ /dev/null @@ -1,524 +0,0 @@ -/** - * General Key Window - * - * Copyright (C) 2011 - 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.custom; - -import java.util.List; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -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.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.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -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.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.GeneralKeyWindowImageName; -import org.tizen.emulator.skin.layout.SkinPatches; -import org.tizen.emulator.skin.util.SwtUtil; - -public class GeneralKeyWindow extends SkinWindow { - private static final int SHELL_MARGIN_BOTTOM = 3; - private static final int PAIRTAG_CIRCLE_SIZE = 8; - private static final int PAIRTAG_MARGIN_BOTTOM = 6; - private static final int BUTTON_DEFAULT_CNT = 4; - private static final int BUTTON_VERTICAL_SPACING = 7; - private static final int SCROLLBAR_HORIZONTAL_SPACING = 4; - private static final int SCROLLBAR_SIZE_WIDTH = 14; - - private EmulatorSkin skin; - private SkinPatches frameMaker; - - private int widthBase; - private int heightBase; - private int widthScrollbar; - private int cntHiddenButton; - - private Image imageNormal; /* ImageButton image */ - private Image imageHover; /* hovered ImageButton image */ - private Image imagePushed; /* pushed ImageButton image */ - private Image imageFrame; /* nine-patch image */ - - private Color colorFrame; - private GeneralKeyWindowImageRegistry imageRegistry; - private List keyMapList; - - private ShellListener shellListener; - private PaintListener shellPaintListener; - private MouseMoveListener shellMouseMoveListener; - private MouseListener shellMouseListener; - - private boolean isGrabbedShell; - private Point grabPosition; - - public GeneralKeyWindow(EmulatorSkin skin, - GeneralKeyWindowImageRegistry imageRegstry, List keyMapList) { - super(skin.getShell(), SWT.RIGHT | SWT.CENTER); - - this.skin = skin; - this.parent = skin.getShell(); - this.shell = new Shell(parent.getDisplay() /* for Mac & Always on Top */, - SWT.NO_TRIM | SWT.RESIZE | SWT.TOOL | SWT.NO_FOCUS); - - this.imageRegistry = imageRegstry; - this.frameMaker = new SkinPatches( - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYWINDOW_PATCH_LT), - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYWINDOW_PATCH_T), - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYWINDOW_PATCH_RT), - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYWINDOW_PATCH_L), - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYWINDOW_PATCH_R), - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYWINDOW_PATCH_LB), - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYWINDOW_PATCH_B), - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYWINDOW_PATCH_RB)); - - this.keyMapList = keyMapList; //TODO: null - this.grabPosition = new Point(0, 0); - - shell.setText(parent.getText()); - shell.setImage(parent.getImage()); - - /* load image for HW key button */ - imageNormal = imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYBUTTON_NORMAL); - imageHover = imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYBUTTON_HOVER); - imagePushed = imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.KEYBUTTON_PUSHED); - - /* calculate the key window size */ - widthBase = imageNormal.getImageData().width; - heightBase = (imageNormal.getImageData().height * BUTTON_DEFAULT_CNT) + - (BUTTON_VERTICAL_SPACING * (BUTTON_DEFAULT_CNT - 1)); - - widthScrollbar = SCROLLBAR_SIZE_WIDTH + SCROLLBAR_HORIZONTAL_SPACING; - int heightHeaderPart = (PAIRTAG_CIRCLE_SIZE + PAIRTAG_MARGIN_BOTTOM); - int heightTailPart = SHELL_MARGIN_BOTTOM; - - /* make a frame image */ - if (keyMapList != null) { - this.cntHiddenButton = keyMapList.size() - BUTTON_DEFAULT_CNT; - } - - this.imageFrame = frameMaker.getPatchedImage( - widthBase + ((cntHiddenButton > 0) ? widthScrollbar : 0), - heightBase + heightHeaderPart + heightTailPart); - this.colorFrame = new Color(shell.getDisplay(), new RGB(38, 38, 38)); - - shell.setBackground(colorFrame); - - createContents(); - trimPatchedShell(shell, imageFrame); - - addKeyWindowListener(); - - shell.setSize(imageFrame.getImageData().width, - imageFrame.getImageData().height); - } - - protected void createContents() { - GridLayout shellGridLayout = new GridLayout(1, false); - shellGridLayout.marginLeft = shellGridLayout.marginRight = frameMaker.getPatchWidth(); - shellGridLayout.marginTop = frameMaker.getPatchHeight(); - shellGridLayout.marginBottom = frameMaker.getPatchHeight() + SHELL_MARGIN_BOTTOM; - shellGridLayout.marginWidth = shellGridLayout.marginHeight = 0; - shellGridLayout.horizontalSpacing = shellGridLayout.verticalSpacing = 0; - - shell.setLayout(shellGridLayout); - - /* make a pair tag circle */ - ColorTag pairTagCanvas = new ColorTag(shell, SWT.NONE, skin.getColorVM()); - pairTagCanvas.setLayoutData(new GridData(PAIRTAG_CIRCLE_SIZE, - PAIRTAG_CIRCLE_SIZE + PAIRTAG_MARGIN_BOTTOM)); - - /* make a region of HW keys */ - if (cntHiddenButton > 0) { - /* added custom scrollbar */ - Image imagesScrollArrowUp[] = new Image[3]; - Image imagesScrollArrowDown[] = new Image[3]; - - imagesScrollArrowUp[0] = imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.SCROLL_UPBUTTON_NORMAL); - imagesScrollArrowUp[1] = imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.SCROLL_UPBUTTON_HOVER); - imagesScrollArrowUp[2] = imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.SCROLL_UPBUTTON_PUSHED); - - imagesScrollArrowDown[0] = imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_NORMAL); - imagesScrollArrowDown[1] = imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_HOVER); - imagesScrollArrowDown[2] = imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_PUSHED); - - CustomScrolledComposite compositeScroll = - new CustomScrolledComposite(shell, SWT.NONE, - imagesScrollArrowUp, imagesScrollArrowDown, - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.SCROLL_THUMB), - imageRegistry.getKeyWindowImage( - GeneralKeyWindowImageName.SCROLL_SHAFT)); - compositeScroll.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1)); - - Composite compositeBase = new Composite(compositeScroll, SWT.NONE); - - createHwKeys(compositeBase); - - Point sizeContent = compositeBase.computeSize( - widthBase + widthScrollbar, heightBase); - compositeScroll.setContent(compositeBase, sizeContent); - compositeScroll.setExpandHorizontal(true); - compositeScroll.setExpandVertical(true); - - sizeContent.y += (imageNormal.getImageData().height * cntHiddenButton) + - (BUTTON_VERTICAL_SPACING * cntHiddenButton); - compositeScroll.setMinSize(sizeContent); - } else { - ScrolledComposite compositeScroll = new ScrolledComposite(shell, SWT.V_SCROLL); - compositeScroll.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1)); - - Composite compositeBase = new Composite(compositeScroll, SWT.NONE); - createHwKeys(compositeBase); - - compositeScroll.setContent(compositeBase); - compositeScroll.setExpandHorizontal(true); - compositeScroll.setExpandVertical(true); - - compositeScroll.setMinSize( - compositeBase.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - } - } - - protected void createHwKeys(Composite composite) { - composite.setBackground(colorFrame); - - GridLayout compositeGridLayout = new GridLayout(1, false); - compositeGridLayout.marginLeft = compositeGridLayout.marginRight = 0; - compositeGridLayout.marginTop = compositeGridLayout.marginBottom = 0; - compositeGridLayout.marginWidth = compositeGridLayout.marginHeight = 0; - compositeGridLayout.horizontalSpacing = 0; - compositeGridLayout.verticalSpacing = BUTTON_VERTICAL_SPACING; - composite.setLayout(compositeGridLayout); - - /* attach HW keys */ - if (keyMapList != null && keyMapList.isEmpty() == false) { - for (KeyMapType keyEntry : keyMapList) { - final CustomButton HWKeyButton = new CustomButton(composite, - SWT.NO_FOCUS, imageNormal, imageHover, imagePushed); - HWKeyButton.setText(keyEntry.getEventInfo().getKeyName()); - HWKeyButton.setToolTipText(keyEntry.getTooltip()); - HWKeyButton.setBackground(colorFrame); - HWKeyButton.setLayoutData(new GridData(imageNormal.getImageData().width, - imageNormal.getImageData().height)); - - final int keycode = keyEntry.getEventInfo().getKeyCode(); - HWKeyButton.addMouseListener(new MouseListener() { - @Override - public void mouseDown(MouseEvent e) { - logger.info(HWKeyButton.getText() + " key is pressed"); - - KeyEventData keyEventData = new KeyEventData( - KeyEventType.PRESSED.value(), keycode, 0, 0); - skin.communicator.sendToQEMU( - SendCommand.SEND_HW_KEY_EVENT, keyEventData, false); - } - - @Override - public void mouseUp(MouseEvent e) { - logger.info(HWKeyButton.getText() + " key is released"); - - KeyEventData keyEventData = new KeyEventData( - KeyEventType.RELEASED.value(), keycode, 0, 0); - skin.communicator.sendToQEMU( - SendCommand.SEND_HW_KEY_EVENT, keyEventData, false); - } - - @Override - public void mouseDoubleClick(MouseEvent e) { - /* do nothing */ - } - }); - } - } - } - - 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 (imageFrame != null) { - e.gc.drawImage(imageFrame, 0, 0); - } - } - }; - - shell.addPaintListener(shellPaintListener); - - shellListener = new ShellListener() { - @Override - public void shellClosed(ShellEvent event) { - logger.info("General Key Window is closed"); - - dispose(); - } - - @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 (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 */ - isGrabbedShell = false; - grabPosition.x = grabPosition.y = 0; - - /* Let me check whether the key window was landed - * on docking area. */ - Rectangle parentBounds = parent.getBounds(); - Rectangle childBounds = shell.getBounds(); - - int heightOneThird = parentBounds.height / 3; - int widthDockingArea = 30; - int widthIntersectRegion = 5; - - /* right-middle */ - Rectangle attachBoundsRC = new Rectangle( - (parentBounds.x + parentBounds.width) - widthIntersectRegion, - parentBounds.y + heightOneThird, - widthDockingArea, heightOneThird); - /* right-top */ - Rectangle attachBoundsRT = new Rectangle( - (parentBounds.x + parentBounds.width) - widthIntersectRegion, - parentBounds.y, - widthDockingArea, heightOneThird); - /* right-bottom */ - Rectangle attachBoundsRB = new Rectangle( - (parentBounds.x + parentBounds.width) - widthIntersectRegion, - parentBounds.y + (heightOneThird * 2), - widthDockingArea, heightOneThird); - - /* left-middle */ - Rectangle attachBoundsLC = new Rectangle( - parentBounds.x - (widthDockingArea - widthIntersectRegion), - parentBounds.y + heightOneThird, - widthDockingArea, heightOneThird); - /* left-top */ - Rectangle attachBoundsLT = new Rectangle( - parentBounds.x - (widthDockingArea - widthIntersectRegion), - parentBounds.y, - widthDockingArea, heightOneThird); - /* left-bottom */ - Rectangle attachBoundsLB = new Rectangle( - parentBounds.x - (widthDockingArea - widthIntersectRegion), - parentBounds.y + (heightOneThird * 2), - widthDockingArea, heightOneThird); - - if (childBounds.intersects(attachBoundsRC) == true) { - dock(SWT.RIGHT | SWT.CENTER, false, true); - } else if (childBounds.intersects(attachBoundsRT) == true) { - dock(SWT.RIGHT | SWT.TOP, false, true); - } else if (childBounds.intersects(attachBoundsRB) == true) { - dock(SWT.RIGHT | SWT.BOTTOM, false, true); - } else if (childBounds.intersects(attachBoundsLC) == true) { - dock(SWT.LEFT | SWT.CENTER, false, true); - } else if (childBounds.intersects(attachBoundsLT) == true) { - dock(SWT.LEFT | SWT.TOP, false, true); - } else if (childBounds.intersects(attachBoundsLB) == true) { - dock(SWT.LEFT | SWT.BOTTOM, false, true); - } else { - dock(SWT.NONE, false, true); - } - } - } - - @Override - public void mouseDown(MouseEvent e) { - if (1 == e.button) { /* left button */ - isGrabbedShell = true; - grabPosition.x = e.x; - grabPosition.y = e.y; - } - } - - @Override - public void mouseDoubleClick(MouseEvent e) { - /* do nothing */ - } - }; - - 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(); - } -} 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 deleted file mode 100644 index 48fb3a1cf1..0000000000 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java +++ /dev/null @@ -1,513 +0,0 @@ -/** - * Special Key Window - * - * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * GiWoong Kim - * Hyunjin Lee - * 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.custom; - -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.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.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.graphics.Region; -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.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.HWKeyRegion; -import org.tizen.emulator.skin.util.SkinUtil; -import org.tizen.emulator.skin.util.SwtUtil; - -public class SpecialKeyWindow extends SkinWindow { - public static final String KEYWINDOW_LAYOUT_ROOT = "keywindow-layout"; - public static final String DBI_FILE_NAME = "default.dbi"; - - private EmulatorSkin skin; - private SpecialKeyWindowImageRegistry imageRegistry; - private SocketCommunicator communicator; - - private KeyWindowUI dbiContents; - private Image keyWindowImage; - private Image keyWindowPressedImage; - - private ShellListener shellListener; - private PaintListener shellPaintListener; - private MouseMoveListener shellMouseMoveListener; - private MouseListener shellMouseListener; - - 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(); - 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_ROOT + File.separator + layoutName; - logger.info("special key window path : " + specialKeyWindowPath); - - this.dbiContents = loadXMLForKeyWindow(specialKeyWindowPath); - - /* image init */ - this.imageRegistry = new SpecialKeyWindowImageRegistry( - shell.getDisplay(), dbiContents, specialKeyWindowPath); - - /* get keywindow image */ - //TODO: null - this.keyWindowImage = imageRegistry.getKeyWindowImage( - EmulatorConfig.DEFAULT_WINDOW_ROTATION, - SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL); - this.keyWindowPressedImage = imageRegistry.getKeyWindowImage( - EmulatorConfig.DEFAULT_WINDOW_ROTATION, - SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED); - - /* set window size */ - if (keyWindowImage != null) { - ImageData imageData = keyWindowImage.getImageData(); - shell.setSize(imageData.width, imageData.height); - } - - /* custom window shape */ - Region region = SkinUtil.getTrimmingRegion(keyWindowImage); - if (region != null) { - shell.setRegion(region); - } - - addKeyWindowListener(); - } - - private KeyWindowUI loadXMLForKeyWindow(String skinPath) { - String dbiPath = skinPath + File.separator + DBI_FILE_NAME; - logger.info("load dbi file from " + dbiPath); - - FileInputStream fis = null; - KeyWindowUI keyWindowUI = null; - - try { - fis = new FileInputStream(dbiPath); - logger.info("============ dbi contents ============"); - byte[] bytes = IOUtil.getBytes(fis); - logger.info(new String(bytes, "UTF-8")); - logger.info("======================================="); - - keyWindowUI = JaxbUtil.unmarshal(bytes, KeyWindowUI.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 keyWindowUI; - } - - private HWKey getHWKey(int currentX, int currentY) { - List 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 HWKeyRegion(scaledX, scaledY, scaledWidth, scaledHeight), - keyEntry.getTooltip()); - - return hwKey; - } - } - - return null; - } - - 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"); - - dispose(); - } - - @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 KeyWindow : " + 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 (SkinUtil.isInGeometry(e.x, e.y, x, y, width, height)) { - //eventType = MouseEventType.DRAG.value(); - } else { - isTouch = false; - //eventType = MouseEventType.RELEASE.value(); - /* rollback a keyPressed image region */ - 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); - - return; - } 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 */ - 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); - - /* Let me check whether the key window was landed - * on docking area. */ - Rectangle parentBounds = parent.getBounds(); - Rectangle childBounds = shell.getBounds(); - - int heightOneThird = parentBounds.height / 3; - int widthDockingArea = 30; - int widthIntersectRegion = 5; - - /* right-middle */ - Rectangle attachBoundsRC = new Rectangle( - (parentBounds.x + parentBounds.width) - widthIntersectRegion, - parentBounds.y + heightOneThird, - widthDockingArea, heightOneThird); - /* right-top */ - Rectangle attachBoundsRT = new Rectangle( - (parentBounds.x + parentBounds.width) - widthIntersectRegion, - parentBounds.y, - widthDockingArea, heightOneThird); - /* right-bottom */ - Rectangle attachBoundsRB = new Rectangle( - (parentBounds.x + parentBounds.width) - widthIntersectRegion, - parentBounds.y + (heightOneThird * 2), - widthDockingArea, heightOneThird); - - /* left-middle */ - Rectangle attachBoundsLC = new Rectangle( - parentBounds.x - (widthDockingArea - widthIntersectRegion), - parentBounds.y + heightOneThird, - widthDockingArea, heightOneThird); - /* left-top */ - Rectangle attachBoundsLT = new Rectangle( - parentBounds.x - (widthDockingArea - widthIntersectRegion), - parentBounds.y, - widthDockingArea, heightOneThird); - /* left-bottom */ - Rectangle attachBoundsLB = new Rectangle( - parentBounds.x - (widthDockingArea - widthIntersectRegion), - parentBounds.y + (heightOneThird * 2), - widthDockingArea, heightOneThird); - - if (childBounds.intersects(attachBoundsRC) == true) { - dock(SWT.RIGHT | SWT.CENTER, false, true); - } else if (childBounds.intersects(attachBoundsRT) == true) { - dock(SWT.RIGHT | SWT.TOP, false, true); - } else if (childBounds.intersects(attachBoundsRB) == true) { - dock(SWT.RIGHT | SWT.BOTTOM, false, true); - } else if (childBounds.intersects(attachBoundsLC) == true) { - dock(SWT.LEFT | SWT.CENTER, false, true); - } else if (childBounds.intersects(attachBoundsLT) == true) { - dock(SWT.LEFT | SWT.TOP, false, true); - } else if (childBounds.intersects(attachBoundsLB) == true) { - dock(SWT.LEFT | SWT.BOTTOM, false, true); - } else { - dock(SWT.NONE, false, true); - } - - return; - } - - if (pressedHWKey.getKeyCode() != SkinUtil.UNKNOWN_KEYCODE) { - logger.info(pressedHWKey.getName() + " key is released"); - - /* 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_HW_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 */ - /* HW key handling */ - 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() != 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); - } else { - KeyEventData keyEventData = new KeyEventData( - KeyEventType.PRESSED.value(), hwKey.getKeyCode(), 0, 0); - communicator.sendToQEMU( - SendCommand.SEND_HW_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); - } - - 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); - } - - imageRegistry.dispose(); - } -} diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/info/EmulatorSkinState.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/info/EmulatorSkinState.java new file mode 100644 index 0000000000..066efb50c6 --- /dev/null +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/info/EmulatorSkinState.java @@ -0,0 +1,162 @@ +/** + * Emulator Skin State + * + * Copyright (C) 2011 - 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.info; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.tizen.emulator.skin.config.EmulatorConfig; +import org.tizen.emulator.skin.util.SkinRotation; + +public class EmulatorSkinState { + private Point currentResolution; + private int currentScale; + private short currentRotationId; + + private Rectangle displayBounds; + private boolean updateDisplayBounds; + + private Image currentImage; + private Image currentKeyPressedImage; + private Color hoverColor; + + /** + * Constructor + */ + public EmulatorSkinState() { + this.currentResolution = new Point(720, 1280); + this.currentScale = EmulatorConfig.DEFAULT_WINDOW_SCALE; + this.currentRotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION; + + this.displayBounds = null; + this.updateDisplayBounds = false; + } + + /* resolution */ + public synchronized Point getCurrentResolution() { + return currentResolution; + } + + public synchronized int getCurrentResolutionWidth() { + return currentResolution.x; + } + + public synchronized int getCurrentResolutionHeight() { + return currentResolution.y; + } + + public synchronized void setCurrentResolution(Point resolution) { + setCurrentResolutionWidth(resolution.x); + setCurrentResolutionHeight(resolution.y); + } + + public synchronized void setCurrentResolutionWidth(int width) { + if (width < 0) { + width = 0; + } + this.currentResolution.x = width; + } + + public synchronized void setCurrentResolutionHeight(int height) { + if (height < 0) { + height = 0; + } + this.currentResolution.y = height; + } + + /* scale */ + public synchronized int getCurrentScale() { + return currentScale; + } + + public synchronized void setCurrentScale(int scale) { + this.currentScale = scale; + } + + /* rotation */ + public synchronized short getCurrentRotationId() { + return currentRotationId; + } + + public synchronized int getCurrentAngle() { + return SkinRotation.getAngle(currentRotationId); + } + + public synchronized void setCurrentRotationId(short rotationId) { + this.currentRotationId = rotationId; + } + + /* display bounds */ + public synchronized Rectangle getDisplayBounds() { + if (displayBounds == null) { + return new Rectangle(0, 0, 10, 10); + } + + return displayBounds; + } + + public synchronized void setDisplayBounds(Rectangle bounds) { + this.displayBounds = bounds; + } + + public synchronized boolean isNeedToUpdateDisplay() { + return updateDisplayBounds; + } + + public synchronized void setNeedToUpdateDisplay(boolean needUpdate) { + this.updateDisplayBounds = needUpdate; + } + + /* skin image */ + public synchronized Image getCurrentImage() { + return currentImage; + } + + public synchronized void setCurrentImage(Image image) { + this.currentImage = image; + } + + public synchronized Image getCurrentKeyPressedImage() { + return currentKeyPressedImage; + } + + public synchronized void setCurrentKeyPressedImage(Image keyPressedImage) { + this.currentKeyPressedImage = keyPressedImage; + } + + /* color of hover */ + public synchronized Color getHoverColor() { + return hoverColor; + } + + public synchronized void setHoverColor(Color color) { + this.hoverColor = color; + } +} 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 f502828000..a5c11069cf 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 @@ -47,7 +47,6 @@ import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.tizen.emulator.skin.EmulatorSkin; -import org.tizen.emulator.skin.EmulatorSkinState; import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo; import org.tizen.emulator.skin.config.EmulatorConfig; import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants; @@ -58,6 +57,7 @@ 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.info.EmulatorSkinState; import org.tizen.emulator.skin.log.SkinLogger; import org.tizen.emulator.skin.menu.PopupMenu; import org.tizen.emulator.skin.util.SkinUtil; 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 1099c64592..9e15e4ee21 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 @@ -49,7 +49,6 @@ import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Shell; import org.tizen.emulator.skin.EmulatorSkin; -import org.tizen.emulator.skin.EmulatorSkinState; import org.tizen.emulator.skin.comm.ICommunicator.KeyEventType; import org.tizen.emulator.skin.comm.ICommunicator.SendCommand; import org.tizen.emulator.skin.comm.sock.SocketCommunicator; @@ -64,6 +63,7 @@ import org.tizen.emulator.skin.dbi.RotationType; import org.tizen.emulator.skin.image.ImageRegistry.IconName; import org.tizen.emulator.skin.image.ProfileSkinImageRegistry; import org.tizen.emulator.skin.image.ProfileSkinImageRegistry.SkinImageType; +import org.tizen.emulator.skin.info.EmulatorSkinState; import org.tizen.emulator.skin.log.SkinLogger; import org.tizen.emulator.skin.menu.PopupMenu; import org.tizen.emulator.skin.util.HWKeyRegion; diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/GeneralKeyWindow.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/GeneralKeyWindow.java new file mode 100644 index 0000000000..d29ac506df --- /dev/null +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/GeneralKeyWindow.java @@ -0,0 +1,528 @@ +/** + * General Key Window + * + * Copyright (C) 2011 - 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.menu; + +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +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.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.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +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.SendCommand; +import org.tizen.emulator.skin.comm.sock.data.KeyEventData; +import org.tizen.emulator.skin.custom.ColorTag; +import org.tizen.emulator.skin.custom.CustomButton; +import org.tizen.emulator.skin.custom.CustomScrolledComposite; +import org.tizen.emulator.skin.custom.SkinWindow; +import org.tizen.emulator.skin.dbi.KeyMapType; +import org.tizen.emulator.skin.image.GeneralKeyWindowImageRegistry; +import org.tizen.emulator.skin.image.GeneralKeyWindowImageRegistry.GeneralKeyWindowImageName; +import org.tizen.emulator.skin.layout.SkinPatches; +import org.tizen.emulator.skin.util.SwtUtil; + +public class GeneralKeyWindow extends SkinWindow { + private static final int SHELL_MARGIN_BOTTOM = 3; + private static final int PAIRTAG_CIRCLE_SIZE = 8; + private static final int PAIRTAG_MARGIN_BOTTOM = 6; + private static final int BUTTON_DEFAULT_CNT = 4; + private static final int BUTTON_VERTICAL_SPACING = 7; + private static final int SCROLLBAR_HORIZONTAL_SPACING = 4; + private static final int SCROLLBAR_SIZE_WIDTH = 14; + + private EmulatorSkin skin; + private SkinPatches frameMaker; + + private int widthBase; + private int heightBase; + private int widthScrollbar; + private int cntHiddenButton; + + private Image imageNormal; /* ImageButton image */ + private Image imageHover; /* hovered ImageButton image */ + private Image imagePushed; /* pushed ImageButton image */ + private Image imageFrame; /* nine-patch image */ + + private Color colorFrame; + private GeneralKeyWindowImageRegistry imageRegistry; + private List keyMapList; + + private ShellListener shellListener; + private PaintListener shellPaintListener; + private MouseMoveListener shellMouseMoveListener; + private MouseListener shellMouseListener; + + private boolean isGrabbedShell; + private Point grabPosition; + + public GeneralKeyWindow(EmulatorSkin skin, + GeneralKeyWindowImageRegistry imageRegstry, List keyMapList) { + super(skin.getShell(), SWT.RIGHT | SWT.CENTER); + + this.skin = skin; + this.parent = skin.getShell(); + this.shell = new Shell(parent.getDisplay() /* for Mac & Always on Top */, + SWT.NO_TRIM | SWT.RESIZE | SWT.TOOL | SWT.NO_FOCUS); + + this.imageRegistry = imageRegstry; + this.frameMaker = new SkinPatches( + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYWINDOW_PATCH_LT), + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYWINDOW_PATCH_T), + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYWINDOW_PATCH_RT), + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYWINDOW_PATCH_L), + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYWINDOW_PATCH_R), + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYWINDOW_PATCH_LB), + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYWINDOW_PATCH_B), + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYWINDOW_PATCH_RB)); + + this.keyMapList = keyMapList; //TODO: null + this.grabPosition = new Point(0, 0); + + shell.setText(parent.getText()); + shell.setImage(parent.getImage()); + + /* load image for HW key button */ + imageNormal = imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYBUTTON_NORMAL); + imageHover = imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYBUTTON_HOVER); + imagePushed = imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.KEYBUTTON_PUSHED); + + /* calculate the key window size */ + widthBase = imageNormal.getImageData().width; + heightBase = (imageNormal.getImageData().height * BUTTON_DEFAULT_CNT) + + (BUTTON_VERTICAL_SPACING * (BUTTON_DEFAULT_CNT - 1)); + + widthScrollbar = SCROLLBAR_SIZE_WIDTH + SCROLLBAR_HORIZONTAL_SPACING; + int heightHeaderPart = (PAIRTAG_CIRCLE_SIZE + PAIRTAG_MARGIN_BOTTOM); + int heightTailPart = SHELL_MARGIN_BOTTOM; + + /* make a frame image */ + if (keyMapList != null) { + this.cntHiddenButton = keyMapList.size() - BUTTON_DEFAULT_CNT; + } + + this.imageFrame = frameMaker.getPatchedImage( + widthBase + ((cntHiddenButton > 0) ? widthScrollbar : 0), + heightBase + heightHeaderPart + heightTailPart); + this.colorFrame = new Color(shell.getDisplay(), new RGB(38, 38, 38)); + + shell.setBackground(colorFrame); + + createContents(); + trimPatchedShell(shell, imageFrame); + + addKeyWindowListener(); + + shell.setSize(imageFrame.getImageData().width, + imageFrame.getImageData().height); + } + + protected void createContents() { + GridLayout shellGridLayout = new GridLayout(1, false); + shellGridLayout.marginLeft = shellGridLayout.marginRight = frameMaker.getPatchWidth(); + shellGridLayout.marginTop = frameMaker.getPatchHeight(); + shellGridLayout.marginBottom = frameMaker.getPatchHeight() + SHELL_MARGIN_BOTTOM; + shellGridLayout.marginWidth = shellGridLayout.marginHeight = 0; + shellGridLayout.horizontalSpacing = shellGridLayout.verticalSpacing = 0; + + shell.setLayout(shellGridLayout); + + /* make a pair tag circle */ + ColorTag pairTagCanvas = new ColorTag(shell, SWT.NONE, skin.getColorVM()); + pairTagCanvas.setLayoutData(new GridData(PAIRTAG_CIRCLE_SIZE, + PAIRTAG_CIRCLE_SIZE + PAIRTAG_MARGIN_BOTTOM)); + + /* make a region of HW keys */ + if (cntHiddenButton > 0) { + /* added custom scrollbar */ + Image imagesScrollArrowUp[] = new Image[3]; + Image imagesScrollArrowDown[] = new Image[3]; + + imagesScrollArrowUp[0] = imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.SCROLL_UPBUTTON_NORMAL); + imagesScrollArrowUp[1] = imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.SCROLL_UPBUTTON_HOVER); + imagesScrollArrowUp[2] = imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.SCROLL_UPBUTTON_PUSHED); + + imagesScrollArrowDown[0] = imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_NORMAL); + imagesScrollArrowDown[1] = imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_HOVER); + imagesScrollArrowDown[2] = imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.SCROLL_DOWNBUTTON_PUSHED); + + CustomScrolledComposite compositeScroll = + new CustomScrolledComposite(shell, SWT.NONE, + imagesScrollArrowUp, imagesScrollArrowDown, + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.SCROLL_THUMB), + imageRegistry.getKeyWindowImage( + GeneralKeyWindowImageName.SCROLL_SHAFT)); + compositeScroll.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1)); + + Composite compositeBase = new Composite(compositeScroll, SWT.NONE); + + createHwKeys(compositeBase); + + Point sizeContent = compositeBase.computeSize( + widthBase + widthScrollbar, heightBase); + compositeScroll.setContent(compositeBase, sizeContent); + compositeScroll.setExpandHorizontal(true); + compositeScroll.setExpandVertical(true); + + sizeContent.y += (imageNormal.getImageData().height * cntHiddenButton) + + (BUTTON_VERTICAL_SPACING * cntHiddenButton); + compositeScroll.setMinSize(sizeContent); + } else { + ScrolledComposite compositeScroll = new ScrolledComposite(shell, SWT.V_SCROLL); + compositeScroll.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1)); + + Composite compositeBase = new Composite(compositeScroll, SWT.NONE); + createHwKeys(compositeBase); + + compositeScroll.setContent(compositeBase); + compositeScroll.setExpandHorizontal(true); + compositeScroll.setExpandVertical(true); + + compositeScroll.setMinSize( + compositeBase.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + } + } + + protected void createHwKeys(Composite composite) { + composite.setBackground(colorFrame); + + GridLayout compositeGridLayout = new GridLayout(1, false); + compositeGridLayout.marginLeft = compositeGridLayout.marginRight = 0; + compositeGridLayout.marginTop = compositeGridLayout.marginBottom = 0; + compositeGridLayout.marginWidth = compositeGridLayout.marginHeight = 0; + compositeGridLayout.horizontalSpacing = 0; + compositeGridLayout.verticalSpacing = BUTTON_VERTICAL_SPACING; + composite.setLayout(compositeGridLayout); + + /* attach HW keys */ + if (keyMapList != null && keyMapList.isEmpty() == false) { + for (KeyMapType keyEntry : keyMapList) { + final CustomButton HWKeyButton = new CustomButton(composite, + SWT.NO_FOCUS, imageNormal, imageHover, imagePushed); + HWKeyButton.setText(keyEntry.getEventInfo().getKeyName()); + HWKeyButton.setToolTipText(keyEntry.getTooltip()); + HWKeyButton.setBackground(colorFrame); + HWKeyButton.setLayoutData(new GridData(imageNormal.getImageData().width, + imageNormal.getImageData().height)); + + final int keycode = keyEntry.getEventInfo().getKeyCode(); + HWKeyButton.addMouseListener(new MouseListener() { + @Override + public void mouseDown(MouseEvent e) { + logger.info(HWKeyButton.getText() + " key is pressed"); + + KeyEventData keyEventData = new KeyEventData( + KeyEventType.PRESSED.value(), keycode, 0, 0); + skin.communicator.sendToQEMU( + SendCommand.SEND_HW_KEY_EVENT, keyEventData, false); + } + + @Override + public void mouseUp(MouseEvent e) { + logger.info(HWKeyButton.getText() + " key is released"); + + KeyEventData keyEventData = new KeyEventData( + KeyEventType.RELEASED.value(), keycode, 0, 0); + skin.communicator.sendToQEMU( + SendCommand.SEND_HW_KEY_EVENT, keyEventData, false); + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + /* do nothing */ + } + }); + } + } + } + + 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 (imageFrame != null) { + e.gc.drawImage(imageFrame, 0, 0); + } + } + }; + + shell.addPaintListener(shellPaintListener); + + shellListener = new ShellListener() { + @Override + public void shellClosed(ShellEvent event) { + logger.info("General Key Window is closed"); + + dispose(); + } + + @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 (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 */ + isGrabbedShell = false; + grabPosition.x = grabPosition.y = 0; + + /* Let me check whether the key window was landed + * on docking area. */ + Rectangle parentBounds = parent.getBounds(); + Rectangle childBounds = shell.getBounds(); + + int heightOneThird = parentBounds.height / 3; + int widthDockingArea = 30; + int widthIntersectRegion = 5; + + /* right-middle */ + Rectangle attachBoundsRC = new Rectangle( + (parentBounds.x + parentBounds.width) - widthIntersectRegion, + parentBounds.y + heightOneThird, + widthDockingArea, heightOneThird); + /* right-top */ + Rectangle attachBoundsRT = new Rectangle( + (parentBounds.x + parentBounds.width) - widthIntersectRegion, + parentBounds.y, + widthDockingArea, heightOneThird); + /* right-bottom */ + Rectangle attachBoundsRB = new Rectangle( + (parentBounds.x + parentBounds.width) - widthIntersectRegion, + parentBounds.y + (heightOneThird * 2), + widthDockingArea, heightOneThird); + + /* left-middle */ + Rectangle attachBoundsLC = new Rectangle( + parentBounds.x - (widthDockingArea - widthIntersectRegion), + parentBounds.y + heightOneThird, + widthDockingArea, heightOneThird); + /* left-top */ + Rectangle attachBoundsLT = new Rectangle( + parentBounds.x - (widthDockingArea - widthIntersectRegion), + parentBounds.y, + widthDockingArea, heightOneThird); + /* left-bottom */ + Rectangle attachBoundsLB = new Rectangle( + parentBounds.x - (widthDockingArea - widthIntersectRegion), + parentBounds.y + (heightOneThird * 2), + widthDockingArea, heightOneThird); + + if (childBounds.intersects(attachBoundsRC) == true) { + dock(SWT.RIGHT | SWT.CENTER, false, true); + } else if (childBounds.intersects(attachBoundsRT) == true) { + dock(SWT.RIGHT | SWT.TOP, false, true); + } else if (childBounds.intersects(attachBoundsRB) == true) { + dock(SWT.RIGHT | SWT.BOTTOM, false, true); + } else if (childBounds.intersects(attachBoundsLC) == true) { + dock(SWT.LEFT | SWT.CENTER, false, true); + } else if (childBounds.intersects(attachBoundsLT) == true) { + dock(SWT.LEFT | SWT.TOP, false, true); + } else if (childBounds.intersects(attachBoundsLB) == true) { + dock(SWT.LEFT | SWT.BOTTOM, false, true); + } else { + dock(SWT.NONE, false, true); + } + } + } + + @Override + public void mouseDown(MouseEvent e) { + if (1 == e.button) { /* left button */ + isGrabbedShell = true; + grabPosition.x = e.x; + grabPosition.y = e.y; + } + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + /* do nothing */ + } + }; + + 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(); + } +} 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 c4cd21720f..3ebcbd6aaa 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 @@ -34,9 +34,7 @@ import java.util.logging.Logger; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MenuItem; import org.tizen.emulator.skin.EmulatorSkin; -import org.tizen.emulator.skin.custom.GeneralKeyWindow; 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.image.GeneralKeyWindowImageRegistry; import org.tizen.emulator.skin.log.SkinLogger; diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/PopupMenu.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/PopupMenu.java index b6d7389fb4..d9ec723f69 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/PopupMenu.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/PopupMenu.java @@ -40,7 +40,6 @@ import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; import org.tizen.emulator.skin.EmulatorSkin; import org.tizen.emulator.skin.config.EmulatorConfig; -import org.tizen.emulator.skin.custom.SpecialKeyWindow; import org.tizen.emulator.skin.dbi.MenuItemType; import org.tizen.emulator.skin.dbi.PopupMenuType; import org.tizen.emulator.skin.image.ImageRegistry; diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/SpecialKeyWindow.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/SpecialKeyWindow.java new file mode 100644 index 0000000000..0e0c3261ca --- /dev/null +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/menu/SpecialKeyWindow.java @@ -0,0 +1,514 @@ +/** + * Special Key Window + * + * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * Hyunjin Lee + * 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.menu; + +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.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.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.graphics.Region; +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.custom.SkinWindow; +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.HWKeyRegion; +import org.tizen.emulator.skin.util.SkinUtil; +import org.tizen.emulator.skin.util.SwtUtil; + +public class SpecialKeyWindow extends SkinWindow { + public static final String KEYWINDOW_LAYOUT_ROOT = "keywindow-layout"; + public static final String DBI_FILE_NAME = "default.dbi"; + + private EmulatorSkin skin; + private SpecialKeyWindowImageRegistry imageRegistry; + private SocketCommunicator communicator; + + private KeyWindowUI dbiContents; + private Image keyWindowImage; + private Image keyWindowPressedImage; + + private ShellListener shellListener; + private PaintListener shellPaintListener; + private MouseMoveListener shellMouseMoveListener; + private MouseListener shellMouseListener; + + 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(); + 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_ROOT + File.separator + layoutName; + logger.info("special key window path : " + specialKeyWindowPath); + + this.dbiContents = loadXMLForKeyWindow(specialKeyWindowPath); + + /* image init */ + this.imageRegistry = new SpecialKeyWindowImageRegistry( + shell.getDisplay(), dbiContents, specialKeyWindowPath); + + /* get keywindow image */ + //TODO: null + this.keyWindowImage = imageRegistry.getKeyWindowImage( + EmulatorConfig.DEFAULT_WINDOW_ROTATION, + SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL); + this.keyWindowPressedImage = imageRegistry.getKeyWindowImage( + EmulatorConfig.DEFAULT_WINDOW_ROTATION, + SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED); + + /* set window size */ + if (keyWindowImage != null) { + ImageData imageData = keyWindowImage.getImageData(); + shell.setSize(imageData.width, imageData.height); + } + + /* custom window shape */ + Region region = SkinUtil.getTrimmingRegion(keyWindowImage); + if (region != null) { + shell.setRegion(region); + } + + addKeyWindowListener(); + } + + private KeyWindowUI loadXMLForKeyWindow(String skinPath) { + String dbiPath = skinPath + File.separator + DBI_FILE_NAME; + logger.info("load dbi file from " + dbiPath); + + FileInputStream fis = null; + KeyWindowUI keyWindowUI = null; + + try { + fis = new FileInputStream(dbiPath); + logger.info("============ dbi contents ============"); + byte[] bytes = IOUtil.getBytes(fis); + logger.info(new String(bytes, "UTF-8")); + logger.info("======================================="); + + keyWindowUI = JaxbUtil.unmarshal(bytes, KeyWindowUI.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 keyWindowUI; + } + + private HWKey getHWKey(int currentX, int currentY) { + List 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 HWKeyRegion(scaledX, scaledY, scaledWidth, scaledHeight), + keyEntry.getTooltip()); + + return hwKey; + } + } + + return null; + } + + 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"); + + dispose(); + } + + @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 KeyWindow : " + 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 (SkinUtil.isInGeometry(e.x, e.y, x, y, width, height)) { + //eventType = MouseEventType.DRAG.value(); + } else { + isTouch = false; + //eventType = MouseEventType.RELEASE.value(); + /* rollback a keyPressed image region */ + 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); + + return; + } 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 */ + 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); + + /* Let me check whether the key window was landed + * on docking area. */ + Rectangle parentBounds = parent.getBounds(); + Rectangle childBounds = shell.getBounds(); + + int heightOneThird = parentBounds.height / 3; + int widthDockingArea = 30; + int widthIntersectRegion = 5; + + /* right-middle */ + Rectangle attachBoundsRC = new Rectangle( + (parentBounds.x + parentBounds.width) - widthIntersectRegion, + parentBounds.y + heightOneThird, + widthDockingArea, heightOneThird); + /* right-top */ + Rectangle attachBoundsRT = new Rectangle( + (parentBounds.x + parentBounds.width) - widthIntersectRegion, + parentBounds.y, + widthDockingArea, heightOneThird); + /* right-bottom */ + Rectangle attachBoundsRB = new Rectangle( + (parentBounds.x + parentBounds.width) - widthIntersectRegion, + parentBounds.y + (heightOneThird * 2), + widthDockingArea, heightOneThird); + + /* left-middle */ + Rectangle attachBoundsLC = new Rectangle( + parentBounds.x - (widthDockingArea - widthIntersectRegion), + parentBounds.y + heightOneThird, + widthDockingArea, heightOneThird); + /* left-top */ + Rectangle attachBoundsLT = new Rectangle( + parentBounds.x - (widthDockingArea - widthIntersectRegion), + parentBounds.y, + widthDockingArea, heightOneThird); + /* left-bottom */ + Rectangle attachBoundsLB = new Rectangle( + parentBounds.x - (widthDockingArea - widthIntersectRegion), + parentBounds.y + (heightOneThird * 2), + widthDockingArea, heightOneThird); + + if (childBounds.intersects(attachBoundsRC) == true) { + dock(SWT.RIGHT | SWT.CENTER, false, true); + } else if (childBounds.intersects(attachBoundsRT) == true) { + dock(SWT.RIGHT | SWT.TOP, false, true); + } else if (childBounds.intersects(attachBoundsRB) == true) { + dock(SWT.RIGHT | SWT.BOTTOM, false, true); + } else if (childBounds.intersects(attachBoundsLC) == true) { + dock(SWT.LEFT | SWT.CENTER, false, true); + } else if (childBounds.intersects(attachBoundsLT) == true) { + dock(SWT.LEFT | SWT.TOP, false, true); + } else if (childBounds.intersects(attachBoundsLB) == true) { + dock(SWT.LEFT | SWT.BOTTOM, false, true); + } else { + dock(SWT.NONE, false, true); + } + + return; + } + + if (pressedHWKey.getKeyCode() != SkinUtil.UNKNOWN_KEYCODE) { + logger.info(pressedHWKey.getName() + " key is released"); + + /* 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_HW_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 */ + /* HW key handling */ + 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() != 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); + } else { + KeyEventData keyEventData = new KeyEventData( + KeyEventType.PRESSED.value(), hwKey.getKeyCode(), 0, 0); + communicator.sendToQEMU( + SendCommand.SEND_HW_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); + } + + 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); + } + + imageRegistry.dispose(); + } +}