1 /* 2 * Copyright (c) 2019, 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 */ 23 24 /* 25 * @test 26 * @bug 8226783 27 * @key headful 28 * @summary Verify System L&F 29 */ 30 31 /* 32 * Verify the System LAF is what we expect based on platform and, 33 * in at least one case, the desktop environment. 34 * Since changes to the system LAF are a once in a blue moon event, 35 * this test is useful to tell us of unexpected problems. 36 * Note: this test must be run in a headful environment 37 * since otherwise a system LAF may not be available. 38 */ 39 40 public class SystemLookAndFeelTest { 41 42 public static void main(String[] args) { 43 44 String laf = javax.swing.UIManager.getSystemLookAndFeelClassName(); 45 String os = System.getProperty("os.name").toLowerCase(); 46 System.out.println("OS is " + os); 47 System.out.println("Reported System LAF is " + laf); 48 49 String expLAF = null; 50 if (os.contains("windows")) { 51 expLAF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; 52 } else if (os.contains("macos")) { 53 expLAF = "com.apple.laf.AquaLookAndFeel"; 54 } else if (os.contains("linux") || os.contains("sunos")) { 55 /* 56 * The implementation keys off the following desktop setting to 57 * decide if GTK is an appropriate system L&F. 58 * In its absence, there probably isn't support for the GTK L&F 59 * anyway. It does not tell us if the GTK libraries are available 60 * but they really should be if this is a gnome session. 61 * If it proves necessary the test can perhaps be updated to see 62 * if the GTK LAF is listed as installed and can be instantiated. 63 */ 64 String gnome = System.getenv("GNOME_DESKTOP_SESSION_ID"); 65 System.out.println("Gnome desktop session ID is " + gnome); 66 if (gnome != null) { 67 expLAF = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; 68 } else if (os.contains("linux")) { 69 expLAF = "javax.swing.plaf.metal.MetalLookAndFeel"; 70 } else if (os.contains("sunos")) { 71 expLAF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; 72 } 73 } 74 System.out.println("Expected System LAF is " + expLAF); 75 if (expLAF == null) { 76 System.out.println("No match for expected LAF, unknown OS ?"); 77 return; 78 } 79 if (!(laf.equals(expLAF))) { 80 throw new RuntimeException("LAF not as expected"); 81 } 82 } 83 }