Search in sources :

Example 6 with JFXPanel

use of javafx.embed.swing.JFXPanel in project BlocklyArduinoIDEPlugin by technologiescollege.

the class BlocklyArduinoPlugin method initGUI.

private void initGUI() {
    window = new JFrame();
    window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    window.setLayout(new BorderLayout());
    window.setSize(1024, 768);
    window.setLocationRelativeTo(null);
    window.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            SwingUtilities.invokeLater(() -> {
                Platform.runLater(() -> {
                    // browser.webEngine.load("about:blank");
                    SwingUtilities.invokeLater(() -> {
                        // System.out.println("test");
                        try {
                            e.getWindow().dispose();
                        } catch (NullPointerException ex) {
                        // System.out.println("This is a bug in java: https://bugs.openjdk.java.net/browse/JDK-8089371");
                        }
                    });
                });
            });
        }
    });
    jfxPanel = new JFXPanel();
    jfxPanel.setPreferredSize(new Dimension(JFXPANEL_WIDTH_INT, JFXPANEL_HEIGHT_INT));
    window.add(jfxPanel, BorderLayout.CENTER);
    window.setVisible(true);
    Platform.runLater(() -> {
        showBrowser();
    });
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension)

Example 7 with JFXPanel

use of javafx.embed.swing.JFXPanel in project BlocklyArduinoIDEPlugin by technologiescollege.

the class StartupApplet method init.

@Override
public void init() {
    BlocklyArduinoPlugin.startTimestamp = System.currentTimeMillis();
    fxContainer = new JFXPanel();
    fxContainer.setPreferredSize(new Dimension(JFXPANEL_WIDTH_INT, JFXPANEL_HEIGHT_INT));
    add(fxContainer, BorderLayout.CENTER);
    Platform.setImplicitExit(false);
    Runnable activeRunnable = new Runnable() {

        @Override
        public void run() {
            createScene();
        }
    };
    Platform.runLater(activeRunnable);
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) Dimension(java.awt.Dimension)

Example 8 with JFXPanel

use of javafx.embed.swing.JFXPanel in project osumer by mob41.

the class Main method runUi.

