skin: separate a event handlers
authorgiwoong.kim <giwoong.kim@samsung.com>
Tue, 13 Nov 2012 07:22:50 +0000 (16:22 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Tue, 13 Nov 2012 13:00:13 +0000 (22:00 +0900)
Separate event handlers according to skin type.

Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
12 files changed:
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinState.java
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/RamdumpDialog.java
tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/HWKey.java [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/PhoneShapeSkinComposer.java
tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java
tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java

index cae80926abc9daec5c3ab112bb4dcd189be44402..d93e78ae3c06a6fcda7a41dc7f07108f2d77cd20 100644 (file)
@@ -56,10 +56,8 @@ public class EmulatorSdlSkin extends EmulatorSkin {
        public long initLayout() {
                super.initLayout();
 
-               // sdl uses this handle id.
-               windowHandleId = getWindowHandleId();
-
-               return windowHandleId;
+               /* sdl uses this handle ID */
+               return getWindowHandleId();
        }
 
        private long getWindowHandleId() {
index 676da2afdb07be9855ea1d80db5e4c6307846fba..8a0ce6dcb76330d5766c8699e154524b4dd7a282 100644 (file)
@@ -139,6 +139,8 @@ public class EmulatorShmSkin extends EmulatorSkin {
 
        protected void skinFinalize() {
                pollThread.stopRequest();
+
+               super.skinFinalize();
        }
 
        public long initLayout() {
index 05c7fa30f06e1c81b5b3fb2c6876f84b1b4208aa..f34fffd184364a30aa5fe79504ad14aa291fc8e0 100644 (file)
@@ -53,15 +53,10 @@ import org.eclipse.swt.events.MenuDetectListener;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.MouseListener;
 import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.MouseTrackAdapter;
-import org.eclipse.swt.events.MouseTrackListener;
 import org.eclipse.swt.events.MouseWheelListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.widgets.Canvas;
@@ -98,7 +93,6 @@ import org.tizen.emulator.skin.layout.ISkinComposer;
 import org.tizen.emulator.skin.layout.PhoneShapeSkinComposer;
 import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.screenshot.ScreenShotDialog;
-import org.tizen.emulator.skin.util.SkinRegion;
 import org.tizen.emulator.skin.util.SkinRotation;
 import org.tizen.emulator.skin.util.SkinUtil;
 import org.tizen.emulator.skin.util.SwtUtil;
@@ -142,35 +136,22 @@ public class EmulatorSkin {
        protected Canvas lcdCanvas;
        protected SkinInformation skinInfo;
        protected ISkinComposer skinComposer;
-       private Color hoverColor;
-       private boolean isDefaultHoverColor;
 
        protected EmulatorSkinState currentState;
-       protected SkinRegion currentHoverRegion;
-       protected SkinRegion currentPressedRegion;
 
-       private int pressedMouseX;
-       private int pressedMouseY;
-       private boolean isMousePressed;
        private boolean isDragStartedInLCD;
-       private boolean isHoverState;
        private boolean isShutdownRequested;
        private boolean isAboutToReopen;
        private boolean isOnTop;
        private boolean isOnKbd;
 
-       private SkinWindow controlPanel;
+       private SkinWindow controlPanel; //not used yet
        protected ScreenShotDialog screenShotDialog;
        private Menu contextMenu;
 
        protected SocketCommunicator communicator;
-       protected long windowHandleId;
 
        private Listener shellCloseListener;
-       private PaintListener shellPaintListener;
-       private MouseTrackListener shellMouseTrackListener;
-       private MouseMoveListener shellMouseMoveListener;
-       private MouseListener shellMouseListener;
        private MenuDetectListener shellMenuDetectListener;
 
        //private DragDetectListener canvasDragDetectListener;
@@ -182,7 +163,6 @@ public class EmulatorSkin {
        private FocusListener canvasFocusListener;
 
        private LinkedList<KeyEventData> pressedKeyEventList;
-       private int pressedHWKeyCode;
 
        private EmulatorSkin reopenSkin;
        
@@ -194,13 +174,9 @@ public class EmulatorSkin {
        protected EmulatorSkin(EmulatorConfig config, SkinInformation skinInfo, boolean isOnTop) {
                this.config = config;
                this.skinInfo = skinInfo;
-               this.isDefaultHoverColor = true;
                this.isOnTop = isOnTop;
                this.pressedKeyEventList = new LinkedList<KeyEventData>();
 
-               this.windowHandleId = 0;
-               this.pressedHWKeyCode = 0;
-               
                int style = SWT.NO_TRIM;
                if (skinInfo.isPhoneShape() == false) {
                        style = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.BORDER;
@@ -217,20 +193,26 @@ public class EmulatorSkin {
        public long initLayout() {
                imageRegistry = ImageRegistry.getInstance();
 
-               if (skinInfo.isPhoneShape() == true) {
+               if (skinInfo.isPhoneShape() == true) { /* phone shape skin */
                        skinComposer = new PhoneShapeSkinComposer(config, shell,
-                                       currentState, imageRegistry);
-               } else {
+                                       currentState, imageRegistry, communicator);
+
+                       ((PhoneShapeSkinComposer) skinComposer).addPhoneShapeListener(shell);
+               } else { /* general purpose skin */
                        skinComposer = new GeneralPurposeSkinComposer(config, shell,
                                        currentState, imageRegistry, communicator);
                }
+
                lcdCanvas = skinComposer.compose();
 
-               seteHoverColor();
+               /* load a hover color */
+               currentState.setHoverColor(loadHoverColor());
 
+               /* added event handlers */
                addShellListener(shell);
                addCanvasListener(shell, lcdCanvas);
 
+               /* attach a menu */
                this.isOnKbd = false;
                setMenu();
 
@@ -279,26 +261,25 @@ public class EmulatorSkin {
 //
 //     }
 
-       private void seteHoverColor() {
-
+       private Color loadHoverColor() {
                ColorsType colors = config.getDbiContents().getColors();
-               if ( null != colors ) {
+
+               if (null != colors) {
                        RgbType hoverRgb = colors.getHoverColor();
-                       if ( null != hoverRgb ) {
+                       if (null != hoverRgb) {
                                Long r = hoverRgb.getR();
                                Long g = hoverRgb.getG();
                                Long b = hoverRgb.getB();
-                               if ( null != r && null != g && null != b ) {
-                                       hoverColor = new Color( shell.getDisplay(), new RGB( r.intValue(), g.intValue(), b.intValue() ) );
-                                       isDefaultHoverColor = false;
+                               if (null != r && null != g && null != b) {
+                                       Color hoverColor = new Color(shell.getDisplay(),
+                                                       new RGB(r.intValue(), g.intValue(), b.intValue()));
+                                       return hoverColor;
                                }
                        }
                }
 
-               if ( isDefaultHoverColor ) {
-                       hoverColor = shell.getDisplay().getSystemColor( SWT.COLOR_WHITE );
-               }
-
+               /* white */
+               return (new Color(shell.getDisplay(), new RGB(255, 255, 255)));
        }
 
        public SkinReopenPolicy open() {
@@ -334,10 +315,10 @@ public class EmulatorSkin {
        }
 
        protected void skinFinalize() {
-               //TODO:
+               skinComposer.composerFinalize();
        }
 
-       private void addShellListener( final Shell shell ) {
+       private void addShellListener(final Shell shell) {
 
                shellCloseListener = new Listener() {
                        @Override
@@ -367,7 +348,7 @@ public class EmulatorSkin {
                                                        controlPanel = null;
                                                }
 
-                                               // save config only for emulator close
+                                               /* save config only for emulator close */
                                                config.setSkinProperty(
                                                                SkinPropertiesConstants.WINDOW_X, shell.getLocation().x);
                                                config.setSkinProperty(
@@ -388,8 +369,8 @@ public class EmulatorSkin {
                                                currentState.getCurrentKeyPressedImage().dispose();
                                        }
 
-                                       if ( !isDefaultHoverColor ) {
-                                               hoverColor.dispose();
+                                       if (currentState.getHoverColor() != null) {
+                                               currentState.getHoverColor().dispose();
                                        }
 
                                        skinFinalize();
@@ -409,242 +390,12 @@ public class EmulatorSkin {
 
                shell.addListener( SWT.Close, shellCloseListener );
 
-               shellPaintListener = new PaintListener() {
-
-                       @Override
-                       public void paintControl( final PaintEvent e ) {
-                               // general shell does not support native transparency, so draw image with GC.
-                               if (currentState.getCurrentImage() != null) {
-                                       e.gc.drawImage(currentState.getCurrentImage(), 0, 0);
-                               }
-
-                       }
-               };
-
-               if (skinInfo.isPhoneShape()) {
-                       shell.addPaintListener(shellPaintListener);
-               }
-
-               shellMouseTrackListener = new MouseTrackAdapter() {
-                       @Override
-                       public void mouseExit( MouseEvent e ) {
-                               // MouseMoveListener of shell does not receive event only with MouseMoveListener
-                               // in case that : hover hardkey -> mouse move into LCD area
-                               if ( isHoverState ) {
-                                       if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
-                                               shell.redraw();
-                                       } else {
-                                               shell.redraw( currentHoverRegion.x, currentHoverRegion.y, currentHoverRegion.width + 1,
-                                                               currentHoverRegion.height + 1, false );
-                                       }
-                                       shell.setToolTipText(null);
-
-                                       isHoverState = false;
-                                       currentHoverRegion.width = currentHoverRegion.height = 0;
-                               }
-                       }
-
-               };
-
-               if (skinInfo.isPhoneShape()) {
-                       shell.addMouseTrackListener(shellMouseTrackListener);
-               }
-
-               shellMouseMoveListener = new MouseMoveListener() {
-                       @Override
-                       public void mouseMove( MouseEvent e ) {
-                               if ( EmulatorSkin.this.isMousePressed ) {
-                                       if (0 == e.button) { /* left button */
-
-                                               SkinRegion hardkeyRegion = SkinUtil.getHardKeyArea(e.x, e.y,
-                                                               currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
-                                               if ( null == hardkeyRegion ) {
-                                                       Point previouseLocation = shell.getLocation();
-                                                       int x = previouseLocation.x + ( e.x - EmulatorSkin.this.pressedMouseX );
-                                                       int y = previouseLocation.y + ( e.y - EmulatorSkin.this.pressedMouseY );
-
-                                                       shell.setLocation( x, y );
-                                               }
-
-                                       }
-                               } else {
-                                       SkinRegion region = SkinUtil.getHardKeyArea(e.x, e.y,
-                                                       currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
-                                       if ( null == region ) {
-                                               if ( isHoverState ) {
-                                                       if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
-                                                               shell.redraw();
-                                                       } else {
-                                                               shell.redraw( currentHoverRegion.x, currentHoverRegion.y, currentHoverRegion.width + 1,
-                                                                               currentHoverRegion.height + 1, false );
-                                                       }
-                                                       shell.setToolTipText(null);
-
-                                                       isHoverState = false;
-                                                       currentHoverRegion.width = currentHoverRegion.height = 0;
-                                               }
-                                       } else {
-                                               if (isHoverState == false) {
-                                                       shell.setToolTipText(SkinUtil.getHardKeyToolTip(e.x, e.y,
-                                                                       currentState.getCurrentRotationId(), currentState.getCurrentScale()));
-                                               }
-
-                                               isHoverState = true;
-                                               currentHoverRegion = region;
-
-                                               /* draw hover */
-                                               shell.getDisplay().syncExec(new Runnable() {
-                                                       public void run() {
-                                                               if (currentHoverRegion.width != 0 && currentHoverRegion.height != 0) {
-                                                                       GC gc = new GC(shell);
-                                                                       if (gc != null) {
-                                                                               gc.setLineWidth(1);
-                                                                               gc.setForeground(hoverColor);
-                                                                               gc.drawRectangle(currentHoverRegion.x, currentHoverRegion.y,
-                                                                                               currentHoverRegion.width, currentHoverRegion.height);
-
-                                                                               gc.dispose();
-                                                                       }
-                                                               }
-                                                       }
-                                               });
-                                       }
-                               }
-
-                       } //end of mouseMove
-               };
-
-               if (skinInfo.isPhoneShape()) {
-                       shell.addMouseMoveListener(shellMouseMoveListener);
-               }
-
-               shellMouseListener = new MouseListener() {
-                       @Override
-                       public void mouseUp( MouseEvent e ) {
-                               if (1 == e.button) { /* left button */
-                                       logger.info( "mouseUp in Skin" );
-                                       EmulatorSkin.this.pressedMouseX = 0;
-                                       EmulatorSkin.this.pressedMouseY = 0;
-                                       EmulatorSkin.this.isMousePressed = false;
-
-                                       if (pressedHWKeyCode != 0) {
-                                               /* send event */
-                                               KeyEventData keyEventData = new KeyEventData(
-                                                               KeyEventType.RELEASED.value(), pressedHWKeyCode, 0, 0);
-                                               communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
-                                               pressedHWKeyCode = 0;
-                                       }
-
-                                       int keyCode = SkinUtil.getHardKeyCode(e.x, e.y,
-                                                       currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
-                                       if ( SkinUtil.UNKNOWN_KEYCODE != keyCode ) {
-                                               /* null check : prevent from mouse up without a hover
-                                               ex. doing always on top in hardkey area */
-                                               if ( null != currentHoverRegion ) {
-                                                       if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
-                                                               shell.redraw();
-                                                       } else {
-                                                               shell.redraw( currentHoverRegion.x, currentHoverRegion.y, currentHoverRegion.width + 1,
-                                                                               currentHoverRegion.height + 1, false );
-                                                       }
-                                               }
-
-                                               SkinRegion region = SkinUtil.getHardKeyArea(e.x, e.y,
-                                                               currentState.getCurrentRotationId(), currentState.getCurrentScale());
-                                               if (keyCode != 101) { // TODO: not necessary for home key
-                                                       SkinUtil.trimShell(shell, currentState.getCurrentImage(),
-                                                                       region.x, region.y, region.width, region.height);
-                                               }
-                                       }
-
-                               }
-                       }
-
-                       @Override
-                       public void mouseDown( MouseEvent e ) {
-                               if (1 == e.button) { /* left button */
-                                       logger.info( "mouseDown in Skin" );
-                                       EmulatorSkin.this.pressedMouseX = e.x;
-                                       EmulatorSkin.this.pressedMouseY = e.y;
-                                       EmulatorSkin.this.isMousePressed = true;
-
-                                       final int keyCode = SkinUtil.getHardKeyCode(e.x, e.y,
-                                                       currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
-                                       if (SkinUtil.UNKNOWN_KEYCODE != keyCode) {
-                                               /* send event */
-                                               KeyEventData keyEventData = new KeyEventData(
-                                                               KeyEventType.PRESSED.value(), keyCode, 0, 0);
-                                               communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
-                                               pressedHWKeyCode = keyCode;
-
-                                               shell.setToolTipText(null);
-
-                                               /* draw the button region as the cropped keyPressed image area */
-                                               currentPressedRegion = SkinUtil.getHardKeyArea(e.x, e.y,
-                                                               currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
-                                               if (currentPressedRegion != null &&
-                                                               currentPressedRegion.width != 0 && currentPressedRegion.height != 0) {
-                                                       shell.getDisplay().syncExec(new Runnable() {
-                                                               public void run() {
-                                                                       if (currentState.getCurrentKeyPressedImage() != null) {
-                                                                               GC gc = new GC( shell );
-                                                                               if (gc != null) {
-
-                                                                                       /* button */
-                                                                                       gc.drawImage(currentState.getCurrentKeyPressedImage(),
-                                                                                               currentPressedRegion.x + 1, currentPressedRegion.y + 1,
-                                                                                               currentPressedRegion.width - 1, currentPressedRegion.height - 1, //src
-                                                                                               currentPressedRegion.x + 1, currentPressedRegion.y + 1,
-                                                                                               currentPressedRegion.width - 1, currentPressedRegion.height - 1); //dst
-
-                                                                                       /* hover */
-                                                                                       if (currentHoverRegion.width != 0 && currentHoverRegion.height != 0) {
-                                                                                               gc.setLineWidth(1);
-                                                                                               gc.setForeground(hoverColor);
-                                                                                               gc.drawRectangle(currentHoverRegion.x, currentHoverRegion.y,
-                                                                                                               currentHoverRegion.width, currentHoverRegion.height);
-                                                                                       }
-
-                                                                                       gc.dispose();
-
-                                                                                       if (keyCode != 101) { // TODO: not necessary for home key
-                                                                                               SkinUtil.trimShell(shell, currentState.getCurrentKeyPressedImage(),
-                                                                                                               currentPressedRegion.x, currentPressedRegion.y,
-                                                                                                               currentPressedRegion.width, currentPressedRegion.height);
-                                                                                       }
-
-                                                                                       currentPressedRegion = null;
-                                                                               }
-                                                                       }
-                                                               }
-                                                       });
-                                               }
-
-                                       }
-                               }
-                       }
-
-                       @Override
-                       public void mouseDoubleClick(MouseEvent e) {
-                               /* do nothing */
-                       }
-               };
-
-               if (skinInfo.isPhoneShape()) {
-                       shell.addMouseListener(shellMouseListener);
-               }
-
                shellMenuDetectListener = new MenuDetectListener() {
                        @Override
                        public void menuDetected(MenuDetectEvent e) {
                                Menu menu = EmulatorSkin.this.contextMenu;
 
-                               if (menu != null && EmulatorSkin.this.isMousePressed == false) {
+                               if (menu != null) {
                                        shell.setMenu(menu);
                                        menu.setVisible(true);
                                        e.doit = false;
@@ -658,23 +409,13 @@ public class EmulatorSkin {
        }
 
        private void removeShellListeners() {
-
-               if ( null != shellCloseListener ) {
-                       shell.removeListener( SWT.Close, shellCloseListener );
-               }
-               if ( null != shellPaintListener ) {
-                       shell.removePaintListener( shellPaintListener );
-               }
-               if ( null != shellMouseTrackListener ) {
-                       shell.removeMouseTrackListener( shellMouseTrackListener );
-               }
-               if ( null != shellMouseMoveListener ) {
-                       shell.removeMouseMoveListener( shellMouseMoveListener );
-               }
-               if ( null != shellMouseListener ) {
-                       shell.removeMouseListener( shellMouseListener );
+               if (null != shellCloseListener) {
+                       shell.removeListener(SWT.Close, shellCloseListener);
                }
 
+               if (null != shellMenuDetectListener) {
+                       shell.removeMenuDetectListener(shellMenuDetectListener);
+               }
        }
 
        private void addCanvasListener(final Shell shell, final Canvas canvas) {
index 846050097a1952a85f8b08b0cfab6b79cd17bd37..247a36efb38870e0a7d612583b6d1179f029f32b 100644 (file)
 
 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.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
+import org.tizen.emulator.skin.layout.HWKey;
 
 public class EmulatorSkinState {
        private Point currentResolution;
@@ -40,6 +42,10 @@ public class EmulatorSkinState {
 
        private Image currentImage;
        private Image currentKeyPressedImage;
+       private Color hoverColor;
+
+       private HWKey currentPressedHWKey;
+       private HWKey currentHoveredHWKey;
 
        public EmulatorSkinState() {
                this.currentResolution = new Point(480, 800);
@@ -108,19 +114,46 @@ public class EmulatorSkinState {
        }
 
        /* skin image */
-       public Image getCurrentImage() {
+       public synchronized Image getCurrentImage() {
                return currentImage;
        }
 
-       public void setCurrentImage(Image image) {
+       public synchronized void setCurrentImage(Image image) {
                this.currentImage = image;
        }
 
-       public Image getCurrentKeyPressedImage() {
+       public synchronized Image getCurrentKeyPressedImage() {
                return currentKeyPressedImage;
        }
 
-       public void setCurrentKeyPressedImag(Image keyPressedImage) {
+       public synchronized void setCurrentKeyPressedImag(Image keyPressedImage) {
                this.currentKeyPressedImage = keyPressedImage;
        }
+
+       /* color of hover */
+       public synchronized Color getHoverColor() {
+               return hoverColor;
+       }
+
+       public synchronized void setHoverColor(Color color) {
+               this.hoverColor = color;
+       }
+
+       /* pressed HW key */
+       public synchronized HWKey getCurrentPressedHWKey() {
+               return currentPressedHWKey;
+       }
+
+       public synchronized void setCurrentPressedHWKey(HWKey hwKey) {
+               this.currentPressedHWKey = hwKey;
+       }
+
+       /* hovered HW key */
+       public synchronized HWKey getCurrentHoveredHWKey() {
+               return currentHoveredHWKey;
+       }
+
+       public synchronized void setCurrentHoveredHWKey(HWKey hwKey) {
+               this.currentHoveredHWKey = hwKey;
+       }
 }
index 90a5aecf44efd6d94b92f74df2dec02fd622856e..faba7e2a21b943d9b00a9feca1972a8534ec45b7 100644 (file)
@@ -6,7 +6,6 @@ import java.util.logging.Logger;
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Cursor;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.ImageData;
 import org.eclipse.swt.graphics.ImageLoader;
index c90a041e51fa841c00480a39310b6e2ab7224cd4..1d60b5f122a798bc1ab6209765126984aee90c72 100644 (file)
@@ -105,8 +105,6 @@ public class ImageRegistry {
        }
        
        private Display display;
-       private int resolutionWidth;
-       private int resolutionHeight;
        private EmulatorUI dbiContents;
 
        private Map<String, Image> skinImageMap;
@@ -127,21 +125,15 @@ public class ImageRegistry {
                return instance;
        }
 
-       public void initialize( EmulatorConfig config ) {
-
-               if ( isInitialized ) {
+       public void initialize(EmulatorConfig config) {
+               if (isInitialized) {
                        return;
                }
                isInitialized = true;
 
                this.display = Display.getDefault();
 
-               int resolutionW = config.getArgInt(ArgsConstants.RESOLUTION_WIDTH);
-               int resolutionH = config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT);
                this.argSkinPath = config.getArg(ArgsConstants.SKIN_PATH);
-
-               this.resolutionWidth = resolutionW;
-               this.resolutionHeight = resolutionH;
                this.dbiContents = config.getDbiContents();
                this.skinImageMap = new HashMap<String, Image>();
                this.iconMap = new HashMap<String, Image>();
index e136643e5fecc6e63161a9f51b41c8681e0e1c3b..daa8024be54b3f0b1dc14d40dfa8f3389ce9d6d9 100644 (file)
@@ -75,7 +75,8 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
        private SocketCommunicator communicator;
 
        public GeneralPurposeSkinComposer(EmulatorConfig config, Shell shell,
-                       EmulatorSkinState currentState, ImageRegistry imageRegistry, SocketCommunicator communicator) {
+                       EmulatorSkinState currentState, ImageRegistry imageRegistry,
+                       SocketCommunicator communicator) {
                this.config = config;
                this.shell = shell;
                this.currentState = currentState;
@@ -228,4 +229,9 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
 
                return lcdBounds;
        }
+
+       @Override
+       public void composerFinalize() {
+               /* do nothing */
+       }
 }
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/HWKey.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/HWKey.java
new file mode 100644 (file)
index 0000000..32b18c0
--- /dev/null
@@ -0,0 +1,69 @@
+/**
+ *
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.skin.layout;
+
+import org.tizen.emulator.skin.util.SkinRegion;
+import org.tizen.emulator.skin.util.SkinUtil;
+
+public class HWKey {
+       private int keyCode;
+       private SkinRegion region;
+       private String tooltip;
+
+       public HWKey() {
+               this.keyCode = SkinUtil.UNKNOWN_KEYCODE;
+       }
+
+       /* keycode */
+       public int getKeyCode() {
+               return keyCode;
+       }
+
+       public void setKeyCode(int keyCode) {
+               this.keyCode = keyCode;
+       }
+
+       /* region */
+       public SkinRegion getRegion() {
+               return region;
+       }
+
+       public void setRegion(SkinRegion region) {
+               this.region = region;
+       }
+
+       /* tooltip */
+       public String getTooltip() {
+               return tooltip;
+       }
+
+       public void setTooltip(String tooltip) {
+               this.tooltip = tooltip;
+       }
+}
index 5862ee70d92f4ac91e278481c058a980d3867c50..402a3238bf7278173518bcbcf538fbfb675fc836 100644 (file)
@@ -42,4 +42,6 @@ public interface ISkinComposer {
        public abstract Rectangle adjustLcdGeometry(
                        Canvas lcdCanvas, int resolutionW, int resolutionH,
                        int scale, short rotationId);
+
+       public abstract void composerFinalize();
 }
index 980cf4897701fe9c13c2c6a1daa1ab084e616ac6..e6250f3ddba16835a177668a06ab352c9f8f3971 100644 (file)
@@ -31,12 +31,25 @@ package org.tizen.emulator.skin.layout;
 import java.util.logging.Logger;
 
 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.MouseTrackAdapter;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+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.widgets.Canvas;
 import org.eclipse.swt.widgets.Shell;
 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;
+import org.tizen.emulator.skin.comm.sock.data.KeyEventData;
 import org.tizen.emulator.skin.config.EmulatorConfig;
 import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
 import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
@@ -59,15 +72,27 @@ public class PhoneShapeSkinComposer implements ISkinComposer {
        private Shell shell;
        private Canvas lcdCanvas;
        private EmulatorSkinState currentState;
-
        private ImageRegistry imageRegistry;
+       private SocketCommunicator communicator;
+
+       private PaintListener shellPaintListener;
+       private MouseTrackListener shellMouseTrackListener;
+       private MouseMoveListener shellMouseMoveListener;
+       private MouseListener shellMouseListener;
+
+       private boolean isGrabbedShell;
+       private Point grabPosition;
 
        public PhoneShapeSkinComposer(EmulatorConfig config, Shell shell,
-                       EmulatorSkinState currentState, ImageRegistry imageRegistry) {
+                       EmulatorSkinState currentState, ImageRegistry imageRegistry,
+                       SocketCommunicator communicator) {
                this.config = config;
                this.shell = shell;
                this.currentState = currentState;
                this.imageRegistry = imageRegistry;
+               this.communicator = communicator;
+               this.isGrabbedShell= false;
+               this.grabPosition = new Point(0, 0);
        }
 
        @Override
@@ -93,7 +118,7 @@ public class PhoneShapeSkinComposer implements ISkinComposer {
                composeInternal(lcdCanvas, x, y, scale, rotationId);
                logger.info("resolution : " + currentState.getCurrentResolution() +
                                ", scale : " + scale);
-               
+
                return lcdCanvas;
        }
 
@@ -117,7 +142,7 @@ public class PhoneShapeSkinComposer implements ISkinComposer {
 
                arrangeSkin(scale, rotationId);
 
-               if (/*skinInfo.isPhoneShape() &&*/ currentState.getCurrentImage() == null) {
+               if (currentState.getCurrentImage() == null) {
                        logger.severe("Failed to load initial skin image file. Kill this skin process.");
                        SkinUtil.openMessage(shell, null,
                                        "Failed to load Skin image file.", SWT.ICON_ERROR, config);
@@ -216,4 +241,223 @@ public class PhoneShapeSkinComposer implements ISkinComposer {
 
                return lcdBounds;
        }
+
+       public void addPhoneShapeListener(final Shell shell) {
+               shellPaintListener = new PaintListener() {
+                       @Override
+                       public void paintControl(final PaintEvent e) {
+                               /* general shell does not support native transparency,
+                                * so draw image with GC. */
+                               if (currentState.getCurrentImage() != null) {
+                                       e.gc.drawImage(currentState.getCurrentImage(), 0, 0);
+                               }
+
+                       }
+               };
+
+               shell.addPaintListener(shellPaintListener);
+
+               shellMouseTrackListener = new MouseTrackAdapter() {
+                       @Override
+                       public void mouseExit(MouseEvent e) {
+                               /* shell does not receive event only with MouseMoveListener
+                                * in case that : hover hardkey -> mouse move into LCD area */
+                               HWKey hoveredHWKey = currentState.getCurrentHoveredHWKey();
+
+                               if (hoveredHWKey != null) {
+                                       shell.redraw(hoveredHWKey.getRegion().x,
+                                                       hoveredHWKey.getRegion().y,
+                                                       hoveredHWKey.getRegion().width,
+                                                       hoveredHWKey.getRegion().height, false);
+
+                                       currentState.setCurrentHoveredHWKey(null);
+                                       shell.setToolTipText(null);
+                               }
+                       }
+               };
+
+               shell.addMouseTrackListener(shellMouseTrackListener);
+
+               shellMouseMoveListener = new MouseMoveListener() {
+                       @Override
+                       public void mouseMove(MouseEvent e) {
+                               if (isGrabbedShell == true && e.button == 0/* left button */ &&
+                                               currentState.getCurrentPressedHWKey() == null) {
+                                       /* 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;
+                               }
+
+                               final HWKey hwKey = SkinUtil.getHWKey(e.x, e.y,
+                                               currentState.getCurrentRotationId(), currentState.getCurrentScale());
+                               if (hwKey == null) {
+                                       /* remove hover */
+                                       HWKey hoveredHWKey = currentState.getCurrentHoveredHWKey();
+
+                                       if (hoveredHWKey != null) {
+                                               shell.redraw(hoveredHWKey.getRegion().x,
+                                                               hoveredHWKey.getRegion().y,
+                                                               hoveredHWKey.getRegion().width,
+                                                               hoveredHWKey.getRegion().height, false);
+
+                                               currentState.setCurrentHoveredHWKey(null);
+                                               shell.setToolTipText(null);
+                                       }
+
+                                       return;
+                               }
+
+                               /* register a tooltip */
+                               if (currentState.getCurrentHoveredHWKey() == null &&
+                                               hwKey.getTooltip().isEmpty() == false) {
+                                       shell.setToolTipText(hwKey.getTooltip());
+                               }
+
+                               /* draw hover */
+                               shell.getDisplay().syncExec(new Runnable() {
+                                       public void run() {
+                                               if (hwKey.getRegion().width != 0 && hwKey.getRegion().height != 0) {
+                                                       GC gc = new GC(shell);
+                                                       if (gc != null) {
+                                                               gc.setLineWidth(1);
+                                                               gc.setForeground(currentState.getHoverColor());
+                                                               gc.drawRectangle(hwKey.getRegion().x, hwKey.getRegion().y,
+                                                                               hwKey.getRegion().width - 1, hwKey.getRegion().height - 1);
+
+                                                               gc.dispose();
+
+                                                               currentState.setCurrentHoveredHWKey(hwKey);
+                                                       }
+                                               }
+                                       }
+                               });
+
+                       }
+               };
+
+               shell.addMouseMoveListener(shellMouseMoveListener);
+
+               shellMouseListener = new MouseListener() {
+                       @Override
+                       public void mouseUp(MouseEvent e) {
+                               if (e.button == 1) { /* left button */
+                                       logger.info("mouseUp in Skin");
+
+                                       isGrabbedShell = false;
+                                       grabPosition.x = grabPosition.y = 0;
+
+                                       HWKey pressedHWKey = currentState.getCurrentPressedHWKey();
+                                       if (pressedHWKey == null) {
+                                               return;
+                                       }
+
+                                       if (pressedHWKey.getKeyCode() != SkinUtil.UNKNOWN_KEYCODE) {
+                                               /* send event */
+                                               KeyEventData keyEventData = new KeyEventData(
+                                                               KeyEventType.RELEASED.value(), pressedHWKey.getKeyCode(), 0, 0);
+                                               communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
+
+                                               currentState.setCurrentPressedHWKey(null);
+
+                                               /* roll back a keyPressed image region */
+                                               shell.redraw(pressedHWKey.getRegion().x, pressedHWKey.getRegion().y,
+                                                               pressedHWKey.getRegion().width, pressedHWKey.getRegion().height, false);
+
+                                               if (pressedHWKey.getKeyCode() != 101) { // TODO: not necessary for home key
+                                                       SkinUtil.trimShell(shell, currentState.getCurrentImage(),
+                                                                       pressedHWKey.getRegion().x, pressedHWKey.getRegion().y,
+                                                                       pressedHWKey.getRegion().width, pressedHWKey.getRegion().height);
+                                               }
+                                       }
+                               }
+                       }
+
+                       @Override
+                       public void mouseDown(MouseEvent e) {
+                               if (1 == e.button) { /* left button */
+                                       logger.info("mouseDown in Skin");
+
+                                       isGrabbedShell = true;
+                                       grabPosition.x = e.x;
+                                       grabPosition.y = e.y;
+
+                                       final HWKey hwKey = SkinUtil.getHWKey(e.x, e.y,
+                                                       currentState.getCurrentRotationId(), currentState.getCurrentScale());
+                                       if (hwKey == null) {
+                                               return;
+                                       }
+
+                                       if (hwKey.getKeyCode() != SkinUtil.UNKNOWN_KEYCODE) {
+                                               /* send event */
+                                               KeyEventData keyEventData = new KeyEventData(
+                                                               KeyEventType.PRESSED.value(), hwKey.getKeyCode(), 0, 0);
+                                               communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
+
+                                               currentState.setCurrentPressedHWKey(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 (currentState.getCurrentKeyPressedImage() != null) {
+                                                                               GC gc = new GC(shell);
+                                                                               if (gc != null) {
+                                                                                       gc.drawImage(currentState.getCurrentKeyPressedImage(),
+                                                                                                       hwKey.getRegion().x, hwKey.getRegion().y,
+                                                                                                       hwKey.getRegion().width, hwKey.getRegion().height, //src
+                                                                                                       hwKey.getRegion().x, hwKey.getRegion().y,
+                                                                                                       hwKey.getRegion().width, hwKey.getRegion().height); //dst
+
+                                                                                       gc.dispose();
+
+                                                                                       if (hwKey.getKeyCode() != 101) { // TODO: not necessary for home key
+                                                                                               SkinUtil.trimShell(shell, currentState.getCurrentKeyPressedImage(),
+                                                                                                               hwKey.getRegion().x, hwKey.getRegion().y,
+                                                                                                               hwKey.getRegion().width, hwKey.getRegion().height);
+                                                                                       }
+
+                                                                               }
+                                                                       }
+                                                               } /* end of run */
+                                                       });
+                                               }
+
+                                       }
+                               }
+                       }
+
+                       @Override
+                       public void mouseDoubleClick(MouseEvent e) {
+                               /* do nothing */
+                       }
+               };
+
+               shell.addMouseListener(shellMouseListener);
+       }
+
+       @Override
+       public void composerFinalize() {
+               if (null != shellPaintListener) {
+                       shell.removePaintListener(shellPaintListener);
+               }
+
+               if (null != shellMouseTrackListener) {
+                       shell.removeMouseTrackListener(shellMouseTrackListener);
+               }
+
+               if (null != shellMouseMoveListener) {
+                       shell.removeMouseMoveListener(shellMouseMoveListener);
+               }
+
+               if (null != shellMouseListener) {
+                       shell.removeMouseListener(shellMouseListener);
+               }
+       }
 }
index de7f50afeec799bbfd9b8d35ade2dfb79d1a89f4..7cf1ffd20130db1afdbd8d3be69193896a50885f 100644 (file)
@@ -67,9 +67,7 @@ import org.eclipse.swt.widgets.ToolBar;
 import org.eclipse.swt.widgets.ToolItem;
 import org.tizen.emulator.skin.EmulatorSkin;
 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.SocketCommunicator.DataTranfer;
 import org.tizen.emulator.skin.config.EmulatorConfig;
 import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
 import org.tizen.emulator.skin.exception.ScreenShotException;
index 75f83032df334640b490df401938feb3cb4254a9..76df3fb77bc32253161d12d4cbda326f675eb9f0 100644 (file)
@@ -49,6 +49,7 @@ import org.tizen.emulator.skin.dbi.RegionType;
 import org.tizen.emulator.skin.dbi.RotationType;
 import org.tizen.emulator.skin.image.ImageRegistry;
 import org.tizen.emulator.skin.image.ImageRegistry.ImageType;
+import org.tizen.emulator.skin.layout.HWKey;
 
 
 /**
@@ -106,83 +107,34 @@ public class SkinUtil {
                return sdbPath;
        }
 
-       public static SkinRegion getHardKeyArea( int currentX, int currentY, short rotationId, int scale ) {
-
-               float convertedScale = convertScale( scale );
-
-               RotationType rotation = SkinRotation.getRotation( rotationId );
+       public static HWKey getHWKey(
+                       int currentX, int currentY, short rotationId, int scale) {
+               float convertedScale = convertScale(scale);
+               RotationType rotation = SkinRotation.getRotation(rotationId);
 
                List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
 
-               for ( KeyMapType keyMap : keyMapList ) {
-
+               for (KeyMapType keyMap : keyMapList) {
                        RegionType region = keyMap.getRegion();
 
-                       int scaledX = (int) ( region.getLeft() * convertedScale );
-                       int scaledY = (int) ( region.getTop() * convertedScale );
-                       int scaledWidth = (int) ( region.getWidth() * convertedScale );
-                       int scaledHeight = (int) ( region.getHeight() * convertedScale );
-
-                       if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
-                               return new SkinRegion( scaledX, scaledY, scaledWidth, scaledHeight );
-                       }
-
-               }
-
-               return null;
-
-       }
-
-       public static int getHardKeyCode( int currentX, int currentY, short rotationId, int scale ) {
-
-               float convertedScale = convertScale( scale );
-
-               RotationType rotation = SkinRotation.getRotation( rotationId );
-
-               List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
+                       int scaledX = (int) (region.getLeft() * convertedScale);
+                       int scaledY = (int) (region.getTop() * convertedScale);
+                       int scaledWidth = (int) (region.getWidth() * convertedScale);
+                       int scaledHeight = (int) (region.getHeight() * convertedScale);
 
-               for ( KeyMapType keyMap : keyMapList ) {
-                       RegionType region = keyMap.getRegion();
-
-                       int scaledX = (int) ( region.getLeft() * convertedScale );
-                       int scaledY = (int) ( region.getTop() * convertedScale );
-                       int scaledWidth = (int) ( region.getWidth() * convertedScale );
-                       int scaledHeight = (int) ( region.getHeight() * convertedScale );
-
-                       if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
+                       if (isInGeometry(currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight)) {
                                EventInfoType eventInfo = keyMap.getEventInfo();
-                               return eventInfo.getKeyCode();
-                       }
-               }
 
-               return UNKNOWN_KEYCODE;
+                               HWKey hwKey = new HWKey();
+                               hwKey.setKeyCode(eventInfo.getKeyCode());
+                               hwKey.setRegion(new SkinRegion(scaledX, scaledY, scaledWidth, scaledHeight));
+                               hwKey.setTooltip(keyMap.getTooltip());
 
-       }
-
-       //TODO: HardKey object
-       public static String getHardKeyToolTip( int currentX, int currentY, short rotationId, int scale ) {
-
-               float convertedScale = convertScale( scale );
-
-               RotationType rotation = SkinRotation.getRotation( rotationId );
-
-               List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
-
-               for ( KeyMapType keyMap : keyMapList ) {
-                       RegionType region = keyMap.getRegion();
-
-                       int scaledX = (int) ( region.getLeft() * convertedScale );
-                       int scaledY = (int) ( region.getTop() * convertedScale );
-                       int scaledWidth = (int) ( region.getWidth() * convertedScale );
-                       int scaledHeight = (int) ( region.getHeight() * convertedScale );
-
-                       if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
-                               return keyMap.getTooltip();
+                               return hwKey;
                        }
                }
 
                return null;
-
        }
 
        public static boolean isInGeometry( int currentX, int currentY, int targetX, int targetY, int targetWidth,