Re: useful Java2D bridge
Posted by
Martin on
Mar 02, 2012; 9:25am
URL: https://forum.jogamp.org/useful-Java2D-bridge-tp3391708p3792937.html
Brandon Borkholder wrote
Martin, I'm sorry for taking so long to reply. I've been looking into that
issue and I have only a partial answer so far.
Nooo, sorry for my impatience!

Component.getGraphics() is not the right way check if the component is
being drawn with GLGraphics2D. I'm still learning a lot about Swing
painting, but most painting calls happen when *something* calls
JComponent.paint(Graphics) on the top level, which then calls
paint(Graphics) on all the children with the same Graphics object. So it
doesn't matter what JComponent.getGraphics() returns, it matters what's
being passed in. And in my testing, I can verify that's usually the case
(unless there's a bug).
Thanks for clarifying. Indeed, still in your GraphTest demo, adding:
JPanel paintingComponent = new JPanel() {
...
public void paint(Graphics g){
super.paint(g);
System.out.println(g);
}
};
really print:
glg2d.GLGraphics2D[font=javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=plain,size=12],color=sun.swing.PrintColorUIResource[r=51,g=51,b=51]]
The second part of your question - what's the right way to verify then?
Well, I've been trying to use Javassist, Guice, ASM or other libraries to
instrument JComponent.paint(Graphics) and print out the Graphics class if
it's not GLGraphics2D. That would tell us painting is not being done into
OpenGL.
But that's a work in progress...
If you want me to test it, do not hesitate to send a piece of javassist or similar code to instrument the painting methods of my component stack.