mirror of
https://github.com/Maschell/HIDtoVPADNetworkClient.git
synced 2024-11-22 05:59:16 +01:00
Refactor messageboxes for cross-thread wonders.
My god, @Maschell.
This commit is contained in:
parent
24864ebf43
commit
751d06e97e
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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() {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
src/net/ash/HIDToVPADNetworkClient/util/MessageBox.java
Normal file
39
src/net/ash/HIDToVPADNetworkClient/util/MessageBox.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user