Update HelpTab.java

This commit is contained in:
Jafea7 2025-06-02 17:29:54 +10:00
parent 23b38bb6a2
commit 90d0479ea7
2 changed files with 84 additions and 12 deletions

View File

@ -3,12 +3,13 @@ package ctbrec.ui.tabs;
import ctbrec.Config;
import ctbrec.docs.DocServer;
import ctbrec.ui.DesktopIntegration;
import ctbrec.WANIPFetcher;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import lombok.extern.slf4j.Slf4j;
@ -22,33 +23,65 @@ public class HelpTab extends Tab {
private boolean serverStarted = false;
private String getWanIp() {
try {
return WANIPFetcher.getWANIP();
} catch (Exception e) {
return "Unavailable";
}
}
public HelpTab() {
setClosable(false);
setText("Help");
Label wanStaticLabel = new Label("WAN IP:");
wanStaticLabel.setStyle("-fx-font-family: 'Arial'; -fx-font-size: 14px; -fx-font-weight: bold; -fx-alignment: center;");
Label wanValueLabel = new Label(getWanIp());
wanValueLabel.setStyle("-fx-font-family: 'Arial'; -fx-font-size: 14px; -fx-underline: true; -fx-alignment: center;");
VBox wanLabelBox = new VBox(2);
wanLabelBox.setAlignment(Pos.CENTER);
wanLabelBox.getChildren().addAll(wanStaticLabel, wanValueLabel);
Button openHelp = new Button("Open Help");
openHelp.setStyle("-fx-font-family: 'Arial'; -fx-font-size: 16px; -fx-font-weight: bold; -fx-text-fill: #ffffff; -fx-background-color: #4CAF50; -fx-padding: 15 30; -fx-border-radius: 5; -fx-background-radius: 5;");
Button openLog = new Button("Open Log File");
Button openCfg = new Button("Open config dir");
openHelp.setPadding(new Insets(20));
openLog.setPadding(new Insets(20));
openCfg.setPadding(new Insets(20));
Label logFilePathLabel = new Label("Log file: " + new File("ctbrec.log").getAbsolutePath());
openLog.setStyle("-fx-font-family: 'Arial'; -fx-font-size: 16px; -fx-font-weight: bold; -fx-text-fill: #ffffff; -fx-background-color: #2196F3; -fx-padding: 15 30; -fx-border-radius: 5; -fx-background-radius: 5;");
Button openCfg = new Button("Open Config Dir");
openCfg.setStyle("-fx-font-family: 'Arial'; -fx-font-size: 16px; -fx-font-weight: bold; -fx-text-fill: #ffffff; -fx-background-color: #FF9800; -fx-padding: 15 30; -fx-border-radius: 5; -fx-background-radius: 5;");
File cfgDir = Config.getInstance().getConfigDir();
String path = (cfgDir != null) ? cfgDir.getAbsolutePath() : "Unknown";
Label configPathLabel = new Label("Config dir: " + path);
Label configStaticLabel = new Label("Config Dir:");
configStaticLabel.setStyle("-fx-font-family: 'Arial'; -fx-font-size: 14px; -fx-font-weight: bold; -fx-alignment: center;");
Label configValueLabel = new Label(path);
configValueLabel.setStyle("-fx-font-family: 'Arial'; -fx-font-size: 14px; -fx-underline: true; -fx-alignment: center;");
VBox configLabelBox = new VBox(2);
configLabelBox.setAlignment(Pos.CENTER);
configLabelBox.getChildren().addAll(configStaticLabel, configValueLabel);
Label logStaticLabel = new Label("Log File:");
logStaticLabel.setStyle("-fx-font-family: 'Arial'; -fx-font-size: 14px; -fx-font-weight: bold; -fx-alignment: center;");
Label logValueLabel = new Label(new File("ctbrec.log").getAbsolutePath());
logValueLabel.setStyle("-fx-font-family: 'Arial'; -fx-font-size: 14px; -fx-underline: true; -fx-alignment: center;");
VBox logLabelBox = new VBox(2);
logLabelBox.setAlignment(Pos.CENTER);
logLabelBox.getChildren().addAll(logStaticLabel, logValueLabel);
// Create VBox for all components
VBox vbox = new VBox();
vbox.setAlignment(Pos.CENTER); // Center align the buttons
vbox.setSpacing(20); // Set a 20 pixel gap between the buttons
vbox.getChildren().addAll(openHelp, openCfg, configPathLabel, openLog, logFilePathLabel);
vbox.setAlignment(Pos.CENTER);
vbox.setSpacing(20);
vbox.getChildren().addAll(wanLabelBox, openHelp, configLabelBox, openCfg, logLabelBox, openLog);
BorderPane layout = new BorderPane();
// Add the VBox to the center region of the BorderPane
layout.setCenter(vbox);
setContent(layout);
// Button actions remain unchanged
openHelp.setOnAction(e -> {
if (!serverStarted) {
startDocumentationServer();

View File

@ -0,0 +1,39 @@
package ctbrec;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
public class WANIPFetcher {
public static void main(String[] args) {
try {
String ip = getWANIP();
System.out.println("Your WAN IP address is: " + ip);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getWANIP() throws Exception {
URI uri = new URI("https://icanhazip.com");
URL url = uri.toURL(); // Convert URI to URL
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
connection.disconnect();
return content.toString().trim();
}
}