Re: useful Java2D bridge
Posted by Martin on Feb 29, 2012; 11:44am
URL: https://forum.jogamp.org/useful-Java2D-bridge-tp3391708p3786990.html
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;
}
}