use of javafx.scene.web.WebEngine in project azure-tools-for-java by Microsoft.
the class JobViewFxUtil method startFx.
public static Object startFx(Object composite, final String webUrl, Object jobUtils) {
try {
Class compositeClass = Class.forName("org.eclipse.swt.widgets.Composite");
Class[] paramTypes = { compositeClass, int.class };
Constructor con = FXCanvas.class.getConstructor(paramTypes);
Object[] parames = { composite, 1 << 16 };
final FXCanvas canvas = (FXCanvas) con.newInstance(parames);
Platform.setImplicitExit(false);
Platform.runLater(new Runnable() {
@Override
public void run() {
final WebView webView = new WebView();
Scene scene = new Scene(webView);
canvas.setScene(scene);
WebEngine webEngine = webView.getEngine();
webEngine.load(webUrl);
webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
@Override
public void changed(ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) {
if (newState == Worker.State.SUCCEEDED) {
JSObject win = (JSObject) webEngine.executeScript("window");
win.setMember("JobUtils", new JobUtilsForEclipse());
}
}
});
}
});
return canvas;
} catch (Exception e) {
return e;
}
}
use of javafx.scene.web.WebEngine 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.scene.web.WebEngine in project Gargoyle by callakrsos.
the class WebViewConsole method exec.
private void exec() {
try {
WebEngine engine = wb.getEngine();
Object obj = engine.executeScript(txtCommand.getText());
// JSObject obj = (JSObject)
if (obj instanceof String) {
txtResult.appendText(obj.toString());
} else if (obj instanceof HTMLDocument) {
txtResult.appendText(toHtmlElement((HTMLDocument) obj));
} else if (obj instanceof Node) {
Node n = (Node) obj;
txtResult.appendText(toNodeInfo(n));
} else {
txtResult.appendText(obj.toString());
}
txtResult.appendText("\n");
} catch (NullPointerException e) {
txtResult.appendText("undefinded");
txtResult.appendText("\n");
} catch (Exception e) {
txtResult.appendText(e.getMessage());
txtResult.appendText("\n");
}
}
use of javafx.scene.web.WebEngine in project PokeGOAPI-Java by Grover-c13.
the class SolveCaptchaExample method completeCaptcha.
private static void completeCaptcha(final PokemonGo api, final String challengeURL) {
//Run this on the swing thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
//Run on JFX Thread
Platform.runLater(new Runnable() {
@Override
public void run() {
JFXPanel panel = new JFXPanel();
//Create a WebView and WebEngine to display the captcha from challengeURL.
WebView view = new WebView();
WebEngine engine = view.getEngine();
//Set UserAgent so the captcha shows correctly in the WebView.
engine.setUserAgent(CaptchaSolveHelper.USER_AGENT);
engine.load(challengeURL);
final JFrame frame = new JFrame("Solve Captcha");
//Register listener to receive the token when the captcha has been solved from inside the WebView.
CaptchaSolveHelper.Listener listener = new CaptchaSolveHelper.Listener() {
@Override
public void onTokenReceived(String token) {
System.out.println("Token received: " + token + "!");
//Remove this listener as we no longer need to listen for tokens, the captcha has been solved.
CaptchaSolveHelper.removeListener(this);
try {
//Close this window, it not valid anymore.
frame.setVisible(false);
frame.dispose();
if (api.verifyChallenge(token)) {
System.out.println("Captcha was correctly solved!");
} else {
//verifyChallenge will receive a new captcha url if this one is invalid
System.out.println("Captcha was incorrectly solved! Please try again.");
}
} catch (Exception e) {
Log.e("Main", "Error while solving captcha!", e);
}
}
};
CaptchaSolveHelper.registerListener(listener);
//Applies the WebView to this panel
panel.setScene(new Scene(view));
frame.getContentPane().add(panel);
frame.setSize(500, 500);
frame.setVisible(true);
//Don't allow this window to be closed
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.out.println("Please solve the captcha before closing the window!");
}
});
}
});
}
});
}
use of javafx.scene.web.WebEngine in project intellij-community by JetBrains.
the class IpnbJfxUtils method adjustHeight.
private static void adjustHeight(final WebView webView, final JFXPanel javafxPanel, String source) {
final WebEngine engine = webView.getEngine();
final Document document = engine.getDocument();
if (document != null) {
final Element mydiv = document.getElementById("mydiv");
if (mydiv != null) {
final WebPage webPage = Accessor.getPageFor(engine);
final WCSize wcsize = webPage.getContentSize(webPage.getMainFrame());
final int height = wcsize.getIntHeight();
int width = wcsize.getIntWidth();
if (width < javafxPanel.getWidth())
width = javafxPanel.getWidth();
if (height <= 0 || width <= 0)
return;
webView.setPrefWidth(wcsize.getWidth());
webView.setMinWidth(wcsize.getWidth());
int count = 1;
if (source.contains("```")) {
count += 1;
}
boolean inMath = false;
if (source.contains("\\frac")) {
count += 1;
}
while (source.contains("$$")) {
if (inMath) {
final String substring = source.substring(0, source.indexOf("$$") + 2);
count += StringUtil.countNewLines(substring);
for (int i = 0, len = substring.length(); i < len; ++i) {
if (substring.charAt(i) == '\\' && i + 1 < substring.length() && substring.charAt(i + 1) == '\\') {
count++;
i += 1;
}
}
}
inMath = !inMath;
source = source.substring(source.indexOf("$$") + 2);
}
int finalHeight = height + count * EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize();
int finalWidth = width;
UIUtil.invokeLaterIfNeeded(() -> {
final Dimension size = new Dimension(finalWidth, finalHeight);
javafxPanel.setPreferredSize(size);
javafxPanel.setMinimumSize(size);
javafxPanel.revalidate();
});
}
}
}
Aggregations