Program: 77479
Project: 77479
Buggy source:
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();
  Bounds boTitle=tb.getBounds();
  Anchor titleAnchor=tb.getAnchor();
  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("String_Node_Str",ULocale.getDefault()));
  }
  double plotWidthHint=-1, plotHeightHint=-1;
  if (p.isSetWidthHint()) {
    plotWidthHint=p.getWidthHint();
  }
  if (p.isSetHeightHint()) {
    plotHeightHint=p.getHeightHint();
  }
  double plotLeft, plotTop;
  Position po=lg.getPosition();
  if (isRightToLeft) {
    if (po == Position.RIGHT_LITERAL) {
      po=Position.LEFT_LITERAL;
    }
 else     if (po == Position.LEFT_LITERAL) {
      po=Position.RIGHT_LITERAL;
    }
  }
switch (po.getValue()) {
case Position.ABOVE:
case Position.BELOW:
    if (szLegend.getHeight() > bo.getHeight() / 3) {
      szLegend.setHeight(bo.getHeight() / 3);
    }
  break;
case Position.LEFT:
case Position.RIGHT:
case Position.OUTSIDE:
if (szLegend.getWidth() > bo.getWidth() / 3) {
  szLegend.setWidth(bo.getWidth() / 3);
}
break;
default :
break;
}
Anchor anchor=p.getAnchor();
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);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? bo.getHeight() : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
plotLeft=bo.getLeft();
plotTop=bo.getTop();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
plotLeft=bo.getLeft() + szTitle.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + szTitle.getHeight();
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
boLegend.set(0,0,szLegend.getWidth(),szLegend.getHeight());
break;
case Position.RIGHT:
case Position.OUTSIDE:
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);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - boLegend.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? bo.getHeight() : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
boLegend.setHeight(bo.getHeight());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
boLegend.setTop(bo.getTop());
boLegend.setLeft(bo.getLeft() + bo.getWidth() - szLegend.getWidth());
plotLeft=bo.getLeft();
plotTop=bo.getTop();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
plotLeft=bo.getLeft() + szTitle.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
boLegend.setLeft(boTitle.getLeft() - szLegend.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + szTitle.getHeight();
boLegend.setTop(bo.getTop() + szTitle.getHeight());
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boLegend.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boLegend.getWidth()- boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
break;
case Position.LEFT:
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);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - boLegend.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? bo.getHeight() : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
boLegend.setHeight(bo.getHeight());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
boLegend.setTop(bo.getTop());
boLegend.setLeft(bo.getLeft());
plotLeft=bo.getLeft() + szLegend.getWidth();
plotTop=bo.getTop();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
boLegend.setLeft(bo.getLeft() + szTitle.getWidth());
plotLeft=boLegend.getLeft() + szLegend.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + szTitle.getHeight();
boLegend.setTop(bo.getTop() + szTitle.getHeight());
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boLegend.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boLegend.getWidth()- boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
break;
case Position.ABOVE:
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);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? (bo.getHeight() - boLegend.getHeight()) : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
boLegend.setWidth(bo.getWidth() - szTitle.getWidth());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
boLegend.setTop(bo.getTop());
boLegend.setLeft(bo.getLeft());
plotLeft=bo.getLeft();
plotTop=bo.getTop() + boLegend.getHeight();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
boLegend.setLeft(bo.getLeft() + szTitle.getWidth());
plotLeft=bo.getLeft() + szTitle.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + boLegend.getHeight() + szTitle.getHeight();
boLegend.setTop(bo.getTop() + szTitle.getHeight());
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boLegend.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boLegend.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
break;
case Position.BELOW:
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);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? (bo.getHeight() - boLegend.getHeight()) : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
boLegend.setWidth(bo.getWidth() - szTitle.getWidth());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
boLegend.setTop(bo.getTop() + bo.getHeight() - szLegend.getHeight());
boLegend.setLeft(bo.getLeft());
plotLeft=bo.getLeft();
plotTop=bo.getTop();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
boLegend.setLeft(bo.getLeft() + szTitle.getWidth());
plotLeft=bo.getLeft() + szTitle.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + szTitle.getHeight();
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boLegend.setTop(boTitle.getTop() - szLegend.getHeight());
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boLegend.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boLegend.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
break;
}
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);
}
}
for (Iterator itr=lg.getChildren().iterator(); itr.hasNext(); ) {
Block cbl=(Block)itr.next();
layoutBlock(xs,cm,lg.getBounds(),lg.getInsets(),cbl,rtc);
}
for (Iterator itr=tb.getChildren().iterator(); itr.hasNext(); ) {
Block cbl=(Block)itr.next();
layoutBlock(xs,cm,tb.getBounds(),tb.getInsets(),cbl,rtc);
}
for (Iterator itr=p.getChildren().iterator(); itr.hasNext(); ) {
Block cbl=(Block)itr.next();
layoutBlock(xs,cm,p.getBounds(),p.getInsets(),cbl,rtc);
}
}

