当前位置: 首页>>代码示例>>Java>>正文


Java TextLayout.getBounds方法代码示例

本文整理汇总了Java中java.awt.font.TextLayout.getBounds方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.getBounds方法的具体用法?Java TextLayout.getBounds怎么用?Java TextLayout.getBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.font.TextLayout的用法示例。


在下文中一共展示了TextLayout.getBounds方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runTest

import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    TLContext tlctx = (TLContext)ctx;
    TextLayout tl = tlctx.tl;
    Rectangle2D r;
    do {
        r = tl.getBounds();
    } while (--numReps >= 0);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:TextMeasureTests.java

示例2: computeDimensions

import java.awt.font.TextLayout; //导入方法依赖的package包/类
private void computeDimensions(Graphics g, Font font, FontMetrics fm) {
	String s = text;
	FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
	width = fm.stringWidth(s);
	ascent = fm.getAscent();
	descent = fm.getDescent();
	int[] xs = new int[s.length()];
	int[] ys = new int[s.length()];
	for (int i = 0; i < xs.length; i++) {
		xs[i] = fm.stringWidth(s.substring(0, i + 1));
		TextLayout lay = new TextLayout(s.substring(i, i + 1), font, frc);
		Rectangle2D rect = lay.getBounds();
		int asc = (int) Math.ceil(-rect.getMinY());
		int desc = (int) Math.ceil(rect.getMaxY());
		if (asc < 0)
			asc = 0;
		if (asc > 0xFFFF)
			asc = 0xFFFF;
		if (desc < 0)
			desc = 0;
		if (desc > 0xFFFF)
			desc = 0xFFFF;
		ys[i] = (asc << 16) | desc;
	}
	charX = xs;
	charY = ys;
	dimsKnown = true;
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:29,代码来源:EditableLabel.java

示例3: textLayoutDump

import java.awt.font.TextLayout; //导入方法依赖的package包/类
private static String textLayoutDump(TextLayout textLayout) {
    return "\n  TL.getAdvance()=" + textLayout.getAdvance() + // NOI18N
            "\n  TL.getBounds()=" + textLayout.getBounds() + // NOI18N
            "\n  TL: " + textLayout; // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:TextLayoutUtils.java

示例4: paintComponent

import java.awt.font.TextLayout; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void paintComponent(Graphics g) {
    updateSizes();
    Graphics2D g2d = (Graphics2D) g;
    chatDisplay.removeOldMessages();
    Dimension size = getSize();

    if (freeColClient.isMapEditor()) {
        if (hasMap()) {
            mapViewer.displayMap(g2d);
        } else {
            g2d.setColor(Color.BLACK);
            g2d.fillRect(0, 0, size.width, size.height);
        }

    } else if (freeColClient.isInGame() && hasMap()) {
        mapViewer.displayMap(g2d);

        // Grey out the map if it is not my turn (and a multiplayer game).
        if (!freeColClient.currentPlayerIsMyPlayer()) {
            if (greyLayer == null) {
                greyLayer = new GrayLayer(freeColClient);
            }
            if (greyLayer.getParent() == null) {
                add(greyLayer, JLayeredPane.DRAG_LAYER);
            }
            greyLayer.setBounds(0, 0, size.width, size.height);
            greyLayer.setPlayer(freeColClient.getGame().getCurrentPlayer());
        } else {
            if (greyLayer != null && greyLayer.getParent() != null) {
                removeFromCanvas(greyLayer);
            }
        }

        // paint chat display
        chatDisplay.display(g2d, mapViewer.getImageLibrary(), size);

    } else {
        /* main menu */
        // TODO: Check if its right to sometimes have an unfocused map
        //       ingame and end up here after clicking outside map.
        final String bgImageKey = "image.flavor.Canvas.map";
        if (ResourceManager.hasImageResource(bgImageKey)) {
            // Get the background without scaling, to avoid wasting
            // memory needlessly keeping an unbounded number of rescaled
            // versions of the largest image in FreeCol, forever.
            final Image bgImage = ResourceManager.getImage(bgImageKey);
            // Draw background image with scaling.
            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g2d.drawImage(bgImage, 0, 0, size.width, size.height, this);
            String versionStr = "v. " + FreeCol.getVersion();
            Font oldFont = g2d.getFont();
            Color oldColor = g2d.getColor();
            Font newFont = oldFont.deriveFont(Font.BOLD);
            TextLayout layout = new TextLayout(versionStr, newFont,
                g2d.getFontRenderContext());
            Rectangle2D bounds = layout.getBounds();
            float x = size.width - (float) bounds.getWidth() - 5;
            float y = size.height - (float) bounds.getHeight();
            g2d.setColor(Color.white);
            layout.draw(g2d, x, y);
            g2d.setFont(oldFont);
            g2d.setColor(oldColor);
        } else {
            g2d.setColor(Color.BLACK);
            g2d.fillRect(0, 0, size.width, size.height);
        }
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:74,代码来源:Canvas.java


注:本文中的java.awt.font.TextLayout.getBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。