use of javafx.concurrent.Worker.State in project Gargoyle by callakrsos.
the class WebViewExam method start.
/***********************************************************************************/
/* 이벤트 구현 */
@Override
public void start(Stage primaryStage) throws Exception {
WebView view = new WebView();
WebEngine engine = view.getEngine();
engine.setJavaScriptEnabled(true);
engine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {
@Override
public WebEngine call(PopupFeatures p) {
Stage stage = new Stage(StageStyle.UTILITY);
WebView wv2 = new WebView();
VBox vBox = new VBox(5);
vBox.getChildren().add(wv2);
vBox.getChildren().add(new Button("업로딩"));
wv2.getEngine().setJavaScriptEnabled(true);
stage.setScene(new Scene(vBox));
stage.show();
return wv2.getEngine();
}
});
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
primaryStage.setTitle(engine.getLocation());
}
}
});
engine.setConfirmHandler(new Callback<String, Boolean>() {
@Override
public Boolean call(String param) {
System.out.println("confirm handler : " + param);
return true;
}
});
engine.setOnAlert((WebEvent<String> wEvent) -> {
System.out.println("Alert Event - Message: " + wEvent.getData());
});
engine.load("http://localhost:15501/MemoWebapp/SmartEditor2.html");
primaryStage.setScene(new Scene(new BorderPane(view), 1200, 700));
primaryStage.show();
}
use of javafx.concurrent.Worker.State 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;
}
Aggregations