src/main/java/swinghx/chapter12/hack96/ComponentGlassPane.java
private void rPaint(Component comp, Graphics g, final int rlevel) {

        final boolean isContainer = comp instanceof Container; // so ... everything is a Container in Swing
        final Container cont = isContainer ? (Container)comp : null;
        // final boolean hasChildren = isContainer ? (cont.getComponentCount() > 0) : false;

        System.out.print(".");

        int x = comp.getX();
        int y = comp.getY();
        g.translate(x,y);
        cursor.translate(-x,-y);

        int w = comp.getWidth();
        int h = comp.getHeight();

        // draw background
        g.setColor(BACKGROUND_COLOR);
        g.fillRect(0,0,w,h);

        g.setColor(Color.red);
        g.drawRect(0,0,w,h);

        // if the mouse is over this component
        if (comp.contains(cursor)) { // && !hasChildren) {

            // draw the text
            final String cls_name = comp.getClass().getName() + " : " + rlevel;
            // Graphics2D g2 = (Graphics2D)g; // TODO IS THIS NECESSARY/BENEFICIAL?
            // Font fnt = g.getFont();
            FontMetrics fm = g.getFontMetrics();
            int text_width = fm.stringWidth(cls_name);
            int text_height = fm.getHeight();
            int text_ascent = fm.getAscent();

            // draw text background
            g.setColor(TEXT_BACKGROUND);
            g.fillRect(0,0,text_width,text_height);
            g.setColor(Color.white);
            g.drawRect(0,0,text_width,text_height);

            // draw text
            g.setColor(Color.black);
            g.drawString(cls_name, 0, 0+text_ascent);
        }

        if (isContainer) {
            for (Component child : cont.getComponents()) {
                rPaint(child, g, rlevel + 1);
            }
//            for (int i=0; i<cont.getComponentCount(); i++) {
//                final Component child = cont.getComponent(i);
//                rPaint(child,g, rlevel + 1);
//            }
        }

        cursor.translate(x,y);
        g.translate(-x,-y);
    }
/**
     * Paint algorithm that recursively navigates the component hierarchy
     *
     * @param comp
     * @param g
     * @param rlevel
     */
Paint algorithm that recursively navigates the component hierarchy
@param comp
@param g
@param rlevel
Paint algorithm that recursively navigates the component hierarchy @param comp @param g @param rlevel
private void rPaint(Component comp, Graphics g, final int rlevel) {
        final boolean isContainer = comp instanceof Container; 
        final Container cont = isContainer ? (Container)comp : null;
        System.out.print(".");
        int x = comp.getX();
        int y = comp.getY();
        g.translate(x,y);
        cursor.translate(-x,-y);
        int w = comp.getWidth();
        int h = comp.getHeight();
        g.setColor(BACKGROUND_COLOR);
        g.fillRect(0,0,w,h);
        g.setColor(Color.red);
        g.drawRect(0,0,w,h);
        if (comp.contains(cursor)) { 
            final String cls_name = comp.getClass().getName() + " : " + rlevel;
            FontMetrics fm = g.getFontMetrics();
            int text_width = fm.stringWidth(cls_name);
            int text_height = fm.getHeight();
            int text_ascent = fm.getAscent();
            g.setColor(TEXT_BACKGROUND);
            g.fillRect(0,0,text_width,text_height);
            g.setColor(Color.white);
            g.drawRect(0,0,text_width,text_height);
            g.setColor(Color.black);
            g.drawString(cls_name, 0, 0+text_ascent);
        }
        if (isContainer) {
            for (Component child : cont.getComponents()) {
                rPaint(child, g, rlevel + 1);
            }
        }
        cursor.translate(x,y);
        g.translate(-x,-y);
    }
private void rPaint ( Component comp , Graphics g , final int rlevel ) { final boolean isContainer = comp instanceof Container ; final Container cont = isContainer ? ( Container ) comp : null ; System . out . print ( "." ) ; int x = comp . getX ( ) ; int y = comp . getY ( ) ; g . translate ( x , y ) ; cursor . translate ( - x , - y ) ; int w = comp . getWidth ( ) ; int h = comp . getHeight ( ) ; g . setColor ( BACKGROUND_COLOR ) ; g . fillRect ( 0 , 0 , w , h ) ; g . setColor ( Color . red ) ; g . drawRect ( 0 , 0 , w , h ) ; if ( comp . contains ( cursor ) ) { final String cls_name = comp . getClass ( ) . getName ( ) + " : " + rlevel ; FontMetrics fm = g . getFontMetrics ( ) ; int text_width = fm . stringWidth ( cls_name ) ; int text_height = fm . getHeight ( ) ; int text_ascent = fm . getAscent ( ) ; g . setColor ( TEXT_BACKGROUND ) ; g . fillRect ( 0 , 0 , text_width , text_height ) ; g . setColor ( Color . white ) ; g . drawRect ( 0 , 0 , text_width , text_height ) ; g . setColor ( Color . black ) ; g . drawString ( cls_name , 0 , 0 + text_ascent ) ; } if ( isContainer ) { for ( Component child : cont . getComponents ( ) ) { rPaint ( child , g , rlevel + 1 ) ; } } cursor . translate ( x , y ) ; g . translate ( - x , - y ) ; }
Paint algorithm that recursively navigates the component hierarchy
 @param comp
 @param g
 @param rlevel
Paint algorithm that recursively navigates the component hierarchy @param comp @param g @param rlevel
// so ... everything is a Container in Swing // final boolean hasChildren = isContainer ? (cont.getComponentCount() > 0) : false; // draw background // if the mouse is over this component // && !hasChildren) { // draw the text // Graphics2D g2 = (Graphics2D)g; // TODO IS THIS NECESSARY/BENEFICIAL? // Font fnt = g.getFont(); // draw text background // draw text //            for (int i=0; i<cont.getComponentCount(); i++) { //                final Component child = cont.getComponent(i); //                rPaint(child,g, rlevel + 1); //            }