eseifert / vectorgraphics2d

Graphics2D implementations to export various vector file formats
Eclipse Public License 2.0
108 stars 28 forks source link

NullPointerException when using Alloy as a Swing Look And Feel #34

Closed mudgen closed 8 years ago

mudgen commented 8 years ago

I am getting the following exception when I run: comp.paint(g). And "g" is an SVGGraphics2D. Can something be done to fix this?

ERROR [ActionAdapter-AWT-EventQueue-2] <HTML>Error executing script for event:&nbsp;<code><b>actionPerformed</b></code><BR>on component:&nbsp;<code><b>Button 1</b></code>.
Traceback (most recent call last):
File "<event:actionPerformed>", line 4, in <module>
    at com.incors.plaf.m.a(Unknown Source)
    at com.incors.plaf.m.b(Unknown Source)
    at com.incors.plaf.c.b(Unknown Source)
    at com.incors.plaf.alloy.AlloyButtonUI.update(Unknown Source)
    at javax.swing.JComponent.paintComponent(Unknown Source)
    at com.inductiveautomation.vision.api.client.components.model.AbstractVisionButton.paintComponent(AbstractVisionButton.java:366)
    at javax.swing.JComponent.paint(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)

java.lang.NullPointerException: java.lang.NullPointerException
    at org.python.core.Py.JavaError(Py.java:495)
    at org.python.core.Py.JavaError(Py.java:488)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
    at org.python.core.PyObject.__call__(PyObject.java:404)
    at org.python.core.PyObject.__call__(PyObject.java:408)
    at org.python.core.PyMethod.__call__(PyMethod.java:124)
    at org.python.pycode._pyx10.f$0(<event:actionPerformed>:5)
    at org.python.pycode._pyx10.call_function(<event:actionPerformed>)
    at org.python.core.PyTableCode.call(PyTableCode.java:165)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1275)
    at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:624)
    at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:168)
    at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:265)
    at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
    at com.sun.proxy.$Proxy29.actionPerformed(Unknown Source)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at com.incors.plaf.m.a(Unknown Source)
    at com.incors.plaf.m.b(Unknown Source)
    at com.incors.plaf.c.b(Unknown Source)
    at com.incors.plaf.alloy.AlloyButtonUI.update(Unknown Source)
    at javax.swing.JComponent.paintComponent(Unknown Source)
    at com.inductiveautomation.vision.api.client.components.model.AbstractVisionButton.paintComponent(AbstractVisionButton.java:366)
    at javax.swing.JComponent.paint(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
    ... 50 more
seifertm commented 8 years ago

Which Java Virtual Machine and which version of it are you using? Are you running it in Jython or something along those lines?

mudgen commented 8 years ago

Yes, I am using Jython. I am using Oracle Java 8. I am also using the Alloy Look and Feel: http://lookandfeel.incors.com

Best,

On Tue, Dec 29, 2015 at 2:02 PM, Michael Seifert notifications@github.com wrote:

Which Java Virtual Machine and which version of it are you using? Are you running it in Jython or something along those lines?

— Reply to this email directly or view it on GitHub https://github.com/eseifert/vectorgraphics2d/issues/34#issuecomment-167887171 .

eseifert commented 8 years ago

I don't see any VectorGraphics2D code involved in your stack trace. To make sure the problem is caused by SVGGraphics2D could you please try to use a Graphics instance from an image object in g instead of SVGGraphics2D like this

BufferedImage img = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) img.getGraphics();

and report back?

mudgen commented 8 years ago

Using the Graphics instance from a BufferedImage works without a problem. Here is the code that works without an exception. My code is in Jython:

from java.awt.image import BufferedImage 
from de.erichseifert.vectorgraphics2d import SVGGraphics2D
button = event.source.parent.getComponent("Button 1")
img = BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB)
g = img.getGraphics()
button.paint(g)

This is the exact code that is throwing the exception:

from de.erichseifert.vectorgraphics2d import SVGGraphics2D
button = event.source.parent.getComponent("Button 1")
g = SVGGraphics2D(0,0,200,200)
button.paint(g)

The problems seems to be related to the Alloy look and feel.

mudgen commented 8 years ago

I was told by someone that the Alloy look and feel is getting a null value from the Graphics2D object when it needs a GraphicsConfiguration object. Is the getDeviceConfiguration() method returning null?

eseifert commented 8 years ago

Indeed, this is the case. I'll have a look at it.

eseifert commented 8 years ago

Could you please clone and test the 0.9 branch from git? If it solves the issue I can do a new VectorGraphics2D release. Thanks.

mudgen commented 8 years ago

Thanks. I tested it out and it solved the null exception error. But the generated svg file is not good. I tried converted a swing container with various swing components in it to SVG. Only the button displays in the SVG file and it does not display well. I attached an image that shows this. The left side is what the container with components look like, and the right side shows what the generated SVG file looks like swingsvg .

mudgen commented 8 years ago

Here is the exact code I am using in Jython. Am I doing something wrong? This script is on the mouseClicked event of the container.

from de.erichseifert.vectorgraphics2d import SVGGraphics2D path = system.file.saveFile("window.svg",".svg","SVG") if path == None: sys.exit() comp = event.source g = SVGGraphics2D(0,0,comp.width,comp.height) comp.paint(g) system.file.writeFile(path, g.toString())

mudgen commented 8 years ago

Why does it not print all the components in the container?

seifertm commented 8 years ago

I cannot speak for the Alloy L&F specifically, but as far as I remember we had problems with Swing in general. Swing makes extensive use of Graphics.create() and Graphics.dispose(), which wasn't handled properly in the past. However, this has been addressed quite some time ago and should work in the current master branch.

We are trying to get out a new release of VG2D with all the new code, but a few issues are left. If you don't want to wait or cannot wait, you test the version in master. The tests for Swing work fine in commit b23b003c62c8a5c71a557fc3ca58510105fe9e36 (at least for EPS and PDF, haven't checked SVG recently).

eseifert commented 8 years ago

No response from reporter. Please reopen if necessary.