Hi,
No problem to test glg2d on this app, however I unfortunately can't share the source code it will work on. When I tried your library few month ago, I used to log Graphics2D.getClass().getName() into the renderer main draw(Graphics2D) method, and it did not seam to be any object of your library so we might work on that :).
Do you suggest any tracking/testing method? Cheers, Martin 2012/2/17 Brandon Borkholder [via jogamp] <[hidden email]>
|
On Fri, Feb 17, 2012 at 11:47, Martin [via jogamp] <[hidden email]> wrote: Hi, That's the tricky part. In many cases I had to put a breakpoint in JComponent.paint(Graphics) to make sure my GLGraphics2D object was being passed in. It's very difficult to discover how Swing will paint a component because it varies by component and situation. You mentioned that the issue occurred with JDesktopPane and JInternalFrames. I haven't tested with those, but I can modify my UIDemo to include those and then I'll be able to test. |
In reply to this post by Brandon Borkholder
Hi,
Sorry for late reply. I have written a class that simply visits components in order to print the class name of component.getGraphics() (see end of this message). I was surprised to see what follows, so I believe something might be wrong in my test: GraphTest: sun.java2d.SunGraphics2D JRootPane: sun.java2d.SunGraphics2D JPanel: sun.java2d.SunGraphics2D JLayeredPane: sun.java2d.SunGraphics2D G2DGLPanel: sun.java2d.SunGraphics2D GLJPanel: sun.java2d.SunGraphics2D NO_CLASS_NAME: sun.java2d.SunGraphics2D What I do is calling a diagnostic once the main frame is made visible: public static void main(String[] args) throws Exception { JFrame test = new GraphTest(); ... test.setVisible(true); GraphicsDiagnose gd = new GraphicsDiagnose(); gd.printGraphics(test); } Am I wrong somewhere? Will the GLGraphics2D replace default SunGraphics2D latter? Martin -------------------------------------- public class GraphicsDiagnose { protected boolean shortName = false; public void printGraphics(Component c){ printGraphics(c, 0); } protected void printGraphics(Component c, int depth){ if(c==null) System.out.println(blanks(depth) + "component null"); else{ String className = c.getClass().getSimpleName(); String me = blanks(depth) + ("".equals(className)?"NO_CLASS_NAME":className); if(c.getGraphics()!=null){ if(shortName) me += ": " + c.getGraphics().getClass().getSimpleName(); else me += ": " + c.getGraphics().getClass().getName(); } else me += ": graphics is null at this point"; System.out.println(me); if(c instanceof Container){ Container ct = ((Container)c); for(Component child: ct.getComponents()){ printGraphics(child, depth+1); } } } } protected String blanks(int length){ String b = ""; for (int i = 0; i < length; i++) b += " "; return b; } } |
By the way, I am using a clone of your git repository and the last log is:
03efe90f3d044d287842e0ee263d0a23bc80d7a3 I was working off jdk7 but now removed I use JOGL2 RC5.
Also added a Thread.sleep(10000) before diagnostic just in case Graphics2D get replaced latter, but it did not change anything.
2012/2/29 Martin [via jogamp] <[hidden email]> Hi, |
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.
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). 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... |
Nooo, sorry for my impatience! 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]] 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. |
That would be great. I just committed a change that adds a new class to the test code, called glg2d.misc.InstrumentPaint. If you call InstrumentPaint.instrument() as the first line in your main and then use the GLG2D library, it will print to stderr every time a component gets painted with the SunGraphics2D object. I'd be very interested to hear about your results. |
Free forum by Nabble | Edit this page |