Java Code Examples for java.awt.DisplayMode

The following are top voted examples for showing how to use java.awt.DisplayMode. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jaer   File: MotionViewer.java   View source code 6 votes vote down vote up
int getScreenRefreshRate() {
        int rate = 60;
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] gs = ge.getScreenDevices();
        for (int i = 0; i < gs.length; i++) {
            DisplayMode dm = gs[i].getDisplayMode();
            // Get refresh rate in Hz
            int refreshRate = dm.getRefreshRate();
            if (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) {
//                log.warning("MotionViewer.getScreenRefreshRate: got unknown refresh rate for screen "+i+", assuming 60");
                refreshRate = 60;
            } else {
//                log.info("MotionViewer.getScreenRefreshRate: screen "+i+" has refresh rate "+refreshRate);
            }
            if (i == 0) {
                rate = refreshRate;
            }
        }
        return rate;
    }
 
Example 2
Project: jaer   File: AEViewer.java   View source code 6 votes vote down vote up
int getScreenRefreshRate() {
    int rate = 60;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    if (ge == null) {
        return rate;
    }
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (int i = 0; i < gs.length; i++) {
        DisplayMode dm = gs[i].getDisplayMode();
        // Get refresh rate in Hz
        if (dm == null) {
            return rate;
        }
        int refreshRate = dm.getRefreshRate();
        if (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) {
            log.warning("AEViewer.getScreenRefreshRate: got unknown refresh rate for screen " + i + ", assuming 60");
            refreshRate = 60;
        } else {
            //                log.info("AEViewer.getScreenRefreshRate: screen "+i+" has refresh rate "+refreshRate);
        }
        if (i == 0) {
            rate = refreshRate;
        }
    }
    return rate;
}
 
Example 3
Project: OpenJSharp   File: D3DGraphicsDevice.java   View source code 6 votes vote down vote up
@Override
protected DisplayMode getCurrentDisplayMode(final int screen) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        class Result {
            DisplayMode dm = null;
        };
        final Result res = new Result();
        rq.flushAndInvokeNow(new Runnable() {
            public void run() {
                res.dm = getCurrentDisplayModeNative(screen);
            }
        });
        if (res.dm == null) {
            return super.getCurrentDisplayMode(screen);
        }
        return res.dm;
    } finally {
        rq.unlock();
    }
}
 
Example 4
Project: OpenJSharp   File: Win32GraphicsDevice.java   View source code 6 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    if (dm == null || (dm = getMatchingDisplayMode(dm)) == null) {
        throw new IllegalArgumentException("Invalid display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    Window w = getFullScreenWindow();
    if (w != null) {
        WWindowPeer peer = (WWindowPeer)w.getPeer();
        configDisplayMode(screen, peer, dm.getWidth(), dm.getHeight(),
            dm.getBitDepth(), dm.getRefreshRate());
        // resize the fullscreen window to the dimensions of the new
        // display mode
        Rectangle screenBounds = getDefaultConfiguration().getBounds();
        w.setBounds(screenBounds.x, screenBounds.y,
                    dm.getWidth(), dm.getHeight());
        // Note: no call to replaceSurfaceData is required here since
        // replacement will be caused by an upcoming display change event
    } else {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
}
 
Example 5
Project: OpenJSharp   File: Win32GraphicsDevice.java   View source code 6 votes vote down vote up
protected synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 6
Project: OpenJSharp   File: X11GraphicsDevice.java   View source code 6 votes vote down vote up
private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 7
Project: jdk8u-jdk   File: D3DGraphicsDevice.java   View source code 6 votes vote down vote up
@Override
protected DisplayMode getCurrentDisplayMode(final int screen) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        class Result {
            DisplayMode dm = null;
        };
        final Result res = new Result();
        rq.flushAndInvokeNow(new Runnable() {
            public void run() {
                res.dm = getCurrentDisplayModeNative(screen);
            }
        });
        if (res.dm == null) {
            return super.getCurrentDisplayMode(screen);
        }
        return res.dm;
    } finally {
        rq.unlock();
    }
}
 
