Java Code Examples for sun.awt.OSInfo#getOSType()

The following examples show how to use sun.awt.OSInfo#getOSType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileDialogForDirectories.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        Sysout.createDialogWithInstructions(new String[]{
                "Press PASS, this test is for MacOS X only."});
        return;
    }

    System.setProperty("apple.awt.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    showBtn = new Button("Show File Dialog");
    showBtn.addActionListener(this);
    add(showBtn);
    String[] instructions = {
            "1) Click on 'Show File Dialog' button. A file dialog will come up.",
            "2) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example 2
Source File: bug6550546.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test is suitable only for Windows, skipped.");

        return;
    }

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            File[] files = (File[]) ShellFolder.get("fileChooserComboBoxFolders");

            for (File file : files) {
                if (file instanceof ShellFolder && ((ShellFolder) file).isLink()) {
                    throw new RuntimeException("Link shouldn't be in FileChooser combobox, " + file.getPath());
                }
            }
        }
    });
}
 
Example 3
Source File: bug7154841.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        return; // Test only for Mac OS X
    }

    try {
        Robot r = new Robot();
        r.setAutoDelay(100);
        r.setAutoWaitForIdle(true);
        r.mouseMove(0, 0);

        SwingUtilities.invokeAndWait(bug7154841::initAndShowUI);

        sleep();

        SwingUtilities.invokeAndWait(() -> {
            popupMenu.show(frame, frame.getX() + frame.getWidth() / 2, frame.getY() + frame.getHeight() / 2);
        });

        sleep();

        int y = (int)screenBounds.get().getY() + (int)screenBounds.get().getHeight() - 10;
        int center = (int)(screenBounds.get().getX() + screenBounds.get().getWidth() / 2);
        for (int x = center - 10 * STEP; x < center + 10 * STEP; x += STEP) {
            r.mouseMove(x, y);
        }

        if (!passed) {
            throw new RuntimeException("Failed: no mouse events on the popup menu");
        }
    } finally {
        SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        });
    }
}
 
Example 4
Source File: bug6416920.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        if(OSInfo.getOSType() != OSInfo.OSType.WINDOWS){
            return;
        }

        bug6416920 test = new bug6416920();
        test.layout.padSelectedTab(SwingConstants.TOP, 0);
        if (test.rects[0].width < 0) {
            throw new RuntimeException("A selected tab isn't painted properly " +
                    "in the scroll tab layout under WindowsLookAndFeel " +
                    "in Windows' \"Windows XP\" theme.");
        }
    }
 
Example 5
Source File: bug4847375.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test is suitable only for Windows OS. Skipped.");

        return;
    }

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            new bug4847375("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

            new bug4847375("javax.swing.plaf.metal.MetalLookAndFeel");
        }
    });
}
 
Example 6
Source File: bug6945316.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test is suitable only for Windows OS. Skipped.");

        return;
    }

    // Init toolkit because it shouldn't be interrupted while initialization
    Toolkit.getDefaultToolkit();

    // Init the sun.awt.shell.Win32ShellFolderManager2.drives field
    ShellFolder.get("fileChooserComboBoxFolders");

    // To get NPE the path must obey the following rules:
    // path.length() == 3 && path.charAt(1) == ':'
    final File tempFile = new File("c:\\");

    for (int i = 0; i < 10000; i++) {
        final CountDownLatch countDownLatch = new CountDownLatch(1);

        final Thread thread = new Thread() {
            public void run() {
                countDownLatch.countDown();

                ShellFolder.isFileSystemRoot(tempFile);
            }
        };

        thread.start();

        countDownLatch.await();

        thread.interrupt();
    }
}
 
Example 7
Source File: bug4847375.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test is suitable only for Windows OS. Skipped.");

        return;
    }

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            new bug4847375("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

            new bug4847375("javax.swing.plaf.metal.MetalLookAndFeel");
        }
    });
}
 
Example 8
Source File: bug4251301.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
        System.out.println("This test is not applicable for MacOS. Passed.");
        return;
    }
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
    toolkit.realSync();
    test.waitTestResult();
}
 
