本文整理匯總了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);
}
示例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;
}
示例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
}
示例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);
}
}
}