use of cbit.vcell.graph.StructureMappingStructureShape in project vcell by virtualcell.
the class GraphContainerLayoutVCellClassical method getPreferedSizeStructureMappingFeatureShape.
public Dimension getPreferedSizeStructureMappingFeatureShape(StructureMappingStructureShape shape, Graphics2D g) throws GraphModel.NotReadyException {
FontMetrics fm = g.getFontMetrics();
shape.getLabelSize().height = fm.getMaxAscent() + fm.getMaxDescent();
shape.getLabelSize().width = fm.stringWidth(shape.getLabel());
if (shape.countChildren() > 0) {
int totalHeight = shape.getLabelSize().height;
int maxWidth = shape.getLabelSize().width;
for (Shape child : shape.getChildren()) {
Dimension childDim = getPreferedSize(child, g);
totalHeight += childDim.height + StructureShape.defaultSpacingY;
maxWidth = Math.max(maxWidth, childDim.width);
}
shape.getSpaceManager().setSizePreferred((maxWidth + StructureShape.defaultSpacingX * 2), (totalHeight + StructureShape.defaultSpacingY));
} else {
shape.getSpaceManager().setSizePreferred((shape.getLabelSize().width + StructureShape.defaultSpacingX * 2), (shape.getLabelSize().height + StructureShape.defaultSpacingY * 2));
}
return shape.getSpaceManager().getSizePreferred();
}
use of cbit.vcell.graph.StructureMappingStructureShape in project vcell by virtualcell.
the class GraphContainerLayoutVCellClassical method refreshLayoutChildrenStructureMappingFeatureShape.
public void refreshLayoutChildrenStructureMappingFeatureShape(StructureMappingStructureShape shape) {
// calculate total height and max width of Child compartments (membranes)
int memHeight = 0;
int memWidth = 0;
for (Shape child : shape.getChildren()) {
memHeight += child.getSpaceManager().getSize().height;
memWidth = Math.max(memWidth, child.getSpaceManager().getSize().width);
}
// position label
int currentY = shape.getLabelSize().height;
currentY += shape.getLabelSize().height;
// find current centerX
int totalSpacingX = shape.getSpaceManager().getSize().width - memWidth;
if (totalSpacingX < 0) {
LayoutErrorLog.logErrorMessage("unable to fit children within container (width)");
}
int spacingX = totalSpacingX / 2;
int extraSpacingX = totalSpacingX % 2;
int currentX = spacingX + extraSpacingX;
// position child compartments
int totalSpacingY = (shape.getSpaceManager().getSize().height - currentY) - memHeight;
if (totalSpacingY < 0) {
LayoutErrorLog.logErrorMessage("unable to fit children within container (height)");
}
int spacingY = totalSpacingY / (shape.countChildren() + 1);
int extraSpacingY = totalSpacingY % (shape.countChildren() + 1);
int centerX = currentX + memWidth / 2;
// position children (and label)
int colY = currentY + extraSpacingY;
for (Shape child : shape.getChildren()) {
child.getSpaceManager().setRelPos(centerX - child.getSpaceManager().getSize().width / 2, colY);
colY += child.getSpaceManager().getSize().height + spacingY;
}
currentX += spacingX;
colY += spacingY;
if (colY != shape.getSpaceManager().getSize().height) {
throw new RuntimeException("layout for column incorrect (" + shape.getLabel() + "), currentY=" + currentY + ", screenSize.height=" + shape.getSpaceManager().getSize().height);
}
if (shape.countChildren() > 0) {
currentX += memWidth;
}
if (currentX != shape.getSpaceManager().getSize().width) {
throw new RuntimeException("layout for column widths incorrect (" + shape.getLabel() + "), currentX=" + currentX + ", screenSize.width=" + shape.getSpaceManager().getSize().width);
}
}
Aggregations