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();
  }
Beispiel #2
0
 public @Override void setVisible(boolean visible) {
   PlatformImpl.startup(
       new Runnable() {
         @Override
         public void run() {
           // No need to do anything here
         }
       });
   Platform.runLater(
       new Runnable() {
         @Override
         public void run() {
           final Stage s = new Stage();
           s.setTitle(title);
           Group root = new javafx.scene.Group();
           Scene scene = new Scene(root);
           GridPane gridpane = new GridPane();
           gridpane.setPadding(new Insets(5));
           gridpane.setHgap(5);
           gridpane.setVgap(5);
           int i = 0;
           for (Component c : components) {
             gridpane.add((Node) c, i % w, i / w);
             i++;
             if (i == w * h) break;
           }
           root.getChildren().add(gridpane);
           s.setScene(scene);
           s.setOnCloseRequest(
               new EventHandler<WindowEvent>() {
                 @Override
                 public void handle(WindowEvent event) {
                   Platform.runLater(
                       new Runnable() {
                         @Override
                         public void run() {
                           Platform.exit();
                         }
                       });
                 }
               });
           s.show();
         }
       });
 }
Beispiel #3
0
  /**
   * createScene
   *
   * <p>Note: Key is that Scene needs to be created and run on "FX user thread" NOT on the
   * AWT-EventQueue Thread
   */
  private void createScene() {
    PlatformImpl.startup(
        new Runnable() {
          @Override
          public void run() {

            stage = new Stage();

            stage.setTitle("Hello Java FX");
            stage.setResizable(true);

            StackPane root = new StackPane();
            //                Scene scene = new Scene(root, 519,165);
            Scene scene = new Scene(root, 519, 400);
            stage.setScene(scene);
            Platform.setImplicitExit(false);

            // Set up the embedded browser:
            browser = new WebView();
            final WebEngine webEngine = browser.getEngine();
            webEngine.setJavaScriptEnabled(true);
            webEngine.load(
                "http://warfront1.github.io/AutoFletcherElite/UserInterfaces/AutoFletcherElitePaint.html");
            webEngine
                .getLoadWorker()
                .stateProperty()
                .addListener(
                    new ChangeListener<Worker.State>() {
                      @Override
                      public void changed(
                          ObservableValue ov, Worker.State oldState, Worker.State newState) {
                        if (newState == Worker.State.SUCCEEDED) {
                          JSObject jso = (JSObject) webEngine.executeScript("window");
                          jso.setMember("java", new Bridge(webEngine));
                        }
                      }
                    });
            ObservableList<Node> children = root.getChildren();
            children.add(browser);

            jfxPanel.setScene(scene);
            webenginetoModify = webEngine;
          }
        });
  }
Beispiel #4
0
  private void checkVersion() {
    try {
      if (currentVersion.equals("dev") || currentVersion.equals("0.0.0")) {
        return;
      }

      if (!checker.isCurrent(currentVersion)) {
        final boolean required = !checker.isAllowed(currentVersion);

        String message =
            required
                ? getResources().getString("updateRequired")
                : getResources().getString("updatePossible");
        PlatformImpl.runAndWait(
            () -> {
              Alert alert =
                  new Alert(required ? WARNING : INFORMATION, message, cancelButton, updateButton);
              alertRef.set(alert);
              alert.setHeaderText(null);
              alert
                  .showAndWait()
                  .ifPresent(
                      buttonType -> {
                        if (buttonType == updateButton) {
                          try {
                            documentLauncher.accept(checker.getDesktopVersion().getDownloadURL());
                            shutdown.run();
                          } catch (Exception e) {
                            logger.error("failed to open download: " + e.getMessage(), e);
                          }
                        }
                        if (required) {
                          shutdown.run();
                        }
                      });
            });
      }
    } catch (Exception e) {
      logger.error("failed to check for updates: " + e.getMessage(), e);
    }
  }