Example 9
Source File: NSImageToMultiResolutionImageTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        String icon = "NSImage://NSApplicationIcon";
        final Image image = Toolkit.getDefaultToolkit().getImage(icon);

        if (!(image instanceof MultiResolutionImage)) {
            throw new RuntimeException("Icon does not have resolution variants!");
        }

        MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

        int width = 0;
        int height = 0;

        for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
            int rvWidth = resolutionVariant.getWidth(null);
            int rvHeight = resolutionVariant.getHeight(null);
            if (rvWidth < width || rvHeight < height) {
                throw new RuntimeException("Resolution variants are not sorted!");
            }
            width = rvWidth;
            height = rvHeight;
        }
    }
 
Example 10
Source File: DeadKeyMacOSXInputText.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Robot robot = new Robot();
        robot.setAutoDelay(50);

        createAndShowGUI();

        // Pressed keys: Alt + E + A
        // Results:  ALT + VK_DEAD_ACUTE + a with accute accent
        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_E);
        robot.keyRelease(KeyEvent.VK_E);
        robot.keyRelease(KeyEvent.VK_ALT);

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        if (state != 3) {
            throw new RuntimeException("Wrong number of key events.");
        }
    }
 
Example 11
Source File: bug6579827.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS ||
            OSInfo.getWindowsVersion() != OSInfo.WINDOWS_VISTA) {
        System.out.println("This test is only for Windows Vista. Skipped.");

        return;
    }

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            } catch (Exception e) {
                e.printStackTrace();

                throw new RuntimeException(e);
            }

            JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, 0);

            Dimension prefferdSize = slider.getPreferredSize();

            slider.setPaintTrack(false);
            slider.putClientProperty("Slider.paintThumbArrowShape", Boolean.TRUE);

            if (prefferdSize.equals(slider.getPreferredSize())) {
                throw new RuntimeException();
            }
        }
    });
}
 
Example 12
Source File: UITest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    OSType os = OSInfo.getOSType();
    LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();

    switch (os) {
        case WINDOWS:

            // Make sure we don't have GTK.
            if (hasLAF("gtk", lafInfo)) {
                throw new RuntimeException("On windows, but GTK is present");
            }

            // Make sure we don't have Aqua.
            if (hasLAF("mac", lafInfo)) {
                throw new RuntimeException("On windows, but Aqua is present");
            }

            // Make sure we have Windows.
            if (!hasLAF("windows", lafInfo)) {
                throw new RuntimeException("On windows and don't have Windows");
            }

            break;

        case MACOSX:

            // Make sure we don't have GTK.
            if (hasLAF("gtk", lafInfo)) {
                throw new RuntimeException("On mac, but GTK is present");
            }

            // Make sure we don't have Windows.
            if (hasLAF("windows", lafInfo)) {
                throw new RuntimeException("On mac, but Windows is present");
            }

            // Make sure we have Aqua.
            if (!hasLAF("mac", lafInfo)) {
                throw new RuntimeException("On mac and don't have Aqua");
            }

            break;

        default:
            // Not windows and mac

            // Make sure we don't have Windows.
            if (hasLAF("windows", lafInfo)) {
                throw new RuntimeException("Not on windows and have Windows");
            }

            // Make sure we don't have Aqua.
            if (hasLAF("mac", lafInfo)) {
                throw new RuntimeException("Not on mac and have Aqua");
            }

            // Make sure we have GTK.
            if (!hasLAF("gtk", lafInfo)) {
                throw new RuntimeException(
                        "Not on Windows and Mac and don't have GTK!");
            }
    }

}
 
Example 13
Source File: UITest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    OSType os = OSInfo.getOSType();
    LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();

    switch (os) {
        case WINDOWS:

            // Make sure we don't have GTK.
            if (hasLAF("gtk", lafInfo)) {
                throw new RuntimeException("On windows, but GTK is present");
            }

            // Make sure we don't have Aqua.
            if (hasLAF("mac", lafInfo)) {
                throw new RuntimeException("On windows, but Aqua is present");
            }

            // Make sure we have Windows.
            if (!hasLAF("windows", lafInfo)) {
                throw new RuntimeException("On windows and don't have Windows");
            }

            break;

        case MACOSX:

            // Make sure we don't have GTK.
            if (hasLAF("gtk", lafInfo)) {
                throw new RuntimeException("On mac, but GTK is present");
            }

            // Make sure we don't have Windows.
            if (hasLAF("windows", lafInfo)) {
                throw new RuntimeException("On mac, but Windows is present");
            }

            // Make sure we have Aqua.
            if (!hasLAF("mac", lafInfo)) {
                throw new RuntimeException("On mac and don't have Aqua");
            }

            break;

        default:
            // Not windows and mac

            // Make sure we don't have Windows.
            if (hasLAF("windows", lafInfo)) {
                throw new RuntimeException("Not on windows and have Windows");
            }

            // Make sure we don't have Aqua.
            if (hasLAF("mac", lafInfo)) {
                throw new RuntimeException("Not on mac and have Aqua");
            }

            // Make sure we have GTK.
            if (!hasLAF("gtk", lafInfo)) {
                throw new RuntimeException(
                        "Not on Windows and Mac and don't have GTK!");
            }
    }

}
 
