本文整理匯總了Java中com.cburch.logisim.util.GraphicsUtil.getTextBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java GraphicsUtil.getTextBounds方法的具體用法?Java GraphicsUtil.getTextBounds怎麽用?Java GraphicsUtil.getTextBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.cburch.logisim.util.GraphicsUtil
的用法示例。
在下文中一共展示了GraphicsUtil.getTextBounds方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: paintGhost
import com.cburch.logisim.util.GraphicsUtil; //導入方法依賴的package包/類
@Override
public void paintGhost(InstancePainter painter) {
TextAttributes attrs = (TextAttributes) painter.getAttributeSet();
String text = attrs.getText();
if (text == null || text.equals(""))
return;
int halign = attrs.getHorizontalAlign();
int valign = attrs.getVerticalAlign();
Graphics g = painter.getGraphics();
Font oldFont = g.getFont();
Color oldColor = g.getColor();
g.setFont(attrs.getFont());
g.setColor(painter.getAttributeValue(ATTR_COLOR));
GraphicsUtil.drawText(g, text, 0, 0, halign, valign);
String textTrim = text.endsWith(" ") ? text.substring(0, text.length() - 1) : text;
Bounds newBds;
if (textTrim.equals("")) {
newBds = Bounds.EMPTY_BOUNDS;
} else {
Rectangle bdsOut = GraphicsUtil.getTextBounds(g, textTrim, 0, 0, halign, valign);
newBds = Bounds.create(bdsOut).expand(4);
}
if (attrs.setOffsetBounds(newBds)) {
Instance instance = painter.getInstance();
if (instance != null)
instance.recomputeBounds();
}
g.setFont(oldFont);
g.setColor(oldColor);
}