Fixed version (ground truth):
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();
  Bounds boTitle=tb.getBounds();
  Anchor titleAnchor=tb.getAnchor();
  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("String_Node_Str",ULocale.getDefault()));
  }
  double plotWidthHint=-1, plotHeightHint=-1;
  if (p.isSetWidthHint()) {
    plotWidthHint=p.getWidthHint();
  }
  if (p.isSetHeightHint()) {
    plotHeightHint=p.getHeightHint();
  }
  double plotLeft, plotTop;
  Position po=lg.getPosition();
  if (isRightToLeft) {
    if (po == Position.RIGHT_LITERAL) {
      po=Position.LEFT_LITERAL;
    }
 else     if (po == Position.LEFT_LITERAL) {
      po=Position.RIGHT_LITERAL;
    }
  }
  final double renderLegendHeight=szLegend.getHeight();
  final double renderLegendWidth=szLegend.getWidth();
switch (po.getValue()) {
case Position.ABOVE:
case Position.BELOW:
    if (szLegend.getHeight() > bo.getHeight() / 3) {
      szLegend.setHeight(bo.getHeight() / 3);
    }
  break;
case Position.LEFT:
case Position.RIGHT:
case Position.OUTSIDE:
if (szLegend.getWidth() > bo.getWidth() / 3) {
  szLegend.setWidth(bo.getWidth() / 3);
}
break;
default :
break;
}
Anchor anchor=p.getAnchor();
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);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? bo.getHeight() : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
plotLeft=bo.getLeft();
plotTop=bo.getTop();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
plotLeft=bo.getLeft() + szTitle.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + szTitle.getHeight();
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
boLegend.set(0,0,szLegend.getWidth(),szLegend.getHeight());
break;
case Position.RIGHT:
case Position.OUTSIDE:
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);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - boLegend.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? bo.getHeight() : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
boLegend.setHeight(bo.getHeight());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
boLegend.setTop(bo.getTop());
boLegend.setLeft(bo.getLeft() + bo.getWidth() - szLegend.getWidth());
plotLeft=bo.getLeft();
plotTop=bo.getTop();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
plotLeft=bo.getLeft() + szTitle.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
boLegend.setLeft(boTitle.getLeft() - szLegend.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + szTitle.getHeight();
boLegend.setTop(bo.getTop() + szTitle.getHeight());
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boLegend.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boLegend.getWidth()- boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
break;
case Position.LEFT:
boLegend.setWidth(renderLegendWidth);
boLegend.setHeight(bo.getHeight() - szTitle.getHeight());
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - boLegend.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? (bo.getHeight() - szTitle.getHeight()) : plotHeightHint);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - boLegend.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? bo.getHeight() : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
boLegend.setHeight(bo.getHeight());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
boLegend.setTop(bo.getTop());
boLegend.setLeft(bo.getLeft() + szLegend.getWidth() - renderLegendWidth);
plotLeft=bo.getLeft() + szLegend.getWidth();
plotTop=bo.getTop();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
boLegend.setLeft(bo.getLeft() + szTitle.getWidth() + szLegend.getWidth() - renderLegendWidth);
plotLeft=bo.getLeft() + szTitle.getWidth() + szLegend.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + szTitle.getHeight();
boLegend.setTop(bo.getTop() + szTitle.getHeight());
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boLegend.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boLegend.getWidth()- boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
break;
case Position.ABOVE:
boLegend.setWidth(bo.getWidth());
boLegend.setHeight(renderLegendHeight);
boPlot.setWidth(plotWidthHint < 0 ? bo.getWidth() : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? (bo.getHeight() - szTitle.getHeight() - szLegend.getHeight()) : plotHeightHint);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? (bo.getHeight() - boLegend.getHeight()) : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
boLegend.setWidth(bo.getWidth() - szTitle.getWidth());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
boLegend.setTop(bo.getTop() + szLegend.getHeight() - renderLegendHeight);
boLegend.setLeft(bo.getLeft());
plotLeft=bo.getLeft();
plotTop=bo.getTop() + szLegend.getHeight();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
boLegend.setLeft(bo.getLeft() + szTitle.getWidth());
plotLeft=bo.getLeft() + szTitle.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + szLegend.getHeight() + szTitle.getHeight();
boLegend.setTop(bo.getTop() + szTitle.getHeight() + szLegend.getHeight() - renderLegendHeight);
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boLegend.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boLegend.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
break;
case Position.BELOW:
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);
switch (titleAnchor.getValue()) {
case Anchor.EAST:
case Anchor.WEST:
boPlot.setWidth(plotWidthHint < 0 ? (bo.getWidth() - szTitle.getWidth()) : plotWidthHint);
boPlot.setHeight(plotHeightHint < 0 ? (bo.getHeight() - boLegend.getHeight()) : plotHeightHint);
boTitle.setHeight(bo.getHeight());
boTitle.setWidth(szTitle.getWidth());
boLegend.setWidth(bo.getWidth() - szTitle.getWidth());
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boTitle.setTop(bo.getTop() + bo.getHeight() - szTitle.getHeight());
break;
}
boLegend.setTop(bo.getTop() + bo.getHeight() - szLegend.getHeight());
boLegend.setLeft(bo.getLeft());
plotLeft=bo.getLeft();
plotTop=bo.getTop();
switch (titleAnchor.getValue()) {
case Anchor.WEST:
boLegend.setLeft(bo.getLeft() + szTitle.getWidth());
plotLeft=bo.getLeft() + szTitle.getWidth();
break;
case Anchor.EAST:
boTitle.setLeft(bo.getLeft() + bo.getWidth() - szTitle.getWidth());
break;
case Anchor.NORTH:
case Anchor.NORTH_EAST:
case Anchor.NORTH_WEST:
plotTop=bo.getTop() + szTitle.getHeight();
break;
case Anchor.SOUTH:
case Anchor.SOUTH_EAST:
case Anchor.SOUTH_WEST:
boLegend.setTop(boTitle.getTop() - szLegend.getHeight());
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
plotLeft=plotLeft + bo.getWidth() - szTitle.getWidth() - boPlot.getWidth();
break;
case Anchor.NORTH:
case Anchor.SOUTH:
plotLeft=plotLeft + (bo.getWidth() - szTitle.getWidth() - boPlot.getWidth()) / 2;
break;
}
break;
default :
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;
}
break;
}
switch (titleAnchor.getValue()) {
case Anchor.WEST:
case Anchor.EAST:
switch (anchor.getValue()) {
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
plotTop=plotTop + bo.getHeight() - boLegend.getHeight() - boPlot.getHeight();
break;
case Anchor.WEST:
case Anchor.EAST:
plotTop=plotTop + (bo.getHeight() - boLegend.getHeight() - boPlot.getHeight()) / 2;
break;
}
break;
default :
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;
}
break;
}
boPlot.setLeft(plotLeft);
boPlot.setTop(plotTop);
break;
}
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);
}
}
for (Iterator itr=lg.getChildren().iterator(); itr.hasNext(); ) {
Block cbl=(Block)itr.next();
layoutBlock(xs,cm,lg.getBounds(),lg.getInsets(),cbl,rtc);
}
for (Iterator itr=tb.getChildren().iterator(); itr.hasNext(); ) {
Block cbl=(Block)itr.next();
layoutBlock(xs,cm,tb.getBounds(),tb.getInsets(),cbl,rtc);
}
for (Iterator itr=p.getChildren().iterator(); itr.hasNext(); ) {
Block cbl=(Block)itr.next();
layoutBlock(xs,cm,p.getBounds(),p.getInsets(),cbl,rtc);
}
}