Update HelpTab.java
This commit is contained in:
parent
6a7db51663
commit
1e7620452c
|
@ -4,12 +4,13 @@ import ctbrec.Config;
|
||||||
import ctbrec.OS;
|
import ctbrec.OS;
|
||||||
import ctbrec.docs.DocServer;
|
import ctbrec.docs.DocServer;
|
||||||
import ctbrec.ui.DesktopIntegration;
|
import ctbrec.ui.DesktopIntegration;
|
||||||
|
import ctbrec.WANIPFetcher;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Tab;
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.Tab;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -23,33 +24,65 @@ public class HelpTab extends Tab {
|
||||||
|
|
||||||
private boolean serverStarted = false;
|
private boolean serverStarted = false;
|
||||||
|
|
||||||
|
private String getWanIp() {
|
||||||
|
try {
|
||||||
|
return WANIPFetcher.getWANIP();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "Unavailable";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public HelpTab() {
|
public HelpTab() {
|
||||||
setClosable(false);
|
setClosable(false);
|
||||||
setText("Help");
|
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");
|
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 openLog = new Button("Open Log File");
|
||||||
Button openCfg = new Button("Open config dir");
|
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;");
|
||||||
openHelp.setPadding(new Insets(20));
|
|
||||||
openLog.setPadding(new Insets(20));
|
Button openCfg = new Button("Open Config Dir");
|
||||||
openCfg.setPadding(new Insets(20));
|
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;");
|
||||||
Label logFilePathLabel = new Label("Log file: " + new File("ctbrec.log").getAbsolutePath());
|
|
||||||
File cfgDir = Config.getInstance().getConfigDir();
|
File cfgDir = Config.getInstance().getConfigDir();
|
||||||
String path = (cfgDir != null) ? cfgDir.getAbsolutePath() : "Unknown";
|
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 vbox = new VBox();
|
||||||
vbox.setAlignment(Pos.CENTER); // Center align the buttons
|
vbox.setAlignment(Pos.CENTER);
|
||||||
vbox.setSpacing(20); // Set a 20 pixel gap between the buttons
|
vbox.setSpacing(20);
|
||||||
vbox.getChildren().addAll(openHelp, openCfg, configPathLabel, openLog, logFilePathLabel);
|
vbox.getChildren().addAll(wanLabelBox, openHelp, configLabelBox, openCfg, logLabelBox, openLog);
|
||||||
|
|
||||||
BorderPane layout = new BorderPane();
|
BorderPane layout = new BorderPane();
|
||||||
|
|
||||||
// Add the VBox to the center region of the BorderPane
|
|
||||||
layout.setCenter(vbox);
|
layout.setCenter(vbox);
|
||||||
|
|
||||||
setContent(layout);
|
setContent(layout);
|
||||||
|
|
||||||
|
// Button actions remain unchanged
|
||||||
openHelp.setOnAction(e -> {
|
openHelp.setOnAction(e -> {
|
||||||
if (!serverStarted) {
|
if (!serverStarted) {
|
||||||
startDocumentationServer();
|
startDocumentationServer();
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue