mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-16 05:40:56 +00:00
move everything out of subdirectory
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
package com.limelight.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import com.limelight.Limelight;
|
||||
import com.limelight.binding.PlatformBinding;
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.nvstream.http.NvHTTP;
|
||||
|
||||
public class MainFrame {
|
||||
private JTextField hostField;
|
||||
private JButton pair;
|
||||
private JButton stream;
|
||||
private JCheckBox fullscreen;
|
||||
private JFrame limeFrame;
|
||||
|
||||
public JFrame getLimeFrame() {
|
||||
return limeFrame;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
limeFrame = new JFrame("Limelight");
|
||||
limeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Container mainPane = limeFrame.getContentPane();
|
||||
|
||||
mainPane.setLayout(new BorderLayout());
|
||||
|
||||
JPanel centerPane = new JPanel();
|
||||
centerPane.setLayout(new BoxLayout(centerPane, BoxLayout.Y_AXIS));
|
||||
|
||||
hostField = new JTextField();
|
||||
hostField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 24));
|
||||
hostField.setToolTipText("Enter host name or IP address");
|
||||
hostField.setText("GeForce PC host");
|
||||
hostField.setSelectionStart(0);
|
||||
hostField.setSelectionEnd(hostField.getText().length());
|
||||
|
||||
stream = new JButton("Start Streaming");
|
||||
stream.addActionListener(createStreamButtonListener());
|
||||
stream.setToolTipText("Start the GeForce stream");
|
||||
|
||||
pair = new JButton("Pair");
|
||||
pair.addActionListener(createPairButtonListener());
|
||||
pair.setToolTipText("Send pair request to GeForce PC");
|
||||
|
||||
fullscreen = new JCheckBox("Fullscreen", true);
|
||||
|
||||
Box streamBox = Box.createHorizontalBox();
|
||||
streamBox.add(Box.createHorizontalGlue());
|
||||
streamBox.add(stream);
|
||||
streamBox.add(Box.createHorizontalGlue());
|
||||
|
||||
Box pairBox = Box.createHorizontalBox();
|
||||
pairBox.add(Box.createHorizontalGlue());
|
||||
pairBox.add(pair);
|
||||
pairBox.add(Box.createHorizontalGlue());
|
||||
|
||||
Box hostBox = Box.createHorizontalBox();
|
||||
hostBox.add(Box.createHorizontalStrut(20));
|
||||
hostBox.add(hostField);
|
||||
hostBox.add(Box.createHorizontalStrut(20));
|
||||
|
||||
|
||||
Box contentBox = Box.createVerticalBox();
|
||||
contentBox.add(Box.createVerticalStrut(20));
|
||||
contentBox.add(hostBox);
|
||||
contentBox.add(Box.createVerticalStrut(5));
|
||||
contentBox.add(fullscreen);
|
||||
contentBox.add(Box.createVerticalStrut(5));
|
||||
contentBox.add(streamBox);
|
||||
contentBox.add(Box.createVerticalStrut(10));
|
||||
contentBox.add(pairBox);
|
||||
contentBox.add(Box.createVerticalGlue());
|
||||
|
||||
centerPane.add(contentBox);
|
||||
mainPane.add(centerPane, "Center");
|
||||
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
|
||||
limeFrame.getRootPane().setDefaultButton(stream);
|
||||
limeFrame.setSize(300, 175);
|
||||
limeFrame.setLocation(dim.width/2-limeFrame.getSize().width/2, dim.height/2-limeFrame.getSize().height/2);
|
||||
limeFrame.setResizable(false);
|
||||
limeFrame.setVisible(true);
|
||||
}
|
||||
|
||||
private ActionListener createStreamButtonListener() {
|
||||
return new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Limelight.createInstance(hostField.getText(), fullscreen.isSelected());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ActionListener createPairButtonListener() {
|
||||
return new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String macAddress;
|
||||
try {
|
||||
macAddress = NvConnection.getMacAddressString();
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (macAddress == null) {
|
||||
System.out.println("Couldn't find a MAC address");
|
||||
return;
|
||||
}
|
||||
|
||||
NvHTTP httpConn;
|
||||
String message;
|
||||
try {
|
||||
httpConn = new NvHTTP(InetAddress.getByName(hostField.getText()),
|
||||
macAddress, PlatformBinding.getDeviceName());
|
||||
try {
|
||||
if (httpConn.getPairState()) {
|
||||
message = "Already paired";
|
||||
}
|
||||
else {
|
||||
int session = httpConn.getSessionId();
|
||||
if (session == 0) {
|
||||
message = "Pairing was declined by the target";
|
||||
}
|
||||
else {
|
||||
message = "Pairing was successful";
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
message = e.getMessage();
|
||||
} catch (XmlPullParserException e) {
|
||||
message = e.getMessage();
|
||||
}
|
||||
} catch (UnknownHostException e1) {
|
||||
message = "Failed to resolve host";
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(limeFrame, message, "Limelight", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package com.limelight.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
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;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
|
||||
import com.limelight.input.KeyboardHandler;
|
||||
import com.limelight.input.MouseHandler;
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.nvstream.NvConnectionListener.Stage;
|
||||
|
||||
public class StreamFrame extends JFrame {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private KeyboardHandler keyboard;
|
||||
private MouseHandler mouse;
|
||||
private JProgressBar spinner;
|
||||
private JLabel spinnerLabel;
|
||||
private Cursor noCursor;
|
||||
private NvConnection conn;
|
||||
|
||||
private static final int WIDTH = 1280;
|
||||
private static final int HEIGHT = 720;
|
||||
|
||||
|
||||
public void freeMouse() {
|
||||
mouse.free();
|
||||
showCursor();
|
||||
}
|
||||
|
||||
public void captureMouse() {
|
||||
mouse.capture();
|
||||
hideCursor();
|
||||
}
|
||||
|
||||
public void build(NvConnection conn, boolean fullscreen) {
|
||||
this.conn = conn;
|
||||
|
||||
keyboard = new KeyboardHandler(conn, this);
|
||||
mouse = new MouseHandler(conn, this);
|
||||
|
||||
this.addKeyListener(keyboard);
|
||||
this.addMouseListener(mouse);
|
||||
this.addMouseMotionListener(mouse);
|
||||
|
||||
this.setFocusTraversalKeysEnabled(false);
|
||||
|
||||
this.setSize(WIDTH, HEIGHT);
|
||||
|
||||
this.setBackground(Color.BLACK);
|
||||
this.getContentPane().setBackground(Color.BLACK);
|
||||
this.getRootPane().setBackground(Color.BLACK);
|
||||
|
||||
if (fullscreen) {
|
||||
makeFullScreen();
|
||||
}
|
||||
|
||||
hideCursor();
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
private DisplayMode getBestDisplay(DisplayMode[] configs) {
|
||||
Arrays.sort(configs, new Comparator<DisplayMode>() {
|
||||
@Override
|
||||
public int compare(DisplayMode o1, DisplayMode o2) {
|
||||
if (o1.getWidth() > o2.getWidth()) {
|
||||
return -1;
|
||||
} else if (o2.getWidth() > o1.getWidth()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
DisplayMode bestConfig = null;
|
||||
for (DisplayMode config : configs) {
|
||||
if (config.getWidth() >= 1280 && config.getHeight() >= 720) {
|
||||
bestConfig = config;
|
||||
}
|
||||
}
|
||||
if (bestConfig == null) {
|
||||
return configs[0];
|
||||
}
|
||||
return bestConfig;
|
||||
}
|
||||
|
||||
private void makeFullScreen() {
|
||||
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||
if (gd.isFullScreenSupported()) {
|
||||
this.setUndecorated(true);
|
||||
gd.setFullScreenWindow(this);
|
||||
|
||||
if (gd.isDisplayChangeSupported()) {
|
||||
DisplayMode config = getBestDisplay(gd.getDisplayModes());
|
||||
if (config != null) {
|
||||
gd.setDisplayMode(config);
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(
|
||||
this,
|
||||
"Unable to change display resolution. \nThis may not be the correct resolution",
|
||||
"Display Resolution",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(
|
||||
this,
|
||||
"Your operating system does not support fullscreen.",
|
||||
"Fullscreen Unsupported",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public void hideCursor() {
|
||||
if (noCursor == null) {
|
||||
// Transparent 16 x 16 pixel cursor image.
|
||||
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
// Create a new blank cursor.
|
||||
noCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
||||
cursorImg, new Point(0, 0), "blank cursor");
|
||||
}
|
||||
// Set the blank cursor to the JFrame.
|
||||
this.setCursor(noCursor);
|
||||
this.getContentPane().setCursor(noCursor);
|
||||
}
|
||||
|
||||
public void showCursor() {
|
||||
this.setCursor(Cursor.getDefaultCursor());
|
||||
this.getContentPane().setCursor(Cursor.getDefaultCursor());
|
||||
}
|
||||
|
||||
public void showSpinner(Stage stage) {
|
||||
|
||||
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();
|
||||
spinner.setIndeterminate(true);
|
||||
spinner.setMaximumSize(new Dimension(150, 30));
|
||||
|
||||
spinnerLabel = new JLabel();
|
||||
spinnerLabel.setForeground(Color.white);
|
||||
|
||||
Box spinBox = Box.createHorizontalBox();
|
||||
spinBox.add(Box.createHorizontalGlue());
|
||||
spinBox.add(spinner);
|
||||
spinBox.add(Box.createHorizontalGlue());
|
||||
|
||||
Box lblBox = Box.createHorizontalBox();
|
||||
lblBox.add(Box.createHorizontalGlue());
|
||||
lblBox.add(spinnerLabel);
|
||||
lblBox.add(Box.createHorizontalGlue());
|
||||
|
||||
panel.add(Box.createVerticalGlue());
|
||||
panel.add(spinBox);
|
||||
panel.add(Box.createVerticalStrut(10));
|
||||
panel.add(lblBox);
|
||||
panel.add(Box.createVerticalGlue());
|
||||
|
||||
c.setLayout(new BorderLayout());
|
||||
c.add(panel, "Center");
|
||||
}
|
||||
spinnerLabel.setText("Starting " + stage.getName() + "...");
|
||||
}
|
||||
|
||||
public void hideSpinner() {
|
||||
spinner.setVisible(false);
|
||||
spinnerLabel.setVisible(false);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
dispose();
|
||||
conn.stop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user