private static void runUi(Config config, String[] args, ArgParser ap) {
    if (!SockThread.testPortFree(SockThread.PORT)) {
        // osumer to work
        try {
            Socket socket = new Socket(InetAddress.getLoopbackAddress().getHostName(), SockThread.PORT);
            socket.setSoTimeout(5000);
            PrintWriter writer = new PrintWriter(socket.getOutputStream());
            writer.println("RUN " + buildArgStr(args));
            writer.flush();
            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String line = reader.readLine();
            if (line == null || !line.equals("OK")) {
                reader.close();
                socket.close();
                System.out.println("Not OK: " + line);
                DebugDump dump = new DebugDump(null, null, "Asking BG osumer to run with args: \"" + buildArgStr(args) + "\"", null, false, "Could not start up BG osumer sucessfully. Destination did not response \"OK\": " + line);
                DumpManager.getInstance().addDump(dump);
                ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
                dialog.setModal(true);
                dialog.setVisible(true);
                return;
            }
            reader.close();
            socket.close();
            System.exit(0);
            return;
        } catch (IOException e) {
            e.printStackTrace();
            DebugDump dump = new DebugDump(null, null, "Opening connection to BG osumer socket", null, "Could not open socket at 46725 for BG call. Not osumer running at that port?", false, e);
            DumpManager.getInstance().addDump(dump);
            ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
            dialog.setModal(true);
            dialog.setVisible(true);
            System.exit(-1);
            return;
        }
    } else {
        String urlStr = null;
        for (int i = 0; i < args.length; i++) {
            if (Osums.isVaildBeatMapUrl(args[i])) {
                urlStr = args[i];
                break;
            }
        }
        boolean runUi = true;
        if (args.length > 0 && urlStr == null && !ap.isDaemonFlag()) {
            if (config.isSwitchToBrowserIfWithoutUiArg()) {
                System.out.println("Configuration specified that switch to browser if an \"-ui\" arugment wasn't specified.");
                if (runUi = ap.isUiFlag() && !ap.isNoUiFlag()) {
                    System.out.println("An \"-ui\" argument was specified. Launching UI.");
                } else {
                    System.out.println("An \"-ui\" argument wasn't specified. Opening the default browser instead.");
                    runBrowser(config, args);
                    return;
                }
            } else {
                System.out.println("Non-beatmap URL detected.");
                if (!config.isAutoSwitchBrowser()) {
                    System.out.println("Auto switch to default browser is off. Nothing to do with such URL.");
                    return;
                } else {
                    System.out.println("Switching to default browser with the URL.");
                    runBrowser(config, args);
                }
            }
        }
        // Initialize JFX toolkit
        new JFXPanel();
        TrayIcon icon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(UIFrame.class.getResource("/com/github/mob41/osumer/ui/osumerIcon_16px.png")));
        UIFrame frame = new UIFrame(config, new QueueManager(config), icon);
        if (ap.isDaemonFlag()) {
            if (!SystemTray.isSupported()) {
                JOptionPane.showMessageDialog(null, "Your operating system does not support System Tray.\nAs a result, you are not able to start osumer from the tray.", "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
            frame.setDaemonMode(true);
            SystemTray tray = SystemTray.getSystemTray();
            icon.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    frame.setVisible(!frame.isVisible());
                    if (!frame.isVisible()) {
                        icon.displayMessage("osumer2", "osumer2 is now running in background.", TrayIcon.MessageType.INFO);
                    }
                }
            });
            icon.setToolTip("osumer2");
            try {
                tray.add(icon);
                icon.displayMessage("osumer2", "osumer2 is now running in background.", TrayIcon.MessageType.INFO);
            } catch (AWTException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(null, "Error when adding tray icon: " + e + "\nAs a result, you are not able to start osumer from the tray.", "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
        } else {
            frame.setVisible(true);
            new Thread() {

                public void run() {
                    JOptionPane.showMessageDialog(frame, "The osumer2 daemon (background process) is not running.\nThis might slow down further osumerExpress downloads.\nNow this process is listening for more queues till it is stopped.\n\nPlease check \"Help\" for more details.", "Warning", JOptionPane.WARNING_MESSAGE);
                }
            }.start();
        }
        if (urlStr != null) {
            frame.addBtQueue(urlStr, false);
        }
    }
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) InputStreamReader(java.io.InputStreamReader) ErrorDumpDialog(com.github.mob41.osumer.ui.ErrorDumpDialog) SystemTray(java.awt.SystemTray) ActionEvent(java.awt.event.ActionEvent) UIFrame(com.github.mob41.osumer.ui.UIFrame) IOException(java.io.IOException) QueueManager(com.github.mob41.osumer.io.queue.QueueManager) SockThread(com.github.mob41.osumer.sock.SockThread) ActionListener(java.awt.event.ActionListener) TrayIcon(java.awt.TrayIcon) BufferedReader(java.io.BufferedReader) DebugDump(com.github.mob41.organdebug.DebugDump) Socket(java.net.Socket) PrintWriter(java.io.PrintWriter) AWTException(java.awt.AWTException)

Example 9 with JFXPanel

use of javafx.embed.swing.JFXPanel in project blue by kunstmusik.

the class EffectEditorManager method openEffectEditor.

public void openEffectEditor(Frame root, Effect effect) {
    JDialog dialog = null;
    WeakReference<JDialog> ref = map.get(effect);
    if (ref != null) {
        dialog = ref.get();
    }
    if (dialog == null) {
        dialog = new JDialog(root);
        JFXPanel panel = new JFXPanel();
        CountDownLatch latch = new CountDownLatch(1);
        double[] dims = new double[2];
        BlueFX.runOnFXThread(() -> {
            try {
                BSBEditPane editPanel = new BSBEditPane(BSBObjectRegistry.getBSBObjects(), false);
                editPanel.editBSBGraphicInterface(effect.getGraphicInterface());
                Scene scene = new Scene(editPanel);
                BlueFX.style(scene);
                panel.setScene(scene);
            } finally {
                latch.countDown();
            }
        });
        try {
            latch.await();
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        }
        dialog.getContentPane().add(panel);
        dialog.setTitle(effect.getName());
        dialog.getRootPane().putClientProperty("SeparateWindow", Boolean.TRUE);
        dialog.setVisible(true);
        final JDialog dlg = dialog;
        SwingUtilities.invokeLater(() -> {
            dlg.pack();
            dlg.setSize(dlg.getWidth() + 5, dlg.getHeight() + 5);
        });
        map.put(effect, new WeakReference(dialog));
    } else {
        dialog.setVisible(true);
    }
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) WeakReference(java.lang.ref.WeakReference) CountDownLatch(java.util.concurrent.CountDownLatch) BSBEditPane(blue.orchestra.editor.blueSynthBuilder.jfx.BSBEditPane) Scene(javafx.scene.Scene) JDialog(javax.swing.JDialog)

Example 10 with JFXPanel

use of javafx.embed.swing.JFXPanel in project blue by kunstmusik.

the class Installer method restored.

