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.lists;
|
|
24 |
|
|
25 |
import java.awt.Point;
|
|
26 |
import java.awt.event.InputEvent;
|
|
27 |
|
|
28 |
import org.netbeans.jemmy.QueueTool;
|
|
29 |
import org.netbeans.jemmy.drivers.DriverManager;
|
|
30 |
import org.netbeans.jemmy.drivers.LightSupportiveDriver;
|
|
31 |
import org.netbeans.jemmy.drivers.OrderedListDriver;
|
|
32 |
import org.netbeans.jemmy.operators.ComponentOperator;
|
|
33 |
import org.netbeans.jemmy.operators.JTableHeaderOperator;
|
|
34 |
import org.netbeans.jemmy.operators.Operator;
|
|
35 |
|
|
36 |
/**
|
|
37 |
* List driver for javax.swing.table.JTableHeader component type.
|
|
38 |
*
|
|
39 |
* @author Alexandre Iline(alexandre.iline@oracle.com)
|
|
40 |
*/
|
|
41 |
public class JTableHeaderDriver extends LightSupportiveDriver implements OrderedListDriver {
|
|
42 |
|
|
43 |
private QueueTool queueTool;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Constructs a JTableHeaderDriver.
|
|
47 |
*/
|
|
48 |
public JTableHeaderDriver() {
|
|
49 |
super(new String[]{"org.netbeans.jemmy.operators.JTableHeaderOperator"});
|
|
50 |
queueTool = new QueueTool();
|
|
51 |
}
|
|
52 |
|
|
53 |
@Override
|
|
54 |
public void selectItem(ComponentOperator oper, int index) {
|
|
55 |
clickOnHeader((JTableHeaderOperator) oper, index);
|
|
56 |
}
|
|
57 |
|
|
58 |
@Override
|
|
59 |
public void selectItems(ComponentOperator oper, int[] indices) {
|
|
60 |
clickOnHeader((JTableHeaderOperator) oper, indices[0]);
|
|
61 |
for (int i = 1; i < indices.length; i++) {
|
|
62 |
clickOnHeader((JTableHeaderOperator) oper, indices[i], InputEvent.CTRL_MASK);
|
|
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
@Override
|
|
67 |
public void moveItem(ComponentOperator oper, int moveColumn, int moveTo) {
|
|
68 |
Point start = ((JTableHeaderOperator) oper).getPointToClick(moveColumn);
|
|
69 |
Point end = ((JTableHeaderOperator) oper).getPointToClick(moveTo);
|
|
70 |
oper.dragNDrop(start.x, start.y, end.x, end.y);
|
|
71 |
}
|
|
72 |
|
|
73 |
/**
|
|
74 |
* Clicks on a column header.
|
|
75 |
*
|
|
76 |
* @param oper an operator to click on.
|
|
77 |
* @param index column index.
|
|
78 |
*/
|
|
79 |
protected void clickOnHeader(JTableHeaderOperator oper, int index) {
|
|
80 |
clickOnHeader(oper, index, 0);
|
|
81 |
}
|
|
82 |
|
|
83 |
/**
|
|
84 |
* Clicks on a column header.
|
|
85 |
*
|
|
86 |
* @param oper an operator to click on.
|
|
87 |
* @param index column index.
|
|
88 |
* @param modifiers a combination of {@code InputEvent.*_MASK} fields.
|
|
89 |
*/
|
|
90 |
protected void clickOnHeader(final JTableHeaderOperator oper, final int index, final int modifiers) {
|
|
91 |
queueTool.invokeSmoothly(new QueueTool.QueueAction<Void>("Column selecting") {
|
|
92 |
@Override
|
|
93 |
public Void launch() {
|
|
94 |
Point toClick = oper.getPointToClick(index);
|
|
95 |
DriverManager.getMouseDriver(oper).
|
|
96 |
clickMouse(oper,
|
|
97 |
toClick.x,
|
|
98 |
toClick.y,
|
|
99 |
1, Operator.getDefaultMouseButton(), modifiers,
|
|
100 |
oper.getTimeouts().create("ComponentOperator.MouseClickTimeout"));
|
|
101 |
return null;
|
|
102 |
}
|
|
103 |
});
|
|
104 |
}
|
|
105 |
}
|