}
@Test
public void testGetSize() {
// horizontal
ScalebarAttribute attribute = new ScalebarAttribute();
attribute.setWidth(180);
attribute.setHeight(40);
ScalebarAttributeValues params = attribute.createValue(null);
params.labelDistance = 3;
params.barSize = 8;
ScaleBarRenderSettings settings = new ScaleBarRenderSettings();
settings.setParams(params);
settings.setDpiRatio(1.0);
settings.setIntervalLengthInPixels(40);
settings.setLeftLabelMargin(3.0f);
settings.setRightLabelMargin(4.0f);
settings.setMaxSize(new Dimension(180, 40));
settings.setBarSize(8);
settings.setPadding(4);
settings.setLabelDistance(3);
assertEquals(
new Dimension(135, 31),
ScalebarGraphic.getSize(params, settings, new Dimension(30, 12)));
// horizontal: barSize and labelDistance calculated from height
params.orientation = Orientation.HORIZONTAL_LABELS_ABOVE.getLabel();
params.labelDistance = null;
params.barSize = null;
settings.setBarSize(ScalebarGraphic.getBarSize(settings));
settings.setLabelDistance(ScalebarGraphic.getLabelDistance(settings));
assertEquals(
new Dimension(135, 34),
ScalebarGraphic.getSize(params, settings, new Dimension(30, 12)));
// vertical
attribute.setWidth(60);
attribute.setHeight(180);
settings.setMaxSize(new Dimension(60, 180));
params = attribute.createValue(null);
settings.setParams(params);
params.orientation = Orientation.VERTICAL_LABELS_LEFT.getLabel();
params.labelDistance = 3;
params.barSize = 8;
settings.setTopLabelMargin(5.0f);