@Override
public void restored() {
    Locale.setDefault(Locale.Category.FORMAT, Locale.ENGLISH);
    System.setProperty("jffi.unsafe.disabled", "true");
    PolyObjectLayerGroupProvider.setDefaultHeightIndexProvider(() -> {
        return ProjectDefaultsSettings.getInstance().layerHeightDefault;
    });
    // System.setProperty("netbeans.winsys.no_toolbars", "true");
    // 
    // SwingUtilities.invokeLater(new Runnable() {
    // 
    // @Override
    // public void run() {
    // //Get the main window of the NetBeans Platform:
    // JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
    // //Get our custom main toolbar:
    // JPanel panel = new JPanel();
    // panel.setLayout(new FlowLayout(FlowLayout.CENTER));
    // panel.add(new blue.ui.core.toolbar.MainToolBar(), BorderLayout.CENTER);
    // panel.setPreferredSize(new Dimension(100, 70));
    // 
    // //Set the new layout of our root pane:
    // frame.getRootPane().setLayout(new MyRootPaneLayout(panel));
    // //Install a new toolbar component into the layered pane
    // //of the main frame on layer 0:
    // panel.putClientProperty(JLayeredPane.LAYER_PROPERTY, 0);
    // frame.getRootPane().getLayeredPane().add(panel, 0);
    // }
    // });
    ParameterTimeManagerFactory.setInstance(new ParameterTimeManagerImpl());
    windowTitlePropertyChangeListener = (PropertyChangeEvent evt) -> {
        SwingUtilities.invokeLater(() -> {
            if (WindowManager.getDefault().getMainWindow() != null) {
                setWindowTitle();
            }
        });
    };
    BlueProjectManager.getInstance().addPropertyChangeListener(windowTitlePropertyChangeListener);
    BlueProjectManager.getInstance().addPropertyChangeListener(tempFileCleaner);
    WindowManager.getDefault().invokeWhenUIReady(() -> {
        setWindowTitle();
        backupFileSaver = new BackupFileSaver();
        Thread t = new Thread(backupFileSaver);
        t.setPriority(Thread.MIN_PRIORITY);
        t.setDaemon(true);
        t.start();
    });
    PythonProxy.setLibDir(InstalledFileLocator.getDefault().locate("pythonLib", "jython", false));
    // WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
    // 
    // public void run() {
    // 
    // new Thread() {
    // 
    // public void run() {
    // 
    // ProgressHandle handle = ProgressHandleFactory.createHandle("Initializing Python Interpreter...");
    // handle.start();
    // handle.progress("Initializing...");
    // 
    // try {
    // PythonProxy.reinitialize();
    // PythonProxy.processScript("import random");
    // } catch (Exception e) {
    // 
    // }
    // 
    // handle.finish();
    // }
    // 
    // }.start();
    // }
    // });
    SwingUtilities.invokeLater(() -> {
        MidiInputManager.getInstance().addReceiver(MidiInputEngine.getInstance());
    });
    new Thread(() -> {
        OSCManager oscManager = OSCManager.getInstance();
        OSCActions.installActions(oscManager);
        oscManager.start();
    }).start();
    Lookup lkp = Lookups.forPath("blue/score/layers");
    result = lkp.lookupResult(LayerGroupProvider.class);
    result.addLookupListener(lookupListener);
    LayerGroupProviderManager.getInstance().updateProviders(result.allInstances());
    lookupListener = (LookupEvent ev) -> {
        LayerGroupProviderManager.getInstance().updateProviders(result.allInstances());
    };
    // for(LayerGroupPanelProvider provider : lkp.lookupAll(
    // LayerGroupPanelProvider.class)) {
    // JComponent comp = provider.getLayerGroupPanel(layerGroup, timeState, data);
    // 
    // if(comp != null) {
    // return comp;
    // }
    // }
    Platform.setImplicitExit(false);
    // Initialize JavaFX by using this call
    new JFXPanel();
// Platform.runLater(()
// -> jfxPanel.setScene(new Scene(new Group())));
// FileChooserManager.getDefault().setJFXPanel(jfxPanel);
// WindowManager.getDefault().invokeWhenUIReady(()
// -> WindowManager.getDefault().getMainWindow().add(jfxPanel));
}
Also used : PolyObjectLayerGroupProvider(blue.soundObject.PolyObjectLayerGroupProvider) LayerGroupProvider(blue.score.layers.LayerGroupProvider) PropertyChangeEvent(java.beans.PropertyChangeEvent) LookupEvent(org.openide.util.LookupEvent) JFXPanel(javafx.embed.swing.JFXPanel) OSCManager(blue.osc.OSCManager) ParameterTimeManagerImpl(blue.automation.ParameterTimeManagerImpl) Lookup(org.openide.util.Lookup)

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