Example 8
Project: jdk8u-jdk   File: Win32GraphicsDevice.java   View source code 6 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    if (dm == null || (dm = getMatchingDisplayMode(dm)) == null) {
        throw new IllegalArgumentException("Invalid display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    Window w = getFullScreenWindow();
    if (w != null) {
        WWindowPeer peer = (WWindowPeer)w.getPeer();
        configDisplayMode(screen, peer, dm.getWidth(), dm.getHeight(),
            dm.getBitDepth(), dm.getRefreshRate());
        // resize the fullscreen window to the dimensions of the new
        // display mode
        Rectangle screenBounds = getDefaultConfiguration().getBounds();
        w.setBounds(screenBounds.x, screenBounds.y,
                    dm.getWidth(), dm.getHeight());
        // Note: no call to replaceSurfaceData is required here since
        // replacement will be caused by an upcoming display change event
    } else {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
}
 
Example 9
Project: jdk8u-jdk   File: Win32GraphicsDevice.java   View source code 6 votes vote down vote up
protected synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 10
Project: jdk8u-jdk   File: X11GraphicsDevice.java   View source code 6 votes vote down vote up
private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 11
Project: jdk8u-jdk   File: CheckDisplayModes.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
    if (!graphicDevice.isDisplayChangeSupported()) {
        System.err.println("Display mode change is not supported on this host. Test is considered passed.");
        return;
    }
    DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    checkDisplayMode(defaultDisplayMode);
    graphicDevice.setDisplayMode(defaultDisplayMode);

    DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    boolean isDefaultDisplayModeIncluded = false;
    for (DisplayMode displayMode : displayModes) {
        checkDisplayMode(displayMode);
        graphicDevice.setDisplayMode(displayMode);
        if (defaultDisplayMode.equals(displayMode)) {
            isDefaultDisplayModeIncluded = true;
        }
    }

    if (!isDefaultDisplayModeIncluded) {
        throw new RuntimeException("Default display mode is not included");
    }
}
 
Example 12
Project: jdk8u-jdk   File: DisplayModeChanger.java   View source code 6 votes vote down vote up
/**
 * Finds a display mode that is different from the current display
 * mode and is likely to cause a display change event.
 */
private static DisplayMode findDisplayMode(GraphicsDevice gd) {
    DisplayMode dms[] = gd.getDisplayModes();
    DisplayMode currentDM = gd.getDisplayMode();
    for (DisplayMode dm : dms) {
        if (!dm.equals(currentDM) &&
             dm.getRefreshRate() == currentDM.getRefreshRate())
        {
            // different from the current dm and refresh rate is the same
            // means that something else is different => more likely to
            // cause a DM change event
            return dm;
        }
    }
    return null;
}
 
Example 13
Project: jdk8u-jdk   File: FullScreenInsets.java   View source code 6 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 14
Project: openjdk-jdk10   File: X11GraphicsDevice.java   View source code 6 votes vote down vote up
private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 15
Project: openjdk-jdk10   File: D3DGraphicsDevice.java   View source code 6 votes vote down vote up
@Override
protected DisplayMode getCurrentDisplayMode(final int screen) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        class Result {
            DisplayMode dm = null;
        };
        final Result res = new Result();
        rq.flushAndInvokeNow(new Runnable() {
            public void run() {
                res.dm = getCurrentDisplayModeNative(screen);
            }
        });
        if (res.dm == null) {
            return super.getCurrentDisplayMode(screen);
        }
        return res.dm;
    } finally {
        rq.unlock();
    }
}
 
