Java Code Examples for sun.misc.ThreadGroupUtils#getRootThreadGroup()

The following examples show how to use sun.misc.ThreadGroupUtils#getRootThreadGroup() . 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: AWTAutoShutdown.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 2
Source File: AWTAutoShutdown.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 3
Source File: AWTAutoShutdown.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 4
Source File: AWTAutoShutdown.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 5
Source File: AWTAutoShutdown.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 6
Source File: AWTAutoShutdown.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 7
Source File: AWTAutoShutdown.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 8
Source File: AWTAutoShutdown.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 9
Source File: AWTAutoShutdown.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 10
Source File: AWTAutoShutdown.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and starts a new blocker thread. Doesn't return until
 * the new blocker thread starts.
 *
 * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
 */
private void activateBlockerThread() {
    Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
    thread.setContextClassLoader(null);
    thread.setDaemon(false);
    blockerThread = thread;
    thread.start();
    try {
        /* Wait for the blocker thread to start. */
        mainLock.wait();
    } catch (InterruptedException e) {
        System.err.println("AWT blocker activation interrupted:");
        e.printStackTrace();
    }
}
 
Example 11
Source File: X11GraphicsDevice.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    setDisplayMode(origDisplayMode);
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}
 
Example 12
Source File: X11GraphicsDevice.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    setDisplayMode(origDisplayMode);
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}
 
Example 13
Source File: X11GraphicsDevice.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    if (isDisplayChangeSupported()) {
                        setDisplayMode(origDisplayMode);
                    }
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}
 
Example 14
Source File: X11GraphicsDevice.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    if (isDisplayChangeSupported()) {
                        setDisplayMode(origDisplayMode);
                    }
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}
 
Example 15
Source File: X11GraphicsDevice.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    if (isDisplayChangeSupported()) {
                        setDisplayMode(origDisplayMode);
                    }
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}
 
Example 16
Source File: X11GraphicsDevice.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    if (isDisplayChangeSupported()) {
                        setDisplayMode(origDisplayMode);
                    }
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}
 
Example 17
Source File: X11GraphicsDevice.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    if (isDisplayChangeSupported()) {
                        setDisplayMode(origDisplayMode);
                    }
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}
 
Example 18
Source File: X11GraphicsDevice.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    if (isDisplayChangeSupported()) {
                        setDisplayMode(origDisplayMode);
                    }
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}
 
Example 19
Source File: X11GraphicsDevice.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    if (isDisplayChangeSupported()) {
                        setDisplayMode(origDisplayMode);
                    }
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}
 
Example 20
Source File: X11GraphicsDevice.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    Window w = getFullScreenWindow();
    if (w == null) {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    if (dm == null ||
        (dm = getMatchingDisplayMode(dm)) == null)
    {
        throw new IllegalArgumentException("Invalid display mode");
    }

    if (!shutdownHookRegistered) {
        // register a shutdown hook so that we return to the
        // original DisplayMode when the VM exits (if the application
        // is already in the original DisplayMode at that time, this
        // hook will have no effect)
        shutdownHookRegistered = true;
        PrivilegedAction<Void> a = () -> {
            ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
            Runnable r = () -> {
                Window old = getFullScreenWindow();
                if (old != null) {
                    exitFullScreenExclusive(old);
                    if (isDisplayChangeSupported()) {
                        setDisplayMode(origDisplayMode);
                    }
                }
            };
            Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
            t.setContextClassLoader(null);
            Runtime.getRuntime().addShutdownHook(t);
            return null;
        };
        AccessController.doPrivileged(a);
    }

    // switch to the new DisplayMode
    configDisplayMode(screen,
                      dm.getWidth(), dm.getHeight(),
                      dm.getRefreshRate());

    // update bounds of the fullscreen window
    w.setBounds(0, 0, dm.getWidth(), dm.getHeight());

    // configDisplayMode() is synchronous, so the display change will be
    // complete by the time we get here (and it is therefore safe to call
    // displayChanged() now)
    ((X11GraphicsEnvironment)
     GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
}