Example #1
1
 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();
 }
Example #2
0
  /** 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));
                }
              }
            });
  }
Example #3
0
  @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();
  }
 public void initView() {
   try {
     // check if 3d sample and on supported platform
     loadCode();
     // create code view
     WebView webView = getWebView();
     webView.setPrefWidth(300);
     engine.loadContent(htmlCode);
     ToolBar codeToolBar = new ToolBar();
     codeToolBar.setId("code-tool-bar");
     Button copyCodeButton = new Button("Copy Source");
     copyCodeButton.setOnAction(
         new EventHandler<ActionEvent>() {
           public void handle(ActionEvent actionEvent) {
             Map<DataFormat, Object> clipboardContent = new HashMap<DataFormat, Object>();
             clipboardContent.put(DataFormat.PLAIN_TEXT, rawCode);
             clipboardContent.put(DataFormat.HTML, htmlCode);
             Clipboard.getSystemClipboard().setContent(clipboardContent);
           }
         });
     codeToolBar.getItems().addAll(copyCodeButton);
     setTop(codeToolBar);
     setCenter(webView);
   } catch (Exception e) {
     e.printStackTrace();
     setCenter(new Text("Failed to create sample because of [" + e.getMessage() + "]"));
   }
 }
  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);
  }
Example #6
0
 @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;
   }
 }
  @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());
            }
          }
        });
  }
 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);
 }
 /*     */ public void setCursor(long paramLong) /*     */ {
   /*  48 */ WebView localWebView = this.accessor.getView();
   /*  49 */ if (localWebView != null) {
     /*  50 */ Object localObject = CursorManager.getCursorManager().getCursor(paramLong);
     /*  51 */ localWebView.setCursor(
         (localObject instanceof Cursor) ? (Cursor) localObject : Cursor.DEFAULT);
     /*     */ }
   /*     */ }
Example #11
0
 protected WebView getWebView() {
   if (engine == null) {
     webView = new WebView();
     webView.setContextMenuEnabled(false);
     engine = webView.getEngine();
   }
   return webView;
 }
 /*     */ public void confirmStartDrag() /*     */ {
   /* 174 */ WebView localWebView = this.accessor.getView();
   /* 175 */ if ((localWebView != null) && (this.content != null))
   /*     */ {
     /* 177 */ Dragboard localDragboard = localWebView.startDragAndDrop(TransferMode.ANY);
     /* 178 */ localDragboard.setContent(this.content);
     /*     */ }
   /* 180 */ this.content = null;
   /*     */ }
Example #13
0
 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 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();
  }
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;
  }
}
Example #16
0
  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);
  }
 /*     */ public WCPoint screenToWindow(WCPoint paramWCPoint) {
   /* 108 */ WebView localWebView = this.accessor.getView();
   /* 109 */ Scene localScene = localWebView.getScene();
   /* 110 */ Window localWindow = null;
   /*     */
   /* 112 */ if ((localScene != null) && ((localWindow = localScene.getWindow()) != null))
   /*     */ {
     /* 115 */ Point2D localPoint2D =
         localWebView.sceneToLocal(
             paramWCPoint.getX() - localWindow.getX() - localScene.getX(),
             paramWCPoint.getY() - localWindow.getY() - localScene.getY());
     /*     */
     /* 118 */ return new WCPoint((float) localPoint2D.getX(), (float) localPoint2D.getY());
     /*     */ }
   /* 120 */ return new WCPoint(0.0F, 0.0F);
   /*     */ }
 /*     */ public WCPoint windowToScreen(WCPoint paramWCPoint) /*     */ {
   /* 125 */ WebView localWebView = this.accessor.getView();
   /* 126 */ Scene localScene = localWebView.getScene();
   /* 127 */ Window localWindow = null;
   /*     */
   /* 129 */ if ((localScene != null) && ((localWindow = localScene.getWindow()) != null))
   /*     */ {
     /* 132 */ Point2D localPoint2D =
         localWebView.localToScene(paramWCPoint.getX(), paramWCPoint.getY());
     /* 133 */ return new WCPoint(
         (float) (localPoint2D.getX() + localScene.getX() + localWindow.getX()),
         (float) (localPoint2D.getY() + localScene.getY() + localWindow.getY()));
     /*     */ }
   /*     */
   /* 136 */ return new WCPoint(0.0F, 0.0F);
   /*     */ }
Example #19
0
  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());
            });
  }
  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 WCRectangle getViewBounds() /*     */ {
   /*  71 */ WebView localWebView = this.accessor.getView();
   /*  72 */ Window localWindow = null;
   /*  73 */ if ((localWebView != null)
       && (localWebView.getScene() != null)
       && ((localWindow = localWebView.getScene().getWindow()) != null))
   /*     */ {
     /*  77 */ return new WCRectangle(
         (float) localWindow.getX(),
         (float) localWindow.getY(),
         (float) localWindow.getWidth(),
         (float) localWindow.getHeight());
     /*     */ }
   /*     */
   /*  81 */ return null;
   /*     */ }
  /**
   * 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();
    }
  }
Example #23
0
 public static BufferedImage getScreenshot(WebView browser) {
   if (browser != null) {
     WritableImage returnimage = browser.snapshot(new SnapshotParameters(), null);
     return SwingFXUtils.fromFXImage(returnimage, null);
   }
   return null;
 }
 /**
  * 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;
   }
 }
  @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();
        });
  }
Example #26
0
 public void goToAddress() {
   String address = addressBar.getText();
   if (!address.startsWith("http")) {
     address = "http://" + address;
   }
   WebEngine engine = webView.getEngine();
   engine.load(address);
 }
  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);
  }
Example #28
0
 @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();
 }
Example #29
0
  public void goForward() {
    try {
      WebEngine engine = webView.getEngine();
      WebHistory history = engine.getHistory();
      history.go(1);
    } catch (Exception e) {

    }
  }
Example #30
0
 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());
   }
 }