Example 16
Project: openjdk-jdk10   File: D3DGraphicsDevice.java   View source code 6 votes vote down vote up
@Override
protected void enumDisplayModes(final int screen, final ArrayList<DisplayMode> modes) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        rq.flushAndInvokeNow(new Runnable() {
            public void run() {
                enumDisplayModesNative(screen, modes);
            }
        });
        if (modes.size() == 0) {
            modes.add(getCurrentDisplayModeNative(screen));
        }
    } finally {
        rq.unlock();
    }
}
 
Example 17
Project: openjdk-jdk10   File: Win32GraphicsDevice.java   View source code 6 votes vote down vote up
@Override
public synchronized void setDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        super.setDisplayMode(dm);
        return;
    }
    if (dm == null || (dm = getMatchingDisplayMode(dm)) == null) {
        throw new IllegalArgumentException("Invalid display mode");
    }
    if (getDisplayMode().equals(dm)) {
        return;
    }
    Window w = getFullScreenWindow();
    if (w != null) {
        WWindowPeer peer = AWTAccessor.getComponentAccessor().getPeer(w);
        configDisplayMode(screen, peer, dm.getWidth(), dm.getHeight(),
            dm.getBitDepth(), dm.getRefreshRate());
        // resize the fullscreen window to the dimensions of the new
        // display mode
        Rectangle screenBounds = getDefaultConfiguration().getBounds();
        w.setBounds(screenBounds.x, screenBounds.y,
                    dm.getWidth(), dm.getHeight());
        // Note: no call to replaceSurfaceData is required here since
        // replacement will be caused by an upcoming display change event
    } else {
        throw new IllegalStateException("Must be in fullscreen mode " +
                                        "in order to set display mode");
    }
}
 
Example 18
Project: openjdk-jdk10   File: Win32GraphicsDevice.java   View source code 6 votes vote down vote up
protected synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 19
Project: openjdk-jdk10   File: CheckDisplayModes.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
    if (!graphicDevice.isDisplayChangeSupported()) {
        System.err.println("Display mode change is not supported on this host. Test is considered passed.");
        return;
    }
    DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    checkDisplayMode(defaultDisplayMode);
    graphicDevice.setDisplayMode(defaultDisplayMode);

    DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    boolean isDefaultDisplayModeIncluded = false;
    for (DisplayMode displayMode : displayModes) {
        checkDisplayMode(displayMode);
        graphicDevice.setDisplayMode(displayMode);
        if (defaultDisplayMode.equals(displayMode)) {
            isDefaultDisplayModeIncluded = true;
        }
    }

    if (!isDefaultDisplayModeIncluded) {
        throw new RuntimeException("Default display mode is not included");
    }
}
 
Example 20
Project: openjdk-jdk10   File: DisplayModeChanger.java   View source code 6 votes vote down vote up
/**
 * Finds a display mode that is different from the current display
 * mode and is likely to cause a display change event.
 */
private static DisplayMode findDisplayMode(GraphicsDevice gd) {
    DisplayMode dms[] = gd.getDisplayModes();
    DisplayMode currentDM = gd.getDisplayMode();
    for (DisplayMode dm : dms) {
        if (!dm.equals(currentDM) &&
             dm.getRefreshRate() == currentDM.getRefreshRate())
        {
            // different from the current dm and refresh rate is the same
            // means that something else is different => more likely to
            // cause a DM change event
            return dm;
        }
    }
    return null;
}
 
Example 21
Project: openjdk-jdk10   File: FullScreenInsets.java   View source code 6 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 22
Project: CitizenOfTheStars2D   File: ShowDisplayModes.java   View source code 6 votes vote down vote up
/**
 * Creates new form ShowDisplayModes
 */
public ShowDisplayModes(Frame parent) {
    this.parent = parent;
    initComponents();
    jToggleButton1.setSelected(doFullScreen);
    
    GraphicsEnvironment environment = 
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    
    possibleModes = environment.getDefaultScreenDevice().getDisplayModes();
   
    for (DisplayMode mode : possibleModes){
        jComboBox1.addItem(
                mode.getWidth()+ " x; "+mode.getHeight()+" y; "
                        +mode.getBitDepth() +" Bit; "+ mode.getRefreshRate()+" Hz");
    }
}
 
