使用JavaFx的浏览器的MagicDraw插件

时间:2018-05-14 11:28:51

标签: javafx jfxpanel magic-draw

我正在使用JavaFx Framework编写Magicdraw插件来添加新的浏览器。以下是LibraryBrowser类中新浏览器的初始化代码。

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);
        }
    });
}

其中LibraryBrowserView是一个扩展ExtendedPanel的类,它实现了WindowComponent,如下面的代码所示。

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;
}}

当我打开MagicDraw时会发生错误。

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

2 个答案:

答案 0 :(得分:0)

他们的社区论坛上没有魔术代表声称MagicDraw与JavaFX不兼容:

https://community.nomagic.com/post15641.html?hilit=javafx#p15641

答案 1 :(得分:0)

NoMagic代表仅声明它们不适用于JavaFX;他们没有声明MagicDraw与JavaFX不兼容。那样很好,因为如果他们这么说,那他们是错的。我们已经创建了许多使用JavaFX的MagicDraw插件。

Nasa在github上的OpenMBEE MDK项目包含一个如何完成此操作的示例。在他们的插件类中,他们加载所需的扩展名.jars,然后调用此方法:

    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();
}

以下是链接:https://github.com/Open-MBEE/mdk/blob/develop/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java

有关为何有效的更多信息,请查看以下Oracle文章:Integrating JavaFX into Swing Applications(magicdraw是一个摆动应用程序,以防万一您不知道)