Re: useful Java2D bridge
Posted by
Martin on
Feb 29, 2012; 12:15pm
URL: https://forum.jogamp.org/useful-Java2D-bridge-tp3391708p3787084.html
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,
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;
}
}