1 /*
   2  * Copyright (c) 1997, 2018, 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;
  26 
  27 import org.netbeans.jemmy.ClassReference;
  28 import org.netbeans.jemmy.JemmyException;
  29 import org.netbeans.jemmy.JemmyProperties;
  30 import org.netbeans.jemmy.drivers.buttons.ButtonMouseDriver;
  31 import org.netbeans.jemmy.drivers.focus.APIFocusDriver;
  32 import org.netbeans.jemmy.drivers.focus.MouseFocusDriver;
  33 import org.netbeans.jemmy.drivers.lists.ChoiceDriver;
  34 import org.netbeans.jemmy.drivers.lists.JComboMouseDriver;
  35 import org.netbeans.jemmy.drivers.lists.JListMouseDriver;
  36 import org.netbeans.jemmy.drivers.lists.JTabMouseDriver;
  37 import org.netbeans.jemmy.drivers.lists.JTableHeaderDriver;
  38 import org.netbeans.jemmy.drivers.lists.ListKeyboardDriver;
  39 import org.netbeans.jemmy.drivers.menus.DefaultJMenuDriver;
  40 import org.netbeans.jemmy.drivers.menus.QueueJMenuDriver;
  41 import org.netbeans.jemmy.drivers.scrolling.JScrollBarDriver;
  42 import org.netbeans.jemmy.drivers.scrolling.JSliderDriver;
  43 import org.netbeans.jemmy.drivers.scrolling.JSplitPaneDriver;
  44 import org.netbeans.jemmy.drivers.scrolling.ScrollPaneDriver;
  45 import org.netbeans.jemmy.drivers.scrolling.ScrollbarDriver;
  46 import org.netbeans.jemmy.drivers.tables.JTableMouseDriver;
  47 import org.netbeans.jemmy.drivers.text.AWTTextKeyboardDriver;
  48 import org.netbeans.jemmy.drivers.text.SwingTextKeyboardDriver;
  49 import org.netbeans.jemmy.drivers.trees.JTreeMouseDriver;
  50 import org.netbeans.jemmy.drivers.windows.DefaultFrameDriver;
  51 import org.netbeans.jemmy.drivers.windows.DefaultInternalFrameDriver;
  52 import org.netbeans.jemmy.drivers.windows.DefaultWindowDriver;
  53 import org.netbeans.jemmy.drivers.windows.InternalFramePopupMenuDriver;
  54 import org.netbeans.jemmy.util.LookAndFeel;
  55 
  56 /**
  57  * Installs all necessary drivers for Jemmy operators except low-level drivers
  58  * which are installed by
  59  * <a href="InputDriverInstaller.java">InputDriverInstaller</a>.
  60  *
  61  * @author Alexandre Iline(alexandre.iline@oracle.com)
  62  */
  63 public class DefaultDriverInstaller extends ArrayDriverInstaller {
  64 
  65     /**
  66      * Constructs a DefaultDriverInstaller object.
  67      *
  68      * @param shortcutEvents Signals whether shortcut mode is used.
  69      */
  70     public DefaultDriverInstaller(boolean shortcutEvents) {
  71         super(new String[]{
  72             DriverManager.LIST_DRIVER_ID,
  73             DriverManager.MULTISELLIST_DRIVER_ID,
  74             DriverManager.TREE_DRIVER_ID,
  75             DriverManager.TEXT_DRIVER_ID,
  76             DriverManager.TEXT_DRIVER_ID,
  77             DriverManager.SCROLL_DRIVER_ID,
  78             DriverManager.SCROLL_DRIVER_ID,
  79             DriverManager.SCROLL_DRIVER_ID,
  80             DriverManager.SCROLL_DRIVER_ID,
  81             DriverManager.SCROLL_DRIVER_ID,
  82             DriverManager.SCROLL_DRIVER_ID,
  83             DriverManager.BUTTON_DRIVER_ID,
  84             DriverManager.LIST_DRIVER_ID,
  85             DriverManager.LIST_DRIVER_ID,
  86             DriverManager.MULTISELLIST_DRIVER_ID,
  87             DriverManager.LIST_DRIVER_ID,
  88             DriverManager.LIST_DRIVER_ID,
  89             DriverManager.MULTISELLIST_DRIVER_ID,
  90             DriverManager.TABLE_DRIVER_ID,
  91             DriverManager.LIST_DRIVER_ID,
  92             DriverManager.FRAME_DRIVER_ID,
  93             DriverManager.WINDOW_DRIVER_ID,
  94             DriverManager.FRAME_DRIVER_ID,
  95             DriverManager.INTERNAL_FRAME_DRIVER_ID,
  96             DriverManager.WINDOW_DRIVER_ID,
  97             DriverManager.FOCUS_DRIVER_ID,
  98             DriverManager.FOCUS_DRIVER_ID,
  99             DriverManager.MENU_DRIVER_ID,
 100             DriverManager.ORDEREDLIST_DRIVER_ID},
 101                 new Object[]{
 102                     new JTreeMouseDriver(),
 103                     new JTreeMouseDriver(),
 104                     new JTreeMouseDriver(),
 105                     new AWTTextKeyboardDriver(),
 106                     new SwingTextKeyboardDriver(),
 107                     new ScrollbarDriver(),
 108                     new ScrollPaneDriver(),
 109                     new JScrollBarDriver(),
 110                     new JSplitPaneDriver(),
 111                     new JSliderDriver(),
 112                     createSpinnerDriver(),
 113                     new ButtonMouseDriver(),
 114                     new JTabMouseDriver(),
 115                     new ListKeyboardDriver(),
 116                     new ListKeyboardDriver(),
 117                     new JComboMouseDriver(),
 118                     new JListMouseDriver(),
 119                     new JListMouseDriver(),
 120                     new JTableMouseDriver(),
 121                     new ChoiceDriver(),
 122                     new DefaultFrameDriver(),
 123                     new DefaultWindowDriver(),
 124                     LookAndFeel.isMotif()? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
 125                     LookAndFeel.isMotif()? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
 126                     LookAndFeel.isMotif()? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
 127                     new APIFocusDriver(),
 128                     new MouseFocusDriver(),
 129                     (shortcutEvents ? new QueueJMenuDriver() : new DefaultJMenuDriver()),
 130                     new JTableHeaderDriver()});
 131     }
 132 
 133     /**
 134      * Constructs a DefaultDriverInstaller object with shortcut mode flag taken
 135      * from {@code JemmyProperties}.
 136      */
 137     public DefaultDriverInstaller() {
 138         this((JemmyProperties.getCurrentDispatchingModel()
 139                 & JemmyProperties.SHORTCUT_MODEL_MASK) != 0);
 140     }
 141 
 142     private static LightDriver createSpinnerDriver() {
 143         if (System.getProperty("java.specification.version").compareTo("1.3") > 0) {
 144             try {
 145                 return ((LightDriver) new ClassReference("org.netbeans.jemmy.drivers.scrolling.JSpinnerDriver").
 146                         newInstance(null, null));
 147             } catch (ClassNotFoundException e) {
 148                 JemmyProperties.getCurrentOutput().
 149                         printErrLine("ATTENTION! you are using Jemmy built by Java earlier then 1.4, under "
 150                                 + "Java 1.4. \nImpossible to create JSpinnerDriver");
 151                 return createEmptyDriver();
 152             } catch (Exception e) {
 153                 throw (new JemmyException("Impossible to create JSpinnerDriver although java version is "
 154                         + System.getProperty("java.version"),
 155                         e));
 156             }
 157         } else {
 158             return createEmptyDriver();
 159         }
 160     }
 161 
 162     private static LightDriver createEmptyDriver() {
 163         return (new LightDriver() {
 164             @Override
 165             public String[] getSupported() {
 166                 return new String[]{Object.class.getName()};
 167             }
 168         });
 169     }
 170 }