From 0a7af5411aea18a90438ebe261873eef40f4c1ec Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP <27149563+ErdbeerbaerLP@users.noreply.github.com> Date: Wed, 27 Mar 2019 18:27:53 +0100 Subject: [PATCH 1/6] Bug Fix --- src/main/java/de/mas/wiiu/streaming/Main.java | 92 +++++++++++++------ 1 file changed, 63 insertions(+), 29 deletions(-) diff --git a/src/main/java/de/mas/wiiu/streaming/Main.java b/src/main/java/de/mas/wiiu/streaming/Main.java index 769c15d..43af7e8 100644 --- a/src/main/java/de/mas/wiiu/streaming/Main.java +++ b/src/main/java/de/mas/wiiu/streaming/Main.java @@ -22,9 +22,11 @@ package de.mas.wiiu.streaming; +import java.awt.GraphicsEnvironment; import java.net.BindException; import java.net.SocketException; +import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; @@ -38,38 +40,70 @@ import de.mas.wiiu.streaming.gui.StreamWindow; public class Main { - public static void main(String[] args) throws Exception { - CommandLineParser parser = new DefaultParser(); + public static void main(String[] args) throws Exception { + CommandLineParser parser = new DefaultParser(); - Options options = new Options(); - options.addOption("ip", "ip", true, "IP address of your Wii U Console."); + Options options = new Options(); + options.addOption("ip", "ip", true, "IP address of your Wii U Console."); - CommandLine line = parser.parse(options, args); - String ip = null; + CommandLine line = parser.parse(options, args); + String ip = null; - if (line.hasOption("ip")) { - ip = line.getOptionValue("ip"); - } else { - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("streamingTool", options); - ip = JOptionPane.showInputDialog(null, "Please enter the local IP address of your Wii U", "Wii U streaming client", JOptionPane.PLAIN_MESSAGE); - } - try { - new Main(ip); - } catch (BindException e) { - JOptionPane.showMessageDialog(null, "Can't bind socket. The client is probably already running.", e.getClass().getName(), - JOptionPane.WARNING_MESSAGE); - System.exit(-1); - } - } + if (line.hasOption("ip")) { + ip = line.getOptionValue("ip"); + } else { + //Check if this is being run in cmd to prevent headless exceptions + if(GraphicsEnvironment.isHeadless()) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp("streamingTool", options); + }else { - public Main(String ip) throws SocketException { - ImageStreamer imageStreamer = new ImageStreamer(ip); + //Create a JFrame to show the icon in the taskbar + final JFrame frame = new JFrame("Wii U Streaming Client - Enter IP..."); + frame.setUndecorated( true ); + frame.setVisible( true ); + frame.setLocationRelativeTo( null ); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - new StreamWindow(imageStreamer.getImageProvider()); - } - }); - } + //Display the IP Dialog + ip = JOptionPane.showInputDialog(frame, "Please enter the local IP address of your Wii U", "Wii U streaming client", JOptionPane.PLAIN_MESSAGE); + + //Check if user clicked "Cancel" + if(ip == null) { + System.out.println("Cancelled. Exiting program"); + frame.dispose(); + System.exit(0); + } + //Close the JFrame again + frame.dispose(); + } + } + + try { + new Main(ip); + } catch (BindException e) { + //Create a JFrame to show the icon in the taskbar + final JFrame frame = new JFrame("Wii U Streaming Client - "+e.getClass().getName()); + frame.setUndecorated( true ); + frame.setVisible( true ); + frame.setLocationRelativeTo( null ); + + //Display the Message + JOptionPane.showMessageDialog(frame, "Can't bind socket. The client is probably already running.", e.getClass().getName(), + JOptionPane.WARNING_MESSAGE); + //Close the JFrame again + frame.dispose(); + + System.exit(-1); + } + } + + public Main(String ip) throws SocketException { + ImageStreamer imageStreamer = new ImageStreamer(ip); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new StreamWindow(imageStreamer.getImageProvider()); + } + }); + } } From f61a3497237c6d67396d43da16cd44f650617260 Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP <27149563+ErdbeerbaerLP@users.noreply.github.com> Date: Wed, 27 Mar 2019 18:32:15 +0100 Subject: [PATCH 2/6] Update README.MD --- README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.MD b/README.MD index e0bb732..0cfa14a 100644 --- a/README.MD +++ b/README.MD @@ -18,5 +18,5 @@ mvn package ``` # Used libraries -- [lombok](https://projectlombok.org/) +- [lombok](https://projectlombok.org/) ([Install to IDE](https://projectlombok.org/setup/overview) too!) - [commons-cli](https://commons.apache.org/proper/commons-cli/) From ee918128f6bece41c734bd8f47e1bd96d1d10dfe Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP <27149563+ErdbeerbaerLP@users.noreply.github.com> Date: Wed, 27 Mar 2019 19:10:12 +0100 Subject: [PATCH 3/6] Change something again --- src/main/java/de/mas/wiiu/streaming/Main.java | 66 +++++++++++-------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/main/java/de/mas/wiiu/streaming/Main.java b/src/main/java/de/mas/wiiu/streaming/Main.java index 43af7e8..c7d8da4 100644 --- a/src/main/java/de/mas/wiiu/streaming/Main.java +++ b/src/main/java/de/mas/wiiu/streaming/Main.java @@ -41,22 +41,31 @@ import de.mas.wiiu.streaming.gui.StreamWindow; public class Main { public static void main(String[] args) throws Exception { - CommandLineParser parser = new DefaultParser(); + if(GraphicsEnvironment.isHeadless()) { + System.out.println("This program does not support running in a headless environment!"); + System.exit(2); + }else { + String ip = null; + if(args.length != 0) { + CommandLineParser parser = new DefaultParser(); - Options options = new Options(); - options.addOption("ip", "ip", true, "IP address of your Wii U Console."); + Options options = new Options(); + options.addOption("ip", "ip", true, "IP address of your Wii U Console."); + + CommandLine line = parser.parse(options, args, true); + - CommandLine line = parser.parse(options, args); - String ip = null; + if (line.hasOption("ip")) { + ip = line.getOptionValue("ip"); + }else { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp("streamingTool", options); + System.exit(2); + } + } else{ + + - if (line.hasOption("ip")) { - ip = line.getOptionValue("ip"); - } else { - //Check if this is being run in cmd to prevent headless exceptions - if(GraphicsEnvironment.isHeadless()) { - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("streamingTool", options); - }else { //Create a JFrame to show the icon in the taskbar final JFrame frame = new JFrame("Wii U Streaming Client - Enter IP..."); @@ -75,25 +84,26 @@ public class Main { } //Close the JFrame again frame.dispose(); + } - } - try { - new Main(ip); - } catch (BindException e) { - //Create a JFrame to show the icon in the taskbar - final JFrame frame = new JFrame("Wii U Streaming Client - "+e.getClass().getName()); - frame.setUndecorated( true ); - frame.setVisible( true ); - frame.setLocationRelativeTo( null ); + try { + new Main(ip); + } catch (BindException e) { + //Create a JFrame to show the icon in the taskbar + final JFrame frame = new JFrame("Wii U Streaming Client - "+e.getClass().getName()); + frame.setUndecorated( true ); + frame.setVisible( true ); + frame.setLocationRelativeTo( null ); - //Display the Message - JOptionPane.showMessageDialog(frame, "Can't bind socket. The client is probably already running.", e.getClass().getName(), - JOptionPane.WARNING_MESSAGE); - //Close the JFrame again - frame.dispose(); + //Display the Message + JOptionPane.showMessageDialog(frame, "Can't bind socket. The client is probably already running.", e.getClass().getName(), + JOptionPane.WARNING_MESSAGE); + //Close the JFrame again + frame.dispose(); - System.exit(-1); + System.exit(-1); + } } } From 012f4da73df2340933ebdc9fe5d94a6353379e44 Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP <27149563+ErdbeerbaerLP@users.noreply.github.com> Date: Wed, 27 Mar 2019 19:27:15 +0100 Subject: [PATCH 4/6] Add dropdown menu and automatic window size --- .../mas/wiiu/streaming/gui/StreamWindow.java | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java b/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java index a0a5aba..a79f826 100644 --- a/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java +++ b/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java @@ -21,18 +21,55 @@ *******************************************************************************/ package de.mas.wiiu.streaming.gui; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.WindowConstants; public class StreamWindow { - private final ImagePanel image = new ImagePanel(1280, 720); + private final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + private final ImagePanel image = new ImagePanel(screenSize.width-15, screenSize.height-100); public StreamWindow(IImageProvider imageProvider) { + JFrame editorFrame = new JFrame("Stream"); + + editorFrame.setMaximumSize(screenSize); editorFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); imageProvider.setOnImageChange((bi) -> image.setImage(bi)); - editorFrame.add(image); + editorFrame.getContentPane().add(image); + + JMenuBar menuBar = new JMenuBar(); + editorFrame.getContentPane().add(menuBar, BorderLayout.NORTH); + + JMenu mnSettings = new JMenu("Settings"); + menuBar.add(mnSettings); + + + JMenuItem mntmNewMenuItem = new JMenuItem("Config (Not implemented!)"); + mntmNewMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + //TODO Add program config + } + }); + JMenuItem mntmExit = new JMenuItem("Exit"); + mntmExit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + + mntmNewMenuItem.setEnabled(false); + mnSettings.add(mntmNewMenuItem); + mnSettings.add(mntmExit); editorFrame.pack(); editorFrame.setLocationRelativeTo(null); From d2b4b0f545e36152b3bbcdae40cfc3c4cd0efa02 Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP <27149563+ErdbeerbaerLP@users.noreply.github.com> Date: Wed, 27 Mar 2019 19:28:28 +0100 Subject: [PATCH 5/6] Changed window title to "Wii U Streaming Client" --- src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java b/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java index a79f826..e390e1d 100644 --- a/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java +++ b/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java @@ -39,7 +39,7 @@ public class StreamWindow { public StreamWindow(IImageProvider imageProvider) { - JFrame editorFrame = new JFrame("Stream"); + JFrame editorFrame = new JFrame("Wii U Streaming Client"); editorFrame.setMaximumSize(screenSize); editorFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); From a0965cc92a53b551266c978e2646d4a0241892af Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP <27149563+ErdbeerbaerLP@users.noreply.github.com> Date: Sat, 30 Mar 2019 15:55:55 +0100 Subject: [PATCH 6/6] Use spaces instead of tabs --- src/main/java/de/mas/wiiu/streaming/Main.java | 128 +++++++++--------- .../mas/wiiu/streaming/gui/StreamWindow.java | 26 ++-- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/main/java/de/mas/wiiu/streaming/Main.java b/src/main/java/de/mas/wiiu/streaming/Main.java index c7d8da4..075e19e 100644 --- a/src/main/java/de/mas/wiiu/streaming/Main.java +++ b/src/main/java/de/mas/wiiu/streaming/Main.java @@ -40,80 +40,80 @@ import de.mas.wiiu.streaming.gui.StreamWindow; public class Main { - public static void main(String[] args) throws Exception { - if(GraphicsEnvironment.isHeadless()) { - System.out.println("This program does not support running in a headless environment!"); - System.exit(2); - }else { - String ip = null; - if(args.length != 0) { - CommandLineParser parser = new DefaultParser(); + public static void main(String[] args) throws Exception { + if(GraphicsEnvironment.isHeadless()) { + System.out.println("This program does not support running in a headless environment!"); + System.exit(2); + }else { + String ip = null; + if(args.length != 0) { + CommandLineParser parser = new DefaultParser(); - Options options = new Options(); - options.addOption("ip", "ip", true, "IP address of your Wii U Console."); - - CommandLine line = parser.parse(options, args, true); - + Options options = new Options(); + options.addOption("ip", "ip", true, "IP address of your Wii U Console."); - if (line.hasOption("ip")) { - ip = line.getOptionValue("ip"); - }else { - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("streamingTool", options); - System.exit(2); - } - } else{ - - + CommandLine line = parser.parse(options, args, true); - //Create a JFrame to show the icon in the taskbar - final JFrame frame = new JFrame("Wii U Streaming Client - Enter IP..."); - frame.setUndecorated( true ); - frame.setVisible( true ); - frame.setLocationRelativeTo( null ); + if (line.hasOption("ip")) { + ip = line.getOptionValue("ip"); + }else { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp("streamingTool", options); + System.exit(2); + } + } else{ - //Display the IP Dialog - ip = JOptionPane.showInputDialog(frame, "Please enter the local IP address of your Wii U", "Wii U streaming client", JOptionPane.PLAIN_MESSAGE); - //Check if user clicked "Cancel" - if(ip == null) { - System.out.println("Cancelled. Exiting program"); - frame.dispose(); - System.exit(0); - } - //Close the JFrame again - frame.dispose(); - } - try { - new Main(ip); - } catch (BindException e) { - //Create a JFrame to show the icon in the taskbar - final JFrame frame = new JFrame("Wii U Streaming Client - "+e.getClass().getName()); - frame.setUndecorated( true ); - frame.setVisible( true ); - frame.setLocationRelativeTo( null ); + //Create a JFrame to show the icon in the taskbar + final JFrame frame = new JFrame("Wii U Streaming Client - Enter IP..."); + frame.setUndecorated( true ); + frame.setVisible( true ); + frame.setLocationRelativeTo( null ); - //Display the Message - JOptionPane.showMessageDialog(frame, "Can't bind socket. The client is probably already running.", e.getClass().getName(), - JOptionPane.WARNING_MESSAGE); - //Close the JFrame again - frame.dispose(); + //Display the IP Dialog + ip = JOptionPane.showInputDialog(frame, "Please enter the local IP address of your Wii U", "Wii U streaming client", JOptionPane.PLAIN_MESSAGE); - System.exit(-1); - } - } - } + //Check if user clicked "Cancel" + if(ip == null) { + System.out.println("Cancelled. Exiting program"); + frame.dispose(); + System.exit(0); + } + //Close the JFrame again + frame.dispose(); - public Main(String ip) throws SocketException { - ImageStreamer imageStreamer = new ImageStreamer(ip); + } - SwingUtilities.invokeLater(new Runnable() { - public void run() { - new StreamWindow(imageStreamer.getImageProvider()); - } - }); - } + try { + new Main(ip); + } catch (BindException e) { + //Create a JFrame to show the icon in the taskbar + final JFrame frame = new JFrame("Wii U Streaming Client - "+e.getClass().getName()); + frame.setUndecorated( true ); + frame.setVisible( true ); + frame.setLocationRelativeTo( null ); + + //Display the Message + JOptionPane.showMessageDialog(frame, "Can't bind socket. The client is probably already running.", e.getClass().getName(), + JOptionPane.WARNING_MESSAGE); + //Close the JFrame again + frame.dispose(); + + System.exit(-1); + } + } + } + + public Main(String ip) throws SocketException { + ImageStreamer imageStreamer = new ImageStreamer(ip); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new StreamWindow(imageStreamer.getImageProvider()); + } + }); + } } diff --git a/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java b/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java index e390e1d..9978f36 100644 --- a/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java +++ b/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java @@ -34,11 +34,11 @@ import javax.swing.JMenuItem; import javax.swing.WindowConstants; public class StreamWindow { - private final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + private final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); private final ImagePanel image = new ImagePanel(screenSize.width-15, screenSize.height-100); public StreamWindow(IImageProvider imageProvider) { - + JFrame editorFrame = new JFrame("Wii U Streaming Client"); editorFrame.setMaximumSize(screenSize); @@ -46,27 +46,27 @@ public class StreamWindow { imageProvider.setOnImageChange((bi) -> image.setImage(bi)); editorFrame.getContentPane().add(image); - + JMenuBar menuBar = new JMenuBar(); editorFrame.getContentPane().add(menuBar, BorderLayout.NORTH); - + JMenu mnSettings = new JMenu("Settings"); menuBar.add(mnSettings); - - + + JMenuItem mntmNewMenuItem = new JMenuItem("Config (Not implemented!)"); mntmNewMenuItem.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - //TODO Add program config - } + public void actionPerformed(ActionEvent e) { + //TODO Add program config + } }); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - System.exit(0); - } + public void actionPerformed(ActionEvent e) { + System.exit(0); + } }); - + mntmNewMenuItem.setEnabled(false); mnSettings.add(mntmNewMenuItem); mnSettings.add(mntmExit);