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);
}
}
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;
}
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;
}
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();
}
}
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;
}
Aggregations