ui: added DragController that helps dialog move.
authorminkee.lee <minkee.lee@samsung.com>
Mon, 24 Aug 2015 06:56:03 +0000 (15:56 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 25 Aug 2015 08:36:25 +0000 (17:36 +0900)
- this can be used at dialog (shell) without titlebar.

Change-Id: Ied157b6a47c9a5599396943640ec508b5b0ed975
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
src/org/tizen/emulator/manager/ui/renewal/widgets/DragController.java [new file with mode: 0644]

diff --git a/src/org/tizen/emulator/manager/ui/renewal/widgets/DragController.java b/src/org/tizen/emulator/manager/ui/renewal/widgets/DragController.java
new file mode 100644 (file)
index 0000000..4a81728
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@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.manager.ui.renewal.widgets;
+
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+public class DragController {
+
+       private Shell dialog;
+       private int posX;
+       private int posY;
+       private boolean isMouseDown;
+
+       /**
+        * This makes shell move by dragging controls.
+        * @param shell
+        * @param controls to receive drag event.
+        */
+       public static void set(Shell shell, Control... controls) {
+               DragController controller = new DragController();
+               controller.setTargetShell(shell);
+               controller.setControls(controls);
+       }
+
+
+       // set dialog (shell)
+       private void setTargetShell(Shell shell) {
+               this.dialog = shell;
+       }
+
+       // set controls that receive drag event
+       private void setControls(Control... controls) {
+               for (Control control : controls) {
+                       if (control == null) {
+                               continue;
+                       }
+
+                       control.addMouseListener(new MouseListener() {
+                               @Override
+                               public void mouseDoubleClick(MouseEvent arg0) {
+                                       // TODO Auto-generated method stub
+                               }
+
+                               @Override
+                               public void mouseDown(MouseEvent e) {
+                                       isMouseDown = true;
+                                       posX = e.x;
+                                       posY = e.y;
+                               }
+
+                               @Override
+                               public void mouseUp(MouseEvent e) {
+                                       isMouseDown = false;
+                               }
+                       });
+
+                       control.addMouseMoveListener(new MouseMoveListener() {
+                               @Override
+                               public void mouseMove(MouseEvent e) {
+                                       if (isMouseDown && dialog != null) {
+                                               dialog.setLocation(dialog.getLocation().x + (e.x - posX),
+                                                               dialog.getLocation().y + (e.y - posY));
+                                       }
+                               }
+                       });
+               }
+       }
+}