Merge pull request #8 from QuarkTheAwesome/msgbox

Refactor messageboxes for cross-thread wonders
This commit is contained in:
Maschell 2017-03-31 13:11:07 +02:00 committed by GitHub
commit 3a0261e3d5
5 changed files with 60 additions and 9 deletions

View File

@ -33,7 +33,7 @@ import javax.swing.Timer;
import lombok.Getter; import lombok.Getter;
import net.ash.HIDToVPADNetworkClient.controller.Controller; import net.ash.HIDToVPADNetworkClient.controller.Controller;
import net.ash.HIDToVPADNetworkClient.network.NetworkManager; import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
import net.ash.HIDToVPADNetworkClient.util.Utilities; import net.ash.HIDToVPADNetworkClient.util.MessageBox;
public class GuiControllerListItem extends JPanel implements ActionListener { public class GuiControllerListItem extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -78,7 +78,7 @@ public class GuiControllerListItem extends JPanel implements ActionListener {
private void checkIfDisplayNoConfigMessage() { private void checkIfDisplayNoConfigMessage() {
if (hasConfigCache == false) { if (hasConfigCache == false) {
Utilities.messageBox("No configuration for this controller found on the console."); MessageBox.show(new MessageBox("No configuration for this controller found on the console.", MessageBox.MESSAGE_ERROR));
} }
} }

View File

@ -23,12 +23,17 @@ package net.ash.HIDToVPADNetworkClient.gui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.Timer;
import net.ash.HIDToVPADNetworkClient.Main; import net.ash.HIDToVPADNetworkClient.Main;
import net.ash.HIDToVPADNetworkClient.util.MessageBox;
public class GuiMain extends JPanel { public class GuiMain extends JPanel {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -65,6 +70,18 @@ public class GuiMain extends JPanel {
Main.fatal(); Main.fatal();
} }
add(rightSideControls, BorderLayout.LINE_END); add(rightSideControls, BorderLayout.LINE_END);
int delay = 100;
ActionListener messageBoxPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
MessageBox msg = MessageBox.getNextMessage();
if (msg != null) {
JOptionPane.showMessageDialog(GuiMain.instance(), msg.getMessage(), "HID To VPAD Network Client", msg.getType());
MessageBox.bumpQueue();
}
}
};
new Timer(delay, messageBoxPerformer).start();
} }
public static GuiMain instance() { public static GuiMain instance() {

View File

@ -44,6 +44,7 @@ import net.ash.HIDToVPADNetworkClient.controller.XInput13Controller;
import net.ash.HIDToVPADNetworkClient.controller.XInput14Controller; import net.ash.HIDToVPADNetworkClient.controller.XInput14Controller;
import net.ash.HIDToVPADNetworkClient.controller.XInputController; import net.ash.HIDToVPADNetworkClient.controller.XInputController;
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException; import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
import net.ash.HIDToVPADNetworkClient.util.MessageBox;
import net.ash.HIDToVPADNetworkClient.util.PureJavaHidApiManager; import net.ash.HIDToVPADNetworkClient.util.PureJavaHidApiManager;
import net.ash.HIDToVPADNetworkClient.util.Settings; import net.ash.HIDToVPADNetworkClient.util.Settings;
import purejavahidapi.HidDeviceInfo; import purejavahidapi.HidDeviceInfo;
@ -161,6 +162,7 @@ public class ControllerManager {
log.info("This error can be fixed! Please install the Visual C++ Redistributables:"); log.info("This error can be fixed! Please install the Visual C++ Redistributables:");
log.info("https://www.microsoft.com/en-us/download/details.aspx?id=48145"); log.info("https://www.microsoft.com/en-us/download/details.aspx?id=48145");
log.info("If that doesn't help, create an issue on GitHub."); log.info("If that doesn't help, create an issue on GitHub.");
MessageBox.show(new MessageBox("There was a problem setting up XInput.\nTo fix this, try installing the Visual C++\nredistributables: https://tinyurl.com/vcredist2015.\n\nOther controller types should still work.", MessageBox.MESSAGE_ERROR));
threwUnsatisfiedLinkError = true; threwUnsatisfiedLinkError = true;
} }
} }

View File

@ -0,0 +1,39 @@
package net.ash.HIDToVPADNetworkClient.util;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import lombok.Getter;
public class MessageBox {
public static final int MESSAGE_INFO = JOptionPane.INFORMATION_MESSAGE;
public static final int MESSAGE_WARNING = JOptionPane.WARNING_MESSAGE;
public static final int MESSAGE_ERROR = JOptionPane.ERROR_MESSAGE;
@Getter
private String message;
@Getter
private int type;
public MessageBox(String message, int type) {
this.message = message;
this.type = type;
}
private static List<MessageBox> messageBoxQueue = new ArrayList<MessageBox>();
public static void show(MessageBox box) {
messageBoxQueue.add(box);
}
public static MessageBox getNextMessage() {
if (messageBoxQueue.size() > 0) {
return messageBoxQueue.get(0);
} else return null;
}
public static void bumpQueue() {
if (messageBoxQueue.size() > 0) {
messageBoxQueue.remove(0);
}
}
}

View File

@ -21,9 +21,6 @@
*******************************************************************************/ *******************************************************************************/
package net.ash.HIDToVPADNetworkClient.util; package net.ash.HIDToVPADNetworkClient.util;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Utilities { public class Utilities {
private Utilities() { private Utilities() {
@ -79,8 +76,4 @@ public class Utilities {
public static short signedShortToByte(short value) { public static short signedShortToByte(short value) {
return signedShortToByte((int) value); return signedShortToByte((int) value);
} }
public static void messageBox(String string) {
JOptionPane.showMessageDialog(new JFrame(), string);
}
} }