Search in sources :

Example 11 with JFXPanel

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

the class SoundEditor method jbInit.

private void jbInit() throws Exception {
    this.setLayout(new BorderLayout());
    this.add(editor);
    editor.setLabelText("[ Sound ]");
    JFXPanel jfxPanel = new JFXPanel();
    CountDownLatch latch = new CountDownLatch(1);
    JFXPanel jfxCommentPanel = new JFXPanel();
    BlueFX.runOnFXThread(() -> {
        try {
            MenuButton btn = new MenuButton("Automations");
            BorderPane mainPane = new BorderPane();
            lineView = new ParameterLineView(lineList);
            lineSelector = new LineSelector(lineList);
            lineView.widthProperty().bind(mainPane.widthProperty());
            lineView.heightProperty().bind(mainPane.heightProperty().subtract(lineSelector.heightProperty()));
            lineSelector.getChildren().add(0, btn);
            lineSelector.setSpacing(5.0);
            lineView.selectedLineProperty().bind(lineSelector.selectedLineProperty());
            TimeBar tb = new TimeBar();
            tb.startTimeProperty().bind(lineView.startTimeProperty());
            tb.durationProperty().bind(lineView.durationProperty());
            Pane p = new Pane(lineView, tb);
            p.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY)));
            lineView.widthProperty().bind(p.widthProperty().subtract(20));
            lineView.heightProperty().bind(p.heightProperty().subtract(40));
            lineView.setLayoutX(10);
            lineView.setLayoutY(30);
            tb.widthProperty().bind(lineView.widthProperty());
            tb.setHeight(20);
            tb.setLayoutX(10);
            tb.setLayoutY(10);
            mainPane.setCenter(p);
            mainPane.setTop(lineSelector);
            btn.showingProperty().addListener((obs, old, newVal) -> {
                if (newVal) {
                    if (sObj != null) {
                        sObj.getBlueSynthBuilder().getParameterList().sorted().forEach((param) -> {
                            MenuItem m = new MenuItem(param.getName());
                            m.setOnAction(e -> {
                                param.setAutomationEnabled(!param.isAutomationEnabled());
                                if (param.isAutomationEnabled()) {
                                    Line line = param.getLine();
                                    line.setVarName(param.getName());
                                    List<LinePoint> points = line.getObservableList();
                                    if (points.size() < 2) {
                                        LinePoint lp = new LinePoint();
                                        lp.setLocation(1.0, points.get(0).getY());
                                        points.add(lp);
                                    }
                                    lineList.add(line);
                                } else {
                                    lineList.remove(param.getLine());
                                }
                                int colorCount = 0;
                                for (Line line : lineList) {
                                    line.setColor(LineColors.getColor(colorCount++));
                                }
                            });
                            if (param.isAutomationEnabled()) {
                                m.setStyle("-fx-text-fill: green;");
                            }
                            btn.getItems().add(m);
                        });
                    }
                } else {
                    btn.getItems().clear();
                }
            });
            final Scene scene = new Scene(mainPane);
            BlueFX.style(scene);
            jfxPanel.setScene(scene);
            commentTextArea = new TextArea();
            commentTextArea.setWrapText(true);
            final Scene scene2 = new Scene(commentTextArea);
            BlueFX.style(scene2);
            jfxCommentPanel.setScene(scene2);
        } finally {
            latch.countDown();
        }
    });
    try {
        latch.await();
    } catch (InterruptedException ex) {
        Exceptions.printStackTrace(ex);
    }
    editor.getTabs().insertTab("Automation", null, jfxPanel, "", 1);
    editor.getTabs().addTab("Comments", jfxCommentPanel);
}
Also used : TimeBar(blue.soundObject.editor.sound.TimeBar) JFXPanel(javafx.embed.swing.JFXPanel) BorderPane(javafx.scene.layout.BorderPane) ParameterLineView(blue.soundObject.editor.sound.ParameterLineView) Background(javafx.scene.layout.Background) TextArea(javafx.scene.control.TextArea) BackgroundFill(javafx.scene.layout.BackgroundFill) MenuButton(javafx.scene.control.MenuButton) LineSelector(blue.orchestra.editor.blueSynthBuilder.jfx.LineSelector) MenuItem(javafx.scene.control.MenuItem) CountDownLatch(java.util.concurrent.CountDownLatch) Scene(javafx.scene.Scene) Pane(javafx.scene.layout.Pane) BorderPane(javafx.scene.layout.BorderPane) LinePoint(blue.components.lines.LinePoint) Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) BorderLayout(java.awt.BorderLayout)

Example 12 with JFXPanel

use of javafx.embed.swing.JFXPanel in project completable-reactor by ru-fix.

the class EditorPanelFactory method create.

