From 735a2e1a80b2fd99ed62d14118a4c9be92c1b5b7 Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Thu, 12 Dec 2013 22:49:34 -0500 Subject: [PATCH] now changes screen resolution when selecting full screen mode --- limelight-pc/src/com/limelight/Limelight.java | 13 +++--- .../src/com/limelight/gui/StreamFrame.java | 43 ++++++++++++------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/limelight-pc/src/com/limelight/Limelight.java b/limelight-pc/src/com/limelight/Limelight.java index 5774e73..06641eb 100644 --- a/limelight-pc/src/com/limelight/Limelight.java +++ b/limelight-pc/src/com/limelight/Limelight.java @@ -35,11 +35,12 @@ public class Limelight implements NvConnectionListener { private void startUp(boolean fullscreen) { streamFrame = new StreamFrame(); conn = new NvConnection(host, this); + streamFrame.build(conn, fullscreen); conn.start(PlatformBinding.getDeviceName(), streamFrame, VideoDecoderRenderer.FLAG_PREFER_QUALITY, PlatformBinding.getAudioRenderer(), PlatformBinding.getVideoDecoderRenderer()); - streamFrame.build(conn, fullscreen); + } private void startControllerListener() { @@ -121,14 +122,14 @@ public class Limelight implements NvConnectionListener { // set the name of the application menu item System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Limelight"); - // set the look and feel + } else { try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { - System.out.println("OH Shit..."); + System.out.println("Unable to set cross platform look and feel."); e.printStackTrace(); - System.exit(1); - }; + System.exit(2); + } } createFrame(); } diff --git a/limelight-pc/src/com/limelight/gui/StreamFrame.java b/limelight-pc/src/com/limelight/gui/StreamFrame.java index 50d12fb..3a0c33f 100644 --- a/limelight-pc/src/com/limelight/gui/StreamFrame.java +++ b/limelight-pc/src/com/limelight/gui/StreamFrame.java @@ -5,6 +5,7 @@ import java.awt.Color; import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; +import java.awt.DisplayMode; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Point; @@ -27,22 +28,15 @@ import com.limelight.nvstream.NvConnectionListener.Stage; public class StreamFrame extends JFrame { private static final long serialVersionUID = 1L; - private int centerX; - private int centerY; private KeyboardHandler keyboard; private MouseHandler mouse; private JProgressBar spinner; private JLabel spinnerLabel; private Cursor noCursor; private NvConnection conn; - - public StreamFrame() { - Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setSize(1280,720); - centerX = dim.width/2-this.getSize().width/2; - centerY = dim.height/2-this.getSize().height/2; - } - + private static final int WIDTH = 1280; + private static final int HEIGHT = 720; + public void freeMouse() { mouse.free(); showCursor(); @@ -65,11 +59,12 @@ public class StreamFrame extends JFrame { this.setFocusTraversalKeysEnabled(false); - //This might break if the screen res is too small...not sure though - this.setLocation(centerX, 0); - + this.setSize(WIDTH, HEIGHT); + this.setBackground(Color.BLACK); - + this.getContentPane().setBackground(Color.BLACK); + this.getRootPane().setBackground(Color.BLACK); + if (fullscreen) { makeFullScreen(); } @@ -83,7 +78,23 @@ public class StreamFrame extends JFrame { if (gd.isFullScreenSupported()) { this.setUndecorated(true); gd.setFullScreenWindow(this); - this.setLocation(centerX, centerY); + + if (gd.isDisplayChangeSupported()) { + DisplayMode[] configs = gd.getDisplayModes(); + for (DisplayMode config : configs) { + if (config.getWidth() == 1280 && config.getHeight() == 720 || + config.getWidth() == 1280 && config.getHeight() == 800) { + gd.setDisplayMode(config); + break; + } + } + } else { + JOptionPane.showMessageDialog( + this, + "Unable to change display resolution. \nThis may not be the correct resolution", + "Display Resolution", + JOptionPane.INFORMATION_MESSAGE); + } } else { JOptionPane.showMessageDialog( this, @@ -117,6 +128,7 @@ public class StreamFrame extends JFrame { if (spinner == null) { Container c = this.getContentPane(); JPanel panel = new JPanel(); + panel.setBackground(Color.BLACK); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); spinner = new JProgressBar(); @@ -157,5 +169,4 @@ public class StreamFrame extends JFrame { dispose(); conn.stop(); } - }