Basic functionality for Info tab

This commit is contained in:
Ash 2017-04-12 17:15:38 +10:00
parent a73873e96d
commit fdf74a0f55
5 changed files with 59 additions and 10 deletions

View File

@ -48,6 +48,7 @@ import javax.swing.border.EtchedBorder;
import lombok.extern.java.Log;
import net.ash.HIDToVPADNetworkClient.util.Settings;
import net.ash.HIDToVPADNetworkClient.util.StatusReport;
@Log
public class GuiOptionsWindow extends JPanel {
@ -217,21 +218,21 @@ public class GuiOptionsWindow extends JPanel {
private static final long serialVersionUID = 1L;
private final JTextArea infoText;
private final JScrollPane infoTextWrap;
private InfoTab() {
super();
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
setBorder(BorderFactory.createEmptyBorder(5, 5, 10, 5));
infoText = new JTextArea();
infoText.setBorder(BorderFactory.createLoweredBevelBorder());
infoText.setEditable(false);
infoText.setText("WIP");
JPanel infoTextWrap = new JPanel(new GridLayout(1, 1));
infoTextWrap.setBorder(BorderFactory.createEmptyBorder(5, 5, 10, 5));
infoTextWrap.add(infoText);
infoTextWrap = new JScrollPane(infoText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
infoTextWrap.setAlignmentX(Component.CENTER_ALIGNMENT);
add(infoTextWrap);
add(Box.createVerticalStrut(10));
JButton copyButton = new JButton("Copy");
copyButton.addActionListener(new ActionListener() {
@Override
@ -242,12 +243,13 @@ public class GuiOptionsWindow extends JPanel {
});
copyButton.setAlignmentX(Component.CENTER_ALIGNMENT);
add(copyButton);
add(Box.createVerticalStrut(10));
}
@Override
public void updateTab() {
//TODO update info text
infoText.setCaretPosition(0);
infoText.setText(StatusReport.generateStatusReport());
infoText.setCaretPosition(0);
}
}

View File

@ -37,7 +37,7 @@ public class HidManager {
public static HidDevice getDeviceByPath(String path) throws IOException {
return backend.getDeviceByPath(path);
}
public static List<HidDevice> getAttachedControllers() {
List<HidDevice> connectedGamepads = new ArrayList<HidDevice>();
@ -64,6 +64,10 @@ public class HidManager {
}
return connectedGamepads;
}
public static List<HidDevice> getAllAttachedControllers() {
return backend.enumerateDevices();
}
public static boolean isGamepad(HidDevice info) {
if (info == null) return false;
@ -98,6 +102,10 @@ public class HidManager {
return (info.getVendorId() == (short) 0x045e) && ((info.getProductId() == (short) 0x02ff) || (info.getProductId() == (short) 0x02a1));
}
public static String getBackendType() {
return backend.getClass().getSimpleName();
}
static {
if (Settings.isMacOSX()) {
backend = new Hid4JavaHidManagerBackend();

View File

@ -68,7 +68,7 @@ class Hid4JavaHidDevice implements HidDevice {
@Override
public String toString() {
return "Hid4JavaHidDevice [vid= " + getVendorId() + ", pid= " + getProductId() + ", data=" + Arrays.toString(data) + "]";
return "Hid4JavaHidDevice [vid= " + getVendorId() + ", pid= " + getProductId() + ", usage= " + String.format("%04X", getUsage()) + ", data=" + Arrays.toString(data) + "]";
}
@Override

View File

@ -93,6 +93,6 @@ class PureJavaHidDevice implements HidDevice, InputReportListener {
@Override
public String toString() {
return "PureJavaHidDevice [vid= " + String.format("%04X", getVendorId()) + ", pid= " + String.format("%04X", getProductId()) + ", path= " + getPath()
+ ", data=" + Arrays.toString(currentData) + "]";
+ ", usage= " + String.format("%04X", getUsage()) + ", data=" + Arrays.toString(currentData) + "]";
}
}

View File

@ -0,0 +1,39 @@
package net.ash.HIDToVPADNetworkClient.util;
import net.ash.HIDToVPADNetworkClient.controller.Controller;
import net.ash.HIDToVPADNetworkClient.hid.HidDevice;
import net.ash.HIDToVPADNetworkClient.hid.HidManager;
import net.ash.HIDToVPADNetworkClient.manager.ControllerManager;
import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
public class StatusReport {
public static String generateStatusReport() {
String report = "HID to VPAD Network Client\n\nRunning on ";
report += Settings.getPlattform();
report += "\nHID Backend: ";
report += HidManager.getBackendType();
report += "\nCurrently ";
report += (NetworkManager.getInstance().isConnected()) ? "Connected.\n" : "Disconnected.\n";
report += (NetworkManager.getInstance().isReconnecting()) ? "" : "Not ";
report += "Reconnecting.";
report += "\n\nCurrently attached controllers:";
for (Controller c : ControllerManager.getAttachedControllers()) {
report += "\n";
report += c.toString();
}
report += "\n\nFiltering settings:\n";
report += Settings.ControllerFiltering.getFilterStates();
report += "\n\nAll HIDs:";
for (HidDevice d : HidManager.getAllAttachedControllers()) {
report += "\n";
report += d.toString();
}
return report;
}
}