Search in sources :

Example 76 with FontMetrics

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();
}
Also used : FontMetrics(java.awt.FontMetrics)

Example 77 with FontMetrics

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();
}
Also used : FontMetrics(java.awt.FontMetrics)

Example 78 with FontMetrics

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);
    }
}
Also used : SubVolumeContainerShape(cbit.vcell.graph.SubVolumeContainerShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) MembraneShape(cbit.vcell.graph.MembraneShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) GeometryContextStructureShape(cbit.vcell.graph.GeometryContextStructureShape) FeatureShape(cbit.vcell.graph.FeatureShape) StructureMappingStructureShape(cbit.vcell.graph.StructureMappingStructureShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) GeometryContextContainerShape(cbit.vcell.graph.GeometryContextContainerShape) GeometryContextGeometryShape(cbit.vcell.graph.GeometryContextGeometryShape) StructureShape(cbit.vcell.graph.StructureShape) GeometryClassLegendShape(cbit.vcell.graph.GeometryClassLegendShape) BioPaxShape(cbit.vcell.client.desktop.biomodel.pathway.shapes.BioPaxShape) GeometryContextStructureShape(cbit.vcell.graph.GeometryContextStructureShape) StructureMappingStructureShape(cbit.vcell.graph.StructureMappingStructureShape) StructureShape(cbit.vcell.graph.StructureShape) FontMetrics(java.awt.FontMetrics) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) Dimension(java.awt.Dimension) Font(java.awt.Font) Point(java.awt.Point)

Example 79 with FontMetrics

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();
}
Also used : FeatureShape(cbit.vcell.graph.FeatureShape) FontMetrics(java.awt.FontMetrics) Dimension(java.awt.Dimension)

Example 80 with FontMetrics

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();
}
Also used : FontMetrics(java.awt.FontMetrics)

Aggregations

FontMetrics (java.awt.FontMetrics)179 Font (java.awt.Font)61 Graphics2D (java.awt.Graphics2D)35 Point (java.awt.Point)34 Dimension (java.awt.Dimension)29 Color (java.awt.Color)23 Rectangle (java.awt.Rectangle)21 Rectangle2D (java.awt.geom.Rectangle2D)21 Insets (java.awt.Insets)20 Graphics (java.awt.Graphics)16 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)14 GradientPaint (java.awt.GradientPaint)14 MPart (gov.sandia.n2a.eqset.MPart)13 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)12 Paint (java.awt.Paint)10 JTree (javax.swing.JTree)10 BasicStroke (java.awt.BasicStroke)9 BufferedImage (java.awt.image.BufferedImage)9 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)8 JLabel (javax.swing.JLabel)8