protected void layout ( Graphics2D gfx , int iconPadding , int extraPadding ) { // if we have an icon, let that dictate our size; otherwise just lay out our label all on // one line int sqwid , sqhei ; if ( _icon == null ) { sqwid = sqhei = 0 ; } else { sqwid = _icon . getIconWidth ( ) ; sqhei = _icon . getIconHeight ( ) ; _label . setTargetHeight ( sqhei ) ; } // lay out our label _label . layout ( gfx ) ; Dimension lsize = _label . getSize ( ) ; // if we have no icon, make sure that the label has enough room if ( _icon == null ) { sqhei = lsize . height + extraPadding * 2 ; sqwid = extraPadding * 2 ; } // compute the diameter of the circle that perfectly encompasses our icon int hhei = sqhei / 2 ; int hwid = sqwid / 2 ; _dia = ( int ) ( Math . sqrt ( hwid * hwid + hhei * hhei ) * 2 ) ; // compute the x and y offsets at which we'll start rendering _xoff = ( _dia - sqwid ) / 2 ; _yoff = ( _dia - sqhei ) / 2 ; // and for the label _lxoff = _dia - _xoff ; _lyoff = ( _dia - lsize . height ) / 2 ; // now compute our closed and open sizes _size . height = _dia ; // width is the diameter of the circle that contains the icon plus space for the label when // we're open _size . width = _dia + lsize . width + _xoff ; // and if we are actually rendering the icon, we need to account for the space between it // and the label. if ( _icon != null ) { // and add the padding needed for the icon _size . width += _xoff + ( iconPadding * 2 ) ; _xoff += iconPadding ; _lxoff += iconPadding * 2 ; } }
Lays out the label sausage . It is assumed that the desired label font is already set in the label .