public static JFXPanel create(Project project, String graphModel) {
    JFXPanel swingFxPanel = new JFXPanel();
    GraphViewer graphViewer = new GraphViewer();
    graphViewer.setShortcut(ShortcutType.GOTO_SERIALIZATION_POINT, new Shortcut(true, KeyCode.B));
    graphViewer.registerListener(new GraphViewer.ActionListener() {

        @Override
        public void goToSource(@NotNull ReactorGraphModel.Source source) {
            ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runReadAction(() -> {
                PsiFile foundFile = null;
                if (source.fileName != null) {
                    foundFile = Arrays.stream(PsiShortNamesCache.getInstance(project).getFilesByName(source.fileName)).findAny().orElse(null);
                } else if (source.className != null) {
                    ProjectAndLibrariesScope searchScope = new ProjectAndLibrariesScope(project);
                    PsiClass payloadPsiClass = JavaPsiFacade.getInstance(project).findClass(source.className, searchScope);
                    if (payloadPsiClass != null) {
                        foundFile = payloadPsiClass.getContainingFile();
                    }
                }
                if (foundFile == null) {
                    log.warn("Can not find file for source: " + source);
                    return;
                }
                OpenFileDescriptor descriptor = new OpenFileDescriptor(project, foundFile.getVirtualFile(), source.fileNameLine != null ? source.fileNameLine - 1 : 0, 0);
                descriptor.navigate(true);
            }));
        }

        @Override
        public void goToSubgraph(String subgraphPayloadClass) {
            ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runReadAction(() -> {
                PsiFile foundFile = null;
                if (subgraphPayloadClass != null) {
                    foundFile = Arrays.stream(PsiShortNamesCache.getInstance(project).getFilesByName(subgraphPayloadClass + ".rg")).findAny().orElse(null);
                }
                if (foundFile == null) {
                    log.warn("Can not find file for subgraph: " + subgraphPayloadClass);
                    return;
                }
                OpenFileDescriptor descriptor = new OpenFileDescriptor(project, foundFile.getVirtualFile());
                descriptor.navigate(true);
            }));
        }

        @Override
        public void coordinatesChanged(List<GraphViewer.CoordinateItem> coordinateItems) {
            ReactorGraphModel graphModel = graphViewer.getGraphModel();
            final ReactorGraphModel.Source codeBlockFrom = graphModel.coordinatesSource;
            if (codeBlockFrom == null) {
                log.warn("Coordinates source start location not specified in model.");
                return;
            }
            ApplicationManager.getApplication().invokeLater(() -> {
                ApplicationManager.getApplication().runReadAction(() -> {
                    PsiFile[] foundFiles = PsiShortNamesCache.getInstance(project).getFilesByName(codeBlockFrom.fileName);
                    if (foundFiles.length == 0) {
                        log.warn("No file with name " + codeBlockFrom.fileName + " found");
                        return;
                    }
                    if (foundFiles.length > 1) {
                        log.warn("Found more than one file with name " + codeBlockFrom.fileName);
                    }
                    PsiFile foundFile = foundFiles[0];
                    Document document = PsiDocumentManager.getInstance(project).getDocument(foundFile);
                    TextRange textRange = new TextRange(document.getLineStartOffset(codeBlockFrom.fileNameLine - 1), document.getLineEndOffset(document.getLineCount() - 1));
                    String codeBlock = document.getText(textRange);
                    String newCodeBlock = codeUpdater.updateCoordinates(codeBlock, coordinateItems);
                    WriteCommandAction.runWriteCommandAction(project, () -> document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), newCodeBlock));
                });
            });
        }
    });
    // Because of https://bugs.openjdk.java.net/browse/JDK-8090517, it is important to disable implicit exit.
    Platform.setImplicitExit(false);
    Platform.runLater(() -> {
        try {
            graphViewer.openGraph(graphModel);
            swingFxPanel.setScene(graphViewer.getScene());
        } catch (Exception exc) {
            log.error("Failed to open graph.", exc);
        }
    });
    return swingFxPanel;
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) PsiClass(com.intellij.psi.PsiClass) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) GraphViewer(ru.fix.completable.reactor.graph.viewer.GraphViewer) ProjectAndLibrariesScope(com.intellij.psi.search.ProjectAndLibrariesScope) Shortcut(ru.fix.completable.reactor.graph.viewer.Shortcut) ReactorGraphModel(ru.fix.completable.reactor.api.ReactorGraphModel) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 13 with JFXPanel

use of javafx.embed.swing.JFXPanel in project dwoss by gg-net.

the class FileListViewCaskFXTryout method main.

public static void main(String[] args) throws InterruptedException {
    // To start the platform
    JFXPanel jfxPanel = new JFXPanel();
    Platform.runLater(() -> {
        Stage stage = new Stage();
        Scene scene = new Scene(new FileListViewCaskFX());
        stage.setScene(scene);
        stage.setTitle("FileListViewCaskFX");
        stage.showAndWait();
        complete = true;
    });
    while (!complete) {
        Thread.sleep(500);
    }
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene)

