skin: define ISkinComposer interface
authorgiwoong.kim <giwoong.kim@samsung.com>
Fri, 9 Nov 2012 10:45:38 +0000 (19:45 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Mon, 12 Nov 2012 03:20:53 +0000 (12:20 +0900)
Enhancement & Refactoring

Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
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/EmulatorSkinMain.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinState.java
tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/PhoneShapeSkinComposer.java [new file with mode: 0644]

index 3250a35d372d5b9dc873b539bea8177d39328ef3..cae80926abc9daec5c3ab112bb4dcd189be44402 100644 (file)
@@ -53,8 +53,8 @@ public class EmulatorSdlSkin extends EmulatorSkin {
                super(config, skinInfo, isOnTop);
        }
 
-       public long compose() {
-               super.compose();
+       public long initLayout() {
+               super.initLayout();
 
                // sdl uses this handle id.
                windowHandleId = getWindowHandleId();
index 061c382ebb973c8f8e6c0fa4a3ebc39fe9798e9a..676da2afdb07be9855ea1d80db5e4c6307846fba 100644 (file)
@@ -141,8 +141,8 @@ public class EmulatorShmSkin extends EmulatorSkin {
                pollThread.stopRequest();
        }
 
-       public long compose() {
-               super.compose();
+       public long initLayout() {
+               super.initLayout();
 
                /* initialize shared memory */
                int result = shmget(
index f8c777ec89a78da266a3f0fec5481f1040272426..bb410741fb11a80a9d8905bfaab1fe0cc374d748 100644 (file)
@@ -62,16 +62,8 @@ 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.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.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Canvas;
 import org.eclipse.swt.widgets.Decorations;
@@ -95,7 +87,6 @@ import org.tizen.emulator.skin.config.EmulatorConfig;
 import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
 import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
 import org.tizen.emulator.skin.dbi.ColorsType;
-import org.tizen.emulator.skin.dbi.KeyMapType;
 import org.tizen.emulator.skin.dbi.RgbType;
 import org.tizen.emulator.skin.dbi.RotationType;
 import org.tizen.emulator.skin.dialog.AboutDialog;
@@ -103,8 +94,10 @@ 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.image.ImageRegistry.IconName;
-import org.tizen.emulator.skin.image.ImageRegistry.ImageType;
 import org.tizen.emulator.skin.info.SkinInformation;
+import org.tizen.emulator.skin.layout.GeneralPurposeSkinComposer;
+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;
@@ -149,9 +142,8 @@ public class EmulatorSkin {
        protected Shell shell;
        protected ImageRegistry imageRegistry;
        protected Canvas lcdCanvas;
-       private SkinInformation skinInfo;
-       private Image currentImage;
-       private Image currentKeyPressedImage;
+       protected SkinInformation skinInfo;
+       protected ISkinComposer skinComposer;
        private Color hoverColor;
        private boolean isDefaultHoverColor;
 
@@ -172,8 +164,6 @@ public class EmulatorSkin {
        private SkinWindow controlPanel;
        protected ScreenShotDialog screenShotDialog;
        private Menu contextMenu;
-       private Button foldingButton; //TODO:
-       private Decorations decoration; //TODO:
 
        protected SocketCommunicator communicator;
        protected long windowHandleId;
@@ -216,7 +206,6 @@ public class EmulatorSkin {
                if (skinInfo.isPhoneShape() == false) {
                        style = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.BORDER;
                }
-
                this.shell = new Shell(Display.getDefault(), style);
 
                this.currentState = new EmulatorSkinState();
@@ -226,65 +215,27 @@ public class EmulatorSkin {
                this.communicator = communicator;
        }
 
-       public long compose() {
-               shell.setLayout(new FormLayout());
-
-               this.lcdCanvas = new Canvas(shell, SWT.EMBEDDED); //TODO:
-
-               int x = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_X,
-                               EmulatorConfig.DEFAULT_WINDOW_X);
-               int y = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_Y,
-                               EmulatorConfig.DEFAULT_WINDOW_Y);
-
-               currentState.setCurrentResolutionWidth(
-                               config.getArgInt(ArgsConstants.RESOLUTION_WIDTH));
-               currentState.setCurrentResolutionHeight(
-                               config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT));
-
-               int scale = SkinUtil.getValidScale(config);
-//             int rotationId = config.getPropertyShort( PropertiesConstants.WINDOW_ROTATION,
-//                             EmulatorConfig.DEFAULT_WINDOW_ROTATION );
-               // has to be portrait mode at first booting time
-               short rotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
-
-               composeInternal(lcdCanvas, x, y, scale, rotationId, false);
-               logger.info("resolution : " + currentState.getCurrentResolution() +
-                               ", scale : " + scale);
-
-               return 0;
-       }
-
-       private void composeInternal(Canvas lcdCanvas,
-                       int x, int y, int scale, short rotationId, boolean isOnKbd) {
-
-               //shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
-               shell.setLocation(x, y);
-
-               String emulatorName = SkinUtil.makeEmulatorName(config);
-               shell.setText(emulatorName);
-
-               lcdCanvas.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
-
+       public long initLayout() {
                imageRegistry = ImageRegistry.getInstance();
-               if (SwtUtil.isWindowsPlatform()) {
-                       shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE_ICO));
-               } else {
-                       shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE));
-               }
-
-               arrangeSkin(scale, rotationId);
 
-               if (skinInfo.isPhoneShape() && null == currentImage) {
-                       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);
-                       System.exit(-1);
+               if (skinInfo.isPhoneShape() == true) {
+                       skinComposer = new PhoneShapeSkinComposer(config, shell,
+                                       currentState, imageRegistry);
+               } else {
+                       skinComposer = new GeneralPurposeSkinComposer(config, shell,
+                                       currentState, imageRegistry, communicator);
                }
+               lcdCanvas = skinComposer.compose();
 
                seteHoverColor();
 
-               this.isOnKbd = isOnKbd;
+               addShellListener(shell);
+               addCanvasListener(shell, lcdCanvas);
+
+               this.isOnKbd = false;
                setMenu();
+
+               return 0;
        }
 
        private void setMenu() {
@@ -292,9 +243,6 @@ public class EmulatorSkin {
 
                addMenuItems(shell, contextMenu);
 
-               addShellListener(shell);
-               addCanvasListener(shell, lcdCanvas);
-
                shell.setMenu(contextMenu);
        }
 
@@ -386,176 +334,6 @@ public class EmulatorSkin {
 
        }
 
-//     private void rearrangeSkin() {
-//             logger.info("rearrange the skin (" + skinInfo.getSkinOption() + ")");
-//             arrangeSkin(currentScale, currentRotationId);
-//     }
-
-       private void arrangeSkin(int scale, short rotationId) {
-               currentState.setCurrentScale(scale);
-               currentState.setCurrentRotationId(rotationId);
-               currentState.setCurrentAngle(SkinRotation.getAngle(rotationId));
-
-               /* arrange the lcd */
-               Rectangle lcdBounds = SkinUtil.adjustLcdGeometry(lcdCanvas,
-                               currentState.getCurrentResolutionWidth(),
-                               currentState.getCurrentResolutionHeight(), scale, rotationId,
-                               skinInfo.isPhoneShape());
-
-               if (lcdBounds == null) {
-                       logger.severe("Failed to lcd information for phone shape skin.");
-                       SkinUtil.openMessage(shell, null,
-                                       "Failed to read lcd information for phone shape skin.\n" +
-                                       "Check the contents of skin dbi file.",
-                                       SWT.ICON_ERROR, config);
-                       System.exit(-1);
-               }
-               logger.info("lcd bounds : " + lcdBounds);
-
-               FormData dataCanvas = new FormData();
-               dataCanvas.left = new FormAttachment(0, lcdBounds.x);
-               dataCanvas.top = new FormAttachment(0, lcdBounds.y);
-               dataCanvas.width = lcdBounds.width;
-               dataCanvas.height = lcdBounds.height;
-               lcdCanvas.setLayoutData(dataCanvas);
-
-               if (skinInfo.isPhoneShape() == false) {
-//                     /* folding button */
-//                     if (foldingButton == null) {
-//                             foldingButton = new Button(shell, SWT.PUSH);
-//                             foldingButton.setText(">");
-//
-//                             foldingButton.addMouseListener(new MouseListener() {
-//                                     @Override
-//                                     public void mouseDown(MouseEvent e) {
-//                                             /* do nothing */
-//                                     }
-//
-//                                     @Override
-//                                     public void mouseUp(MouseEvent e) {
-//                                             if (skinInfo.getSkinOption() == 0) {
-//                                                     skinInfo.setSkinOption(1);
-//                                                     foldingButton.setText("<");
-//                                             } else {
-//                                                     skinInfo.setSkinOption(0);
-//                                                     foldingButton.setText(">");
-//                                             }
-//
-//                                             shell.getDisplay().syncExec(new Runnable() {
-//                                                     public void run() {
-//                                                             rearrangeSkin();
-//                                                     }
-//                                             });
-//                                     }
-//
-//                                     @Override
-//                                     public void mouseDoubleClick(MouseEvent e) {
-//                                             /* do nothing */
-//                                     }
-//                             });
-//
-//                             shell.pack();
-//                     }
-//
-//                     FormData dataFoldingButton = new FormData();
-//                     dataFoldingButton.left = new FormAttachment(lcdCanvas, 0);
-//                     dataFoldingButton.top = new FormAttachment(
-//                                     0, (lcdBounds.height / 2) - (foldingButton.getSize().y / 2));
-//                     foldingButton.setLayoutData(dataFoldingButton);
-//
-//                     if (skinInfo.getSkinOption() == 0) {
-//                             /* HW keys region */
-//                             if (decoration == null) {
-                                       decoration = new Decorations(shell, SWT.BORDER);
-                                       decoration.setLayout(new GridLayout(1, true));
-
-                                       RotationType rotation =
-                                                       SkinRotation.getRotation(currentState.getCurrentRotationId());
-                                       List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
-
-                                       // TODO: function
-                                       if (keyMapList != null && keyMapList.isEmpty() == false) {
-                                               for (KeyMapType keyEntry : keyMapList) {
-                                                       Button hardKeyButton = new Button(decoration, SWT.FLAT);
-                                                       hardKeyButton.setText(keyEntry.getEventInfo().getKeyName());
-                                                       hardKeyButton.setToolTipText(keyEntry.getTooltip());
-
-                                                       hardKeyButton.setLayoutData(new GridData(SWT.FILL,      SWT.FILL, true, false));
-
-                                                       final int keycode = keyEntry.getEventInfo().getKeyCode();
-                                                       hardKeyButton.addMouseListener(new MouseListener() {
-                                                               @Override
-                                                               public void mouseDown(MouseEvent e) {
-                                                                       KeyEventData keyEventData = new KeyEventData(
-                                                                                       KeyEventType.PRESSED.value(), keycode, 0, 0);
-                                                                       communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
-                                                               }
-
-                                                               @Override
-                                                               public void mouseUp(MouseEvent e) {
-                                                                       KeyEventData keyEventData = new KeyEventData(
-                                                                                       KeyEventType.RELEASED.value(), keycode, 0, 0);
-                                                                       communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
-                                                               }
-
-                                                               @Override
-                                                               public void mouseDoubleClick(MouseEvent e) {
-                                                                       /* do nothing */
-                                                               }
-                                                       });
-                                               }
-                                       }
-
-                                       FormData dataDecoration = new FormData();
-                                       dataDecoration.left = new FormAttachment(lcdCanvas, 0);
-                                       dataDecoration.top = new FormAttachment(0, 0);
-                                       decoration.setLayoutData(dataDecoration);
-//                             }
-//                     } else {
-//                             if (decoration != null) {
-//                                     decoration.dispose();
-//                                     decoration = null;
-//                             }
-//                     }
-
-               } else {
-                       Image tempImage = null;
-                       Image tempKeyPressedImage = null;
-
-                       if (null != currentImage) {
-                               tempImage = currentImage;
-                       }
-                       if (null != currentKeyPressedImage) {
-                               tempKeyPressedImage = currentKeyPressedImage;
-                       }
-
-                       currentImage = SkinUtil.createScaledImage(
-                                       imageRegistry, shell, rotationId, scale, ImageType.IMG_TYPE_MAIN);
-                       currentKeyPressedImage = SkinUtil.createScaledImage(
-                                       imageRegistry, shell, rotationId, scale, ImageType.IMG_TYPE_PRESSED);
-
-                       if (tempImage != null) {
-                               tempImage.dispose();
-                       }
-                       if (tempKeyPressedImage != null) {
-                               tempKeyPressedImage.dispose();
-                       }
-
-                       /* custom window shape */
-                       SkinUtil.trimShell(shell, currentImage);
-               }
-
-               /* set window size */
-               if (null != currentImage) {
-                       ImageData imageData = currentImage.getImageData();
-                       shell.setMinimumSize(imageData.width, imageData.height);
-                       shell.setSize(imageData.width, imageData.height);
-               }
-
-               shell.redraw();
-               shell.pack();
-       }
-
        protected void skinFinalize() {
                //TODO:
        }
@@ -604,11 +382,11 @@ public class EmulatorSkin {
                                                config.saveSkinProperties();
                                        }
 
-                                       if ( null != currentImage ) {
-                                               currentImage.dispose();
+                                       if (currentState.getCurrentImage() != null) {
+                                               currentState.getCurrentImage().dispose();
                                        }
-                                       if ( null != currentKeyPressedImage ) {
-                                               currentKeyPressedImage.dispose();
+                                       if (currentState.getCurrentKeyPressedImage() != null) {
+                                               currentState.getCurrentKeyPressedImage().dispose();
                                        }
 
                                        if ( !isDefaultHoverColor ) {
@@ -636,10 +414,9 @@ public class EmulatorSkin {
 
                        @Override
                        public void paintControl( final PaintEvent e ) {
-
                                // general shell does not support native transparency, so draw image with GC.
-                               if ( null != currentImage ) {
-                                       e.gc.drawImage( currentImage, 0, 0 );
+                               if (currentState.getCurrentImage() != null) {
+                                       e.gc.drawImage(currentState.getCurrentImage(), 0, 0);
                                }
 
                        }
@@ -808,7 +585,7 @@ public class EmulatorSkin {
                                                SkinRegion region = SkinUtil.getHardKeyArea(e.x, e.y,
                                                                currentState.getCurrentRotationId(), currentState.getCurrentScale());
                                                if (keyCode != 101) { // TODO: not necessary for home key
-                                                       SkinUtil.trimShell(shell, currentImage,
+                                                       SkinUtil.trimShell(shell, currentState.getCurrentImage(),
                                                                        region.x, region.y, region.width, region.height);
                                                }
                                        }
@@ -844,12 +621,12 @@ public class EmulatorSkin {
                                                                currentPressedRegion.width != 0 && currentPressedRegion.height != 0) {
                                                        shell.getDisplay().syncExec(new Runnable() {
                                                                public void run() {
-                                                                       if ( null != currentKeyPressedImage ) {
+                                                                       if (currentState.getCurrentKeyPressedImage() != null) {
                                                                                GC gc = new GC( shell );
                                                                                if (gc != null) {
 
                                                                                        /* button */
-                                                                                       gc.drawImage(currentKeyPressedImage,
+                                                                                       gc.drawImage(currentState.getCurrentKeyPressedImage(),
                                                                                                currentPressedRegion.x + 1, currentPressedRegion.y + 1,
                                                                                                currentPressedRegion.width - 1, currentPressedRegion.height - 1, //src
                                                                                                currentPressedRegion.x + 1, currentPressedRegion.y + 1,
@@ -866,7 +643,7 @@ public class EmulatorSkin {
                                                                                        gc.dispose();
 
                                                                                        if (keyCode != 101) { // TODO: not necessary for home key
-                                                                                               SkinUtil.trimShell(shell, currentKeyPressedImage,
+                                                                                               SkinUtil.trimShell(shell, currentState.getCurrentKeyPressedImage(),
                                                                                                                currentPressedRegion.x, currentPressedRegion.y,
                                                                                                                currentPressedRegion.width, currentPressedRegion.height);
                                                                                        }
@@ -2106,7 +1883,7 @@ public class EmulatorSkin {
 
                                if ( !communicator.isSensorDaemonStarted() ) {
 
-                                       // reset selection.
+                                       /* roll back a selection */
                                        item.setSelection( false );
 
                                        for ( MenuItem m : rotationList ) {
@@ -2117,16 +1894,16 @@ public class EmulatorSkin {
                                                }
                                        }
 
-                                       SkinUtil.openMessage( shell, null, "Rotation is not ready.\nPlease, wait.", SWT.ICON_WARNING,
-                                                       config );
-
+                                       SkinUtil.openMessage(shell, null,
+                                                       "Rotation is not ready.\nPlease wait until the emulator is completely boot up.",
+                                                       SWT.ICON_WARNING, config);
                                        return;
-
                                }
 
-                               short rotationId = ( (Short) item.getData() );
+                               short rotationId = ((Short) item.getData());
+
+                               skinComposer.arrangeSkin(currentState.getCurrentScale(), rotationId);
 
-                               arrangeSkin(currentState.getCurrentScale(), rotationId);
                                LcdStateData lcdStateData =
                                                new LcdStateData(currentState.getCurrentScale(), rotationId);
                                communicator.sendToQEMU(SendCommand.CHANGE_LCD_STATE, lcdStateData);
@@ -2179,9 +1956,10 @@ public class EmulatorSkin {
                                        return;
                                }
 
-                               int scale = ( (Scale) item.getData() ).value();
+                               int scale = ((Scale) item.getData()).value();
+
+                               skinComposer.arrangeSkin(scale, currentState.getCurrentRotationId());
 
-                               arrangeSkin(scale, currentState.getCurrentRotationId());
                                LcdStateData lcdStateData =
                                                new LcdStateData(scale, currentState.getCurrentRotationId());
                                communicator.sendToQEMU(SendCommand.CHANGE_LCD_STATE, lcdStateData);
index b4b4a1390c90dd1683a9c940361545ebeebe2c74..ca22e41363bbf66cba43d7952c28aa243b7e6072 100644 (file)
@@ -203,7 +203,7 @@ public class EmulatorSkinMain {
                                        SkinPropertiesConstants.WINDOW_ONTOP, Boolean.FALSE.toString());
                        boolean isOnTop = Boolean.parseBoolean(onTopVal);
 
-                       /* create skin */
+                       /* create skin */
                        EmulatorSkin skin;
                        if (SwtUtil.isMacPlatform()) {
                                skin = new EmulatorShmSkin(config, skinInfo, isOnTop);
@@ -211,16 +211,18 @@ public class EmulatorSkinMain {
                                skin = new EmulatorSdlSkin(config, skinInfo, isOnTop);
                        }
 
-                       long windowHandleId = skin.compose();
+                       /* create a qemu communicator */
+                       int uid = config.getArgInt(ArgsConstants.UID);
+                       communicator = new SocketCommunicator(config, uid, skin);
+                       skin.setCommunicator(communicator);
 
-                       int uid = config.getArgInt( ArgsConstants.UID );
-                       communicator = new SocketCommunicator( config, uid, windowHandleId, skin );
-
-                       skin.setCommunicator( communicator );
+                       /* initialize a skin layout */
+                       long windowHandleId = skin.initLayout();
+                       communicator.setInitialData(windowHandleId);
 
                        Socket commSocket = communicator.getSocket();
 
-                       if ( null != commSocket ) {
+                       if (null != commSocket) {
 
                                Runtime.getRuntime().addShutdownHook( new EmulatorShutdownhook( communicator ) );
 
index 3b204f1ec0de6654ab2a5caa13ec366b8103c5e5..846050097a1952a85f8b08b0cfab6b79cd17bd37 100644 (file)
@@ -28,6 +28,7 @@
 
 package org.tizen.emulator.skin;
 
+import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.Point;
 import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
 
@@ -36,7 +37,10 @@ public class EmulatorSkinState {
        private int currentScale;
        private short currentRotationId;
        private int currentAngle;
-       
+
+       private Image currentImage;
+       private Image currentKeyPressedImage;
+
        public EmulatorSkinState() {
                this.currentResolution = new Point(480, 800);
                this.currentScale = 50;
@@ -48,22 +52,27 @@ public class EmulatorSkinState {
        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;
@@ -75,6 +84,7 @@ public class EmulatorSkinState {
        public synchronized int getCurrentScale() {
                return currentScale;
        }
+
        public synchronized void setCurrentScale(int scale) {
                this.currentScale = scale;
        }
@@ -83,6 +93,7 @@ public class EmulatorSkinState {
        public synchronized short getCurrentRotationId() {
                return currentRotationId;
        }
+
        public synchronized void setCurrentRotationId(short rotationId) {
                this.currentRotationId = rotationId;
        }
@@ -91,7 +102,25 @@ public class EmulatorSkinState {
        public synchronized int getCurrentAngle() {
                return currentAngle;
        }
+
        public synchronized void setCurrentAngle(int angle) {
                this.currentAngle = angle;
-       };
+       }
+
+       /* skin image */
+       public Image getCurrentImage() {
+               return currentImage;
+       }
+
+       public void setCurrentImage(Image image) {
+               this.currentImage = image;
+       }
+
+       public Image getCurrentKeyPressedImage() {
+               return currentKeyPressedImage;
+       }
+
+       public void setCurrentKeyPressedImag(Image keyPressedImage) {
+               this.currentKeyPressedImage = keyPressedImage;
+       }
 }
index ce7d54e11e6fa5cc00450d03d9daf1fa4e40ffd0..6a63f8a03e7f9ec9c3575cd36a6634a389a17305 100644 (file)
@@ -102,7 +102,7 @@ public class SocketCommunicator implements ICommunicator {
 
        private EmulatorConfig config;
        private int uId;
-       private long windowHandleId;
+       private long initialData;
        private EmulatorSkin skin;
 
        private Socket socket;
@@ -121,11 +121,10 @@ public class SocketCommunicator implements ICommunicator {
        private Thread sendThread;
        private LinkedList<SkinSendData> sendQueue;
 
-       public SocketCommunicator( EmulatorConfig config, int uId, long windowHandleId, EmulatorSkin skin ) {
+       public SocketCommunicator(EmulatorConfig config, int uId, EmulatorSkin skin) {
 
                this.config = config;
                this.uId = uId;
-               this.windowHandleId = windowHandleId;
                this.skin = skin;
 
                this.screenShotDataTransfer = new DataTranfer();
@@ -153,6 +152,10 @@ public class SocketCommunicator implements ICommunicator {
 
        }
 
+       public void setInitialData(long data) {
+               this.initialData = data;
+       }
+
        @Override
        public void run() {
 
@@ -218,7 +221,7 @@ public class SocketCommunicator implements ICommunicator {
 //                                     EmulatorConfig.DEFAULT_WINDOW_ROTATION );
                        // has to be portrait mode at first booting time
                        short rotation = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
-                       StartData startData = new StartData( windowHandleId, width, height, scale, rotation );
+                       StartData startData = new StartData(initialData, width, height, scale, rotation);
                        logger.info("StartData" + startData);
 
                        sendToQEMU( SendCommand.SEND_START, startData );
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
new file mode 100644 (file)
index 0000000..13adf71
--- /dev/null
@@ -0,0 +1,210 @@
+/**
+ * 
+ *
+ * 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 java.util.List;
+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.graphics.Rectangle;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Decorations;
+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;
+import org.tizen.emulator.skin.dbi.KeyMapType;
+import org.tizen.emulator.skin.dbi.RotationType;
+import org.tizen.emulator.skin.image.ImageRegistry;
+import org.tizen.emulator.skin.image.ImageRegistry.IconName;
+import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.util.SkinRotation;
+import org.tizen.emulator.skin.util.SkinUtil;
+import org.tizen.emulator.skin.util.SwtUtil;
+
+public class GeneralPurposeSkinComposer implements ISkinComposer {
+       private Logger logger = SkinLogger.getSkinLogger(
+                       GeneralPurposeSkinComposer.class).getLogger();
+
+       private EmulatorConfig config;
+       private Shell shell;
+       private Canvas lcdCanvas;
+       private EmulatorSkinState currentState;
+
+       private ImageRegistry imageRegistry;
+       private SocketCommunicator communicator;
+
+       public GeneralPurposeSkinComposer(EmulatorConfig config, Shell shell,
+                       EmulatorSkinState currentState, ImageRegistry imageRegistry, SocketCommunicator communicator) {
+               this.config = config;
+               this.shell = shell;
+               this.currentState = currentState;
+               this.imageRegistry = imageRegistry;
+               this.communicator = communicator;
+       }
+
+       @Override
+       public Canvas compose() {
+               shell.setLayout(new FormLayout());
+
+               lcdCanvas = new Canvas(shell, SWT.EMBEDDED); //TODO:
+
+               int x = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_X,
+                               EmulatorConfig.DEFAULT_WINDOW_X);
+               int y = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_Y,
+                               EmulatorConfig.DEFAULT_WINDOW_Y);
+
+               currentState.setCurrentResolutionWidth(
+                               config.getArgInt(ArgsConstants.RESOLUTION_WIDTH));
+               currentState.setCurrentResolutionHeight(
+                               config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT));
+
+               int scale = SkinUtil.getValidScale(config);
+               short rotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
+
+               composeInternal(lcdCanvas, x, y, scale, rotationId, false);
+               logger.info("resolution : " + currentState.getCurrentResolution() +
+                               ", scale : " + scale);
+               
+               return lcdCanvas;
+       }
+
+       @Override
+       public void composeInternal(Canvas lcdCanvas,
+                       int x, int y, int scale, short rotationId, boolean isOnKbd) {
+
+               //shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+               shell.setLocation(x, y);
+
+               String emulatorName = SkinUtil.makeEmulatorName(config);
+               shell.setText(emulatorName);
+
+               lcdCanvas.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+
+               if (SwtUtil.isWindowsPlatform()) {
+                       shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE_ICO));
+               } else {
+                       shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE));
+               }
+
+               arrangeSkin(scale, rotationId);
+       }
+
+       @Override
+       public void arrangeSkin(int scale, short rotationId) {
+               currentState.setCurrentScale(scale);
+               currentState.setCurrentRotationId(rotationId);
+               currentState.setCurrentAngle(SkinRotation.getAngle(rotationId));
+
+               /* arrange the lcd */
+               Rectangle lcdBounds = SkinUtil.adjustLcdGeometry(lcdCanvas,
+                               currentState.getCurrentResolutionWidth(),
+                               currentState.getCurrentResolutionHeight(), scale, rotationId,
+                               false);
+
+               if (lcdBounds == null) {
+                       logger.severe("Failed to lcd information for phone shape skin.");
+                       SkinUtil.openMessage(shell, null,
+                                       "Failed to read lcd information for phone shape skin.\n" +
+                                       "Check the contents of skin dbi file.",
+                                       SWT.ICON_ERROR, config);
+                       System.exit(-1);
+               }
+               logger.info("lcd bounds : " + lcdBounds);
+
+               FormData dataCanvas = new FormData();
+               dataCanvas.left = new FormAttachment(0, lcdBounds.x);
+               dataCanvas.top = new FormAttachment(0, lcdBounds.y);
+               dataCanvas.width = lcdBounds.width;
+               dataCanvas.height = lcdBounds.height;
+               lcdCanvas.setLayoutData(dataCanvas);
+
+               Decorations decoration = new Decorations(shell, SWT.BORDER);
+               decoration.setLayout(new GridLayout(1, true));
+
+               RotationType rotation =
+                               SkinRotation.getRotation(currentState.getCurrentRotationId());
+               List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
+
+               // TODO: function
+               if (keyMapList != null && keyMapList.isEmpty() == false) {
+                       for (KeyMapType keyEntry : keyMapList) {
+                               Button hardKeyButton = new Button(decoration, SWT.FLAT);
+                               hardKeyButton.setText(keyEntry.getEventInfo().getKeyName());
+                               hardKeyButton.setToolTipText(keyEntry.getTooltip());
+
+                               hardKeyButton.setLayoutData(new GridData(SWT.FILL,      SWT.FILL, true, false));
+
+                               final int keycode = keyEntry.getEventInfo().getKeyCode();
+                               hardKeyButton.addMouseListener(new MouseListener() {
+                                       @Override
+                                       public void mouseDown(MouseEvent e) {
+                                               KeyEventData keyEventData = new KeyEventData(
+                                                               KeyEventType.PRESSED.value(), keycode, 0, 0);
+                                               communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
+                                       }
+
+                                       @Override
+                                       public void mouseUp(MouseEvent e) {
+                                               KeyEventData keyEventData = new KeyEventData(
+                                                               KeyEventType.RELEASED.value(), keycode, 0, 0);
+                                               communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
+                                       }
+
+                                       @Override
+                                       public void mouseDoubleClick(MouseEvent e) {
+                                               /* do nothing */
+                                       }
+                               });
+                       }
+               }
+
+               FormData dataDecoration = new FormData();
+               dataDecoration.left = new FormAttachment(lcdCanvas, 0);
+               dataDecoration.top = new FormAttachment(0, 0);
+               decoration.setLayoutData(dataDecoration);
+               
+               shell.redraw();
+               shell.pack();
+       }
+
+}
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java
new file mode 100644 (file)
index 0000000..1b4c788
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * 
+ *
+ * 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.eclipse.swt.widgets.Canvas;
+
+public interface ISkinComposer {
+       public abstract Canvas compose();
+       public abstract void composeInternal(Canvas lcdCanvas,
+                                       int x, int y, int scale, short rotationId, boolean isOnKbd);
+       public abstract void arrangeSkin(int scale, short rotationId);
+}
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/PhoneShapeSkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/PhoneShapeSkinComposer.java
new file mode 100644 (file)
index 0000000..b1a0a49
--- /dev/null
@@ -0,0 +1,189 @@
+/**
+ * 
+ *
+ * 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 java.util.logging.Logger;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+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.config.EmulatorConfig;
+import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
+import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
+import org.tizen.emulator.skin.image.ImageRegistry;
+import org.tizen.emulator.skin.image.ImageRegistry.IconName;
+import org.tizen.emulator.skin.image.ImageRegistry.ImageType;
+import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.util.SkinRotation;
+import org.tizen.emulator.skin.util.SkinUtil;
+import org.tizen.emulator.skin.util.SwtUtil;
+
+public class PhoneShapeSkinComposer implements ISkinComposer {
+       private Logger logger = SkinLogger.getSkinLogger(
+                       PhoneShapeSkinComposer.class).getLogger();
+
+       private EmulatorConfig config;
+       private Shell shell;
+       private Canvas lcdCanvas;
+       private EmulatorSkinState currentState;
+
+       private ImageRegistry imageRegistry;
+
+       public PhoneShapeSkinComposer(EmulatorConfig config, Shell shell,
+                       EmulatorSkinState currentState, ImageRegistry imageRegistry) {
+               this.config = config;
+               this.shell = shell;
+               this.currentState = currentState;
+               this.imageRegistry = imageRegistry;
+       }
+
+       @Override
+       public Canvas compose() {
+               lcdCanvas = new Canvas(shell, SWT.EMBEDDED); //TODO:
+
+               int x = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_X,
+                               EmulatorConfig.DEFAULT_WINDOW_X);
+               int y = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_Y,
+                               EmulatorConfig.DEFAULT_WINDOW_Y);
+
+               currentState.setCurrentResolutionWidth(
+                               config.getArgInt(ArgsConstants.RESOLUTION_WIDTH));
+               currentState.setCurrentResolutionHeight(
+                               config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT));
+
+               int scale = SkinUtil.getValidScale(config);
+//             int rotationId = config.getPropertyShort( PropertiesConstants.WINDOW_ROTATION,
+//                             EmulatorConfig.DEFAULT_WINDOW_ROTATION );
+               // has to be portrait mode at first booting time
+               short rotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
+
+               composeInternal(lcdCanvas, x, y, scale, rotationId, false);
+               logger.info("resolution : " + currentState.getCurrentResolution() +
+                               ", scale : " + scale);
+               
+               return lcdCanvas;
+       }
+
+       @Override
+       public void composeInternal(Canvas lcdCanvas,
+                       int x, int y, int scale, short rotationId, boolean isOnKbd) {
+
+               //shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+               shell.setLocation(x, y);
+
+               String emulatorName = SkinUtil.makeEmulatorName(config);
+               shell.setText(emulatorName);
+
+               lcdCanvas.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+
+               if (SwtUtil.isWindowsPlatform()) {
+                       shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE_ICO));
+               } else {
+                       shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE));
+               }
+
+               arrangeSkin(scale, rotationId);
+
+               if (/*skinInfo.isPhoneShape() &&*/ 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);
+                       System.exit(-1);
+               }
+       }
+
+       @Override
+       public void arrangeSkin(int scale, short rotationId) {
+               currentState.setCurrentScale(scale);
+               currentState.setCurrentRotationId(rotationId);
+               currentState.setCurrentAngle(SkinRotation.getAngle(rotationId));
+
+               /* arrange the lcd */
+               Rectangle lcdBounds = SkinUtil.adjustLcdGeometry(lcdCanvas,
+                               currentState.getCurrentResolutionWidth(),
+                               currentState.getCurrentResolutionHeight(), scale, rotationId,
+                               true);
+
+               if (lcdBounds == null) {
+                       logger.severe("Failed to lcd information for phone shape skin.");
+                       SkinUtil.openMessage(shell, null,
+                                       "Failed to read lcd information for phone shape skin.\n" +
+                                       "Check the contents of skin dbi file.",
+                                       SWT.ICON_ERROR, config);
+                       System.exit(-1);
+               }
+               logger.info("lcd bounds : " + lcdBounds);
+
+               /* arrange the skin image */
+               Image tempImage = null;
+               Image tempKeyPressedImage = null;
+
+               if (currentState.getCurrentImage() != null) {
+                       tempImage = currentState.getCurrentImage();
+               }
+               if (currentState.getCurrentKeyPressedImage() != null) {
+                       tempKeyPressedImage = currentState.getCurrentKeyPressedImage();
+               }
+
+               currentState.setCurrentImage(SkinUtil.createScaledImage(
+                               imageRegistry, shell, rotationId, scale, ImageType.IMG_TYPE_MAIN));
+               currentState.setCurrentKeyPressedImag(SkinUtil.createScaledImage(
+                               imageRegistry, shell, rotationId, scale, ImageType.IMG_TYPE_PRESSED));
+
+               if (tempImage != null) {
+                       tempImage.dispose();
+               }
+               if (tempKeyPressedImage != null) {
+                       tempKeyPressedImage.dispose();
+               }
+
+               /* custom window shape */
+               SkinUtil.trimShell(shell, currentState.getCurrentImage());
+
+               /* set window size */
+               if (currentState.getCurrentImage() != null) {
+                       ImageData imageData = currentState.getCurrentImage().getImageData();
+                       shell.setMinimumSize(imageData.width, imageData.height);
+                       shell.setSize(imageData.width, imageData.height);
+               }
+
+               shell.redraw();
+               shell.pack();
+
+               lcdCanvas.setBounds(lcdBounds);
+       }
+}