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