use of java.awt.FontMetrics 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 java.awt.FontMetrics in project vcell by virtualcell.
the class FluxReactionShape method getPreferedSizeSelf.
@Override
public Dimension getPreferedSizeSelf(Graphics2D g) {
getSpaceManager().setSizePreferred(25, 25);
if (getLabel() != null && getLabel().length() > 0) {
FontMetrics fontMetrics = g.getFontMetrics();
setLabelSize(fontMetrics.stringWidth(getLabel()), fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent());
}
return getSpaceManager().getSizePreferred();
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class MolecularComponentLargeShape method getStateStringWidth.
private static int getStateStringWidth(String s, Graphics gc, LargeShapeCanvas shapePanel) {
Font font = deriveStateFont(gc, shapePanel);
FontMetrics fm = gc.getFontMetrics(font);
return fm.stringWidth(s);
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class MolecularComponentLargeShape method computeStateHeight.
public static int computeStateHeight(Graphics gc, LargeShapeCanvas shapePanel) {
Font font = deriveStateFont(gc, shapePanel);
FontMetrics fm = gc.getFontMetrics(font);
if (shapePanel.getZoomFactor() < LargeShapeCanvas.SmallestZoomFactorWithText) {
// when we zoom to very small shapes we stop showing text, hence no need to reserve pixels
return fm.getHeight() + 1;
} else {
// we allow 2 pixels above and below the state text
return fm.getHeight() + 4;
}
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class MolecularComponentLargeShape method getStringHeight.
private int getStringHeight(Font font) {
Graphics gc = shapePanel.getGraphics();
FontMetrics fm = gc.getFontMetrics(font);
int stringHeight = fm.getHeight();
return stringHeight;
}
Aggregations