LightweightGUI

This commit is contained in:
rusefi 2020-06-05 22:11:38 -04:00
parent 9990a48c7f
commit 830a3ee4dd
4 changed files with 93 additions and 1 deletions

View File

@ -38,7 +38,7 @@ public class StartupFrame {
// todo: figure out a better way to work with absolute path
private static final String APPICON = "appicon.png";
private static final String LOGO = "logo.gif";
public static final String LINK_TEXT = "rusEfi (c) 2012-2020";
public static final String LINK_TEXT = "rusEFI (c) 2012-2020";
private static final String URI = "http://rusefi.com/?java_console";
// private static final int RUSEFI_ORANGE = 0xff7d03;

View File

@ -21,6 +21,7 @@ import com.rusefi.maintenance.ExecHelper;
import com.rusefi.tools.online.Online;
import com.rusefi.tune.xml.Msq;
import com.rusefi.ui.AuthTokenPanel;
import com.rusefi.ui.light.LightweightGUI;
import org.jetbrains.annotations.Nullable;
import javax.xml.bind.JAXBException;
@ -57,11 +58,18 @@ public class ConsoleTools {
registerTool("upload_tune", ConsoleTools::uploadTune, "Upload specified tune file using auth token from settings");
registerTool("lightui", ConsoleTools::lightUI, "Start lightweight GUI for tiny screens");
registerTool("detect", ConsoleTools::detect, "Find attached rusEFI");
registerTool("reboot_ecu", args -> sendCommand(Fields.CMD_REBOOT), "Sends a command to reboot rusEFI controller.");
registerTool(Fields.CMD_REBOOT_DFU, args -> sendCommand(Fields.CMD_REBOOT_DFU), "Sends a command to switch rusEFI controller into DFU mode.");
}
private static void lightUI(String[] strings) {
LightweightGUI.start();
}
private static void uploadTune(String[] args) throws IOException {
String fileName = args[1];
String authToken = AuthTokenPanel.getAuthToken();

View File

@ -0,0 +1,60 @@
package com.rusefi.ui.light;
import com.rusefi.Timeouts;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.HttpURLConnection;
import java.net.URL;
public class InternetStatus {
public static final String GOOGLE = "http://google.com";
private final JLabel status = new JLabel();
public InternetStatus() {
new Thread(() -> {
while (true) {
boolean isConnected = isServerReachable();
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
if (isConnected) {
status.setText("online");
status.setForeground(Color.green);
} else {
status.setText("offline");
status.setForeground(Color.red);
}
}
});
Thread.sleep(Timeouts.SECOND);
} catch (InterruptedException | InvocationTargetException e) {
// ignore
}
}
}).start();
}
private static boolean isServerReachable() {
try {
URL urlServer = new URL(GOOGLE);
HttpURLConnection urlConn = (HttpURLConnection) urlServer.openConnection();
urlConn.setConnectTimeout(3000); //<- 3Seconds Timeout
urlConn.connect();
if (urlConn.getResponseCode() == 200) {
return true;
} else {
return false;
}
} catch (IOException e1) {
return false;
}
}
public Component getContent() {
return status;
}
}

View File

@ -0,0 +1,24 @@
package com.rusefi.ui.light;
import com.rusefi.StartupFrame;
import com.rusefi.rusEFIVersion;
import com.rusefi.ui.util.FrameHelper;
import javax.swing.*;
import java.awt.*;
public class LightweightGUI {
public static void start() {
FrameHelper frameHelper = new FrameHelper();
JPanel content = new JPanel(new BorderLayout());
frameHelper.getFrame().setTitle("rusEFI Lightweight " + rusEFIVersion.CONSOLE_VERSION);
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
topPanel.add(new InternetStatus().getContent());
content.add(topPanel, BorderLayout.NORTH);
content.add(new JLabel(StartupFrame.LINK_TEXT), BorderLayout.CENTER);
frameHelper.showFrame(content, true);
}
}