Example 14
Source File: bug6741890.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test is applicable only for Windows. Skipped.");

        return;
    }

    String tmpDir = System.getProperty("java.io.tmpdir");

    if (tmpDir.length() == 0) { //'java.io.tmpdir' isn't guaranteed to be defined
        tmpDir = System.getProperty("user.home");
    }

    final ShellFolder tmpFile = ShellFolder.getShellFolder(new File(tmpDir));

    System.out.println("Temp directory: " + tmpDir);

    System.out.println("Stress test was run");

    Thread thread = new Thread() {
        public void run() {
            while (!isInterrupted()) {
                ShellFolder.invoke(new Callable<Void>() {
                    public Void call() throws Exception {
                        synchronized (mux) {
                            tmpFile.isFileSystem();
                            tmpFile.isLink();
                        }

                        return null;
                    }
                });
            }
        }
    };

    thread.start();

    for (int i = 0; i < COUNT; i++) {
        synchronized (mux) {
            clearField(tmpFile, "cachedIsLink");
            clearField(tmpFile, "cachedIsFileSystem");
        }

        tmpFile.isFileSystem();
        tmpFile.isLink();
    }

    thread.interrupt();
    thread.join();

    System.out.println("Test passed successfully");
}
 
Example 15
Source File: SubMenuShowTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    menu.setMnemonic('f');
    submenu.setMnemonic('m');
    menu.add(submenu);
    submenu.add(item);
    bar.add(menu);
    frame.setJMenuBar(bar);
    frame.pack();

    item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Sysout.println(e.toString());
                synchronized (activated) {
                    activated.set(true);
                    activated.notifyAll();
                }
            }
        });

    frame.setVisible(true);
    Util.waitForIdle(robot);

    boolean isMacOSX = (OSInfo.getOSType() == OSInfo.OSType.MACOSX);
    if (isMacOSX) {
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.delay(20);
    }
    robot.keyPress(KeyEvent.VK_ALT);
    robot.delay(20);
    robot.keyPress(KeyEvent.VK_F);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_F);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_ALT);
    if (isMacOSX) {
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.delay(20);
    }
    Util.waitForIdle(robot);

    robot.keyPress(KeyEvent.VK_M);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_M);
    Util.waitForIdle(robot);

    robot.keyPress(KeyEvent.VK_SPACE);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_SPACE);
    Util.waitForIdle(robot);

    if (!Util.waitForCondition(activated, 2000)) {
        throw new TestFailedException("a submenu wasn't activated by mnemonic key press");
    }

    Sysout.println("Test passed.");
}
 
Example 16
Source File: FullScreenAfterSplash.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            System.out.println("The test is applicable only to Mac OS X. Passed");
            return;
        }
        try {
            //Move the mouse out, because it could interfere with the test.
            Robot r = new Robot();
            r.mouseMove(0, 0);
            sleep();

            SwingUtilities.invokeAndWait(FullScreenAfterSplash::createAndShowGUI);
            sleep();

            Point fullScreenButtonPos = frame.getLocation();
            fullScreenButtonPos.translate(frame.getWidth() - 10, 10);
            r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);

            //Cant use waitForIdle for full screen transition.
            int waitCount = 0;
            while (!windowEnteringFullScreen) {
                r.mousePress(InputEvent.BUTTON1_MASK);
                r.mouseRelease(InputEvent.BUTTON1_MASK);
                Thread.sleep(100);
                if (waitCount++ > 10) {
                    System.err.println("Can't enter full screen mode. Failed.");
                    System.exit(1);
                }
            }

            waitCount = 0;
            while (!windowEnteredFullScreen) {
                Thread.sleep(100);
                if (waitCount++ > 10) {
                    System.err.println("Can't enter full screen mode. Failed.");
                    System.exit(1);
                }
            }
        } finally {
            if (frame != null) {
                frame.dispose();
            }
        }
    }
 
Example 17
Source File: bug4624207.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            createAndShowGUI();
        }
    });

    toolkit.realSync();

    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            txtField.requestFocus();
        }
    });

    toolkit.realSync();

    if (!focusGained) {
        throw new RuntimeException("Couldn't gain focus for text field");
    }

    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            tab.addChangeListener((ChangeListener) listener);
            txtField.removeFocusListener((FocusListener) listener);
        }
    });

    toolkit.realSync();

    if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
        Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_B);
    } else {
        Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_B);
    }

    toolkit.realSync();

    if (!stateChanged || tab.getSelectedIndex() != 1) {
        throw new RuntimeException("JTabbedPane mnemonics don't work from outside the tabbed pane");
    }
}
 
Example 18
Source File: SubMenuShowTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    menu.setMnemonic('f');
    submenu.setMnemonic('m');
    menu.add(submenu);
    submenu.add(item);
    bar.add(menu);
    frame.setJMenuBar(bar);
    frame.pack();

    item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Sysout.println(e.toString());
                synchronized (activated) {
                    activated.set(true);
                    activated.notifyAll();
                }
            }
        });

    frame.setVisible(true);
    Util.waitForIdle(robot);

    boolean isMacOSX = (OSInfo.getOSType() == OSInfo.OSType.MACOSX);
    if (isMacOSX) {
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.delay(20);
    }
    robot.keyPress(KeyEvent.VK_ALT);
    robot.delay(20);
    robot.keyPress(KeyEvent.VK_F);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_F);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_ALT);
    if (isMacOSX) {
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.delay(20);
    }
    Util.waitForIdle(robot);

    robot.keyPress(KeyEvent.VK_M);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_M);
    Util.waitForIdle(robot);

    robot.keyPress(KeyEvent.VK_SPACE);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_SPACE);
    Util.waitForIdle(robot);

    if (!Util.waitForCondition(activated, 2000)) {
        throw new TestFailedException("a submenu wasn't activated by mnemonic key press");
    }

    Sysout.println("Test passed.");
}
 
Example 19
Source File: UITest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    OSType os = OSInfo.getOSType();
    LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();

    switch (os) {
        case WINDOWS:

            // Make sure we don't have GTK.
            if (hasLAF("gtk", lafInfo)) {
                throw new RuntimeException("On windows, but GTK is present");
            }

            // Make sure we don't have Aqua.
            if (hasLAF("mac", lafInfo)) {
                throw new RuntimeException("On windows, but Aqua is present");
            }

            // Make sure we have Windows.
            if (!hasLAF("windows", lafInfo)) {
                throw new RuntimeException("On windows and don't have Windows");
            }

            break;

        case MACOSX:

            // Make sure we don't have GTK.
            if (hasLAF("gtk", lafInfo)) {
                throw new RuntimeException("On mac, but GTK is present");
            }

            // Make sure we don't have Windows.
            if (hasLAF("windows", lafInfo)) {
                throw new RuntimeException("On mac, but Windows is present");
            }

            // Make sure we have Aqua.
            if (!hasLAF("mac", lafInfo)) {
                throw new RuntimeException("On mac and don't have Aqua");
            }

            break;

        default:
            // Not windows and mac

            // Make sure we don't have Windows.
            if (hasLAF("windows", lafInfo)) {
                throw new RuntimeException("Not on windows and have Windows");
            }

            // Make sure we don't have Aqua.
            if (hasLAF("mac", lafInfo)) {
                throw new RuntimeException("Not on mac and have Aqua");
            }

            // Make sure we have GTK.
            if (!hasLAF("gtk", lafInfo)) {
                throw new RuntimeException(
                        "Not on Windows and Mac and don't have GTK!");
            }
    }

}
 
Example 20
Source File: WindowsLookAndFeel.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean isNativeLookAndFeel() {
    return OSInfo.getOSType() == OSInfo.OSType.WINDOWS;
}