Search in sources :

Example 26 with JFXPanel

use of javafx.embed.swing.JFXPanel in project open-ecard by ecsec.

the class HTMLPanel method createPanel.

/**
 * Create a new JPanel containing the Java FX components to render HTML.
 *
 * @param mimeType The MimeType of the {@code content} to display.
 * @param content The content to display.
 * @return A JPanel displaying the content.
 */
public static JPanel createPanel(final String mimeType, final byte[] content) {
    contentPane = new JPanel();
    jfxPane = new JFXPanel();
    contentPane.add(jfxPane);
    Platform.runLater(new Runnable() {

        @Override
        public void run() {
            initFx(mimeType, content);
        }
    });
    return contentPane;
}
Also used : JPanel(javax.swing.JPanel) JFXPanel(javafx.embed.swing.JFXPanel)

Example 27 with JFXPanel

use of javafx.embed.swing.JFXPanel in project intellij-community by JetBrains.

the class IpnbJfxUtils method createHtmlPanel.

public static JComponent createHtmlPanel(@NotNull final String source, int width) {
    final JFXPanel javafxPanel = new JFXPanel() {

        @Override
        protected void processMouseWheelEvent(MouseWheelEvent e) {
            final Container parent = getParent();
            final MouseEvent parentEvent = SwingUtilities.convertMouseEvent(this, e, parent);
            parent.dispatchEvent(parentEvent);
        }
    };
    javafxPanel.setBackground(IpnbEditorUtil.getBackground());
    Platform.runLater(() -> {
        final WebView webView = new WebView();
        webView.setContextMenuEnabled(false);
        webView.setOnDragDetected(event -> {
        });
        final WebEngine engine = webView.getEngine();
        initHyperlinkListener(engine);
        final boolean hasMath = source.contains("$");
        if (hasMath) {
            engine.setOnStatusChanged(event -> adjustHeight(webView, javafxPanel, source));
        } else {
            engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
                if (newValue == Worker.State.SUCCEEDED) {
                    adjustHeight(webView, javafxPanel, source);
                }
            });
        }
        final BorderPane pane = new BorderPane(webView);
        final String prefix;
        if (hasMath) {
            prefix = String.format(ourMathJaxPrefix, width - 500, EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize());
        } else {
            prefix = String.format(ourPrefix, width - 500);
        }
        final String content = prefix + convertToHtml(source) + ourPostfix;
        engine.loadContent(content);
        final Scene scene = new Scene(pane, 0, 0);
        javafxPanel.setScene(scene);
        updateLaf(LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo, engine, javafxPanel);
    });
    return javafxPanel;
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) BorderPane(javafx.scene.layout.BorderPane) MouseEvent(java.awt.event.MouseEvent) MouseWheelEvent(java.awt.event.MouseWheelEvent) DarculaLookAndFeelInfo(com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo) WebView(javafx.scene.web.WebView) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine)

Example 28 with JFXPanel

use of javafx.embed.swing.JFXPanel in project ETUmulator by kasirgalabs.

the class BaseConsoleTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException, ExecutionException, TimeoutException {
    assert !Platform.isFxApplicationThread();
    new JFXPanel();
    FutureTask<Void> futureTask = new FutureTask<>(() -> {
        console = new BaseConsole(this);
        ClassLoader classLoader = BaseConsoleTest.class.getClassLoader();
        FXMLLoader fxmlLoader = new FXMLLoader(classLoader.getResource("fxml/Console.fxml"));
        fxmlLoader.setControllerFactory((Class<?> param) -> {
            return console;
        });
        fxmlLoader.load();
        console = fxmlLoader.getController();
        return null;
    });
    Platform.runLater(futureTask);
    futureTask.get(10, TimeUnit.SECONDS);
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) FutureTask(java.util.concurrent.FutureTask) FXMLLoader(javafx.fxml.FXMLLoader) Before(org.junit.Before)

Example 29 with JFXPanel

use of javafx.embed.swing.JFXPanel in project ETUmulator by kasirgalabs.

the class RegistersTabTest method testUpdate.

/**
 * Test of update method, of class RegistersTab.
 *
 * @throws java.lang.InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 */
@Test
public void testUpdate() throws InterruptedException, ExecutionException, TimeoutException {
    assert !Platform.isFxApplicationThread();
    new JFXPanel();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<Void> future = executor.submit(() -> {
        registerFile.setValue("r0", 5);
        return null;
    });
    future.get(5, TimeUnit.SECONDS);
    executor = Executors.newSingleThreadExecutor();
    future = executor.submit(() -> {
        pc.setValue(5);
        return null;
    });
    future.get(5, TimeUnit.SECONDS);
    executor = Executors.newSingleThreadExecutor();
    future = executor.submit(() -> {
        lr.setValue(5);
        return null;
    });
    future.get(5, TimeUnit.SECONDS);
    executor = Executors.newSingleThreadExecutor();
    future = executor.submit(() -> {
        registerFile.reset();
        pc.reset();
        lr.reset();
        return null;
    });
    future.get(5, TimeUnit.SECONDS);
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test) BaseDocumentTest(com.kasirgalabs.etumulator.document.BaseDocumentTest)

Example 30 with JFXPanel

use of javafx.embed.swing.JFXPanel in project ETUmulator by kasirgalabs.

the class GUISafeDispatcherTest method testNotifyObservers_Object.

/**
 * Test of notifyObservers method, of class GUISafeDispatcher.
 *
 * @throws java.lang.InterruptedException
 */
@Test
public void testNotifyObservers_Object() throws InterruptedException {
    assert !Platform.isFxApplicationThread();
    new JFXPanel();
    dispatcher.addObserver(this);
    expResult = "test0";
    latch = new CountDownLatch(1);
    dispatcher.notifyObservers(null, expResult);
    latch.await(5, TimeUnit.SECONDS);
    latch = new CountDownLatch(1);
    expResult = "test1";
    dispatcher.notifyObservers(null, expResult);
    latch.await(5, TimeUnit.SECONDS);
    latch = new CountDownLatch(1);
    expResult = "test2";
    dispatcher.notifyObservers(null, expResult);
    latch.await(5, TimeUnit.SECONDS);
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

JFXPanel (javafx.embed.swing.JFXPanel)50 Scene (javafx.scene.Scene)16 Test (org.junit.Test)16 CountDownLatch (java.util.concurrent.CountDownLatch)11 Dimension (java.awt.Dimension)6 BorderPane (javafx.scene.layout.BorderPane)6 Stage (javafx.stage.Stage)6 FXMLLoader (javafx.fxml.FXMLLoader)5 WebView (javafx.scene.web.WebView)5 BaseDocumentTest (com.kasirgalabs.etumulator.document.BaseDocumentTest)4 BorderLayout (java.awt.BorderLayout)4 WindowAdapter (java.awt.event.WindowAdapter)4 WindowEvent (java.awt.event.WindowEvent)4 ExecutorService (java.util.concurrent.ExecutorService)4 JFrame (javax.swing.JFrame)4 WebEngine (javafx.scene.web.WebEngine)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 Random (java.util.Random)2 FutureTask (java.util.concurrent.FutureTask)2 Memory (php.runtime.Memory)2