本文整理汇总了Java中java.awt.Graphics2D.setFont方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.setFont方法的具体用法?Java Graphics2D.setFont怎么用?Java Graphics2D.setFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.setFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawCenteredText
import java.awt.Graphics2D; //导入方法依赖的package包/类
private Rectangle2D drawCenteredText(String s, Color c, double centerX, double centerY, Graphics2D g2d, boolean drawBorder) {
double x, y;
g2d.setFont(f);
txtBounds = f.getStringBounds(s, g2d.getFontRenderContext());
x = centerX - txtBounds.getWidth() / 2.0;
y = centerY - txtBounds.getY() - txtBounds.getHeight() / 2;
txtBounds.setRect(x - ELEMS_GAP, y - txtBounds.getHeight() / 2.0 - ELEMS_GAP, txtBounds.getWidth() + 2 * ELEMS_GAP, txtBounds.getHeight() + 2
* ELEMS_GAP);
if (drawBorder) {
g2d.setColor(invertedColor(c));
g2d.fill(txtBounds);
g2d.setColor(c);
g2d.draw(txtBounds);
}
Color ctmp = g2d.getColor();
g2d.setColor(c);
g2d.drawString(s, (float) x, (float) y);
g2d.setColor(ctmp);
return txtBounds;
}
示例2: printViewState
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Prints useful internal data, such as rotation angles and transform
* matrices.
*
* @param g
* Graphics context.
*/
protected void printViewState(Graphics2D g) {
int y = 16;
g.setColor(Color.LIGHT_GRAY);
g.setFont(FONT);
// FontMetrics fm = g.getFontMetrics();
g.drawString("rotY = " + floatString(rotY, 6) + " rad", 16, y);
g.drawString("= " + floatString((float) (rotY * 180 / Math.PI), 6)
+ "°", 110, y);
y += 10;
g.drawString("rotX = " + floatString(rotX, 6) + " rad", 16, y);
g.drawString("= " + floatString((float) (rotX * 180 / Math.PI), 6)
+ "°", 110, y);
y += 16;
y = printMatrix4(g, prj.getModelView(), 16, y + 16, "viewMatrix");
y = printMatrix4(g, prj.getProjection(), 16, y + 16, "projMatrix");
y = printMatrix4(g, eyeRT, 16, y + 16, "eyeRT");
}
示例3: paintTitle
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
final View v = getTextViewForTab(tabIndex);
if (v != null) {
v.paint(g2d, textRect);
return;
}
if (title == null) return;
final Color color = tabPane.getForegroundAt(tabIndex);
if (color instanceof UIResource) {
g2d.setColor(getNonSelectedTabTitleColor());
if (tabPane.getSelectedIndex() == tabIndex) {
boolean pressed = isPressedAt(tabIndex);
boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
Color textColor = getSelectedTabTitleColor(enabled, pressed);
Color shadowColor = getSelectedTabTitleShadowColor(enabled);
AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
return;
}
} else {
g2d.setColor(color);
}
g2d.setFont(font);
SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
示例4: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
atualizar();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setFont(FONT);
FontRenderContext frc = g2.getFontRenderContext();
TextLayout textLayout = new TextLayout(Integer.toString(value), FONT, frc);
g2.setPaint(textColor);
AffineTransform at = AffineTransform.getTranslateInstance(20, 30);
Shape outline = textLayout.getOutline(at);
g2.fill(outline);
g2.setPaint(BLACK);
g2.draw(outline);
}
示例5: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g1) {
Graphics2D g = (Graphics2D) g1;
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, Main.config.getBackgroundOpacity()));
g.setColor(Main.config.getBackgroundColor());
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getForegroundOpacity()));
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
BufferedImage colorImage = isActive() ? ColorManager.pressed : ColorManager.unpressed;
g.drawImage(colorImage, 2, 2, this.getWidth() - 2, this.getHeight() - 2, 0, 0, colorImage.getWidth(), colorImage.getHeight(), this);
g.setColor(isActive() ? Main.config.getBackgroundColor() : Main.config.getForegroundColor());
String titleString = getTitle();
Font titleFont = Main.config.mode.getTitleFont(titleString);
Point namePos = Main.config.mode.getTitleDrawPosition(g, this, titleString, titleFont);
g.setFont(titleFont);
g.drawString(titleString, namePos.x, namePos.y);
String valueString = getValue();
Font valueFont = Main.config.mode.getValueFont(valueString);
Point keyCountPos = Main.config.mode.getValueDrawPosition(g, this, valueString, valueFont);
g.setFont(valueFont);
g.drawString(valueString, keyCountPos.x, keyCountPos.y);
}
示例6: apply
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void apply(Graphics2D g)
{
g.setTransform(transform);
g.setPaint(paint);
g.setStroke(stroke);
g.setFont(font);
g.setComposite(composite);
g.setBackground(bgrnd);
g.setClip(shape);
g.setRenderingHints(hints);
}
示例7: drawItemLabel
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws an item label.
*
* @param g2 the graphics device.
* @param orientation the orientation.
* @param dataset the dataset.
* @param row the row.
* @param column the column.
* @param x the x coordinate (in Java2D space).
* @param y the y coordinate (in Java2D space).
* @param negative indicates a negative value (which affects the item
* label position).
*/
protected void drawItemLabel(Graphics2D g2,
PlotOrientation orientation,
CategoryDataset dataset,
int row, int column,
double x, double y,
boolean negative) {
CategoryItemLabelGenerator generator
= getItemLabelGenerator(row, column);
if (generator != null) {
Font labelFont = getItemLabelFont(row, column);
Paint paint = getItemLabelPaint(row, column);
g2.setFont(labelFont);
g2.setPaint(paint);
String label = generator.generateLabel(dataset, row, column);
ItemLabelPosition position = null;
if (!negative) {
position = getPositiveItemLabelPosition(row, column);
}
else {
position = getNegativeItemLabelPosition(row, column);
}
Point2D anchorPoint = calculateLabelAnchorPoint(
position.getItemLabelAnchor(), x, y, orientation);
TextUtilities.drawRotatedString(label, g2,
(float) anchorPoint.getX(), (float) anchorPoint.getY(),
position.getTextAnchor(),
position.getAngle(), position.getRotationAnchor());
}
}
示例8: paintText
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void paintText(final Graphics2D g) {
if (!transparent && !movingArea.isPrinting() || isNegative()) {
final Rectangle2D rec = movingArea.getBounds(getBounds());
g.setColor(fiterColor(movingArea.getBackground()));
g.fill(rec);
}
g.setFont(getFont());
g.setColor(fiterColor(getColor()));
movingArea.paintText(g, getXText(), getTextBounds(), getAlign(), 1, true);
}
示例9: render
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void render(final Graphics2D g) {
Game.getCamera().updateFocus();
if (Game.getEnvironment() != null) {
Game.getEnvironment().render(g);
}
if (ImageCache.IMAGES.size() > 200) {
ImageCache.IMAGES.clear();
log.log(Level.INFO, "cache cleared!");
}
if (this.currentResourceFile != null) {
Game.getScreenManager().setTitle(Game.getInfo().getName() + " " + Game.getInfo().getVersion() + " - " + this.currentResourceFile);
String mapName = Game.getEnvironment() != null && Game.getEnvironment().getMap() != null ? "\nMap: " + Game.getEnvironment().getMap().getName() : "";
Program.trayIcon.setToolTip(Game.getInfo().getName() + " " + Game.getInfo().getVersion() + "\n" + this.currentResourceFile + mapName);
} else if (this.getProjectPath() != null) {
Game.getScreenManager().setTitle(Game.getInfo().toString() + " - " + NEW_GAME_STRING);
Program.trayIcon.setToolTip(Game.getInfo().toString() + "\n" + NEW_GAME_STRING);
} else {
Game.getScreenManager().setTitle(Game.getInfo().toString());
}
super.render(g);
// render mouse/zoom and fps
g.setFont(g.getFont().deriveFont(11f));
g.setColor(Color.WHITE);
Point tile = Input.mouse().getTile();
RenderEngine.drawText(g, "x: " + (int) Input.mouse().getMapLocation().getX() + " y: " + (int) Input.mouse().getMapLocation().getY()
+ " tile: [" + tile.x + ", " + tile.y + "]"
+ " zoom: " + (int) (Game.getCamera().getRenderScale() * 100) + " %", 10, Game.getScreenManager().getResolution().getHeight() - 40);
RenderEngine.drawText(g, Game.getMetrics().getFramesPerSecond() + " FPS", 10, Game.getScreenManager().getResolution().getHeight() - 20);
// render status
if (this.currentStatus != null && !this.currentStatus.isEmpty()) {
long deltaTime = Game.getLoop().getDeltaTime(this.statusTick);
if (deltaTime > STATUS_DURATION) {
this.currentStatus = null;
}
// fade out status color
final double fadeOutTime = 0.75 * STATUS_DURATION;
if (deltaTime > fadeOutTime) {
double fade = deltaTime - fadeOutTime;
int alpha = (int) (255 - (fade / (STATUS_DURATION - fadeOutTime)) * 255);
g.setColor(new Color(255, 255, 255, MathUtilities.clamp(alpha, 0, 255)));
}
Font old = g.getFont();
g.setFont(g.getFont().deriveFont(20.0f));
RenderEngine.drawText(g, this.currentStatus, 10, Game.getScreenManager().getResolution().getHeight() - 60);
g.setFont(old);
}
}
示例10: createBubbleImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void createBubbleImage() {
final BufferedImage img = ImageProcessing.getCompatibleImage(500, 500);
final Graphics2D g = img.createGraphics();
g.setFont(this.font);
final int stringWidth = g.getFontMetrics().stringWidth(this.currentText);
if (stringWidth < this.textBoxWidth) {
this.textBoxWidth = stringWidth;
}
final FontRenderContext frc = g.getFontRenderContext();
final AttributedString styledText = new AttributedString(this.currentText);
styledText.addAttribute(TextAttribute.FONT, this.font);
final AttributedCharacterIterator iterator = styledText.getIterator();
final LineBreakMeasurer measurer = new LineBreakMeasurer(iterator, frc);
measurer.setPosition(0);
float y = 0;
while (measurer.getPosition() < this.currentText.length()) {
final TextLayout layout = measurer.nextLayout(this.textBoxWidth);
y += layout.getAscent() + layout.getLeading() + 0.2;
}
final RoundRectangle2D bounds = new RoundRectangle2D.Double(0, 0, this.textBoxWidth + 2 * PADDING, y + 2 * PADDING, PADDING, PADDING);
// Build a path
final GeneralPath path = new GeneralPath();
path.moveTo(bounds.getWidth() / 2.0 - TRIANGLE_SIZE / 2.0, bounds.getHeight());
path.lineTo(bounds.getWidth() / 2.0, bounds.getHeight() + TRIANGLE_SIZE);
path.lineTo(bounds.getWidth() / 2.0 + TRIANGLE_SIZE / 2.0, bounds.getHeight());
path.closePath();
final Area ar = new Area(bounds);
ar.add(new Area(path));
int width = ar.getBounds().width;
this.height = ar.getBounds().height;
g.setColor(SPEAK_BACKGROUNDCOLOR);
g.fill(ar);
g.setColor(SPEAK_BORDERCOLOR);
g.draw(ar);
g.dispose();
this.bubble = ImageProcessing.crop(img, ImageProcessing.CROP_ALIGN_LEFT, ImageProcessing.CROP_VALIGN_TOP, width + 1, this.height + 1);
}
示例11: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the background to the specified graphics device. If the dial
* frame specifies a window, the clipping region will already have been
* set to this window before this method is called.
*
* @param g2 the graphics device (<code>null</code> not permitted).
* @param plot the plot (ignored here).
* @param frame the dial frame (ignored here).
* @param view the view rectangle (<code>null</code> not permitted).
*/
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
Rectangle2D view) {
// work out the anchor point
Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius,
this.radius);
Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
Point2D pt = arc.getStartPoint();
// calculate the bounds of the template value
FontMetrics fm = g2.getFontMetrics(this.font);
String s = this.formatter.format(this.templateValue);
Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);
// align this rectangle to the frameAnchor
Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(
tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(),
this.frameAnchor);
// add the insets
Rectangle2D fb = this.insets.createOutsetRectangle(bounds);
// draw the background
g2.setPaint(this.backgroundPaint);
g2.fill(fb);
// draw the border
g2.setStroke(this.outlineStroke);
g2.setPaint(this.outlinePaint);
g2.draw(fb);
// now find the text anchor point
double value = plot.getValue(this.datasetIndex);
String valueStr = this.formatter.format(value);
Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
g2.setPaint(this.paint);
g2.setFont(this.font);
TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(),
(float) pt2.getY(), this.textAnchor);
}
示例12: drawHorizontal
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws a the title horizontally within the specified area. This method will be called
* from the {@link #draw(Graphics2D, Rectangle2D) draw} method.
*
* @param g2 the graphics device.
* @param area the area for the title.
*/
protected void drawHorizontal(Graphics2D g2, Rectangle2D area) {
Rectangle2D titleArea = (Rectangle2D) area.clone();
getSpacer().trim(titleArea);
g2.setFont(this.font);
g2.setPaint(this.paint);
TextBlock title = TextUtilities.createTextBlock(
this.text, this.font, this.paint, (float) titleArea.getWidth(), new G2TextMeasurer(g2)
);
TextBlockAnchor anchor = null;
float x = 0.0f;
HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
if (horizontalAlignment == HorizontalAlignment.LEFT) {
x = (float) titleArea.getX();
anchor = TextBlockAnchor.TOP_LEFT;
}
else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
x = (float) titleArea.getMaxX();
anchor = TextBlockAnchor.TOP_RIGHT;
}
else if (horizontalAlignment == HorizontalAlignment.CENTER) {
x = (float) titleArea.getCenterX();
anchor = TextBlockAnchor.TOP_CENTER;
}
float y = 0.0f;
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP) {
y = (float) titleArea.getY();
}
else if (position == RectangleEdge.BOTTOM) {
y = (float) titleArea.getMaxY();
if (horizontalAlignment == HorizontalAlignment.LEFT) {
anchor = TextBlockAnchor.BOTTOM_LEFT;
}
else if (horizontalAlignment == HorizontalAlignment.CENTER) {
anchor = TextBlockAnchor.BOTTOM_CENTER;
}
else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
anchor = TextBlockAnchor.BOTTOM_RIGHT;
}
}
title.draw(g2, x, y, anchor);
}
示例13: drawDominantArrow
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* When is select a Dominat point is draw an arrow from the dominant
* @param g The graphic object
* @param dominant The vector with the dominant points
* @param dominates The vector with the dominates points
*/
public void drawDominantArrow(Graphics2D g, Vector<Point2D> dominant, Vector<Point2D> dominates) {
DPoint p;
DPoint p2;
boolean first = true;
for (int i = 0; i < dominates.size(); i++) {
p = (DPoint) dominates.get(i);
if (p.isSelect()) {
for (int k = dominant.size() - 1; k >= 0; k--) {
p2 = (DPoint) dominant.get(k);
if (p2.isSelect()) {
g.setColor(Color.magenta);
//Draw Arrow
//The angle is calculete throw the rotator point
DPoint rotator = new DPoint(p2.getX() - p.getX(), p2.getY() - p.getY());
double angle = rotator.polarAngle();
//The thestination point in not into the point but near the point
int xPoint = (int) (p.getX() * scale) + tran_x + (int) (pointSize * Math.cos(angle));
int yPoint = tran_y - (int) (p.getY() * scale) - (int) (pointSize * Math.sin(angle));
g.drawLine(xPoint, yPoint, (int) (p2.getX() * scale) + tran_x, tran_y - (int) (p2.getY() * scale));
//The rotation turn the arrow in the right position
g.rotate(-angle, xPoint, yPoint);
g.drawLine(xPoint, yPoint, xPoint + 4 + pointSize, yPoint - pointSize);
g.drawLine(xPoint, yPoint, xPoint + 4 + pointSize, yPoint + pointSize);
g.rotate((2 * Math.PI) + angle, xPoint, yPoint);
//Draw Label on the first arrow (only)
if (first) {
first = false;
g.setColor(new Color(152, 61, 168));
int fontSize = 7 + pointSize;
Font f = new Font("Arial", Font.PLAIN, fontSize);
g.setFont(f);
double x = (p.getX() + p2.getX()) / 2;
double y = (p.getY() + p2.getY()) / 2;
g.drawString("Dominating", (int) (x * scale) + tran_x + 7, tran_y - 3 - (int) (y * scale));
}
}
}
}
}
}
示例14: axis
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* It draws the axis of the graph
* @param g The graphic object
* @param className The name of the classes
*/
public void axis(Graphics2D g, String[] className) {
g.setColor(Color.black);
//Axis
g.drawLine(tran_x, tran_y, tran_x, fromBorderY);
g.drawLine(tran_x, tran_y, width - fromBorderX, tran_y);
//Arrows Y
g.drawLine(tran_x - 4, fromBorderY + 8, tran_x, fromBorderY);
g.drawLine(tran_x + 4, fromBorderY + 8, tran_x, fromBorderY);
//Arrows X
g.drawLine(width - fromBorderX - 8, tran_y - 4, width - fromBorderX, tran_y);
g.drawLine(width - fromBorderX - 8, tran_y + 4, width - fromBorderX, tran_y);
Font label = new Font("Arial", Font.PLAIN, 9 + pointSize);
g.setFont(label);
//Label Y
g.drawString(className[0], tran_x - 15, fromBorderY - 8);
//Label X
g.drawString(className[1], width - Math.max(fromBorderX, (int) (className[1].length() * (9 + pointSize) * 0.58)), height - (pointSize));
//Insert the line on the axis
for (int i = 1; i < 11; i++) {
g.drawLine(tran_x + (int) (((maxValue / 10) * i) * scale), tran_y, tran_x + (int) (((maxValue / 10) * i) * scale), tran_y + 2);
g.drawLine(tran_x, tran_y - (int) (((maxValue / 10) * i) * scale), tran_x - 2, tran_y - (int) (((maxValue / 10) * i) * scale));
}
//Setting the Font
int fontSize = 8 + pointSize;
Font f = new Font("Arial", Font.PLAIN, fontSize);
g.setFont(f);
//Insert the number on the axis X
for (int i = 1; i < 11; i++) {
g.drawString("" + (int) (((maxValue / 10) * i)), tran_x + (int) (((maxValue / 10) * i) * scale) - 7, tran_y + 3 + fontSize);
}
for (int i = 1; i < 11; i++) {
int translationt = ((("" + maxValue).length()) - ((("" + ((int) (((maxValue / 10) * i)))).length()))) - 1;
g.drawString("" + (int) (((maxValue / 10) * i)), (translationt * (fontSize / 2)) - 3, tran_y + 3 - (int) (((maxValue / 10) * i) * scale));
}
//Insert 0
g.drawString("0", tran_x - pointSize - 5, tran_y + pointSize + 5);
}
示例15: generateImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public BufferedImage generateImage(String lang, double upload, double download, double ping, String isp, String typ, String signal, String os) throws IOException {
String unknownString = (lang.equals("de")) ? "unbekannt" : "unknown";
BufferedImage img = new BufferedImage(390, 130, BufferedImage.TYPE_INT_ARGB);
img.createGraphics();
Graphics2D g = (Graphics2D)img.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
BufferedImage img2 = ImageIO.read(getClass().getResourceAsStream("forumsmall_" + lang + ".png"));
g.drawImage(img2, null, 0, 0);
//Speeds
g.setColor(Color.black);
g.setFont(new Font("Droid Sans", Font.BOLD, 40));
drawCenteredString(formatNumber(download, lang), 0, 20,130,65,g);
drawCenteredString(formatNumber(upload, lang), 130, 20,130,65,g);
drawCenteredString(formatNumber(ping, lang), 260, 20,130,65,g);
//ISP and other information
g.setColor(Color.WHITE);
g.setFont(new Font("Verdana", Font.BOLD,10));
//de
if (lang.equals("de")) {
//left
g.drawString((typ == null)?unknownString:typ, 73, 109);
g.drawString((isp == null)?unknownString:isp, 73, 124);
//right
g.drawString((signal==null)?"":signal + " dBm", 270, 109);
g.drawString((os==null)?unknownString:os, 270, 124);
//hide signal caption if signal is null
if (signal==null) {
g.setColor(new Color(89,178,0));
g.fillRect(195, 98, 71, 13);
}
}
else { //en
//left
g.drawString((typ == null)?unknownString:typ, 83, 109);
g.drawString((isp == null)?unknownString:isp, 60, 124);
//right
g.drawString((signal==null)?"":signal + " dBm", 290, 109);
g.drawString((os==null)?unknownString:os, 290, 124);
//hide signal caption if signal is null
if (signal==null) {
g.setColor(new Color(89,178,0));
g.fillRect(195, 98, 90, 13);
}
}
g.dispose();
return img;
}