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. Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 package org.netbeans.jemmy.drivers.lists;
26 
27 import javax.swing.UIManager;
28 
29 import org.netbeans.jemmy.QueueTool;
30 import org.netbeans.jemmy.drivers.DriverManager;
31 import org.netbeans.jemmy.drivers.LightSupportiveDriver;
32 import org.netbeans.jemmy.drivers.ListDriver;
33 import org.netbeans.jemmy.operators.ComponentOperator;
34 import org.netbeans.jemmy.operators.JComboBoxOperator;
35 import org.netbeans.jemmy.operators.JListOperator;
36 import org.netbeans.jemmy.util.EmptyVisualizer;
37 
38 /**
39  * List driver for javax.swing.JCompoBox component type.
40  *
41  * @author Alexandre Iline(alexandre.iline@oracle.com)
42  */
43 public class JComboMouseDriver extends LightSupportiveDriver implements ListDriver {
44 
45     /**
46      * Constructs a JComboMouseDriver.
47      */
48     QueueTool queueTool;
49 
JComboMouseDriver()50     public JComboMouseDriver() {
51         super(new String[]{"org.netbeans.jemmy.operators.JComboBoxOperator"});
52         queueTool = new QueueTool();
53     }
54 
55     @Override
selectItem(ComponentOperator oper, int index)56     public void selectItem(ComponentOperator oper, int index) {
57         JComboBoxOperator coper = (JComboBoxOperator) oper;
58         //1.5 workaround
59         if (System.getProperty("java.specification.version").compareTo("1.4") > 0) {
60             queueTool.setOutput(oper.getOutput().createErrorOutput());
61             queueTool.waitEmpty(10);
62             queueTool.waitEmpty(10);
63             queueTool.waitEmpty(10);
64         }
65         //end of 1.5 workaround
66         if (!coper.isPopupVisible()) {
67             if (UIManager.getLookAndFeel().getClass().getName().equals("com.sun.java.swing.plaf.motif.MotifLookAndFeel")) {
68                 oper.clickMouse(oper.getWidth() - 2, oper.getHeight() / 2, 1);
69             } else {
70                 DriverManager.getButtonDriver(coper.getButton()).
71                         push(coper.getButton());
72             }
73         }
74         JListOperator list = new JListOperator(coper.waitList());
75         list.copyEnvironment(coper);
76         list.setVisualizer(new EmptyVisualizer());
77         coper.getTimeouts().sleep("JComboBoxOperator.BeforeSelectingTimeout");
78         DriverManager.getListDriver(list).
79                 selectItem(list, index);
80     }
81 }
82