Search in sources :

Example 86 with FontMetrics

use of java.awt.FontMetrics in project vcell by virtualcell.

the class MolecularTypeLargeShape method flash.

public void flash(String matchKey) {
    if (!(owner instanceof ReactionRule)) {
        return;
    }
    if (mtp != null && mtp.hasExplicitParticipantMatch() && mtp.getParticipantMatchLabel().equals(matchKey)) {
        Graphics g = shapePanel.getGraphics();
        Graphics2D g2 = (Graphics2D) g;
        Font fontOld = g2.getFont();
        Color colorOld = g2.getColor();
        Color color = (Color.red).darker();
        Font font = deriveMoleculeFontBold(g, shapePanel);
        Font smallerFont = font.deriveFont(font.getSize() * 0.8F);
        g.setFont(smallerFont);
        FontMetrics fm = g.getFontMetrics(font);
        int stringWidth = fm.stringWidth(name);
        int textX = xPos + 11;
        int textY = yPos + baseHeight - (baseHeight - smallerFont.getSize()) / 2;
        g.setColor(color);
        g2.drawString(mtp.getParticipantMatchLabel(), textX + stringWidth + 2, textY + 2);
        g.setFont(fontOld);
        g.setColor(colorOld);
    }
}
Also used : Graphics(java.awt.Graphics) ReactionRule(cbit.vcell.model.ReactionRule) FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Font(java.awt.Font) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 87 with FontMetrics

use of java.awt.FontMetrics in project vcell by virtualcell.

the class MolecularTypeLargeShape method getLabelOutline.

@Override
public Rectangle getLabelOutline() {
    Graphics gc = shapePanel.getGraphics();
    Font font = gc.getFont().deriveFont(Font.BOLD);
    FontMetrics fm = gc.getFontMetrics(font);
    int stringWidth = fm.stringWidth(getFullName());
    Rectangle labelOutline = new Rectangle(xPos + 8, yPos + 7, stringWidth + 11, fm.getHeight() + 5);
    return labelOutline;
}
Also used : Graphics(java.awt.Graphics) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) Font(java.awt.Font) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 88 with FontMetrics

use of java.awt.FontMetrics in project vcell by virtualcell.

the class MolecularTypeLargeShape method getStringWidth.

private int getStringWidth(String s) {
    Graphics gc = shapePanel.getGraphics();
    Font font = gc.getFont().deriveFont(Font.BOLD);
    FontMetrics fm = gc.getFontMetrics(font);
    int stringWidth = fm.stringWidth(s);
    // int textwidth = (int)(font.getStringBounds(s, frc).getWidth());
    return stringWidth;
}
Also used : Graphics(java.awt.Graphics) FontMetrics(java.awt.FontMetrics) Font(java.awt.Font) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 89 with FontMetrics

use of java.awt.FontMetrics in project vcell by virtualcell.

the class ExpressionCanvas method getMinimumSize.

/**
 * Insert the method's description here.
 * Creation date: (11/19/2002 11:26:26 AM)
 * @return java.awt.Dimension
 */
public Dimension getMinimumSize() {
    Graphics2D g = (Graphics2D) getGraphics();
    if (g != null) {
        g.setClip(0, 0, getSize().width, getSize().height);
        Font canvasFont = new Font("SansSerif", Font.ITALIC, 11);
        g.setFont(canvasFont);
        FontMetrics fontMetrics = g.getFontMetrics();
        try {
            Dimension minSize = new Dimension(10, 10);
            if (fieldExpressions != null) {
                for (int i = 0; i < fieldExpressions.length; i++) {
                    ExpressionPrintFormatter expPrintFormatter = new ExpressionPrintFormatter(fieldExpressions[i]);
                    Dimension expressionDim = expPrintFormatter.getSize(g);
                    int labelWidth = 0;
                    if (fieldPrefixLabels != null) {
                        labelWidth += g.getFontMetrics().stringWidth(fieldPrefixLabels[i]) + 20;
                    }
                    if (fieldSuffixLabels != null) {
                        labelWidth += g.getFontMetrics().stringWidth(fieldSuffixLabels[i]) + 20;
                    }
                    minSize.width = Math.max(minSize.width, expressionDim.width + 20 + labelWidth);
                    minSize.height += expressionDim.height + 20;
                }
            } else {
                for (String expString : fieldStrings) {
                    int stringWidth = fontMetrics.stringWidth(expString);
                    int stringHeight = fontMetrics.getHeight();
                    minSize.width = Math.max(minSize.width, stringWidth);
                    minSize.height += stringHeight + 20;
                }
            }
            return minSize;
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
            return super.getMinimumSize();
        }
    } else {
        return super.getMinimumSize();
    }
}
Also used : ExpressionPrintFormatter(cbit.vcell.parser.ExpressionPrintFormatter) FontMetrics(java.awt.FontMetrics) Dimension(java.awt.Dimension) Font(java.awt.Font) ExpressionException(cbit.vcell.parser.ExpressionException) Graphics2D(java.awt.Graphics2D)

Example 90 with FontMetrics

use of java.awt.FontMetrics in project vcell by virtualcell.

the class RbmMolecularTypeTreeCellRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    setBorder(null);
    if (value instanceof BioModelNode) {
        BioModelNode node = (BioModelNode) value;
        Object userObject = node.getUserObject();
        String text = null;
        String toolTip = null;
        Icon icon = null;
        if (userObject instanceof MolecularType) {
            MolecularType mt = (MolecularType) userObject;
            text = toHtml(mt, true);
            toolTip = toHtmlWithTip(mt, true);
            if (owner == null) {
                icon = VCellIcons.rbmMolecularTypeSimpleIcon;
                ;
            } else {
                Graphics gc = owner.getGraphics();
                icon = new MolecularTypeSmallShape(1, 4, mt, null, gc, mt, null, issueManager);
            }
        } else if (userObject instanceof MolecularComponent) {
            BioModelNode parentNode = (BioModelNode) node.getParent();
            MolecularComponent mc = (MolecularComponent) userObject;
            text = toHtml(mc, true);
            toolTip = toHtmlWithTip(mc, true);
            icon = VCellIcons.rbmComponentGreenIcon;
            if (mc.getComponentStateDefinitions().size() > 0) {
                icon = VCellIcons.rbmComponentGreenStateIcon;
            }
            // here is how to set the cell minimum size !!!
            FontMetrics fm = getFontMetrics(getFont());
            int width = fm.stringWidth(text);
            setMinimumSize(new Dimension(width + 50, fm.getHeight() + 5));
        } else if (userObject instanceof ComponentStateDefinition) {
            ComponentStateDefinition cs = (ComponentStateDefinition) userObject;
            text = toHtml(cs);
            toolTip = toHtmlWithTip(cs);
            icon = VCellIcons.rbmComponentStateIcon;
        } else {
            System.out.println("unknown thingie " + userObject);
        }
        setText(text);
        setIcon(icon);
        setToolTipText(toolTip == null ? text : toolTip);
    }
    return this;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) MolecularComponent(org.vcell.model.rbm.MolecularComponent) FontMetrics(java.awt.FontMetrics) BioModelNode(cbit.vcell.desktop.BioModelNode) Icon(javax.swing.Icon) Dimension(java.awt.Dimension) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

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