use of java.awt.FontMetrics in project vcell by virtualcell.
the class EdgeShape method getPreferedSizeSelf.
@Override
public Dimension getPreferedSizeSelf(Graphics2D g) {
FontMetrics fm = g.getFontMetrics();
setLabelSize(fm.stringWidth(getLabel()), fm.getMaxAscent() + fm.getMaxDescent());
getSpaceManager().setSizePreferred((getLabelSize().height + 10), (getLabelSize().width + 10));
return getSpaceManager().getSizePreferred();
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class ElipseShape method getPreferedSizeSelf.
@Override
public Dimension getPreferedSizeSelf(Graphics2D g) {
ShapeSpaceManager spaceManager = getSpaceManager();
FontMetrics fm = g.getFontMetrics();
setLabelSize(fm.stringWidth(getLabel()), fm.getMaxAscent() + fm.getMaxDescent());
spaceManager.setSizePreferred(getLabelSize().width + 10, getLabelSize().height + 10);
return spaceManager.getSizePreferred();
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class GraphContainerLayoutVCellClassical method getPreferedSizeFeatureShape.
public Dimension getPreferedSizeFeatureShape(FeatureShape shape, Graphics2D g) throws GraphModel.NotReadyException {
Font origfont = g.getFont();
g.setFont(shape.getLabelFont(g));
FontMetrics fm = g.getFontMetrics();
shape.setLabelSize(fm.stringWidth(shape.getLabel()), fm.getMaxAscent() + fm.getMaxDescent());
shape.getLabelPos().x = shape.getSpaceManager().getSize().width / 2 - fm.stringWidth(shape.getLabel()) / 2;
shape.getLabelPos().y = 5 + fm.getMaxAscent();
try {
if (shape.countChildren() > 0) {
int structCount = 0;
int childStructureTotalHeight = shape.getLabelSize().height;
int childStructureMaxWidth = shape.getLabelSize().width;
for (Shape child : shape.getChildren()) {
if (child instanceof StructureShape) {
structCount += 1;
Dimension childDim = getPreferedSize(child, g);
childStructureTotalHeight += childDim.height + StructureShape.defaultSpacingY;
childStructureMaxWidth = Math.max(childStructureMaxWidth, childDim.width);
}
}
int scsCount = 0;
// int childSCTotalHeight = 0;
int childSCMaxWidth = 0;
int childSCMaxHeight = 0;
for (Shape child : shape.getChildren()) {
if (child instanceof SpeciesContextShape) {
scsCount += 1;
Dimension childDim = getPreferedSize(child, g);
childSCMaxHeight = Math.max(childSCMaxHeight, childDim.height + ((SpeciesContextShape) child).getSmallLabelSize().height);
childSCMaxWidth = Math.max(childSCMaxWidth, childDim.width);
childSCMaxWidth = Math.max(childSCMaxWidth, ((SpeciesContextShape) child).getSmallLabelSize().width);
}
}
Dimension box = new Dimension();
if (scsCount != 0) {
int squareBoxX = (int) Math.ceil(Math.sqrt(scsCount));
int squareBoxY = squareBoxX - (int) (((squareBoxX * squareBoxX) % scsCount) / (double) squareBoxX);
int width1 = (squareBoxX * (childSCMaxWidth + 0));
// + defaultSpacingX;
int height1 = (squareBoxY * (childSCMaxHeight + 30));
// + defaultSpacingY;
box = new Dimension(width1, height1);
}
if (structCount == 0) {
shape.getSpaceManager().setSizePreferred((box.width + StructureShape.defaultSpacingX * 2), (box.height + StructureShape.defaultSpacingY * 2));
} else {
shape.getSpaceManager().setSizePreferred((childStructureMaxWidth + box.width + StructureShape.defaultSpacingX * 2), (Math.max(childStructureTotalHeight, box.height) + StructureShape.defaultSpacingY * 2));
}
} else {
shape.getSpaceManager().setSizePreferred((shape.getLabelSize().width + StructureShape.defaultSpacingX * 2), (shape.getLabelSize().height + StructureShape.defaultSpacingY * 2));
}
return shape.getSpaceManager().getSizePreferred();
} finally {
g.setFont(origfont);
}
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class GraphContainerLayoutVCellClassical method getPreferedSizeMembraneShape.
public Dimension getPreferedSizeMembraneShape(MembraneShape shape, Graphics2D g) throws GraphModel.NotReadyException {
FontMetrics fm = g.getFontMetrics();
shape.setLabelSize(fm.stringWidth(shape.getLabel()), fm.getMaxAscent() + fm.getMaxDescent());
// has 1 child (featureShape)
if (shape.childShapeList.size() == 1) {
FeatureShape featureShape = (FeatureShape) shape.childShapeList.get(0);
Dimension featureDim = getPreferedSize(featureShape, g);
shape.getSpaceManager().setSizePreferred((featureDim.width + MembraneShape.memSpacingX * 2), (featureDim.height + MembraneShape.memSpacingY * 2));
}
return shape.getSpaceManager().getSizePreferred();
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class BioPaxShape method getPreferedSizeSelf.
@Override
public Dimension getPreferedSizeSelf(Graphics2D g) {
FontMetrics fm = g.getFontMetrics();
setLabelSize(fm.stringWidth(getLabel()), fm.getMaxAscent() + fm.getMaxDescent());
smallLabelSize.width = (smallLabel != null ? fm.stringWidth(smallLabel) : getLabelSize().width);
smallLabelSize.height = getLabelSize().height;
getSpaceManager().setSizePreferred(getPreferredWidth(), getPreferredHeight());
return getSpaceManager().getSizePreferred();
}
Aggregations