Batik Canvas' getUpdateManager returns 空

Batik Canvas' getUpdateManager returns null

当使用 Batik 从 JSVGCanvas 得到 UpdateManager 时,它 returns null.

public void init() {
    canvas = new JSVGCanvas(null, true, false);
    canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
}

public void paint(final DomainObject domainObject) {
    UpdateManager updateManager = canvas.getUpdateManager();
    RunnableQueue runnableQueue = updateManager.getUpdateRunnableQueue();
    runnableQueue.invokeLater(new Runnable() {
        public void run() {
            // Document operations here
        }
    });
}

如何处理这个错误?

绘画方法必须分为两部分,一部分是将 GVTTreeRendererListener 注册到 JSVGCanvas 对象。渲染完成后,此侦听器将调用执行实际绘制工作的方法,届时 UpdateManager 对象将出现在 canvas.

public void init() {
    canvas = new JSVGCanvas(null, true, false);
    canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
}

public void paint(final DomainObject domainObject) {
    canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
        public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
            renderComplete(domainObject);
        }
    });
}

public void renderComplete(DomainObject domainObject) {
    UpdateManager updateManager = canvas.getUpdateManager();
    RunnableQueue runnableQueue = updateManager.getUpdateRunnableQueue();
    runnableQueue.invokeLater(new Runnable() {
        public void run() {
            // Document operations here
        }
    });
}

免责声明: 答案是在这个 Batik 论坛中找到的,我决定将其记录在此处作为更有用的资源 http://batik.2283329.n4.nabble.com/UpdateManager-is-Null-td2974717.html