now changes screen resolution when selecting full screen mode

This commit is contained in:
Diego Waxemberg
2013-12-12 22:49:34 -05:00
parent cd6e9615e3
commit 735a2e1a80
2 changed files with 34 additions and 22 deletions
@@ -35,11 +35,12 @@ public class Limelight implements NvConnectionListener {
private void startUp(boolean fullscreen) { private void startUp(boolean fullscreen) {
streamFrame = new StreamFrame(); streamFrame = new StreamFrame();
conn = new NvConnection(host, this); conn = new NvConnection(host, this);
streamFrame.build(conn, fullscreen);
conn.start(PlatformBinding.getDeviceName(), streamFrame, conn.start(PlatformBinding.getDeviceName(), streamFrame,
VideoDecoderRenderer.FLAG_PREFER_QUALITY, VideoDecoderRenderer.FLAG_PREFER_QUALITY,
PlatformBinding.getAudioRenderer(), PlatformBinding.getAudioRenderer(),
PlatformBinding.getVideoDecoderRenderer()); PlatformBinding.getVideoDecoderRenderer());
streamFrame.build(conn, fullscreen);
} }
private void startControllerListener() { private void startControllerListener() {
@@ -121,14 +122,14 @@ public class Limelight implements NvConnectionListener {
// set the name of the application menu item // set the name of the application menu item
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Limelight"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Limelight");
// set the look and feel } else {
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) { } catch (Exception e) {
System.out.println("OH Shit..."); System.out.println("Unable to set cross platform look and feel.");
e.printStackTrace(); e.printStackTrace();
System.exit(1); System.exit(2);
}; }
} }
createFrame(); createFrame();
} }
@@ -5,6 +5,7 @@ import java.awt.Color;
import java.awt.Container; import java.awt.Container;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice; import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.Point; import java.awt.Point;
@@ -27,21 +28,14 @@ import com.limelight.nvstream.NvConnectionListener.Stage;
public class StreamFrame extends JFrame { public class StreamFrame extends JFrame {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int centerX;
private int centerY;
private KeyboardHandler keyboard; private KeyboardHandler keyboard;
private MouseHandler mouse; private MouseHandler mouse;
private JProgressBar spinner; private JProgressBar spinner;
private JLabel spinnerLabel; private JLabel spinnerLabel;
private Cursor noCursor; private Cursor noCursor;
private NvConnection conn; private NvConnection conn;
private static final int WIDTH = 1280;
public StreamFrame() { private static final int HEIGHT = 720;
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;
}
public void freeMouse() { public void freeMouse() {
mouse.free(); mouse.free();
@@ -65,10 +59,11 @@ public class StreamFrame extends JFrame {
this.setFocusTraversalKeysEnabled(false); this.setFocusTraversalKeysEnabled(false);
//This might break if the screen res is too small...not sure though this.setSize(WIDTH, HEIGHT);
this.setLocation(centerX, 0);
this.setBackground(Color.BLACK); this.setBackground(Color.BLACK);
this.getContentPane().setBackground(Color.BLACK);
this.getRootPane().setBackground(Color.BLACK);
if (fullscreen) { if (fullscreen) {
makeFullScreen(); makeFullScreen();
@@ -83,7 +78,23 @@ public class StreamFrame extends JFrame {
if (gd.isFullScreenSupported()) { if (gd.isFullScreenSupported()) {
this.setUndecorated(true); this.setUndecorated(true);
gd.setFullScreenWindow(this); 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 { } else {
JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(
this, this,
@@ -117,6 +128,7 @@ public class StreamFrame extends JFrame {
if (spinner == null) { if (spinner == null) {
Container c = this.getContentPane(); Container c = this.getContentPane();
JPanel panel = new JPanel(); JPanel panel = new JPanel();
panel.setBackground(Color.BLACK);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
spinner = new JProgressBar(); spinner = new JProgressBar();
@@ -157,5 +169,4 @@ public class StreamFrame extends JFrame {
dispose(); dispose();
conn.stop(); conn.stop();
} }
} }