Example 23
Project: openjdk9   File: X11GraphicsDevice.java   View source code 6 votes vote down vote up
private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 24
Project: openjdk9   File: D3DGraphicsDevice.java   View source code 6 votes vote down vote up
@Override
protected DisplayMode getCurrentDisplayMode(final int screen) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        class Result {
            DisplayMode dm = null;
        };
        final Result res = new Result();
        rq.flushAndInvokeNow(new Runnable() {
            public void run() {
                res.dm = getCurrentDisplayModeNative(screen);
            }
        });
        if (res.dm == null) {
            return super.getCurrentDisplayMode(screen);
        }
        return res.dm;
    } finally {
        rq.unlock();
    }
}
 
Example 25
Project: openjdk9   File: D3DGraphicsDevice.java   View source code 6 votes vote down vote up
@Override
protected void enumDisplayModes(final int screen, final ArrayList<DisplayMode> modes) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        rq.flushAndInvokeNow(new Runnable() {
            public void run() {
                enumDisplayModesNative(screen, modes);
            }
        });
        if (modes.size() == 0) {
            modes.add(getCurrentDisplayModeNative(screen));
        }
    } finally {
        rq.unlock();
    }
}
 
Example 26
Project: openjdk9   File: Win32GraphicsDevice.java   View source code 6 votes vote down vote up
protected synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 27
Project: openjdk9   File: CheckDisplayModes.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
    if (!graphicDevice.isDisplayChangeSupported()) {
        System.err.println("Display mode change is not supported on this host. Test is considered passed.");
        return;
    }
    DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    checkDisplayMode(defaultDisplayMode);
    graphicDevice.setDisplayMode(defaultDisplayMode);

    DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    boolean isDefaultDisplayModeIncluded = false;
    for (DisplayMode displayMode : displayModes) {
        checkDisplayMode(displayMode);
        graphicDevice.setDisplayMode(displayMode);
        if (defaultDisplayMode.equals(displayMode)) {
            isDefaultDisplayModeIncluded = true;
        }
    }

    if (!isDefaultDisplayModeIncluded) {
        throw new RuntimeException("Default display mode is not included");
    }
}
 
Example 28
Project: openjdk9   File: DisplayModeChanger.java   View source code 6 votes vote down vote up
/**
 * Finds a display mode that is different from the current display
 * mode and is likely to cause a display change event.
 */
private static DisplayMode findDisplayMode(GraphicsDevice gd) {
    DisplayMode dms[] = gd.getDisplayModes();
    DisplayMode currentDM = gd.getDisplayMode();
    for (DisplayMode dm : dms) {
        if (!dm.equals(currentDM) &&
             dm.getRefreshRate() == currentDM.getRefreshRate())
        {
            // different from the current dm and refresh rate is the same
            // means that something else is different => more likely to
            // cause a DM change event
            return dm;
        }
    }
    return null;
}
 
Example 29
Project: workcraft   File: MainWindow.java   View source code 6 votes vote down vote up
public void loadWindowGeometryFromConfig() {
    final Framework framework = Framework.getInstance();
    String maximisedStr = framework.getConfigVar(CONFIG_GUI_MAIN_MAXIMISED, false);
    String widthStr = framework.getConfigVar(CONFIG_GUI_MAIN_WIDTH, false);
    String heightStr = framework.getConfigVar(CONFIG_GUI_MAIN_HEIGHT, false);

    boolean maximised = (maximisedStr == null) ? true : Boolean.parseBoolean(maximisedStr);
    setExtendedState(maximised ? JFrame.MAXIMIZED_BOTH : JFrame.NORMAL);

    DisplayMode mode = getDisplayMode();
    Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(getGraphicsConfiguration());
    int width = mode.getWidth() - insets.right - insets.left;
    int height = mode.getHeight() - insets.top - insets.bottom;
    if ((widthStr != null) && (heightStr != null)) {
        width = Integer.parseInt(widthStr);
        if (width < MIN_WIDTH) {
            width = MIN_WIDTH;
        }
        height = Integer.parseInt(heightStr);
        if (height < MIN_HEIGHT) {
            height = MIN_HEIGHT;
        }
    }
    setSize(width, height);
}
 
