use of javafx.scene.web.WebView in project Gargoyle by callakrsos.
the class SimpleTextView method miOpenHtmlWevViewOnAction.
@FXML
public void miOpenHtmlWevViewOnAction() {
String content = codeArea.getText();
try {
WebView webView = new WebView();
webView.getEngine().loadContent(content);
FxUtil.createStageAndShow(webView, stage -> {
stage.setAlwaysOnTop(true);
stage.initOwner(getScene().getWindow());
stage.focusedProperty().addListener((oba, o, n) -> {
if (!n)
stage.close();
});
});
} catch (Exception e) {
e.printStackTrace();
}
}
use of javafx.scene.web.WebView in project Gargoyle by callakrsos.
the class FxUtil method openBrowser.
public static WebView openBrowser(Node parent, String content, boolean isLink) {
WebView view = new WebView();
WebEngine engine = view.getEngine();
engine.setOnError(err -> {
String message = err.getMessage();
DialogUtil.showMessageDialog(FxUtil.getWindow(parent), message);
});
view.setOnKeyPressed(key -> {
if (key.getCode() == KeyCode.F12) {
FxUtil.createStageAndShow("Simple Web Console", new WebViewConsole(view));
}
});
engine.setJavaScriptEnabled(true);
engine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {
@Override
public WebEngine call(PopupFeatures p) {
// Stage stage = new Stage();
// WebView wv2 = new WebView();
//
// wv2.getEngine().setJavaScriptEnabled(true);
//
// stage.setScene(new Scene(wv2, BROWSER_WIDTH,
// BROWSER_HEIGHT));
// stage.initOwner(parent == null ? (Window) null :
// parent.getScene().getWindow());
// stage.show();
WebView openBrowser = openBrowser(view, "", false);
return openBrowser.getEngine();
}
});
engine.setOnAlert(ev -> {
DialogUtil.showMessageDialog(ev.getData());
});
engine.setConfirmHandler(new Callback<String, Boolean>() {
@Override
public Boolean call(String param) {
Optional<Pair<String, String>> showYesOrNoDialog = DialogUtil.showYesOrNoDialog("Confirm.", param);
if (showYesOrNoDialog.isPresent()) {
Pair<String, String> pair = showYesOrNoDialog.get();
if (pair == null)
return false;
return "Y".equals(pair.getValue());
}
return false;
}
});
engine.setOnAlert((WebEvent<String> wEvent) -> {
System.out.println("Alert Event - Message: " + wEvent.getData());
});
if (isLink)
engine.load(content);
else
engine.loadContent(content);
BorderPane root = new BorderPane(view);
TextField txtLink = new TextField(content);
txtLink.addEventHandler(KeyEvent.KEY_PRESSED, ev -> {
if (KeyCode.ENTER == ev.getCode())
engine.load(txtLink.getText());
});
root.setTop(txtLink);
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
// if (newValue == State.SUCCEEDED) {
String location = engine.getLocation();
txtLink.setText(location);
// }
}
});
FxUtil.createStageAndShow(new Scene(root, BROWSER_WIDTH, BROWSER_HEIGHT), stage -> {
stage.initOwner(parent == null ? (Window) null : parent.getScene().getWindow());
});
return view;
}
use of javafx.scene.web.WebView in project Gargoyle by callakrsos.
the class MimeViewerExam method start.
@Override
public void start(Stage primaryStage) throws Exception {
WebView center = new WebView();
WebEngine engine = center.getEngine();
URL resource = MimeViewerExam.class.getResource("Sample.html");
// String externalForm = resource.toExternalForm();
String readToString = FileUtil.readToString(resource.openStream());
System.out.println("##########################################");
System.out.println("mime string");
System.out.println(readToString);
System.out.println("##########################################");
final MessageBuilder builder = new DefaultMessageBuilder();
final Message message = builder.parseMessage(resource.openStream());
Body body = ((Entity) message).getBody();
StringBuilder sb = new StringBuilder();
extracted(sb, body);
Document parse = Jsoup.parse(sb.toString());
Elements select = parse.select("img");
select.forEach(e -> {
String attr = e.attr("src");
if (attr.startsWith("cid:")) {
String cid = attr.replace("cid:", "");
String string = meta.get(cid);
e.attr("src", "data:image/jpg;base64,".concat(string));
}
});
System.out.println("##########################################");
System.out.println("html string");
System.out.println(sb.toString());
System.out.println("##########################################");
System.out.println(parse.toString());
engine.loadContent(sb.toString(), "text/html");
primaryStage.setScene(new Scene(new BorderPane(center)));
primaryStage.show();
}
use of javafx.scene.web.WebView in project Gargoyle by callakrsos.
the class HtmlEditorExam method start.
@Override
public void start(Stage stage) {
stage.setTitle("HTMLEditor Sample");
stage.setWidth(500);
stage.setHeight(500);
Scene scene = new Scene(new Group());
VBox root = new VBox();
root.setPadding(new Insets(8, 8, 8, 8));
root.setSpacing(5);
root.setAlignment(Pos.BOTTOM_LEFT);
final HTMLEditor htmlEditor = new HTMLEditor();
htmlEditor.setPrefHeight(245);
htmlEditor.setHtmlText(INITIAL_TEXT);
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
ScrollPane scrollPane = new ScrollPane();
scrollPane.getStyleClass().add("noborder-scroll-pane");
scrollPane.setStyle("-fx-background-color: white");
scrollPane.setContent(browser);
scrollPane.setFitToWidth(true);
scrollPane.setPrefHeight(180);
Button showHTMLButton = new Button("Load Content in Browser");
root.setAlignment(Pos.CENTER);
showHTMLButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
webEngine.loadContent(htmlEditor.getHtmlText());
}
});
root.getChildren().addAll(htmlEditor, showHTMLButton, scrollPane);
scene.setRoot(root);
stage.setScene(scene);
stage.show();
}
Aggregations