skin: added toggle button in general skin
authorgiwoong.kim <giwoong.kim@samsung.com>
Fri, 30 Nov 2012 11:55:26 +0000 (20:55 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Fri, 30 Nov 2012 11:55:26 +0000 (20:55 +0900)
The key window can be turned on/off by toggle button
in general skin.

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/layout/GeneralPurposeSkinComposer.java
tizen/src/skin/client/src/org/tizen/emulator/skin/window/ControlPanel.java
tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java

index 0065ebd0a0c58995ae7735520c8946eab2f7de36..fa12d0b9bd0b69a32fbfad2d8c09bde52eac4c0e 100644 (file)
@@ -117,6 +117,7 @@ public class EmulatorSdlSkin extends EmulatorSkin {
                return windowHandleId;
        }
 
+       @Override
        protected void openScreenShotWindow() {
                if (screenShotDialog != null) {
                        return;
index b3dbc7dd1e51db99020c2b6782c53b5c1e895962..ca0685950f85adfc6fa8496519a93c064c23c4f3 100644 (file)
@@ -220,6 +220,7 @@ public class EmulatorShmSkin extends EmulatorSkin {
                return 0;
        }
 
+       @Override
        protected void openScreenShotWindow() {
                if (screenShotDialog != null) {
                        return;
index a9b2564ea1912662c57d2fd796ec799f08d7da01..61610fc927f3e63c82467e53367c755ccf78a726 100644 (file)
@@ -148,9 +148,10 @@ public class EmulatorSkin {
        private boolean isControlPanel;
        private boolean isOnKbd;
 
-       private ControlPanel controlPanel; //not used yet
+       public ControlPanel controlPanel;
        protected ScreenShotDialog screenShotDialog;
        private Menu contextMenu;
+       private MenuItem panelItem; /* key window */
 
        protected SocketCommunicator communicator;
 
@@ -205,8 +206,8 @@ public class EmulatorSkin {
 
                        ((PhoneShapeSkinComposer) skinComposer).addPhoneShapeListener(shell);
                } else { /* general purpose skin */
-                       skinComposer = new GeneralPurposeSkinComposer(config, shell,
-                                       currentState, imageRegistry, communicator);
+                       skinComposer = new GeneralPurposeSkinComposer(config, this,
+                                       shell, currentState, imageRegistry);
 
                        ((GeneralPurposeSkinComposer) skinComposer).addGeneralPurposeListener(shell);
                }
@@ -1517,7 +1518,48 @@ public class EmulatorSkin {
        }
 
        protected void openScreenShotWindow() {
-               //TODO:
+               //TODO: abstract
+       }
+
+       /* toggle a key window */
+       public void setIsControlPanel(boolean value) {
+               isControlPanel = value;
+               panelItem.setSelection(isControlPanel);
+               logger.info("Select Key Window : " + isControlPanel);
+       }
+
+       public boolean getIsControlPanel() {
+               return isControlPanel;
+       }
+
+       public void openKeyWindow() {
+               if (controlPanel != null) {
+                       controlPanel.getShell().setVisible(true);
+                       return;
+               }
+
+               /* create a key window */
+               List<KeyMapType> keyMapList =
+                               SkinUtil.getHWKeyMapList(currentState.getCurrentRotationId());
+
+               if (keyMapList == null) {
+                       logger.info("keyMapList is null");
+                       return;
+               } else if (keyMapList.isEmpty() == true) {
+                       logger.info("keyMapList is empty");
+                       return;
+               }
+
+               try {
+                       controlPanel = new ControlPanel(shell, communicator, keyMapList);
+                       controlPanel.open();
+               } finally {
+                       controlPanel = null;
+               }
+       }
+
+       public void hideKeyWindow() {
+               controlPanel.getShell().setVisible(false);
        }
 
        private void addMenuItems(final Shell shell, final Menu menu) {
@@ -1593,7 +1635,7 @@ public class EmulatorSkin {
                new MenuItem(menu, SWT.SEPARATOR);
 
                /* Key Window menu */
-               final MenuItem panelItem = new MenuItem(menu, SWT.CHECK);
+               panelItem = new MenuItem(menu, SWT.CHECK);
                panelItem.setText("&Key Window");
                panelItem.setSelection(isControlPanel);
 
@@ -1602,34 +1644,11 @@ public class EmulatorSkin {
                        public void widgetSelected(SelectionEvent e) {
                                final boolean isControlPanel = panelItem.getSelection();
 
-                               logger.info("Select Key Window : " + isControlPanel);
-
+                               setIsControlPanel(isControlPanel);
                                if (isControlPanel == true) {
-                                       if (controlPanel != null) {
-                                               controlPanel.getShell().setVisible(true);
-                                               return;
-                                       }
-
-                                       /* create a key window */
-                                       List<KeyMapType> keyMapList =
-                                                       SkinUtil.getHWKeyMapList(currentState.getCurrentRotationId());
-
-                                       if (keyMapList == null) {
-                                               logger.info("keyMapList is null");
-                                               return;
-                                       } else if (keyMapList.isEmpty() == true) {
-                                               logger.info("keyMapList is empty");
-                                               return;
-                                       }
-
-                                       try {
-                                               controlPanel = new ControlPanel(shell, communicator, keyMapList);
-                                               controlPanel.open();
-                                       } finally {
-                                               controlPanel = null;
-                                       }
-                               } else { /* isControlPanel == false */
-                                       controlPanel.getShell().setVisible(false);
+                                       openKeyWindow();
+                               } else {
+                                       hideKeyWindow();
                                }
                        }
                } );
index 23a6d78effccac3b835cfe2fe541b57b7eaffbfc..70867d177c7f8c542fa8cb69816f9a3f9d06cb7d 100644 (file)
@@ -36,13 +36,16 @@ import org.eclipse.swt.events.MouseListener;
 import org.eclipse.swt.events.MouseMoveListener;
 import org.eclipse.swt.events.PaintEvent;
 import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.ImageData;
 import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.graphics.Region;
 import org.eclipse.swt.widgets.Canvas;
 import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.skin.EmulatorSkin;
 import org.tizen.emulator.skin.EmulatorSkinState;
 import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
 import org.tizen.emulator.skin.comm.sock.SocketCommunicator;
@@ -55,6 +58,7 @@ 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;
+import org.tizen.emulator.skin.window.ImageButton;
 
 public class GeneralPurposeSkinComposer implements ISkinComposer {
        private static final String PATCH_IMAGES_PATH = "images/emul-window/";
@@ -63,13 +67,14 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                        GeneralPurposeSkinComposer.class).getLogger();
 
        private EmulatorConfig config;
+       private EmulatorSkin skin;
        private Shell shell;
        private Canvas lcdCanvas;
+       private ImageButton toggleButton;
        private EmulatorSkinState currentState;
 
        private ImageRegistry imageRegistry;
        private SkinPatches frameMaker;
-       private SocketCommunicator communicator;
 
        private PaintListener shellPaintListener;
        private MouseMoveListener shellMouseMoveListener;
@@ -78,14 +83,14 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
        private boolean isGrabbedShell;
        private Point grabPosition;
 
-       public GeneralPurposeSkinComposer(EmulatorConfig config, Shell shell,
-                       EmulatorSkinState currentState, ImageRegistry imageRegistry,
-                       SocketCommunicator communicator) {
+       public GeneralPurposeSkinComposer(EmulatorConfig config, EmulatorSkin skin,
+                       Shell shell, EmulatorSkinState currentState,
+                       ImageRegistry imageRegistry) {
                this.config = config;
+               this.skin = skin;
                this.shell = shell;
                this.currentState = currentState;
                this.imageRegistry = imageRegistry;
-               this.communicator = communicator; //TODO: delete
                this.isGrabbedShell= false;
                this.grabPosition = new Point(0, 0);
 
@@ -118,7 +123,7 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
 
        @Override
        public void composeInternal(Canvas lcdCanvas,
-                       int x, int y, int scale, short rotationId) {
+                       final int x, final int y, int scale, short rotationId) {
 
                //shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
                shell.setLocation(x, y);
@@ -134,6 +139,50 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                        shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE));
                }
 
+               /* load image for toggle button of key window */
+               ClassLoader loader = this.getClass().getClassLoader();
+               Image imageNormal = new Image(shell.getDisplay(),
+                               loader.getResourceAsStream(PATCH_IMAGES_PATH + "arrow_nml.png"));
+               Image imageHover = new Image(shell.getDisplay(),
+                                               loader.getResourceAsStream(PATCH_IMAGES_PATH + "arrow_hover.png"));
+               Image imagePushed = new Image(shell.getDisplay(),
+                                               loader.getResourceAsStream(PATCH_IMAGES_PATH + "arrow_pushed.png"));
+
+               /* create a toggle button of key window */
+               toggleButton = new ImageButton(shell, SWT.DRAW_TRANSPARENT,
+                               imageNormal, imageHover, imagePushed);
+               toggleButton.setBackground(
+                               new Color(shell.getDisplay(), new RGB(0x1f, 0x1f, 0x1f)));
+
+               toggleButton.addMouseListener(new MouseListener() {
+                       @Override
+                       public void mouseDown(MouseEvent e) {
+                               if (skin.getIsControlPanel() == true) {
+                                       skin.setIsControlPanel(false);
+                                       skin.hideKeyWindow();
+                               } else {
+                                       skin.setIsControlPanel(true);
+                                       skin.openKeyWindow();
+
+                                       /* move a key window to right of the emulator window */
+                                       skin.controlPanel.getShell().setLocation(
+                                                       shell.getLocation().x + shell.getSize().x,
+                                                       shell.getLocation().y + (shell.getSize().y / 2) -
+                                                       (skin.controlPanel.getShell().getSize().y / 2));
+                               }
+                       }
+
+                       @Override
+                       public void mouseUp(MouseEvent e) {
+                               /* do nothing */
+                       }
+
+                       @Override
+                       public void mouseDoubleClick(MouseEvent e) {
+                               /* do nothing */
+                       }
+               });
+
                arrangeSkin(scale, rotationId);
        }
 
@@ -174,6 +223,11 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                        tempImage.dispose();
                }
 
+               /* arrange the toggle button of key window */
+               toggleButton.setBounds(lcdBounds.x + lcdBounds.width,
+                               lcdBounds.y + (lcdBounds.height / 2) - (toggleButton.getImageSize().y / 2),
+                               toggleButton.getImageSize().x, toggleButton.getImageSize().y);
+
                /* custom window shape */
                trimPatchedShell(shell, currentState.getCurrentImage());
 
index 7be89e1b772c7bcac1e10aeacde0f4f189d6407c..041144dc17a1343ab9714b41106e5a4cadb2f27a 100644 (file)
@@ -85,7 +85,7 @@ public class ControlPanel extends SkinWindow {
                this.shell = new Shell(Display.getDefault(), SWT.NO_TRIM | SWT.RESIZE);
                this.frameMaker = new SkinPatches(PATCH_IMAGES_PATH);
 
-               /* load image for ImageButton */
+               /* load image for HW key button */
                ClassLoader loader = this.getClass().getClassLoader();
                imageNormal = new Image(Display.getDefault(),
                                loader.getResourceAsStream(PATCH_IMAGES_PATH + "keybutton_nml.png"));
index f7502cb563640867f4a474bc85e6fc9a0a3f766d..7864bcbe611699701e7359a135d5ecf1299b2f5e 100644 (file)
@@ -219,4 +219,9 @@ public class ImageButton extends Canvas {
        public String getText() {
                return text;
        }
+
+       public Point getImageSize() {
+               return new Point(imageButton[0].getImageData().width,
+                               imageButton[0].getImageData().height);
+       }
 }
\ No newline at end of file