Example 30
Project: JavaGraphicsEngine   File: Device.java   View source code 6 votes vote down vote up
private void init(int deviceID) throws Exception {
	if (deviceID < -1)
		throw new Exception("Unknown Device Handle");
	ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	if (deviceID != -1) {
		screen = ge.getScreenDevices()[deviceID];
	}
	else {
		screen = ge.getDefaultScreenDevice();
	}
	
	DisplayMode mode = screen.getDisplayMode();
	refreshRate = mode.getRefreshRate();
	bitDepth = mode.getBitDepth();
	colors = (int) Math.pow(2, bitDepth);
	dimensions = new Vector2(mode.getWidth(), mode.getHeight());
}
 
Example 31
Project: PhET   File: PFrame.java   View source code 6 votes vote down vote up
/**
 * Finds the best display mode the graphics device supports. Based on the
 * preferred modes.
 * 
 * @param device the device being inspected
 * 
 * @return best display mode the given device supports
 */
protected DisplayMode getBestDisplayMode(final GraphicsDevice device) {
    final Iterator itr = getPreferredDisplayModes(device).iterator();
    while (itr.hasNext()) {
        final DisplayMode each = (DisplayMode) itr.next();
        final DisplayMode[] modes = device.getDisplayModes();
        for (int i = 0; i < modes.length; i++) {
            if (modes[i].getWidth() == each.getWidth() && modes[i].getHeight() == each.getHeight()
                    && modes[i].getBitDepth() == each.getBitDepth()) {
                return each;
            }
        }
    }

    return null;
}
 
Example 32
Project: PhET   File: SettingsDialog.java   View source code 6 votes vote down vote up
/**
 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
 */
public int compare(DisplayMode a, DisplayMode b) {
    // Width
    if (a.getWidth() != b.getWidth()) {
        return (a.getWidth() > b.getWidth()) ? 1 : -1;
    }
    // Height
    if (a.getHeight() != b.getHeight()) {
        return (a.getHeight() > b.getHeight()) ? 1 : -1;
    }
    // Bit depth
    if (a.getBitDepth() != b.getBitDepth()) {
        return (a.getBitDepth() > b.getBitDepth()) ? 1 : -1;
    }
    // Refresh rate
    if (a.getRefreshRate() != b.getRefreshRate()) {
        return (a.getRefreshRate() > b.getRefreshRate()) ? 1 : -1;
    }
    // All fields are equal
    return 0;
}
 
Example 33
Project: jdk8u_jdk   File: D3DGraphicsDevice.java   View source code 6 votes vote down vote up
@Override
protected DisplayMode getCurrentDisplayMode(final int screen) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        class Result {
            DisplayMode dm = null;
        };
        final Result res = new Result();
        rq.flushAndInvokeNow(new Runnable() {
            public void run() {
                res.dm = getCurrentDisplayModeNative(screen);
            }
        });
        if (res.dm == null) {
            return super.getCurrentDisplayMode(screen);
        }
        return res.dm;
    } finally {
        rq.unlock();
    }
}
 
Example 34
Project: exterminate   File: ExterminateGame.java   View source code 6 votes vote down vote up
public static void updateFullscreen() {
	if(!ExterminateGame.fullscree) {

		Gdx.graphics.setDisplayMode(1280, 720, false);
	
	}
	else {
		// move the window to the right screen
		GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice primary = env.getDefaultScreenDevice();

		DisplayMode pmode = primary.getDisplayMode();
	
		Gdx.graphics.setDisplayMode(pmode.getWidth(), pmode.getHeight(), ExterminateGame.fullscree);
		
	}
}
 