Example 14 with JFXPanel

use of javafx.embed.swing.JFXPanel in project dwoss by gg-net.

the class RedTapeView method initFxComponents.

private void initFxComponents() {
    final JFXPanel jfxp = new JFXPanel();
    positionFxPanel.add(jfxp, BorderLayout.CENTER);
    Platform.runLater(() -> {
        SelectionEnhancer<Position> selectionEnhancer = (selected) -> {
            if (selected != null && selected.getType() == UNIT)
                return Arrays.asList(new PicoUnit(selected.getUniqueUnitId(), selected.getName()));
            return Collections.EMPTY_LIST;
        };
        selector = Ops.seletor(Position.class, selectionEnhancer);
        BorderPane pane = new BorderPane();
        Scene scene = new Scene(pane, javafx.scene.paint.Color.ALICEBLUE);
        final ListView<Position> positionsFxList = new ListView<>();
        MultipleSelectionModel<Position> selectionModel = positionsFxList.getSelectionModel();
        selectionModel.setSelectionMode(SelectionMode.SINGLE);
        selectionModel.selectedItemProperty().addListener((ob, o, n) -> {
            selector.selected(n);
        });
        positionsFxList.setCellFactory(new PositionListCell.Factory());
        positionsFxList.setItems(positions);
        positionsFxList.setContextMenu(FxOps.contextMenuOf(selectionModel, selectionEnhancer));
        positionsFxList.setOnMouseClicked(FxOps.defaultMouseEventOf(selectionModel));
        /*
             positionsFxList.setOnMouseClicked((evt) -> {
             if ( positionsFxList.getSelectionModel().isEmpty() ) return;
             if ( evt.getButton() != PRIMARY ) return;
             if ( evt.getClickCount() != 2 ) return;
             HtmlDialog d = new HtmlDialog(RedTapeView.this, ModalityType.MODELESS);
             d.setText(controller.getDetailedPositionToHtml(positionsFxList.getSelectionModel().getSelectedItem()));
             d.setVisible(true);
             });
             */
        pane.setCenter(positionsFxList);
        jfxp.setScene(scene);
    });
}
Also used : Scene(javafx.scene.Scene) CustomerUpi(eu.ggnet.dwoss.customer.upi.CustomerUpi) java.util(java.util) javafx.scene.control(javafx.scene.control) eu.ggnet.saft.core.ops(eu.ggnet.saft.core.ops) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) JFXPanel(javafx.embed.swing.JFXPanel) eu.ggnet.dwoss.redtapext.ee.state(eu.ggnet.dwoss.redtapext.ee.state) DocumentStringRenderer(eu.ggnet.dwoss.redtapext.ui.cao.common.DocumentStringRenderer) ListSelectionEvent(javax.swing.event.ListSelectionEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) eu.ggnet.dwoss.util(eu.ggnet.dwoss.util) Logger(org.slf4j.Logger) CustomerService(eu.ggnet.dwoss.customer.opi.CustomerService) DossierTableView(eu.ggnet.dwoss.redtapext.ui.cao.dossierTable.DossierTableView) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) ComponentPlacement(javax.swing.LayoutStyle.ComponentPlacement) eu.ggnet.saft.api.ui(eu.ggnet.saft.api.ui) java.awt(java.awt) Platform(javafx.application.Platform) List(java.util.List) Alignment(javax.swing.GroupLayout.Alignment) PropertyChangeListener(java.beans.PropertyChangeListener) java.awt.event(java.awt.event) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UNIT(eu.ggnet.dwoss.rules.PositionType.UNIT) javax.swing.border(javax.swing.border) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) PositionListCell(eu.ggnet.dwoss.redtapext.ui.cao.common.PositionListCell) ListSelectionListener(javax.swing.event.ListSelectionListener) eu.ggnet.saft(eu.ggnet.saft) javax.swing(javax.swing) JFXPanel(javafx.embed.swing.JFXPanel) BorderPane(javafx.scene.layout.BorderPane) PositionListCell(eu.ggnet.dwoss.redtapext.ui.cao.common.PositionListCell) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) Scene(javafx.scene.Scene)

Example 15 with JFXPanel

use of javafx.embed.swing.JFXPanel in project dwoss by gg-net.

the class ReportControllerTest method testJavaFxFxml.

@Test
public void testJavaFxFxml() throws IOException {
    if (GraphicsEnvironment.isHeadless())
        return;
    // Implizit start of JavaFx.
    new JFXPanel();
    FXMLLoader loader = new FXMLLoader(ReportController.loadFxml());
    loader.load();
    assertThat((ReportController) loader.getController()).isNotNull();
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) FXMLLoader(javafx.fxml.FXMLLoader) ReportController(eu.ggnet.dwoss.report.ui.main.ReportController) 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