float yName = yRoomCenter + room.getNameYOffset();
TextStyle nameStyle = room.getNameStyle();
if (nameStyle == null) {
nameStyle = this.preferences.getDefaultTextStyle(room.getClass());
}
FontMetrics nameFontMetrics = getFontMetrics(componentFont, nameStyle);
Rectangle2D nameBounds = nameFontMetrics.getStringBounds(roomName, g);
itemBounds.add(xName - nameBounds.getWidth() / 2,
yName - nameFontMetrics.getAscent());
itemBounds.add(xName + nameBounds.getWidth() / 2,
yName + nameFontMetrics.getDescent());
}
if (room.isAreaVisible()) {
float area = room.getArea();
if (area > 0.01f) {
float xArea = xRoomCenter + room.getAreaXOffset();
float yArea = yRoomCenter + room.getAreaYOffset();
String areaText = this.preferences.getLengthUnit().getAreaFormatWithUnit().format(area);
TextStyle areaStyle = room.getAreaStyle();
if (areaStyle == null) {
areaStyle = this.preferences.getDefaultTextStyle(room.getClass());
}
FontMetrics areaFontMetrics = getFontMetrics(componentFont, areaStyle);
Rectangle2D areaTextBounds = areaFontMetrics.getStringBounds(areaText, g);
itemBounds.add(xArea - areaTextBounds.getWidth() / 2,
yArea - areaFontMetrics.getAscent());
itemBounds.add(xArea + areaTextBounds.getWidth() / 2,
yArea + areaFontMetrics.getDescent());
}
}
} else if (item instanceof HomePieceOfFurniture) {
if (item instanceof HomeDoorOrWindow) {
HomeDoorOrWindow doorOrWindow = (HomeDoorOrWindow)item;
// Add to bounds door and window sashes
for (Sash sash : doorOrWindow.getSashes()) {
itemBounds.add(getDoorOrWindowSashShape(doorOrWindow, sash).getBounds2D());
}
} else if (item instanceof HomeFurnitureGroup) {
itemBounds.add(getItemsBounds(g, ((HomeFurnitureGroup)item).getFurniture()));
}
// Add to bounds the displayed name of the piece of furniture
HomePieceOfFurniture piece = (HomePieceOfFurniture)item;
float xPiece = piece.getX();
float yPiece = piece.getY();
String pieceName = piece.getName();
if (piece.isVisible()
&& piece.isNameVisible()
&& pieceName.length() > 0) {
float xName = xPiece + piece.getNameXOffset();
float yName = yPiece + piece.getNameYOffset();
TextStyle nameStyle = piece.getNameStyle();
if (nameStyle == null) {
nameStyle = this.preferences.getDefaultTextStyle(piece.getClass());
}
FontMetrics nameFontMetrics = getFontMetrics(componentFont, nameStyle);
Rectangle2D nameBounds = nameFontMetrics.getStringBounds(pieceName, g);
itemBounds.add(xName - nameBounds.getWidth() / 2,
yName - nameFontMetrics.getAscent());
itemBounds.add(xName + nameBounds.getWidth() / 2,
yName + nameFontMetrics.getDescent());
}
} else if (item instanceof DimensionLine) {
// Add to bounds the text bounds of the dimension line length
DimensionLine dimensionLine = (DimensionLine)item;
float dimensionLineLength = dimensionLine.getLength();
String lengthText = this.preferences.getLengthUnit().getFormat().format(dimensionLineLength);
TextStyle lengthStyle = dimensionLine.getLengthStyle();
if (lengthStyle == null) {
lengthStyle = this.preferences.getDefaultTextStyle(dimensionLine.getClass());
}
FontMetrics lengthFontMetrics = getFontMetrics(componentFont, lengthStyle);
Rectangle2D lengthTextBounds = lengthFontMetrics.getStringBounds(lengthText, g);
// Transform length text bounding rectangle corners to their real location
double angle = Math.atan2(dimensionLine.getYEnd() - dimensionLine.getYStart(),
dimensionLine.getXEnd() - dimensionLine.getXStart());
AffineTransform transform = new AffineTransform();
transform.translate(dimensionLine.getXStart(), dimensionLine.getYStart());
transform.rotate(angle);
transform.translate(0, dimensionLine.getOffset());
transform.translate((dimensionLineLength - lengthTextBounds.getWidth()) / 2,
dimensionLine.getOffset() <= 0
? -lengthFontMetrics.getDescent() - 1
: lengthFontMetrics.getAscent() + 1);
GeneralPath lengthTextBoundsPath = new GeneralPath(lengthTextBounds);
for (PathIterator it = lengthTextBoundsPath.getPathIterator(transform); !it.isDone(); ) {
float [] pathPoint = new float[2];
if (it.currentSegment(pathPoint) != PathIterator.SEG_CLOSE) {
itemBounds.add(pathPoint [0], pathPoint [1]);
}
it.next();
}
// Add to bounds the end lines drawn at dimension line start and end
transform = new AffineTransform();
transform.translate(dimensionLine.getXStart(), dimensionLine.getYStart());
transform.rotate(angle);
transform.translate(0, dimensionLine.getOffset());
for (PathIterator it = DIMENSION_LINE_END.getPathIterator(transform); !it.isDone(); ) {
float [] pathPoint = new float[2];
if (it.currentSegment(pathPoint) != PathIterator.SEG_CLOSE) {
itemBounds.add(pathPoint [0], pathPoint [1]);
}
it.next();
}
transform.translate(dimensionLineLength, 0);
for (PathIterator it = DIMENSION_LINE_END.getPathIterator(transform); !it.isDone(); ) {
float [] pathPoint = new float[2];
if (it.currentSegment(pathPoint) != PathIterator.SEG_CLOSE) {
itemBounds.add(pathPoint [0], pathPoint [1]);
}
it.next();
}
} else if (item instanceof Label) {
// Add to bounds the displayed text of a label
Label label = (Label)item;
float xLabel = label.getX();
float yLabel = label.getY();
String labelText = label.getText();
TextStyle labelStyle = label.getStyle();
if (labelStyle == null) {
labelStyle = this.preferences.getDefaultTextStyle(label.getClass());
}
FontMetrics labelFontMetrics = getFontMetrics(componentFont, labelStyle);
Rectangle2D labelBounds = labelFontMetrics.getStringBounds(labelText, g);
itemBounds.add(xLabel - labelBounds.getWidth() / 2,
yLabel - labelFontMetrics.getAscent());
itemBounds.add(xLabel + labelBounds.getWidth() / 2,
yLabel + labelFontMetrics.getDescent());
} else if (item instanceof Compass) {
Compass compass = (Compass)item;
AffineTransform transform = AffineTransform.getTranslateInstance(compass.getX(), compass.getY());
transform.scale(compass.getDiameter(), compass.getDiameter());
transform.rotate(compass.getNorthDirection());