skin: added ImageButtons to key window
authorgiwoong.kim <giwoong.kim@samsung.com>
Wed, 28 Nov 2012 13:10:38 +0000 (22:10 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Wed, 28 Nov 2012 13:14:18 +0000 (22:14 +0900)
added ImageButtons to key window.

Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/window/ControlPanel.java
tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java
tizen/src/skin/client/src/org/tizen/emulator/skin/window/SkinWindow.java

index d8d9b4a90a38f70b83d461e6951bd09bb8e6f339..8c79fd65e316694dc716925a69c7fcbd3f1419f8 100644 (file)
@@ -37,13 +37,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.Point;
+import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.skin.comm.ICommunicator.KeyEventType;
 import org.tizen.emulator.skin.comm.ICommunicator.SendCommand;
@@ -56,13 +59,18 @@ public class ControlPanel extends SkinWindow {
        private static final String PATCH_IMAGES_PATH = "images/key-window/";
 
        private SkinPatches frameMaker;
-       private Image imageFrame;
+       private Image imageNormal; /* ImageButton image */
+       private Image imageHover; /* hovered ImageButton image */
+       private Image imagePushed; /* pushed ImageButton image */
+       private Image imageFrame; /* nine-patch image */
+       private Color colorFrame;
        private SocketCommunicator communicator;
        private List<KeyMapType> keyMapList;
 
        private PaintListener shellPaintListener;
        private MouseMoveListener shellMouseMoveListener;
        private MouseListener shellMouseListener;
+       private Listener shellCloseListener;
 
        private boolean isGrabbedShell;
        private Point grabPosition;
@@ -71,43 +79,69 @@ public class ControlPanel extends SkinWindow {
                        SocketCommunicator communicator, List<KeyMapType> keyMapList) {
                super(parent);
 
-               this.shell = new Shell(Display.getDefault(), SWT.NO_TRIM);
-               this.frameMaker = new SkinPatches(PATCH_IMAGES_PATH); //TODO: freePatches
-               this.imageFrame = frameMaker.getPatchedImage(136, 140);
+               this.shell = new Shell(Display.getDefault(), SWT.NO_TRIM | SWT.RESIZE);
+               this.frameMaker = new SkinPatches(PATCH_IMAGES_PATH);
+
+               /* load image for ImageButton */
+               ClassLoader loader = this.getClass().getClassLoader();
+               imageNormal = new Image(Display.getDefault(),
+                               loader.getResourceAsStream(PATCH_IMAGES_PATH + "keybutton_nml.png"));
+               imageHover = new Image(Display.getDefault(),
+                                               loader.getResourceAsStream(PATCH_IMAGES_PATH + "keybutton_hover.png"));
+               imagePushed = new Image(Display.getDefault(),
+                                               loader.getResourceAsStream(PATCH_IMAGES_PATH + "keybutton_pushed.png"));
+
+               /* calculate the key window size */
+               int width = imageNormal.getImageData().width;
+               int height = (imageNormal.getImageData().height * 4) + (4 * 3);
+
+               /* make a frame image */
+               this.imageFrame = frameMaker.getPatchedImage(width, height);
+               this.colorFrame = new Color(shell.getDisplay(), new RGB(38, 38, 38));
 
                this.keyMapList = keyMapList;
                this.communicator = communicator;
                this.grabPosition = new Point(0, 0);
 
                createContents();
-               addControlPanelListener(); //TODO: remove
+               addControlPanelListener();
 
-               shell.setSize((frameMaker.getPatchWidth() * 2) + 136,
-                               (frameMaker.getPatchHeight() * 2) + 140);
+               shell.setBackground(colorFrame);
+               shell.setSize(imageFrame.getImageData().width,
+                               imageFrame.getImageData().height);
        }
 
        protected void createContents() {
-               GridLayout gridLayout = new GridLayout(1, true);
-               gridLayout.marginLeft = gridLayout.marginRight = frameMaker.getPatchWidth() + 6;
-               gridLayout.marginTop = frameMaker.getPatchHeight() + 20;
-               gridLayout.marginBottom = frameMaker.getPatchHeight() + 6;
-               gridLayout.marginWidth = gridLayout.marginHeight = 0;
-               gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
+               GridLayout shellGridLayout = new GridLayout(1, true);
+               shellGridLayout.marginLeft = shellGridLayout.marginRight = frameMaker.getPatchWidth();
+               shellGridLayout.marginTop = shellGridLayout.marginBottom = frameMaker.getPatchHeight();
+               shellGridLayout.marginWidth = shellGridLayout.marginHeight = 0;
+               shellGridLayout.horizontalSpacing = shellGridLayout.verticalSpacing = 0;
 
-               shell.setLayout(gridLayout);
+               shell.setLayout(shellGridLayout);
 
                ScrolledComposite compositeScroll = new ScrolledComposite(shell, SWT.V_SCROLL);
                compositeScroll.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));
                Composite compositeBase = new Composite(compositeScroll, SWT.NONE);
-               compositeBase.setLayout(gridLayout);
+               //compositeBase.setBackground(colorFrame);
+
+               GridLayout compositeGridLayout = new GridLayout(1, false);
+               compositeGridLayout.marginLeft = compositeGridLayout.marginRight = 0;
+               compositeGridLayout.marginTop = compositeGridLayout.marginBottom = 0;
+               compositeGridLayout.marginWidth = compositeGridLayout.marginHeight = 0;
+               compositeGridLayout.horizontalSpacing = 0;
+               compositeGridLayout.verticalSpacing = 4;
+               compositeBase.setLayout(compositeGridLayout);
 
                if (keyMapList != null && keyMapList.isEmpty() == false) {
                        for (KeyMapType keyEntry : keyMapList) {
-                               Button HWKeyButton = new Button(compositeBase, SWT.FLAT);
-                               HWKeyButton.setText(keyEntry.getEventInfo().getKeyName());
-                               HWKeyButton.setToolTipText(keyEntry.getTooltip());
-                               HWKeyButton.setSize(102, 28);
-                               HWKeyButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+                               ImageButton HWKeyButton = new ImageButton(compositeBase, SWT.NONE,
+                                               imageNormal, imageHover, imagePushed);
+                               //HWKeyButton.setText(keyEntry.getEventInfo().getKeyName());
+                               //HWKeyButton.setToolTipText(keyEntry.getTooltip());
+                               HWKeyButton.setBackground(colorFrame);
+                               HWKeyButton.setLayoutData(new GridData(imageNormal.getImageData().width,
+                                                               imageNormal.getImageData().height));
 
                                final int keycode = keyEntry.getEventInfo().getKeyCode();
                                HWKeyButton.addMouseListener(new MouseListener() {
@@ -193,5 +227,28 @@ public class ControlPanel extends SkinWindow {
                };
 
                shell.addMouseListener(shellMouseListener);
+
+               shellCloseListener = new Listener() {
+                       @Override
+                       public void handleEvent(Event event) {
+                               logger.info("Key Window is closed");
+
+                               if (null != shellPaintListener) {
+                                       shell.removePaintListener(shellPaintListener);
+                               }
+
+                               if (null != shellMouseMoveListener) {
+                                       shell.removeMouseMoveListener(shellMouseMoveListener);
+                               }
+
+                               if (null != shellMouseListener) {
+                                       shell.removeMouseListener(shellMouseListener);
+                               }
+
+                               frameMaker.freePatches();
+                       }
+               };
+
+               shell.addListener(SWT.Close, shellCloseListener);
        }
 }
index 92e2d199114b94f6d7f451b32d61fe4236308e34..ccb65ccdd959cf90f3a02f34035a074d68e7b24f 100644 (file)
@@ -37,6 +37,7 @@ import org.eclipse.swt.events.MouseMoveListener;
 import org.eclipse.swt.events.MouseTrackAdapter;
 import org.eclipse.swt.events.PaintEvent;
 import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Canvas;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
@@ -45,24 +46,45 @@ public class ImageButton extends Canvas {
        private int mouse = 0;
        private boolean hit = false;
 
-       public ImageButton(Composite parent, int style) {
+       /* 0 : normal, 1 : hover, 2 : pushed */
+       private Image imageButton[];
+
+       public ImageButton(Composite parent, int style,
+                       Image imageNormal, Image imageHover, Image imagePushed) {
                super(parent, style);
 
+               this.imageButton = new Image[3];
+               imageButton[0] = imageNormal;
+               imageButton[1] = imageHover;
+               imageButton[2] = imagePushed;
+
                this.addPaintListener(new PaintListener() {
                        @Override
                        public void paintControl(PaintEvent e) {
                                switch (mouse) {
                                case 0:
                                        /* default state */
-                                       e.gc.drawString("Normal", 5, 5);
+                                       if (imageButton[0] == null) {
+                                               e.gc.drawString("Normal", 1, 1);
+                                       } else {
+                                               e.gc.drawImage(imageButton[0], 0, 0);
+                                       }
                                        break;
                                case 1:
                                        /* mouse over */
-                                       e.gc.drawString("Mouse over", 5, 5);
+                                       if (imageButton[0] == null) {
+                                               e.gc.drawString("Mouse over", 1, 1);
+                                       } else {
+                                               e.gc.drawImage(imageButton[1], 1, 1);
+                                       }
                                        break;
                                case 2:
                                        /* mouse down */
-                                       e.gc.drawString("Hit", 5, 5);
+                                       if (imageButton[0] == null) {
+                                               e.gc.drawString("Hit", 1, 1);
+                                       } else {
+                                               e.gc.drawImage(imageButton[2], 1, 1);
+                                       }
                                        break;
                                default:
                                        break;
index f35c083833c055fa5be1213cdb36864d94e99f46..47396fddb6bfa989e6995771017fea2c34a62682 100644 (file)
@@ -30,15 +30,14 @@ package org.tizen.emulator.skin.window;
 
 import java.util.logging.Logger;
 
-import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.skin.log.SkinLogger;
 
 public class SkinWindow {
-       private Logger logger = SkinLogger.getSkinLogger(
-                                       SkinWindow.class).getLogger();
+       protected Logger logger = SkinLogger.getSkinLogger(
+                       SkinWindow.class).getLogger();
 
        protected Shell shell;
        protected Shell parent;