Skip to content

Commit 2801f62

Browse files
committed
add test gui for chat gpt
1 parent 33b547d commit 2801f62

1 file changed

Lines changed: 4 additions & 36 deletions

File tree

src/test/java/sqlbrowserfx/ChatGptWebViewTestGui.java

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,18 @@
22

33
import java.io.IOException;
44

5-
import gr.sqlbrowserfx.nodes.codeareas.java.JavaCodeArea;
5+
import gr.sqlbrowserfx.nodes.ChatGptWebView;
66
import javafx.application.Application;
77
import javafx.scene.Scene;
88
import javafx.scene.control.Button;
9-
import javafx.scene.control.ScrollPane;
109
import javafx.scene.layout.VBox;
11-
import javafx.scene.web.WebView;
1210
import javafx.stage.Stage;
1311

1412
public class ChatGptWebViewTestGui extends Application {
1513

1614
@Override
1715
public void start(Stage primaryStage) throws IOException {
18-
var webView = new WebView();
19-
var webEngine = webView.getEngine();
20-
// Force dark color scheme via CSS injection
21-
String darkModeCSS = """
22-
(function() {
23-
const style = document.createElement('style');
24-
style.textContent = `
25-
:root {
26-
color-scheme: dark;
27-
background-color: #222222 !important;
28-
color: #e0e0e0 !important;
29-
}
30-
html, body *:not(pre):not(pre *) {
31-
background-color: #222222 !important;
32-
color: #e0e0e0 !important;
33-
margin: 0 !important;
34-
35-
}
36-
`;
37-
document.documentElement.appendChild(style);
38-
})();
39-
""";
40-
41-
// Load ChatGPT and then apply dark mode styling
42-
webEngine.getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> {
43-
if (newState == javafx.concurrent.Worker.State.SUCCEEDED) {
44-
webEngine.executeScript(darkModeCSS);
45-
}
46-
});
47-
webEngine.load("https://chatgpt.com/");
48-
16+
var chatGptWebView = new ChatGptWebView();
4917
var pasteButton = new Button("test");
5018
pasteButton.setOnAction(event -> {
5119
String safeText = "This is a test text pasted from java"
@@ -66,10 +34,10 @@ public void start(Stage primaryStage) throws IOException {
6634
})();
6735
""".formatted(safeText);
6836

69-
webEngine.executeScript(js);
37+
chatGptWebView.getEngine().executeScript(js);
7038
});
7139
Scene scene = new Scene(
72-
new VBox(pasteButton, webView)
40+
new VBox(pasteButton, chatGptWebView)
7341
);
7442
scene.getStylesheets().add("/styles/flat-dark.css");
7543
primaryStage.setScene(scene);

0 commit comments

Comments
 (0)