changeset 25:ff728c4de6d0

7902349: Add LookAndFeel utility class in Jemmy Reviewed-by: shurailine Contributed-by: abdul.kolarkunnu@oracle.com
author akolarkunnu
date Tue, 11 Dec 2018 22:07:13 -0800
parents 079c447a1c3e
children 464e600a2b0c
files src/org/netbeans/jemmy/drivers/DefaultDriverInstaller.java src/org/netbeans/jemmy/operators/JFileChooserOperator.java src/org/netbeans/jemmy/operators/JInternalFrameOperator.java src/org/netbeans/jemmy/util/LookAndFeel.java src/org/netbeans/jemmy/version_info test/org/netbeans/jemmy/operators/FileChooserTest.java test/org/netbeans/jemmy/operators/JInternalFrameOperatorTest.java
diffstat 7 files changed, 125 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/netbeans/jemmy/drivers/DefaultDriverInstaller.java	Thu Nov 08 23:09:10 2018 -0800
+++ b/src/org/netbeans/jemmy/drivers/DefaultDriverInstaller.java	Tue Dec 11 22:07:13 2018 -0800
@@ -53,6 +53,7 @@
 import org.netbeans.jemmy.drivers.windows.DefaultInternalFrameDriver;
 import org.netbeans.jemmy.drivers.windows.DefaultWindowDriver;
 import org.netbeans.jemmy.drivers.windows.InternalFramePopupMenuDriver;
+import org.netbeans.jemmy.util.LookAndFeel;
 
 /**
  * Installs all necessary drivers for Jemmy operators except low-level drivers
@@ -122,9 +123,9 @@
                     new ChoiceDriver(),
                     new DefaultFrameDriver(),
                     new DefaultWindowDriver(),
-                    "Motif".equals(UIManager.getLookAndFeel().getID())? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
-                    "Motif".equals(UIManager.getLookAndFeel().getID())? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
-                    "Motif".equals(UIManager.getLookAndFeel().getID())? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
+                    LookAndFeel.isMotif()? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
+                    LookAndFeel.isMotif()? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
+                    LookAndFeel.isMotif()? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
                     new APIFocusDriver(),
                     new MouseFocusDriver(),
                     (shortcutEvents ? new QueueJMenuDriver() : new DefaultJMenuDriver()),
--- a/src/org/netbeans/jemmy/operators/JFileChooserOperator.java	Thu Nov 08 23:09:10 2018 -0800
+++ b/src/org/netbeans/jemmy/operators/JFileChooserOperator.java	Tue Dec 11 22:07:13 2018 -0800
@@ -43,7 +43,6 @@
 import javax.swing.JTextField;
 import javax.swing.JToggleButton;
 import javax.swing.ListModel;
-import javax.swing.UIManager;
 import javax.swing.filechooser.FileFilter;
 import javax.swing.filechooser.FileSystemView;
 import javax.swing.filechooser.FileView;
@@ -60,6 +59,7 @@
 import org.netbeans.jemmy.Timeouts;
 import org.netbeans.jemmy.Waitable;
 import org.netbeans.jemmy.Waiter;
+import org.netbeans.jemmy.util.LookAndFeel;
 
 /**
  *
@@ -344,8 +344,7 @@
         int index = 0;
         // In GTK and Motif L&F, there are two JLists, one is to list folders
         // and second one one is to list files
-        if (UIManager.getLookAndFeel().getID().equals("Motif")
-                || UIManager.getLookAndFeel().getID().equals("GTK")) {
+        if (LookAndFeel.isMotif() || LookAndFeel.isGTK()) {
             index =1;
         }
         return innerSearcher.
@@ -445,7 +444,7 @@
         // In Windows and Windows Classic L&F, there is no 'Go Home' button,
         // but there is a toggle button to go desktop. In Windows platform
         // 'Go Home' button usually navigates to Desktop only.
-        if(UIManager.getLookAndFeel().getID().equals("Windows")) {
+        if(LookAndFeel.isWindows() || LookAndFeel.isWindowsClassic()) {
             homeOper =new JToggleButtonOperator(this, 1);
         } else {
             homeOper = new JButtonOperator(getHomeButton());
--- a/src/org/netbeans/jemmy/operators/JInternalFrameOperator.java	Thu Nov 08 23:09:10 2018 -0800
+++ b/src/org/netbeans/jemmy/operators/JInternalFrameOperator.java	Tue Dec 11 22:07:13 2018 -0800
@@ -57,6 +57,7 @@
 import org.netbeans.jemmy.drivers.InternalFrameDriver;
 import org.netbeans.jemmy.drivers.WindowDriver;
 import org.netbeans.jemmy.util.EmptyVisualizer;
+import org.netbeans.jemmy.util.LookAndFeel;
 import org.netbeans.jemmy.util.Platform;
 
 /**
@@ -1419,7 +1420,7 @@
                         return "JInternalFrameOperator.initOperators.ComponentChooser{description = " + getDescription() + '}';
                     }
                 }) != null) {
-                    if("Motif".equals(UIManager.getLookAndFeel().getID())) {
+                    if(LookAndFeel.isMotif()) {
                         popupButtonOper = new JButtonOperator(titleOperator, 0);
                     } else {
                         minOper = new JButtonOperator(titleOperator,
@@ -1436,7 +1437,7 @@
                     maxOper = null;
                 }
                 if (isClosable()) {
-                    if(!"Motif".equals(UIManager.getLookAndFeel().getID())) {
+                    if(!LookAndFeel.isMotif()) {
                         closeOper = new JButtonOperator(titleOperator,
                             new JComponentByTipFinder(CLOSE_BUTTON_TOOLTIP));
                     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/netbeans/jemmy/util/LookAndFeel.java	Tue Dec 11 22:07:13 2018 -0800
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package org.netbeans.jemmy.util;
+
+import javax.swing.UIManager;
+
+/**
+ * Class to provide look and feel related utility APIs
+ */
+public class LookAndFeel {
+
+    /**
+     * Checking whether the current look and feel is Metal L&F
+     *
+     * @return returns true if current look and feel is Metal L&F,
+     *         otherwise false
+     */
+    public static boolean isMetal() {
+        return isLookAndFeel("Metal");
+    }
+
+    /**
+     * Checking whether the current look and feel is Nimbus L&F
+     *
+     * @return returns true if current look and feel is Nimbus L&F,
+     *         otherwise false
+     */
+    public static boolean isNimbus() {
+        return isLookAndFeel("Nimbus");
+    }
+
+    /**
+     * Checking whether the current look and feel is Motif L&F
+     *
+     * @return returns true if current look and feel is Motif L&F,
+     *         otherwise false
+     */
+    public static boolean isMotif() {
+        return isLookAndFeel("Motif");
+    }
+
+    /**
+     * Checking whether the current look and feel is GTK L&F
+     *
+     * @return returns true if current look and feel is GTK L&F,
+     *         otherwise false
+     */
+    public static boolean isGTK() {
+        return isLookAndFeel("GTK");
+    }
+
+    /**
+     * Checking whether the current look and feel is Aqua L&F
+     *
+     * @return returns true if current look and feel is Aqua L&F,
+     *         otherwise false
+     */
+    public static boolean isAqua() {
+        return isLookAndFeel("Aqua");
+    }
+
+    /**
+     * Checking whether the current look and feel is Windows L&F
+     *
+     * @return returns true if current look and feel is Windows L&F,
+     *         otherwise false
+     */
+    public static boolean isWindows() {
+        return UIManager.getLookAndFeel().getClass().
+                getSimpleName().equals("WindowsLookAndFeel");
+    }
+
+    /**
+     * Checking whether the current look and feel is WindowsClassic L&F
+     *
+     * @return returns true if current look and feel is WindowsClassic L&F,
+     *         otherwise false
+     */
+    public static boolean isWindowsClassic() {
+        return UIManager.getLookAndFeel().getClass().
+                getSimpleName().equals("WindowsClassicLookAndFeel");
+    }
+
+    private static boolean isLookAndFeel(String id) {
+        return UIManager.getLookAndFeel().getID().equals(id);
+    }
+}
--- a/src/org/netbeans/jemmy/version_info	Thu Nov 08 23:09:10 2018 -0800
+++ b/src/org/netbeans/jemmy/version_info	Tue Dec 11 22:07:13 2018 -0800
@@ -1,6 +1,6 @@
 Manifest-version: 1.0
 Main-Class: org.netbeans.jemmy.JemmyProperties
 Jemmy-MajorVersion: 3.0
-Jemmy-MinorVersion: 7.0
+Jemmy-MinorVersion: 8.0
 Jemmy-Build: @BUILD_NUMBER@
 
--- a/test/org/netbeans/jemmy/operators/FileChooserTest.java	Thu Nov 08 23:09:10 2018 -0800
+++ b/test/org/netbeans/jemmy/operators/FileChooserTest.java	Tue Dec 11 22:07:13 2018 -0800
@@ -39,6 +39,7 @@
 import org.netbeans.jemmy.ComponentChooser;
 import org.netbeans.jemmy.LookAndFeelProvider;
 import org.netbeans.jemmy.util.Dumper;
+import org.netbeans.jemmy.util.LookAndFeel;
 import org.testng.ITestResult;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeClass;
@@ -105,9 +106,7 @@
     public void testGoHome(String lookAndFeel) throws Exception {
         // In Aqua, GTK and Motif L&Fs, JFileChooser does not have
         // "Go Home" button.
-        if (!UIManager.getLookAndFeel().getID().equals("Aqua")
-                && !UIManager.getLookAndFeel().getID().equals("Motif")
-                && !UIManager.getLookAndFeel().getID().equals("GTK")) {
+        if (!LookAndFeel.isAqua() && !LookAndFeel.isMotif() && !LookAndFeel.isGTK()) {
             File previousDirectory = fileChooser.getCurrentDirectory();
             fileChooser.goHome();
             fileChooser.waitState(chooser -> fileChooser.getCurrentDirectory().getPath().equals(
--- a/test/org/netbeans/jemmy/operators/JInternalFrameOperatorTest.java	Thu Nov 08 23:09:10 2018 -0800
+++ b/test/org/netbeans/jemmy/operators/JInternalFrameOperatorTest.java	Tue Dec 11 22:07:13 2018 -0800
@@ -41,6 +41,7 @@
 
 import org.netbeans.jemmy.JemmyProperties;
 import org.netbeans.jemmy.LookAndFeelProvider;
+import org.netbeans.jemmy.util.LookAndFeel;
 import org.netbeans.jemmy.util.Platform;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -127,7 +128,7 @@
 
     @Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class)
     public void testTitleButtons(String lookAndFeel) throws Exception {
-        if(!Platform.isOSX() && !"Motif".equals(UIManager.getLookAndFeel().getID())) {
+        if(!Platform.isOSX() && !LookAndFeel.isMotif()) {
             // Close, Maximize, and Minimize buttons are adding along with the
             // construction of internal frame itself
             JInternalFrame interanlFrame1 = new JInternalFrame(