MagicDraw plugin of browser with JavaFx

398 Views Asked by At

I am writing a Magicdraw plugin with JavaFx Framework to add a new Browser. Following is the code of initialization of a new browser in LibraryBrowser class.

private static final WindowComponentInfo info = new WindowComponentInfo("test_browser", "Test Browser", null, 
        ProjectWindowsManager.SIDE_WEST, ProjectWindowsManager.STATE_DOCKED, true);
public LibraryBrowser() {
    Browser.addBrowserInitializer(new Browser.BrowserInitializer() {
        @Override
        public void init(@Nonnull Browser browser, @Nonnull Project project) {
            browser.addPanel(new LibraryBrowserView(info)); //add library view
        }
        @Override
        public WindowComponentInfoRegistration getInfo() {
            return new WindowComponentInfoRegistration(info, null);
        }
    });
}

Where LibraryBrowserView is a class that extends ExtendedPanel implements WindowComponent as in following code presented.

public class LibraryBrowserView extends ExtendedPanel  implements WindowComponent {
private WindowComponentInfo info;

public LibraryBrowserView(WindowComponentInfo info) {
    //Set WindowComponentInfo
    this.info = info;
    JFXPanel fxPanel = new JFXPanel();
    add(fxPanel);
    fxPanel.setVisible(true);   
    Group  root1  =  new  Group();  
    Scene  scene  =  new  Scene(root1, Color.ALICEBLUE);    
    Text  text  =  new  Text();
    text.setX(40);
    text.setY(100);
    text.setFont(new Font(25));
    text.setText("Test JavaFX!");
    root1.getChildren().add(text);    
    fxPanel.setScene(scene);
}
@Override
public WindowComponentContent getContent() {
    return new BrowserWindowComponentContext(this);
}
@Override
public WindowComponentInfo getInfo() {
    return info;
}}

class BrowserWindowComponentContext implements WindowComponentContent {
private JPanel panel;
public BrowserWindowComponentContext(JPanel panel) {
    this.panel = panel;
}
@Override
public Component getWindowComponent() {
    return panel;
}
@Override
public Component getDefaultFocusComponent() {
    return panel;
}}

The error occurs when I open the MagicDraw.

java.lang.UnsatisfiedLinkError: com.sun.prism.d3d.D3DVertexBuffer.nDrawIndexedQuads(J[F[BI)I
1

There are 1 best solutions below

0
On

The NoMagic reps only state that they do not work with JavaFX; they do not state MagicDraw is not compatible with JavaFX. Which is good, because they would be wrong if they said that. We have created a number of MagicDraw plugins that use JavaFX.

Nasa's OpenMBEE MDK project on github contains an example of how this can be done. In their plugin class, they load the needed extension .jars and then call this method:

    private void initJavaFX() {
    try {
        Class.forName("javafx.application.Platform");
    } catch (ClassNotFoundException e) {
        System.err.println("[WARNING] JavaFX libraries are unavailable. Please add \"-Dorg.osgi.framework.bundle.parent=ext\" to the \"JAVA_ARGS\" line in your properties file(s) in your MagicDraw bin directory and restart.");
        return;
    }
    new Thread(() -> {
        try {
            Class<?> clazz = Class.forName("gov.nasa.jpl.mbee.mdk.MDKApplication");
            Method method = clazz.getMethod("main", String[].class);
            method.invoke(null, new Object[]{new String[]{}});
        } catch (Exception | Error e) {
            System.err.println("[WARNING] Failed to initialize JavaFX application. JavaFX functionality is disabled.");
            e.printStackTrace();
        }
    }, "JavaFX Init").start();
}

Here is the link:https://github.com/Open-MBEE/mdk/blob/develop/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java.

For more information about why this works check out this Oracle article: Integrating JavaFX into Swing Applications (magicdraw is a swing application in case you didn't know)