36744
|
1 |
/*
|
|
2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.netbeans.jemmy.drivers.scrolling;
|
|
24 |
|
|
25 |
import javax.swing.JButton;
|
|
26 |
import javax.swing.JSplitPane;
|
|
27 |
|
|
28 |
import org.netbeans.jemmy.ComponentSearcher;
|
|
29 |
import org.netbeans.jemmy.drivers.ButtonDriver;
|
|
30 |
import org.netbeans.jemmy.drivers.DriverManager;
|
|
31 |
import org.netbeans.jemmy.drivers.LightSupportiveDriver;
|
|
32 |
import org.netbeans.jemmy.drivers.ScrollDriver;
|
|
33 |
import org.netbeans.jemmy.operators.ComponentOperator;
|
|
34 |
import org.netbeans.jemmy.operators.ContainerOperator;
|
|
35 |
import org.netbeans.jemmy.operators.JButtonOperator;
|
|
36 |
import org.netbeans.jemmy.operators.JSplitPaneOperator;
|
|
37 |
import org.netbeans.jemmy.operators.Operator;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* ScrollDriver for javax.swing.JSplitPane component type.
|
|
41 |
*
|
|
42 |
* @author Alexandre Iline(alexandre.iline@oracle.com)
|
|
43 |
*/
|
|
44 |
public class JSplitPaneDriver extends LightSupportiveDriver implements ScrollDriver {
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Constructs a JSplitPaneDriver.
|
|
48 |
*/
|
|
49 |
public JSplitPaneDriver() {
|
|
50 |
super(new String[]{"org.netbeans.jemmy.operators.JSplitPaneOperator"});
|
|
51 |
}
|
|
52 |
|
|
53 |
@Override
|
|
54 |
public void scroll(ComponentOperator oper, ScrollAdjuster adj) {
|
|
55 |
moveDividerTo((JSplitPaneOperator) oper, adj);
|
|
56 |
}
|
|
57 |
|
|
58 |
@Override
|
|
59 |
public void scrollToMinimum(ComponentOperator oper, int orientation) {
|
|
60 |
expandTo((JSplitPaneOperator) oper, 0);
|
|
61 |
}
|
|
62 |
|
|
63 |
@Override
|
|
64 |
public void scrollToMaximum(ComponentOperator oper, int orientation) {
|
|
65 |
expandTo((JSplitPaneOperator) oper, 1);
|
|
66 |
}
|
|
67 |
|
|
68 |
private void moveDividerTo(JSplitPaneOperator oper, ScrollAdjuster adj) {
|
|
69 |
ContainerOperator<?> divOper = oper.getDivider();
|
|
70 |
/* workaround */
|
|
71 |
if (oper.getDividerLocation() == -1) {
|
|
72 |
moveTo(oper, divOper, divOper.getCenterX() - 1, divOper.getCenterY() - 1);
|
|
73 |
if (oper.getDividerLocation() == -1) {
|
|
74 |
moveTo(oper, divOper, divOper.getCenterX() + 1, divOper.getCenterY() + 1);
|
|
75 |
}
|
|
76 |
}
|
|
77 |
if (oper.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
|
|
78 |
moveOnce(oper, divOper, adj, 0, oper.getWidth());
|
|
79 |
} else {
|
|
80 |
moveOnce(oper, divOper, adj, 0, oper.getHeight());
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
private void moveOnce(JSplitPaneOperator oper,
|
|
85 |
ContainerOperator<?> divOper,
|
|
86 |
ScrollAdjuster adj,
|
|
87 |
int leftPosition,
|
|
88 |
int rightPosition) {
|
|
89 |
int currentPosition = 0;
|
|
90 |
if (oper.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
|
|
91 |
currentPosition = (int) (divOper.getLocationOnScreen().getX()
|
|
92 |
- oper.getLocationOnScreen().getX());
|
|
93 |
} else {
|
|
94 |
currentPosition = (int) (divOper.getLocationOnScreen().getY()
|
|
95 |
- oper.getLocationOnScreen().getY());
|
|
96 |
}
|
|
97 |
int nextPosition = 0;
|
|
98 |
if (adj.getScrollDirection() == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
|
|
99 |
nextPosition = (currentPosition + leftPosition) / 2;
|
|
100 |
moveToPosition(oper, divOper, nextPosition - currentPosition);
|
|
101 |
if (currentPosition
|
|
102 |
== ((adj.getScrollOrientation() == JSplitPane.HORIZONTAL_SPLIT)
|
|
103 |
? (int) (divOper.getLocationOnScreen().getX()
|
|
104 |
- oper.getLocationOnScreen().getX())
|
|
105 |
: (int) (divOper.getLocationOnScreen().getY()
|
|
106 |
- oper.getLocationOnScreen().getY()))) {
|
|
107 |
return;
|
|
108 |
}
|
|
109 |
moveOnce(oper, divOper, adj, leftPosition, currentPosition);
|
|
110 |
} else if (adj.getScrollDirection() == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
|
|
111 |
nextPosition = (currentPosition + rightPosition) / 2;
|
|
112 |
moveToPosition(oper, divOper, nextPosition - currentPosition);
|
|
113 |
if (currentPosition
|
|
114 |
== ((adj.getScrollOrientation() == JSplitPane.HORIZONTAL_SPLIT)
|
|
115 |
? (int) (divOper.getLocationOnScreen().getX()
|
|
116 |
- oper.getLocationOnScreen().getX())
|
|
117 |
: (int) (divOper.getLocationOnScreen().getY()
|
|
118 |
- oper.getLocationOnScreen().getY()))) {
|
|
119 |
return;
|
|
120 |
}
|
|
121 |
moveOnce(oper, divOper, adj, currentPosition, rightPosition);
|
|
122 |
} else { // (currentLocation == dividerLocation) - stop point
|
|
123 |
return;
|
|
124 |
}
|
|
125 |
}
|
|
126 |
|
|
127 |
private void moveTo(JSplitPaneOperator oper, ComponentOperator divOper, int x, int y) {
|
|
128 |
DriverManager.getMouseDriver(divOper).
|
|
129 |
dragNDrop(divOper, divOper.getCenterX(), divOper.getCenterY(), x, y,
|
|
130 |
Operator.getDefaultMouseButton(), 0,
|
|
131 |
oper.getTimeouts().create("ComponentOperator.BeforeDragTimeout"),
|
|
132 |
oper.getTimeouts().create("ComponentOperator.AfterDragTimeout"));
|
|
133 |
}
|
|
134 |
|
|
135 |
private void moveToPosition(JSplitPaneOperator oper, ComponentOperator divOper, int nextPosition) {
|
|
136 |
if (System.getProperty("java.version").startsWith("1.2")) {
|
|
137 |
oper.setDividerLocation(nextPosition);
|
|
138 |
}
|
|
139 |
if (oper.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
|
|
140 |
moveTo(oper, divOper, divOper.getCenterX() + nextPosition, divOper.getCenterY());
|
|
141 |
} else {
|
|
142 |
moveTo(oper, divOper, divOper.getCenterX(), divOper.getCenterY() + nextPosition);
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
private void expandTo(JSplitPaneOperator oper, int index) {
|
|
147 |
ContainerOperator<?> divOper = oper.getDivider();
|
|
148 |
JButtonOperator bo
|
|
149 |
= new JButtonOperator((JButton) divOper.
|
|
150 |
waitSubComponent(new JButtonOperator.JButtonFinder(ComponentSearcher.
|
|
151 |
getTrueChooser("JButton")),
|
|
152 |
index));
|
|
153 |
bo.copyEnvironment(divOper);
|
|
154 |
ButtonDriver bdriver = DriverManager.getButtonDriver(bo);
|
|
155 |
bdriver.push(bo);
|
|
156 |
bdriver.push(bo);
|
|
157 |
}
|
|
158 |
}
|