1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
;
15 import java
.awt
.AWTException
;
16 import java
.awt
.Robot
;
17 import java
.awt
.event
.InputEvent
;
19 import org
.eclipse
.swt
.graphics
.Point
;
20 import org
.eclipse
.swt
.widgets
.Sash
;
21 import org
.eclipse
.swtbot
.swt
.finder
.exceptions
.WidgetNotFoundException
;
22 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
23 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
24 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
25 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.AbstractSWTBotControl
;
26 import org
.hamcrest
.SelfDescribing
;
29 * SWT Bot sash control
31 public class SWTBotSash
extends AbstractSWTBotControl
<Sash
> {
40 * @throws WidgetNotFoundException
41 * if there is no widget
43 public SWTBotSash(Sash w
, SelfDescribing description
) throws WidgetNotFoundException
{
44 super(w
, description
);
48 * Get the central point of the sash
50 * @return the center point, good for dragging
52 public Point
getPoint() {
53 return UIThreadRunnable
.syncExec(new Result
<Point
>() {
57 return widget
.toDisplay(0, widget
.getSize().y
/ 2);
69 public void drag(final Point dst
) {
70 final Point src
= getPoint();
74 * dn : MouseEvent{Sash {} time=262463957 data=null button=1
75 * stateMask=0x0 x=5 y=59 count=1}
77 * move : MouseEvent{Sash {} time=262464038 data=null button=0
78 * stateMask=0x80000 x=131 y=103 count=0}
80 * move : MouseEvent{Sash {} time=262464171 data=null button=0
81 * stateMask=0x80000 x=90 y=116 count=0}
83 * up : MouseEvent{Sash {} time=262464796 data=null button=1
84 * stateMask=0x80000 x=5 y=116 count=1}
87 final Robot awtRobot
= new Robot();
89 // move a maximum of 10 points / event
90 final int magDist
= (src
.x
- dst
.x
) * (src
.x
- dst
.x
) + (src
.y
- dst
.y
) * (src
.y
- dst
.y
);
92 final int steps
= Math
.max(1, (int) Math
.sqrt(magDist
/ 100.0));
94 final int stepX
= (dst
.x
- src
.x
) / steps
;
95 final int stepY
= (dst
.y
- src
.y
) / steps
;
96 syncExec(new VoidResult() {
99 awtRobot
.mouseMove(src
.x
, src
.y
);
100 SWTBotUtils
.delay(15);
101 awtRobot
.mousePress(InputEvent
.BUTTON1_MASK
);
105 for (int i
= 0; i
< steps
; i
++) {
107 asyncExec(new VoidResult() {
110 int x
= src
.x
+ index
* stepX
;
111 int y
= src
.y
+ index
* stepY
;
112 awtRobot
.mouseMove(x
, y
);
116 SWTBotUtils
.delay(10);
119 SWTBotUtils
.delay(100);
120 syncExec(new VoidResult() {
123 awtRobot
.mouseRelease(InputEvent
.BUTTON1_MASK
);
127 } catch (final AWTException e
) {
128 // log.error(e.getMessage(), e);
129 throw new RuntimeException(e
);