mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-15 21:31:12 +00:00
stream frame now closes on errors. now show a progress bar when starting the stream.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.limelight;
|
package com.limelight;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import com.limelight.binding.PlatformBinding;
|
import com.limelight.binding.PlatformBinding;
|
||||||
@@ -16,6 +17,7 @@ public class Limelight implements NvConnectionListener {
|
|||||||
private StreamFrame streamFrame;
|
private StreamFrame streamFrame;
|
||||||
private NvConnection conn;
|
private NvConnection conn;
|
||||||
private boolean connectionFailed;
|
private boolean connectionFailed;
|
||||||
|
private static JFrame limeFrame;
|
||||||
|
|
||||||
public Limelight(String host) {
|
public Limelight(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
@@ -31,6 +33,12 @@ public class Limelight implements NvConnectionListener {
|
|||||||
streamFrame.build(conn);
|
streamFrame.build(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void createFrame() {
|
||||||
|
MainFrame main = new MainFrame();
|
||||||
|
main.build();
|
||||||
|
limeFrame = main.getLimeFrame();
|
||||||
|
}
|
||||||
|
|
||||||
public static void createInstance(String host) {
|
public static void createInstance(String host) {
|
||||||
Limelight limelight = new Limelight(host);
|
Limelight limelight = new Limelight(host);
|
||||||
limelight.startUp();
|
limelight.startUp();
|
||||||
@@ -54,14 +62,13 @@ public class Limelight implements NvConnectionListener {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
createFrame();
|
||||||
MainFrame limeFrame = new MainFrame();
|
|
||||||
limeFrame.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stageStarting(Stage stage) {
|
public void stageStarting(Stage stage) {
|
||||||
System.out.println("Starting "+stage.getName());
|
System.out.println("Starting "+stage.getName());
|
||||||
|
streamFrame.showSpinner(stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -70,12 +77,14 @@ public class Limelight implements NvConnectionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stageFailed(Stage stage) {
|
public void stageFailed(Stage stage) {
|
||||||
JOptionPane.showMessageDialog(streamFrame, "Starting "+stage.getName()+" failed", "Connection Error", JOptionPane.ERROR_MESSAGE);
|
streamFrame.dispose();
|
||||||
conn.stop();
|
conn.stop();
|
||||||
|
displayError("Connection Error", "Starting " + stage.getName() + " failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connectionStarted() {
|
public void connectionStarted() {
|
||||||
|
streamFrame.hideSpinner();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,14 +92,19 @@ public class Limelight implements NvConnectionListener {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (!connectionFailed) {
|
if (!connectionFailed) {
|
||||||
connectionFailed = true;
|
connectionFailed = true;
|
||||||
JOptionPane.showMessageDialog(streamFrame, "The connection failed unexpectedly", "Connection Terminated", JOptionPane.ERROR_MESSAGE);
|
streamFrame.dispose();
|
||||||
|
displayError("Connection Terminated", "The connection failed unexpectedly");
|
||||||
conn.stop();
|
conn.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayMessage(String message) {
|
public void displayMessage(String message) {
|
||||||
JOptionPane.showMessageDialog(streamFrame, message, "Limelight", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(limeFrame, message, "Limelight", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void displayError(String title, String message) {
|
||||||
|
JOptionPane.showMessageDialog(limeFrame, message, title, JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ public class MainFrame {
|
|||||||
private JButton stream;
|
private JButton stream;
|
||||||
private JFrame limeFrame;
|
private JFrame limeFrame;
|
||||||
|
|
||||||
public MainFrame() {
|
public JFrame getLimeFrame() {
|
||||||
|
return limeFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void build() {
|
public void build() {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.limelight.gui;
|
package com.limelight.gui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
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.Frame;
|
||||||
@@ -10,18 +12,26 @@ import java.awt.Point;
|
|||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JProgressBar;
|
||||||
|
|
||||||
import com.limelight.input.KeyboardHandler;
|
import com.limelight.input.KeyboardHandler;
|
||||||
import com.limelight.input.MouseHandler;
|
import com.limelight.input.MouseHandler;
|
||||||
import com.limelight.nvstream.NvConnection;
|
import com.limelight.nvstream.NvConnection;
|
||||||
|
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 KeyboardHandler keyboard;
|
private KeyboardHandler keyboard;
|
||||||
private MouseHandler mouse;
|
private MouseHandler mouse;
|
||||||
|
private JProgressBar spinner;
|
||||||
|
private JLabel spinnerLabel;
|
||||||
|
|
||||||
public void build(NvConnection conn) {
|
public void build(NvConnection conn) {
|
||||||
keyboard = new KeyboardHandler(conn);
|
keyboard = new KeyboardHandler(conn);
|
||||||
mouse = new MouseHandler(conn, this);
|
mouse = new MouseHandler(conn, this);
|
||||||
@@ -65,4 +75,46 @@ public class StreamFrame extends JFrame {
|
|||||||
// Set the blank cursor to the JFrame.
|
// Set the blank cursor to the JFrame.
|
||||||
this.getContentPane().setCursor(blankCursor);
|
this.getContentPane().setCursor(blankCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showSpinner(Stage stage) {
|
||||||
|
|
||||||
|
if (spinner == null) {
|
||||||
|
Container c = this.getContentPane();
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user