public void updateLocation ()
{
final Component component = getComponent ();
if ( getParent () != null && getParent ().isShowing () && component.isShowing () )
{
final TooltipWay displayWay = getActualDisplayWay ();
final Point p = getParent ().getLocationOnScreen ();
final Point c = component.getLocationOnScreen ();
final Dimension ps = getPreferredSize ();
final int x0 = c.x - p.x;
final int y0 = c.y - p.y;
if ( displayWay.equals ( TooltipWay.up ) || displayWay.equals ( TooltipWay.down ) )
{
final int compMiddle;
final int compTipY;
if ( displayLocation == null )
{
if ( relativeToBounds == null )
{
final Component rtc = getRelativeToComponent ();
if ( rtc == null )
{
compMiddle = x0 + component.getWidth () / 2;
compTipY = y0 + ( displayWay.equals ( TooltipWay.up ) ? ( cornerLength / 2 - shadeWidth - ps.height ) :
( component.getHeight () - cornerLength / 2 + shadeWidth ) );
}
else
{
final Rectangle b = SwingUtils.getRelativeBounds ( rtc, component );
compMiddle = x0 + b.x + b.width / 2;
compTipY = y0 + b.y + ( displayWay.equals ( TooltipWay.up ) ? ( cornerLength / 2 - shadeWidth - ps.height ) :
( b.height - cornerLength / 2 + shadeWidth ) );
}
}
else
{
final Rectangle b = relativeToBounds;
compMiddle = x0 + b.x + b.width / 2;
compTipY = y0 + b.y + ( displayWay.equals ( TooltipWay.up ) ? ( cornerLength / 2 - shadeWidth - ps.height ) :
( b.height - cornerLength / 2 + shadeWidth ) );
}
}
else
{
compMiddle = x0 + displayLocation.x;
compTipY = y0 + displayLocation.y - ( displayWay.equals ( TooltipWay.up ) ? ps.height : 0 );
}
if ( compMiddle - ps.width / 2 < windowSideSpacing )
{
final int cw = windowSideSpacing - ( compMiddle - ps.width / 2 );
cornerPeak = Math.max ( shadeWidth + round + cornerSideX + 1, getWidth () / 2 - cw );
setLocation ( windowSideSpacing, compTipY );
}
else if ( compMiddle + ps.width / 2 > getParent ().getWidth () - windowSideSpacing )
{
final int cw = ( compMiddle + ps.width / 2 ) - ( getParent ().getWidth () - windowSideSpacing );
cornerPeak = Math.min ( ps.width - shadeWidth - round - cornerSideX - 1, getWidth () / 2 + cw );
setLocation ( getParent ().getWidth () - windowSideSpacing - ps.width, compTipY );
}
else
{
cornerPeak = getWidth () / 2;
setLocation ( compMiddle - ps.width / 2, compTipY );
}
}
else if ( displayWay.equals ( TooltipWay.left ) || displayWay.equals ( TooltipWay.right ) )
{
final int compMiddle;
final int compTipX;
if ( displayLocation == null )
{
if ( relativeToBounds == null )
{
final Component rtc = getRelativeToComponent ();
if ( rtc == null )
{
compMiddle = y0 + component.getHeight () / 2;
compTipX = x0 + ( displayWay.equals ( TooltipWay.left ) ? ( cornerLength / 2 - shadeWidth - ps.width ) :
( component.getWidth () - cornerLength / 2 + shadeWidth ) );
}
else
{
final Rectangle b = SwingUtils.getRelativeBounds ( rtc, component );
compMiddle = y0 + b.y + b.height / 2;
compTipX = x0 + b.x + ( displayWay.equals ( TooltipWay.left ) ? ( cornerLength / 2 - shadeWidth - ps.width ) :
( b.width - cornerLength / 2 + shadeWidth ) );
}
}
else
{
final Rectangle b = relativeToBounds;
compMiddle = y0 + b.y + b.height / 2;
compTipX = x0 + b.x + ( displayWay.equals ( TooltipWay.left ) ? ( cornerLength / 2 - shadeWidth - ps.width ) :
( b.width - cornerLength / 2 + shadeWidth ) );
}
}
else
{
compMiddle = y0 + displayLocation.y;
compTipX = x0 + displayLocation.x - ( displayWay.equals ( TooltipWay.left ) ? ps.width : 0 );
}
if ( compMiddle - ps.height / 2 < windowSideSpacing )
{
final int cw = windowSideSpacing - ( compMiddle - ps.height / 2 );