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();
}
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 SimpleTextView method miOpenNamoWebViewOnAction.
/**
* Mime 데이터타입을 Html컨텐츠형태로 조회하기 위한 웹 뷰를 오픈함.
* @작성자 : KYJ
* @작성일 : 2016. 12. 29.
*/
@FXML
public void miOpenNamoWebViewOnAction() {
String content = codeArea.getText();
try {
WebView webView = new WebView();
// new ContentMimeHtmlAdapter(content)
// String encodeToString = Base64.getEncoder().encodeToString(content.getBytes());
//
// byte[] decode = Base64.getDecoder().decode(encodeToString);
// String string = new String(decode);
// MimeBodyPart part = new MimeBodyPart(new ByteArrayInputStream(content.getBytes()));
// Enumeration allHeaders = part.getAllHeaders();
// while(allHeaders.hasMoreElements())
// {
// javax.mail.Header nextElement = (Header) allHeaders.nextElement();
//
// System.out.println(nextElement.getName());
// System.out.println(nextElement.getValue());
// }
//
// DataHandler dataHandler = part.getDataHandler();
// Object transferData = dataHandler.getTransferData(new DataFlavor("text/html"));
// System.out.println(transferData);
// ContentMimeHtmlAdapter adapter = new ContentMimeHtmlAdapter(content);
// File tempFile = adapter.toTempFile();
// byte[] decode = Base64.getMimeDecoder().decode(content.getBytes("UTF-8"));
// String string = new String(decode);
FxUtil.createStageAndShow(webView, stage -> {
stage.setAlwaysOnTop(true);
stage.initOwner(getScene().getWindow());
stage.focusedProperty().addListener((oba, o, n) -> {
if (!n)
stage.close();
});
});
javafx.application.Platform.runLater(() -> {
try {
MimeToHtmlAdapter adapter = new MimeToHtmlAdapter(content);
webView.getEngine().loadContent(adapter.getContent());
} catch (Exception e) {
e.printStackTrace();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
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 POL-POM-5 by PhoenicisOrg.
the class ApplicationPanel method populateCenter.
private void populateCenter() {
this.appDescription = new WebView();
this.appDescription.getEngine().loadContent("<body>" + application.getDescription() + "</body>");
themeManager.bindWebEngineStylesheet(appDescription.getEngine().userStyleSheetLocationProperty());
this.installers = new Label(tr("Installers"));
this.installers.getStyleClass().add("descriptionTitle");
this.scriptGrid = new GridPane();
filteredScripts.addListener((InvalidationListener) change -> this.refreshScripts());
this.refreshScripts();
this.miniaturesPane = new HBox();
this.miniaturesPane.getStyleClass().add("appPanelMiniaturesPane");
this.miniaturesPaneWrapper = new ScrollPane(miniaturesPane);
this.miniaturesPaneWrapper.getStyleClass().add("appPanelMiniaturesPaneWrapper");
for (URI miniatureUri : application.getMiniatures()) {
Region image = new Region();
image.getStyleClass().add("appMiniature");
image.setStyle(String.format("-fx-background-image: url(\"%s\");", miniatureUri.toString()));
image.prefHeightProperty().bind(miniaturesPaneWrapper.heightProperty().multiply(0.8));
image.prefWidthProperty().bind(image.prefHeightProperty().multiply(1.5));
miniaturesPane.getChildren().add(image);
}
this.center = new VBox(appDescription, installers, scriptGrid, miniaturesPaneWrapper);
VBox.setVgrow(appDescription, Priority.ALWAYS);
this.setCenter(center);
}
Aggregations