boLegend.setTop( bo.getTop( ) + bo.getHeight( ) - szLegend.getHeight( ) ); boLegend.setLeft( bo.getLeft( ) );
	private void doLayout_tmp( IDisplayServer xs, Chart cm, Bounds boFull,			RunTimeContext rtc ) throws ChartException	{		final boolean isRightToLeft = rtc.isRightToLeft( );		Block bl = cm.getBlock( );		bl.setBounds( boFull );		Insets ins = bl.getInsets( );		Bounds bo = boFull.adjustedInstance( ins );		Legend lg = cm.getLegend( );		Plot p = cm.getPlot( );		TitleBlock tb = cm.getTitle( );		Size szTitle = ( !tb.isVisible( ) ) ? SizeImpl.create( 0, 0 )				: tb.getPreferredSize( xs, cm, rtc );		Bounds boPlot = p.getBounds( );		Bounds boLegend = lg.getBounds( );		// always layout title first.		Bounds boTitle = tb.getBounds( );		boTitle.setLeft( bo.getLeft( ) );		boTitle.setWidth( bo.getWidth( ) );		boTitle.setTop( bo.getTop( ) );		boTitle.setHeight( szTitle.getHeight( ) );		Size szLegend = ( !lg.isVisible( ) ) ? SizeImpl.create( 0, 0 )				: lg.getPreferredSize( xs, cm, rtc );		if ( !lg.isSetPosition( ) )		{			throw new ChartException( ChartEnginePlugin.ID,					ChartException.GENERATION,					Messages.getString( "error.legend.position", //$NON-NLS-1$							ULocale.getDefault( ) ) );		}		double plotWidthHint = -1, plotHeightHint = -1;		if ( p.isSetWidthHint( ) )		{			plotWidthHint = p.getWidthHint( );		}		if ( p.isSetHeightHint( ) )		{			plotHeightHint = p.getHeightHint( );		}		double plotLeft, plotTop;		// SETUP THE POSITION OF THE LEGEND AND THE PLOT		Position po = lg.getPosition( );		// swap right/left		if ( isRightToLeft )		{			if ( po == Position.RIGHT_LITERAL )			{				po = Position.LEFT_LITERAL;			}			else if ( po == Position.LEFT_LITERAL )			{				po = Position.RIGHT_LITERAL;			}		}		Anchor anchor = p.getAnchor( );		// swap west/east		if ( isRightToLeft )		{			switch ( anchor.getValue( ) )			{				case Anchor.EAST :					anchor = Anchor.WEST_LITERAL;					break;				case Anchor.NORTH_EAST :					anchor = Anchor.NORTH_WEST_LITERAL;					break;				case Anchor.SOUTH_EAST :					anchor = Anchor.SOUTH_WEST_LITERAL;					break;				case Anchor.WEST :					anchor = Anchor.EAST_LITERAL;					break;				case Anchor.NORTH_WEST :					anchor = Anchor.NORTH_EAST_LITERAL;					break;				case Anchor.SOUTH_WEST :					anchor = Anchor.SOUTH_EAST_LITERAL;					break;			}		}		switch ( po.getValue( ) )		{			case Position.INSIDE :				boPlot.setWidth( plotWidthHint < 0 ? bo.getWidth( )						: plotWidthHint );				boPlot.setHeight( plotHeightHint < 0 ? ( bo.getHeight( ) - szTitle.getHeight( ) )						: plotHeightHint );				plotLeft = bo.getLeft( );				plotTop = bo.getTop( ) + szTitle.getHeight( );				// adjust left.				switch ( anchor.getValue( ) )				{					case Anchor.EAST :					case Anchor.NORTH_EAST :					case Anchor.SOUTH_EAST :						plotLeft = plotLeft								+ bo.getWidth( )								- boPlot.getWidth( );						break;					case Anchor.NORTH :					case Anchor.SOUTH :						plotLeft = plotLeft								+ ( bo.getWidth( ) - boPlot.getWidth( ) )								/ 2;						break;				}				// adjust top.				switch ( anchor.getValue( ) )				{					case Anchor.SOUTH :					case Anchor.SOUTH_WEST :					case Anchor.SOUTH_EAST :						plotTop = plotTop								+ bo.getHeight( )								- szTitle.getHeight( )								- boPlot.getHeight( );						break;					case Anchor.WEST :					case Anchor.EAST :						plotTop = plotTop								+ ( bo.getHeight( ) - szTitle.getHeight( ) - boPlot.getHeight( ) )								/ 2;						break;				}				boPlot.setLeft( plotLeft );				boPlot.setTop( plotTop );				boLegend.set( 0, 0, szLegend.getWidth( ), szLegend.getHeight( ) );				break;			case Position.RIGHT :			case Position.OUTSIDE :				boLegend.setTop( bo.getTop( ) + szTitle.getHeight( ) );				boLegend.setLeft( bo.getLeft( )						+ bo.getWidth( )						- szLegend.getWidth( ) );				boLegend.setWidth( szLegend.getWidth( ) );				boLegend.setHeight( bo.getHeight( ) - szTitle.getHeight( ) );				boPlot.setWidth( plotWidthHint < 0 ? ( bo.getWidth( ) - boLegend.getWidth( ) )						: plotWidthHint );				boPlot.setHeight( plotHeightHint < 0 ? ( bo.getHeight( ) - szTitle.getHeight( ) )						: plotHeightHint );				plotLeft = bo.getLeft( );				plotTop = bo.getTop( ) + szTitle.getHeight( );				// adjust left.				switch ( anchor.getValue( ) )				{					case Anchor.EAST :					case Anchor.NORTH_EAST :					case Anchor.SOUTH_EAST :						plotLeft = plotLeft								+ bo.getWidth( )								- boLegend.getWidth( )								- boPlot.getWidth( );						break;					case Anchor.NORTH :					case Anchor.SOUTH :						plotLeft = plotLeft								+ ( bo.getWidth( ) - boLegend.getWidth( ) - boPlot.getWidth( ) )								/ 2;						break;				}				// adjust top.				switch ( anchor.getValue( ) )				{					case Anchor.SOUTH :					case Anchor.SOUTH_WEST :					case Anchor.SOUTH_EAST :						plotTop = plotTop								+ bo.getHeight( )								- szTitle.getHeight( )								- boPlot.getHeight( );						break;					case Anchor.WEST :					case Anchor.EAST :						plotTop = plotTop								+ ( bo.getHeight( ) - szTitle.getHeight( ) - boPlot.getHeight( ) )								/ 2;						break;				}				boPlot.setLeft( plotLeft );				boPlot.setTop( plotTop );				break;			case Position.LEFT :				boLegend.setTop( bo.getTop( ) + szTitle.getHeight( ) );				boLegend.setLeft( bo.getLeft( ) );				boLegend.setWidth( szLegend.getWidth( ) );				boLegend.setHeight( bo.getHeight( ) - szTitle.getHeight( ) );				boPlot.setWidth( plotWidthHint < 0 ? ( bo.getWidth( ) - boLegend.getWidth( ) )						: plotWidthHint );				boPlot.setHeight( plotHeightHint < 0 ? ( bo.getHeight( ) - szTitle.getHeight( ) )						: plotHeightHint );				plotLeft = bo.getLeft( ) + szLegend.getWidth( );				plotTop = bo.getTop( ) + szTitle.getHeight( );				// adjust left.				switch ( anchor.getValue( ) )				{					case Anchor.EAST :					case Anchor.NORTH_EAST :					case Anchor.SOUTH_EAST :						plotLeft = plotLeft								+ bo.getWidth( )								- boLegend.getWidth( )								- boPlot.getWidth( );						break;					case Anchor.NORTH :					case Anchor.SOUTH :						plotLeft = plotLeft								+ ( bo.getWidth( ) - boLegend.getWidth( ) - boPlot.getWidth( ) )								/ 2;						break;				}				// adjust top.				switch ( anchor.getValue( ) )				{					case Anchor.SOUTH :					case Anchor.SOUTH_WEST :					case Anchor.SOUTH_EAST :						plotTop = plotTop								+ bo.getHeight( )								- szTitle.getHeight( )								- boPlot.getHeight( );						break;					case Anchor.WEST :					case Anchor.EAST :						plotTop = plotTop								+ ( bo.getHeight( ) - szTitle.getHeight( ) - boPlot.getHeight( ) )								/ 2;						break;				}				boPlot.setLeft( plotLeft );				boPlot.setTop( plotTop );				break;			case Position.ABOVE :				boLegend.setTop( bo.getTop( ) + szTitle.getHeight( ) );				boLegend.setLeft( bo.getLeft( ) );				boLegend.setWidth( bo.getWidth( ) );				boLegend.setHeight( szLegend.getHeight( ) );				boPlot.setWidth( plotWidthHint < 0 ? bo.getWidth( )						: plotWidthHint );				boPlot.setHeight( plotHeightHint < 0 ? ( bo.getHeight( )						- szTitle.getHeight( ) - boLegend.getHeight( ) )						: plotHeightHint );				plotLeft = bo.getLeft( );				plotTop = bo.getTop( )						+ szTitle.getHeight( )						+ boLegend.getHeight( );				// adjust left.				switch ( anchor.getValue( ) )				{					case Anchor.EAST :					case Anchor.NORTH_EAST :					case Anchor.SOUTH_EAST :						plotLeft = plotLeft								+ bo.getWidth( )								- boPlot.getWidth( );						break;					case Anchor.NORTH :					case Anchor.SOUTH :						plotLeft = plotLeft								+ ( bo.getWidth( ) - boPlot.getWidth( ) )								/ 2;						break;				}				// adjust top.				switch ( anchor.getValue( ) )				{					case Anchor.SOUTH :					case Anchor.SOUTH_WEST :					case Anchor.SOUTH_EAST :						plotTop = plotTop								+ bo.getHeight( )								- szTitle.getHeight( )								- boLegend.getHeight( )								- boPlot.getHeight( );						break;					case Anchor.WEST :					case Anchor.EAST :						plotTop = plotTop								+ ( bo.getHeight( )										- szTitle.getHeight( )										- boLegend.getHeight( ) - boPlot.getHeight( ) )								/ 2;						break;				}				boPlot.setLeft( plotLeft );				boPlot.setTop( plotTop );				break;			case Position.BELOW :				boLegend.setTop( bo.getTop( )						+ bo.getHeight( )						- szLegend.getHeight( ) );				boLegend.setLeft( bo.getLeft( ) );				boLegend.setWidth( bo.getWidth( ) );				boLegend.setHeight( szLegend.getHeight( ) );				boPlot.setWidth( plotWidthHint < 0 ? bo.getWidth( )						: plotWidthHint );				boPlot.setHeight( plotHeightHint < 0 ? ( bo.getHeight( )						- boTitle.getHeight( ) - boLegend.getHeight( ) )						: plotHeightHint );				plotLeft = bo.getLeft( );				plotTop = bo.getTop( ) + szTitle.getHeight( );				// adjust left.				switch ( anchor.getValue( ) )				{					case Anchor.EAST :					case Anchor.NORTH_EAST :					case Anchor.SOUTH_EAST :						plotLeft = plotLeft								+ bo.getWidth( )								- boPlot.getWidth( );						break;					case Anchor.NORTH :					case Anchor.SOUTH :						plotLeft = plotLeft								+ ( bo.getWidth( ) - boPlot.getWidth( ) )								/ 2;						break;				}				// adjust top.				switch ( anchor.getValue( ) )				{					case Anchor.SOUTH :					case Anchor.SOUTH_WEST :					case Anchor.SOUTH_EAST :						plotTop = plotTop								+ bo.getHeight( )								- szTitle.getHeight( )								- boLegend.getHeight( )								- boPlot.getHeight( );						break;					case Anchor.WEST :					case Anchor.EAST :						plotTop = plotTop								+ ( bo.getHeight( )										- szTitle.getHeight( )										- boLegend.getHeight( ) - boPlot.getHeight( ) )								/ 2;						break;				}				boPlot.setLeft( plotLeft );				boPlot.setTop( plotTop );				break;		}		// layout custom blocks.		for ( Iterator itr = bl.getChildren( ).iterator( ); itr.hasNext( ); )		{			Block cbl = (Block) itr.next( );			if ( cbl != lg && cbl != p && cbl != tb )			{				layoutBlock( xs, cm, bl.getBounds( ), bl.getInsets( ), cbl, rtc );			}		}		// layout custom legend blocks.		for ( Iterator itr = lg.getChildren( ).iterator( ); itr.hasNext( ); )		{			Block cbl = (Block) itr.next( );			layoutBlock( xs, cm, lg.getBounds( ), lg.getInsets( ), cbl, rtc );		}		// layout custom title blocks.		for ( Iterator itr = tb.getChildren( ).iterator( ); itr.hasNext( ); )		{			Block cbl = (Block) itr.next( );			layoutBlock( xs, cm, tb.getBounds( ), tb.getInsets( ), cbl, rtc );		}		// layout custom plot blocks.		for ( Iterator itr = p.getChildren( ).iterator( ); itr.hasNext( ); )		{			Block cbl = (Block) itr.next( );			layoutBlock( xs, cm, p.getBounds( ), p.getInsets( ), cbl, rtc );		}	}