attempted to fix fullscreen issues on other OS’s

This commit is contained in:
Diego Waxemberg
2013-12-12 18:42:40 -05:00
parent 600a21e66a
commit af3369ec5c

View File

@@ -5,7 +5,6 @@ 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.Frame;
import java.awt.GraphicsDevice; import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.Point; import java.awt.Point;
@@ -16,6 +15,7 @@ import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JProgressBar; import javax.swing.JProgressBar;
@@ -26,14 +26,23 @@ 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 NvConnection conn; 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;
}
public void build(NvConnection conn, boolean fullscreen) { public void build(NvConnection conn, boolean fullscreen) {
this.conn = conn; this.conn = conn;
@@ -46,30 +55,31 @@ public class StreamFrame extends JFrame {
this.setFocusTraversalKeysEnabled(false); this.setFocusTraversalKeysEnabled(false);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(1280,720);
//This might break if the screen res is too small...not sure though //This might break if the screen res is too small...not sure though
this.setLocation(dim.width/2-this.getSize().width/2, 0); this.setLocation(centerX, 0);
this.setUndecorated(true);
this.setBackground(Color.BLACK); this.setBackground(Color.BLACK);
if (fullscreen) { if (fullscreen) {
makeFullScreen(); makeFullScreen();
this.setLocation(getLocation().x, dim.height/2-this.getSize().height/2);
} }
hideCursor(); hideCursor();
this.setVisible(true); this.setVisible(true);
} }
private void makeFullScreen() { private void makeFullScreen() {
this.setExtendedState(Frame.MAXIMIZED_BOTH);
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (gd.isFullScreenSupported()) { if (gd.isFullScreenSupported()) {
this.setUndecorated(true);
gd.setFullScreenWindow(this); gd.setFullScreenWindow(this);
this.setLocation(centerX, centerY);
} else {
JOptionPane.showMessageDialog(
this,
"Your operating system does not support fullscreen.",
"Fullscreen Unsupported",
JOptionPane.ERROR_MESSAGE);
} }
} }