Example 35
Project: jdk8u_jdk   File: X11GraphicsDevice.java   View source code 6 votes vote down vote up
private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 36
Project: jdk8u_jdk   File: CheckDisplayModes.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
    if (!graphicDevice.isDisplayChangeSupported()) {
        System.err.println("Display mode change is not supported on this host. Test is considered passed.");
        return;
    }
    DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    checkDisplayMode(defaultDisplayMode);
    graphicDevice.setDisplayMode(defaultDisplayMode);

    DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    boolean isDefaultDisplayModeIncluded = false;
    for (DisplayMode displayMode : displayModes) {
        checkDisplayMode(displayMode);
        graphicDevice.setDisplayMode(displayMode);
        if (defaultDisplayMode.equals(displayMode)) {
            isDefaultDisplayModeIncluded = true;
        }
    }

    if (!isDefaultDisplayModeIncluded) {
        throw new RuntimeException("Default display mode is not included");
    }
}
 
Example 37
Project: jdk8u_jdk   File: DisplayModeChanger.java   View source code 6 votes vote down vote up
/**
 * Finds a display mode that is different from the current display
 * mode and is likely to cause a display change event.
 */
private static DisplayMode findDisplayMode(GraphicsDevice gd) {
    DisplayMode dms[] = gd.getDisplayModes();
    DisplayMode currentDM = gd.getDisplayMode();
    for (DisplayMode dm : dms) {
        if (!dm.equals(currentDM) &&
             dm.getRefreshRate() == currentDM.getRefreshRate())
        {
            // different from the current dm and refresh rate is the same
            // means that something else is different => more likely to
            // cause a DM change event
            return dm;
        }
    }
    return null;
}
 
Example 38
Project: lookaside_java-1.8.0-openjdk   File: D3DGraphicsDevice.java   View source code 6 votes vote down vote up
@Override
protected DisplayMode getCurrentDisplayMode(final int screen) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        class Result {
            DisplayMode dm = null;
        };
        final Result res = new Result();
        rq.flushAndInvokeNow(new Runnable() {
            public void run() {
                res.dm = getCurrentDisplayModeNative(screen);
            }
        });
        if (res.dm == null) {
            return super.getCurrentDisplayMode(screen);
        }
        return res.dm;
    } finally {
        rq.unlock();
    }
}
 
Example 39
Project: lookaside_java-1.8.0-openjdk   File: Win32GraphicsDevice.java   View source code 6 votes vote down vote up
protected synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
    if (!isDisplayChangeSupported()) {
        return null;
    }
    DisplayMode[] modes = getDisplayModes();
    for (DisplayMode mode : modes) {
        if (dm.equals(mode) ||
            (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
             dm.getWidth() == mode.getWidth() &&
             dm.getHeight() == mode.getHeight() &&
             dm.getBitDepth() == mode.getBitDepth()))
        {
            return mode;
        }
    }
    return null;
}
 
Example 40
Project: javify   File: GdkScreenGraphicsDevice.java   View source code 6 votes vote down vote up
public DisplayMode[] getDisplayModes()
{
  if (fixedDisplayMode != null)
    return new DisplayMode[] { fixedDisplayMode };

  synchronized (this)
    {
      if (displayModes == null)
        displayModes = nativeGetDisplayModes(env);
    }

  ArrayList<DisplayMode> list = new ArrayList<DisplayMode>();
  for(int i=0;i<displayModes.length;i++)
    for(int j=0;j<displayModes[i].rates.length;j++)
      list.add(new DisplayMode(displayModes[i].width,
                               displayModes[i].height,
                               DisplayMode.BIT_DEPTH_MULTI,
                               displayModes[i].rates[j]));

  return list.toArray(new DisplayMode[list.size()]);
}