JComboMouseDriver.java revision 13978:1993af50385d
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 */
23package org.netbeans.jemmy.drivers.lists;
24
25import javax.swing.UIManager;
26
27import org.netbeans.jemmy.QueueTool;
28import org.netbeans.jemmy.drivers.DriverManager;
29import org.netbeans.jemmy.drivers.LightSupportiveDriver;
30import org.netbeans.jemmy.drivers.ListDriver;
31import org.netbeans.jemmy.operators.ComponentOperator;
32import org.netbeans.jemmy.operators.JComboBoxOperator;
33import org.netbeans.jemmy.operators.JListOperator;
34import org.netbeans.jemmy.util.EmptyVisualizer;
35
36/**
37 * List driver for javax.swing.JCompoBox component type.
38 *
39 * @author Alexandre Iline(alexandre.iline@oracle.com)
40 */
41public class JComboMouseDriver extends LightSupportiveDriver implements ListDriver {
42
43    /**
44     * Constructs a JComboMouseDriver.
45     */
46    QueueTool queueTool;
47
48    public JComboMouseDriver() {
49        super(new String[]{"org.netbeans.jemmy.operators.JComboBoxOperator"});
50        queueTool = new QueueTool();
51    }
52
53    @Override
54    public void selectItem(ComponentOperator oper, int index) {
55        JComboBoxOperator coper = (JComboBoxOperator) oper;
56        //1.5 workaround
57        if (System.getProperty("java.specification.version").compareTo("1.4") > 0) {
58            queueTool.setOutput(oper.getOutput().createErrorOutput());
59            queueTool.waitEmpty(10);
60            queueTool.waitEmpty(10);
61            queueTool.waitEmpty(10);
62        }
63        //end of 1.5 workaround
64        if (!coper.isPopupVisible()) {
65            if (UIManager.getLookAndFeel().getClass().getName().equals("com.sun.java.swing.plaf.motif.MotifLookAndFeel")) {
66                oper.clickMouse(oper.getWidth() - 2, oper.getHeight() / 2, 1);
67            } else {
68                DriverManager.getButtonDriver(coper.getButton()).
69                        push(coper.getButton());
70            }
71        }
72        JListOperator list = new JListOperator(coper.waitList());
73        list.copyEnvironment(coper);
74        list.setVisualizer(new EmptyVisualizer());
75        coper.getTimeouts().sleep("JComboBoxOperator.BeforeSelectingTimeout");
76        DriverManager.getListDriver(list).
77                selectItem(list, index);
78    }
79}
80