private void initFooter() { webView.getEngine().load(BuildInfo.instance().getAdUrl()); webView .getEngine() .locationProperty() .addListener( (observable, oldValue, newValue) -> { if (BuildInfo.instance().getAdUrl().equals(oldValue)) { application.getHostServices().showDocument(newValue); } }); final Thread reloadThread = new Thread( () -> { while (true) { try { Thread.sleep(60000); javafx.application.Platform.runLater( () -> { webView.getEngine().reload(); }); } catch (final Exception e) { logger.log(Level.FINE, "Refresh failed", e); } } }, "AdvReloader"); reloadThread.setDaemon(true); reloadThread.start(); }
@Override public void initialize(URL location, ResourceBundle resources) { api = new APIConnect(); ValidatorBase require = new RequiredFieldValidator(); require.setMessage("ユーザIDは必須"); ValidatorBase validator = new UserValidator(api); validator.setMessage("無効なユーザID"); userField.getValidators().addAll(require, validator); userField .focusedProperty() .addListener( (o, oldVal, newVal) -> { if (!newVal) userField.validate(); setProblem(); }); postedCode .getEngine() .load(getClass().getResource("/resources/html/ace.html").toExternalForm()); obj = (JSObject) postedCode.getEngine().executeScript("window"); try { contest.getItems().addAll(api.getContests()); } catch (Exception e) { getAlert(e, "コンテスト情報の取得に失敗しました。").show(); return; } }
private void createWebView() { engine = webView.getEngine(); webView .getEngine() .load( "file:///Users/angelacaicedo/Work/JavaFX/JavaOne/JavaFX-HOLs/solutions/exercise3/JavaFX-HTML5/src/javafx/html5/content.html"); }
public void setClient(WebView view) { this.view = view; this.engine = view.getEngine(); JSObject window = (JSObject) engine.executeScript("window"); window.setMember("ide", this); Collection<IEclipseToBrowserFunction> onLoadFunctions = new ArrayList<IEclipseToBrowserFunction>(); IConfigurationElement[] extensions = BrowserExtensions.getExtensions( BrowserExtensions.EXTENSION_ID_ECLIPSE_TO_BROWSER, null, view.getEngine().locationProperty().get()); for (IConfigurationElement element : extensions) { try { String onLoad = element.getAttribute(BrowserExtensions.ELEMENT_ONLOAD); if (onLoad != null && onLoad.equals("true")) { onLoadFunctions.add( (IEclipseToBrowserFunction) WorkbenchPlugin.createExtension(element, BrowserExtensions.ELEMENT_CLASS)); } } catch (CoreException ex) { StatusManager.getManager() .handle( new Status( IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "Could not instantiate browser element provider extension.", ex)); return; } } callOnBrowser(onLoadFunctions); }
/** * Sets up the GUI, ensuring that everything is loaded nicely. * * @param location * @param resources */ public void initialize(URL location, ResourceBundle resources) { filter = new Filter(); Set<String> books = new HashSet<>(); for (Book book : Book.values()) { books.add(book.toString()); } filter.setBooks(books); results.setItems(listItems); String index = "java_ebook_search/index"; String home = "/java_ebook_search/view/index.html"; try { search = new Search(index); commonTerms = TextFields.bindAutoCompletion(query, search.getAutocomplete()); commonTerms.setVisibleRowCount(10); sc = new SpellCheck(); webEngine = webView.getEngine(); webEngine.load(getClass().getResource(home).toString()); results .getSelectionModel() .selectedItemProperty() .addListener((observable, oldValue, newValue) -> loadResult(newValue)); } catch (NullPointerException e) { System.out.println("It's happened again, ignore it"); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
private void createMasterPane() { webView = new WebView(); webViewAnchorPane = new AnchorPane(webView); AnchorPane.setBottomAnchor(webView, 0.0); AnchorPane.setTopAnchor(webView, 0.0); AnchorPane.setLeftAnchor(webView, 0.0); AnchorPane.setRightAnchor(webView, 0.0); webEngine = webView.getEngine(); dialog = Dialogs.create().lightweight().modal().owner(webView); // locals = new LocalJSObject(webEngine); // globals = GlobalJSObject.getGlobalJSObject(webEngine); javaScriptHelpers = new BurpKitBridge(webEngine); originalUserAgent = webEngine.getUserAgent(); webEngine.setJavaScriptEnabled(true); webEngine.setOnAlert(this::handleAlert); webEngine.setOnError(this::handleError); webEngine.setConfirmHandler(param -> true); webEngine.getLoadWorker().stateProperty().addListener(this::workerStateChanged); createToolBar(); createStatusBar(); webEngine.load("about:blank"); masterPane = new BorderPane(); masterPane.setTop(toolBar); masterPane.setCenter(webViewAnchorPane); masterPane.setBottom(statusBar); }
/** Initializes view and controls after FXML is loaded. */ public void initialize() { // setup view webView.setContextMenuEnabled(false); mWebEngine = webView.getEngine(); loadAceEditor(); loadModeList(); loadThemeList(); // process page loading mWebEngine .getLoadWorker() .stateProperty() .addListener( new ChangeListener<Worker.State>() { @Override public void changed( ObservableValue<? extends Worker.State> ov, Worker.State t, Worker.State t1) { if (mWebEngine.getLoadWorker().getState() == Worker.State.SUCCEEDED) { // extract javascript objects mAce = (JSObject) mWebEngine.executeScript("ace"); JSObject editor = (JSObject) mAce.call("edit", "editor"); mEditor = new Editor(editor); setEventCatchers(editor); setTheme(Themes.Chrome); setMode(Modes.Text); fireEvent(new Event(AceEvents.onLoadEvent)); } } }); }
private void initComponents() { Platform.runLater( () -> { myPane = new StackPane(); myWebComponent = new WebView(); myEngine = myWebComponent.getEngine(); if (myShowProgress) { myProgressBar = makeProgressBarWithListener(); myWebComponent.setVisible(false); myPane.getChildren().addAll(myWebComponent, myProgressBar); } else { myPane.getChildren().add(myWebComponent); } if (myLinkInNewBrowser) { initHyperlinkListener(); } Scene scene = new Scene(myPane); myPanel.setScene(scene); myPanel.setVisible(true); updateLaf( LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo); }); add(myPanel, BorderLayout.CENTER); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); }
@Override public void start(Stage primaryStage) { String url = handler.getConnectionUrl(); WebView browser = new WebView(); WebEngine webEngine = browser.getEngine(); webEngine.load(url); StackPane root = new StackPane(); root.getChildren().add(browser); Scene scene = new Scene(root, 650, 500); primaryStage.setTitle("Acces Token Getter"); primaryStage.setScene(scene); primaryStage.show(); primaryStage.setOnCloseRequest( new EventHandler<WindowEvent>() { public void handle(WindowEvent we) { try { String urlWithAT = webEngine.getLocation(); handler.setInputUrl(urlWithAT); handler.parseUrl(); handler.writeAccesTokenToFile(OUTPUT_FILE_NAME); System.out.print("See file: " + OUTPUT_FILE_NAME); } catch (Exception e) { System.out.print(e.getMessage()); } } }); }
@Override public void createPartControl(Composite container) { Platform.setImplicitExit(false); // Keep the JavaFX thread running // Creating a JavaFX Browser, so create an FXCanvas to contain it FXCanvas canvas = new FXCanvas(container, SWT.NONE); BorderPane borderPane = new BorderPane(); Scene scene = new Scene(borderPane); WebView browser = new WebView(); webEngine = browser.getEngine(); webEngine.load(homeLocation); borderPane.setCenter(browser); canvas.setScene(scene); IActionBars actionBars = getIntroSite().getActionBars(); IToolBarManager toolBar = actionBars.getToolBarManager(); setupToolbarButtons(toolBar); lockUrl(); addJSBridges(); }
private void initPane() { // WebEngine engine = optionView.getEngine(); try { Document document = Jsoup.connect(webView.getEngine().getLocation()).get(); Element table = document.select("#normal_basket_" + document.select("[name=item_id]").val()).first(); Element td = table.select("td").first(); Elements spans = td.select("span"); Elements selects = td.select("select"); // System.out.println(spans.size()); cmb = new ArrayList<ComboBox>(); for (int i = 0; i < spans.size(); i++) { ObservableList<ValuePair> obs = FXCollections.observableArrayList(); Elements options = selects.get(i).select("option"); for (int k = 0; k < options.size(); k++) { Element option = options.get(k); obs.add(new ValuePair("choice", option.text(), option.val())); } cmb.add(new ComboBox<ValuePair>(obs)); optionArea.getChildren().addAll(new Text(spans.get(i).text()), cmb.get(i)); } } catch (Exception e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } }
public void setWebview(WebView webview) { this.webview = webview; webview .getEngine() .setOnError( event -> { logger.error(event.getMessage(), event.getException()); }); webview .getEngine() .setOnAlert( event -> { logger.info(event.getData()); }); }
public class VueRegles extends GridPane { private defaultButton retour; private WebView browser = new WebView(); private WebEngine webEngine = browser.getEngine(); public VueRegles(Stage stage) { setHgap(10); setVgap(10); retour = new defaultButton("Retour"); URL urlRegles = getClass().getResource("Règles.html"); webEngine.load(urlRegles.toExternalForm()); browser.setPrefHeight(850); browser.setPrefWidth(1400); TitledPane tp = new TitledPane("Règles du jeu", browser); tp.setCollapsible(false); add(tp, 0, 0); add(retour, 0, 1); } public defaultButton getRetour() { return retour; } }
/** * Handle calls <i>from</i> Javascript functions on the browser. (This is called by reflection by * JavaFx so there won't be any apparent usages for this method.) * * @param functionId * @param argument */ public void call(String functionId, String argument) { try { IConfigurationElement element = BrowserExtensions.getExtension( BrowserExtensions.EXTENSION_ID_BROWSER_TO_ECLIPSE, functionId, view.getEngine().locationProperty().get()); if (element != null) { IBrowserToEclipseFunction function = (IBrowserToEclipseFunction) WorkbenchPlugin.createExtension(element, BrowserExtensions.ELEMENT_CLASS); function.call(argument); } else { StatusManager.getManager() .handle( new Status( IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "Could not instantiate browser function extension: " + functionId)); } } catch (CoreException ex) { StatusManager.getManager() .handle( new Status( IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "Could not find dashboard extension", ex)); return; } }
protected WebView getWebView() { if (engine == null) { webView = new WebView(); webView.setContextMenuEnabled(false); engine = webView.getEngine(); } return webView; }
@Override public void initialize(URL location, ResourceBundle resources) { urlField.setOnAction( event -> { String text = urlField.getText(); urlField.setText("tetetetetetetete"); webView.getEngine().load(text); }); webView .getEngine() .getLoadWorker() .stateProperty() .addListener( (ov, oldState, newState) -> { if (newState == State.SUCCEEDED) { String url = webView.getEngine().getLocation(); urlField.setText(url); if (Pattern.compile("http://item.rakuten.co.jp/.*").matcher(url).find()) { try { Elements tmp; Document document = Jsoup.connect(url).get(); tmp = document.select("input"); tmp = tmp.select("#etime"); if (tmp.size() != 0) { if (!(Long.parseLong(tmp.first().val()) < new Date().getTime())) { entryButton.setDisable(false); } } else { entryButton.setDisable(false); } } catch (Exception e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } } } ; }); entryButton.setOnAction( event -> { urlField.setText("webView disable"); sendEntryTaskController(); }); }
public void goToAddress() { String address = addressBar.getText(); if (!address.startsWith("http")) { address = "http://" + address; } WebEngine engine = webView.getEngine(); engine.load(address); }
public void goForward() { try { WebEngine engine = webView.getEngine(); WebHistory history = engine.getHistory(); history.go(1); } catch (Exception e) { } }
private void refreshWebView(Resource resource) { if (isVisible) { WebEngine engine = webview.getEngine(); engine .getLoadWorker() .stateProperty() .addListener( (observable, oldValue, newValue) -> { if (newValue.equals(Worker.State.SUCCEEDED)) { Document document = engine.getDocument(); Element documentElement = document.getDocumentElement(); if (documentElement != null) { ((EventTarget) documentElement) .addEventListener( "click", evt -> { if (evt.getTarget() instanceof ElementImpl) { Deque<ElementPosition> positions = new ArrayDeque<>(); ElementImpl currentElement = ((ElementImpl) evt.getTarget()); ElementImpl parent = (ElementImpl) currentElement.getParentElement(); while (parent != null) { NodeList children; if (StringUtils.isNotEmpty(currentElement.getNamespaceURI())) { children = parent.getElementsByTagNameNS( currentElement.getNamespaceURI(), currentElement.getNodeName()); } else { children = parent.getElementsByTagName(currentElement.getNodeName()); } for (int i = 0; i < children.getLength(); i++) { if (children.item(i) == currentElement) { ElementPosition position = new ElementPosition( currentElement.getNodeName(), i, currentElement.getNamespaceURI()); positions.push(position); } } currentElement = parent; parent = (ElementImpl) currentElement.getParentElement(); } editorManager.scrollTo(positions); } else { logger.info("clicked class " + evt.getTarget()); } }, false); } } }); engine.load("http://localhost:8777/" + resource.getHref()); } }
@Override public void initialize(URL location, ResourceBundle resources) { // TODO 自動生成されたメソッド・スタブ addOption.setOnAction( event -> { for (int i = 0; i < cmb.size(); i++) { // System.out.println(cmb.get(i).getValue()); if (cmb.get(i).getValue() == null) { break; } else if (i == cmb.size() - 1) { addTask.setDisable(false); } } }); addTask.setOnAction( event -> { try { String url = webView.getEngine().getLocation(); System.out.println(url); Document document = Jsoup.connect(url).get(); Elements input = document.select("input"); Map params = new HashMap<String, String>(); for (ComboBox cmbx : cmb) { ValuePair vp = (ValuePair) cmbx.getValue(); params.put(vp.getName(), vp.getvalue()); } // System.out.println(input.select("[name=shop_bid]").first()); // System.out.println(input.select("[name=shop_bid]").first().val()); params.put("shop_bid", input.select("[name=shop_bid]").first().val()); params.put("item_id", input.select("[name=item_id]").first().val()); params.put("__event", input.select("[name=__event]").first().val()); params.put("units", "1"); Map map = new HashMap<String, Long>(); // System.out.println(document.select("#stime").size()); if (document.select("#stime").size() != 0) { System.out.println(document.select("#stime")); map.put("stime", Long.parseLong((input.select("#stime").first().val()))); map.put("etime", Long.parseLong((input.select("#etime").first().val()))); } else { map = null; } BuyTask task = new BuyTask(url, params, map); task.call(); this.getScene().getWindow().hide(); } catch (Exception e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } }); }
private ProgressBar makeProgressBarWithListener() { final ProgressBar progress = new ProgressBar(); progress.progressProperty().bind(myWebComponent.getEngine().getLoadWorker().progressProperty()); myWebComponent .getEngine() .getLoadWorker() .stateProperty() .addListener( (ov, oldState, newState) -> { if (myWebComponent.getEngine().getLocation().contains("http") && newState == Worker.State.SUCCEEDED) { myProgressBar.setVisible(false); myWebComponent.setVisible(true); } }); return progress; }
public void initializeWebView(double width, double height) { WebView browser = new WebView(); String start = "file://"; String workingDir = start + System.getProperty("user.dir"); String url = workingDir + "/src/resources/commands.html"; browser.getEngine().load(url); browser.setPrefSize(width, height); myScrollPane.setContent(browser); myPane.getChildren().add(myScrollPane); }
public void setEditorManager(EditorTabManager editorManager) { editorManager .currentXHTMLResourceProperty() .addListener((observable, oldValue, newValue) -> refreshWebView(newValue)); editorManager .needsRefreshProperty() .addListener( (observable, oldValue, newValue) -> { if (newValue) { logger.info("getting reload event from needs refresh property"); webview.getEngine().reload(); } }); this.editorManager = editorManager; }
public JavaFxHtmlPanel() { // System.setProperty("prism.lcdtext", "false"); // System.setProperty("prism.text", "t2k"); myPanelWrapper = new JPanel(new BorderLayout()); myPanelWrapper.setBackground(JBColor.background()); ApplicationManager.getApplication() .invokeLater( () -> PlatformImpl.startup( () -> { myWebView = new WebView(); updateFontSmoothingType( myWebView, MarkdownApplicationSettings.getInstance() .getMarkdownPreviewSettings() .isUseGrayscaleRendering()); myWebView.setContextMenuEnabled(false); final WebEngine engine = myWebView.getEngine(); engine.getLoadWorker().stateProperty().addListener(myBridgeSettingListener); engine .getLoadWorker() .stateProperty() .addListener(myScrollPreservingListener); final Scene scene = new Scene(myWebView); ApplicationManager.getApplication() .invokeLater( () -> { myPanel = new JFXPanelWrapper(); myPanel.setScene(scene); setHtml(""); for (Runnable action : myInitActions) { Platform.runLater(action); } myInitActions.clear(); myPanelWrapper.add(myPanel, BorderLayout.CENTER); myPanelWrapper.repaint(); }); })); subscribeForGrayscaleSetting(); }
// Adding functionality to the forward button public String goForward() { final WebHistory history = browser.getEngine().getHistory(); ObservableList<WebHistory.Entry> entryList = history.getEntries(); int currentIndex = history.getCurrentIndex(); Platform.runLater(() -> history.go(1)); if (currentIndex < entryList.size() - 2) { entryList.get(currentIndex + 1); forwardButton.setDisable(false); } else { entryList.get(history.getCurrentIndex()); forwardButton.setDisable(true); backButton.setDisable(false); } return entryList.get(currentIndex).getUrl(); }
public Box_Guide(Stage owner) { super(); initOwner(owner); webView = new WebView(); webEngine = webView.getEngine(); BorderPane pane = new BorderPane(); String html = "<html><head><title>Test</title></head>" + "<body><h1>Help Guide using WebView</h1></body></html>"; webEngine.loadContent(html); pane.setCenter(webView); Scene scene = new Scene(pane); setScene(scene); setTitle("User Guide"); }
@Override public void start(Stage primaryStage) { WebView webView = new WebView(); final WebEngine engine = webView.getEngine(); engine.load(WebViewCharts.class.getResource("charts.html").toExternalForm()); Scene scene = new Scene(webView, 300, 250); engine .getLoadWorker() .stateProperty() .addListener( (e, o, n) -> { if (n == State.SUCCEEDED) { String js = constructJavaScript( "Beispiel-Tabelle", new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }, "Temperature", new Series( "Tokyo", new float[] { 7.0f, 6.9f, 9.5f, 14.5f, 18.2f, 21.5f, 25.2f, 26.5f, 23.3f, 18.3f, 13.9f, 9.6f }), new Series( "Munich", new float[] { -0.2f, 0.8f, 5.7f, 11.3f, 17.0f, 22.0f, 24.8f, 24.1f, 20.1f, 14.1f, 8.6f, 2.5f }), new Series( "London", new float[] { 3.9f, 4.2f, 5.7f, 8.5f, 11.9f, 15.2f, 17.0f, 16.6f, 14.2f, 10.3f, 6.6f, 4.8f })); engine.executeScript(js); } }); primaryStage.setTitle("JavaFX WebView Chart Demo"); primaryStage.setScene(scene); primaryStage.show(); }
public static void showWebBrowser(String title, String url) { final Stage dialog = new Stage(); dialog.setTitle(title); WebView browser = new WebView(); WebEngine engine = browser.getEngine(); engine.load(url); Scene dialogScene = new Scene(browser); dialogScene.getStylesheets().add(ResourceManager.getUIThemeStyle()); dialog.setScene(dialogScene); dialog.setMinHeight(700); dialog.setMinWidth(1050); dialog.show(); dialog.requestFocus(); }
@Override public void start(Stage stage) { indexer = new Indexer(); indexer.read("index.ser"); window = stage; window.setTitle("Browser"); // Layout BorderPane border = new BorderPane(); HBox hBox = new HBox(10); hBox.setPadding(new Insets(20, 20, 20, 20)); border.setTop(hBox); VBox vBox = new VBox(10); vBox.setPadding(new Insets(20, 20, 20, 20)); border.setCenter(vBox); // Search Bar / Button searchTextField = new TextField(); searchButton = new Button("Search"); searchTextField.setPrefWidth(1000); searchButton.setOnAction(event -> search()); label = new Label("Status: "); label.setPadding(new Insets(20, 20, 20, 20)); border.setBottom(label); // WebView webView = new WebView(); webEngine = webView.getEngine(); webView.isVisible(); vBox.getChildren().addAll(webView); hBox.getChildren().addAll(searchTextField, searchButton); scene = new Scene(border, 1200, 600); window.setScene(scene); stage.setResizable(false); window.show(); System.out.println(searchTextField.getText()); }
@FXML private void HandleValidateButtonAction(ActionEvent event) { String s = StringEscapeUtils.unescapeHtml(markdownToHtml(SourceText.getText())); if (corrector == null) { corrector = new Corrector(); } try { String result = corrector.checkHtmlContent(s); WebEngine webEngine = renderView.getEngine(); webEngine.loadContent( "<!doctype html><html lang='fr'><head><meta charset='utf-8'><base href='file://" + MainApp.class.getResource(".").getPath() + "' /></head><body>" + result + "</body></html>"); webEngine.setUserStyleSheetLocation( MainApp.class.getResource("css/content.css").toExternalForm()); } catch (DOMException e) { logger.error(e.getMessage(), e); } }