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


Java Graphics2D.getFont方法代码示例

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


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

示例1: getResolutionVariant

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public Image getResolutionVariant(double destImageWidth, double destImageHeight) {

    int w = (int) destImageWidth;
    int h = (int) destImageHeight;

    BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    g.scale(scaleX, scaleY);
    int red = (int) (255 / scaleX);
    int green = (int) (250 / scaleX);
    int blue = (int) (20 / scaleX);
    g.setColor(new Color(red, green, blue));
    g.fillRect(0, 0, width, height);

    g.setColor(Color.decode("#87CEFA"));
    Font f = g.getFont();
    g.setFont(new Font(f.getName(), Font.BOLD, 24));
    g.drawString(String.format("scales: [%1.2fx, %1.2fx]", scaleX, scaleY),
            width / 6, height / 2);

    g.dispose();
    return img;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:WindowResizingOnSetLocationTest.java

示例2: render

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void render(final Graphics2D g, final Point2D emitterOrigin) {
  final Point2D renderLocation = this.getLocation(emitterOrigin);
  g.setColor(this.getColor());
  final Font oldFont = g.getFont();
  if (this.getFont() != null) {
    g.setFont(this.getFont());
  }
  final FontMetrics fm = g.getFontMetrics();
  final int x = fm.stringWidth(this.getText()) / 2;
  g.drawString(this.getText(), (float) renderLocation.getX() - x, (float) renderLocation.getY());
  g.setFont(oldFont);
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:14,代码来源:TextParticle.java

示例3: drawStringTextLayout

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void drawStringTextLayout(JComponent c, Graphics g, String text, int x, int baselineY) {
    if (!(g instanceof Graphics2D)) {
        g.drawString(text, x, baselineY);
    } else { // Graphics2D available
        Graphics2D g2d = (Graphics2D)g;
        FontRenderContext frc = g2d.getFontRenderContext();
        TextLayout layout = new TextLayout(text, g2d.getFont(), frc);
        layout.draw(g2d, x, baselineY);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:DrawGraphics.java

示例4: drawLegend

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * drawing the legend
 * @param ca colors of the legend
 * @param sa comments respectivily
 * @param f font
 * @param x initial abscissa
 * @param y initial ordinate
 * @param g2d
 * @return panel size
 */
private double drawLegend(Color[] ca, String[] sa, Font f, double x, double y, Graphics2D g2d) {
	Rectangle2D[] ra = new Rectangle2D[ca.length];
	Rectangle2D[] tba = new Rectangle2D[ca.length];
	double maxw = 0.0, gap = 5.0;
	String ts = "Legenda";
	//backup
	Color ctmp = g2d.getColor();
	Font ftmp = g2d.getFont();

	g2d.setFont(f);
	Rectangle2D tr = f.getStringBounds(ts, g2d.getFontRenderContext());
	maxw = tr.getWidth();
	for (int i = 0; i < ca.length; i++) {
		tba[i] = f.getStringBounds(sa[i], g2d.getFontRenderContext());
		ra[i] = new Rectangle2D.Double(x + gap, y + gap + (tr.getHeight() + gap) * (i + 1), tr.getHeight(), tr.getHeight());
		g2d.setColor(ca[i]);
		g2d.fill(ra[i]);
		g2d.setColor(Color.BLACK);
		g2d.draw(ra[i]);
		g2d.drawString(sa[i], (float) (x + gap * 2 + tr.getHeight()),
				(float) (y + gap + (tr.getHeight() + gap) * (i + 1) + tr.getHeight() / 2.0 - tr.getY() / 2.0));
		if (maxw < tba[i].getWidth()) {
			maxw = tba[i].getWidth();
		}
	}
	g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (y + (tr.getHeight() + gap) * (ca.length + 1) + gap));
	g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
	g2d.fillRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
	g2d.setColor(Color.WHITE);
	g2d.drawString(ts, (float) (x + gap + (maxw - tr.getWidth() + tr.getHeight()) / 2.0), (float) (y + tr.getY() / 2.0 + tr.getHeight()));

	//restore
	g2d.setFont(ftmp);
	g2d.setColor(ctmp);
	return (maxw + 3.0 * gap + tr.getHeight());

}
 
开发者ID:max6cn,项目名称:jmt,代码行数:48,代码来源:StatiDrawer.java

示例5: gInfo

import java.awt.Graphics2D; //导入方法依赖的package包/类
public gInfo(Graphics2D g)
{
	transform = g.getTransform();
	paint = g.getPaint();
	stroke = g.getStroke();
	font = g.getFont();
	composite = g.getComposite();
	bgrnd = g.getBackground();
	shape = g.getClip();
	hints = g.getRenderingHints();
}
 
开发者ID:Chroniaro,项目名称:What-Happened-to-Station-7,代码行数:12,代码来源:TStack.java

示例6: medidaV

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void medidaV(Graphics2D g, int l, int t) {
    FontMetrics fm = g.getFontMetrics();
    String vl = dono.FormateUnidadeMedida(height);
    int traco = width;
    int xIni = l;// + (traco) / 2;
    int xFim = xIni + traco;
    int yIni = t;
    int yFim = t + height;
    int xLin = l + (width / 2);

    g.drawLine(xIni, yIni, xFim, yIni);
    g.drawLine(xIni, yFim, xFim, yFim);
    g.drawLine(xLin, yIni, xLin, yFim);

    int degrees = isInvertido() ? 90 : -90;
    int desse = isInvertido() ? 0 : fm.stringWidth(vl);
    //int centra = fm.getHeight() / 2 - fm.getDescent();
    int centra = fm.getHeight() - fm.getDescent();
    centra = isInvertido() ? -centra : centra;

    AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(degrees));
    Font f = new Font(g.getFont().getName(), Font.BOLD, g.getFont().getSize());
    Font f2 = g.getFont();
    g.setFont(f.deriveFont(at));
    yIni = yIni + (height - fm.stringWidth(vl)) / 2 + desse;
    g.drawString(vl, xLin + centra, yIni);
    g.setFont(f2);
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:29,代码来源:baseDrawerItem.java

示例7: renderTo

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void renderTo(BufferedImage dst) {
    System.out.println("The buffer: " + dst);
    Graphics2D g = dst.createGraphics();

    final int w = dst.getWidth();
    final int h = dst.getHeight();

    g.setColor(Color.blue);
    g.fillRect(0, 0, w, h);

    g.setColor(Color.red);
    Font f = g.getFont();
    g.setFont(f.deriveFont(48f));

    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
           RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    // NB: this clip ctriggers the problem
    g.setClip(50, 50, 200, 100);

    g.drawString("AA Text", 52, 90);

    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
           RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

    // NB: this clip ctriggers the problem
    g.setClip(50, 100, 100, 100);
    g.drawString("Text", 52, 148);

    g.dispose();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:RenderToCustomBufferTest.java

示例8: 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);
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:57,代码来源:EditorScreen.java

示例9: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics2D g, Shape alloc, Rectangle clipBounds) {
    Rectangle2D.Double allocBounds = ViewUtils.shape2Bounds(alloc);
    if (allocBounds.intersects(clipBounds)) {
        Font origFont = g.getFont();
        Color origColor = g.getColor();
        Color origBkColor = g.getBackground();
        Shape origClip = g.getClip();
        try {
            // Leave component font
            
            g.setBackground(getBackgroundColor());

            int xInt = (int) allocBounds.getX();
            int yInt = (int) allocBounds.getY();
            int endXInt = (int) (allocBounds.getX() + allocBounds.getWidth() - 1);
            int endYInt = (int) (allocBounds.getY() + allocBounds.getHeight() - 1);
            g.setColor(getBorderColor());
            g.drawRect(xInt, yInt, endXInt - xInt, endYInt - yInt);
            
            g.setColor(getForegroundColor());
            g.clearRect(xInt + 1, yInt + 1, endXInt - xInt - 1, endYInt - yInt - 1);
            g.clip(alloc);
            TextLayout textLayout = getTextLayout();
            if (textLayout != null) {
                EditorView.Parent parent = (EditorView.Parent) getParent();
                float ascent = parent.getViewRenderContext().getDefaultAscent();
                String desc = fold.getDescription(); // For empty desc a single-space text layout is returned
                float x = (float) (allocBounds.getX() + EXTRA_MARGIN_WIDTH);
                float y = (float) allocBounds.getY();
                if (desc.length() > 0) {
                    
                    textLayout.draw(g, x, y + ascent);
                }
            }
        } finally {
            g.setClip(origClip);
            g.setBackground(origBkColor);
            g.setColor(origColor);
            g.setFont(origFont);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:FoldView.java

示例10: main

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void main(String[] args) {
    Locale.setDefault(Locale.US);

    // initialize j.u.l Looger:
    final Logger log = Logger.getLogger("sun.java2d.marlin");
    log.addHandler(new Handler() {
        @Override
        public void publish(LogRecord record) {
            Throwable th = record.getThrown();
            // detect any Throwable:
            if (th != null) {
                System.out.println("Test failed:\n" + record.getMessage());
                th.printStackTrace(System.out);

                throw new RuntimeException("Test failed: ", th);
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });

    log.info("TextClipErrorTest: start");

    // enable Marlin logging & internal checks:
    System.setProperty("sun.java2d.renderer.log", "true");
    System.setProperty("sun.java2d.renderer.useLogger", "true");
    System.setProperty("sun.java2d.renderer.doChecks", "true");

    BufferedImage image = new BufferedImage(256, 256,
                                            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2d = image.createGraphics();
    g2d.setColor(Color.red);
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);

        Font font = g2d.getFont();
        FontRenderContext frc = new FontRenderContext(
            new AffineTransform(), true, true);

        g2d.setStroke(new BasicStroke(4.0f,
                                      BasicStroke.CAP_ROUND,
                                      BasicStroke.JOIN_ROUND));

        final Shape badShape;
        if (SERIALIZE) {
            final GlyphVector gv1 = font.createGlyphVector(frc, "\u00d6");
            final Shape textShape = gv1.getOutline();

            final AffineTransform at1 = AffineTransform.getTranslateInstance(
                -2091202.554154681, 5548.601436981691);
            badShape = at1.createTransformedShape(textShape);
            serializeShape(badShape);
        } else {
            badShape = deserializeShape();
        }

        g2d.draw(badShape);

        // Draw anything within bounds and it fails:
        g2d.draw(new Line2D.Double(10, 20, 30, 40));

        if (SAVE_IMAGE) {
            final File file = new File("TextClipErrorTest.png");
            System.out.println("Writing file: " + file.getAbsolutePath());
            ImageIO.write(image, "PNG", file);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        g2d.dispose();
        log.info("TextClipErrorTest: end");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:82,代码来源:TextClipErrorTest.java

示例11: drawLegend

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * drawing the legend
 * 
 * @param ca
 *            color of the legend
 * @param sa
 *            Comments
 * @param f
 *            font
 * @param x
 *            initial abscissa
 * @param y
 *            initial ordinate
 * @param g2d
 * @return panel length
 */
private double drawLegend(Color[] ca, String[] sa, Font f, double x, double y, Graphics2D g2d, boolean draw) {
	Rectangle2D[] ra = new Rectangle2D[ca.length];
	Rectangle2D[] tba = new Rectangle2D[ca.length];
	double maxw = 0.0, gap = 5.0;
	String ts = "Legenda";
	// backup
	Color ctmp = g2d.getColor();
	Font ftmp = g2d.getFont();

	g2d.setFont(f);
	Rectangle2D tr = f.getStringBounds(ts, g2d.getFontRenderContext());
	maxw = tr.getWidth();
	for (int i = 0; i < ca.length; i++) {
		tba[i] = f.getStringBounds(sa[i], g2d.getFontRenderContext());
		ra[i] = new Rectangle2D.Double(x + gap, y + gap + (tr.getHeight() + gap) * (i + 1), tr.getHeight(), tr.getHeight());
		if (draw) {
			g2d.setColor(ca[i]);
			g2d.fill(ra[i]);
			g2d.setColor(Color.BLACK);
			g2d.draw(ra[i]);
			g2d.drawString(sa[i], (float) (x + gap * 2 + tr.getHeight()), (float) (y + gap + (tr.getHeight() + gap) * (i + 1) + tr.getHeight()
					/ 2.0 - tr.getY() / 2.0));
		}
		if (maxw < tba[i].getWidth()) {
			maxw = tba[i].getWidth();
		}
	}
	if (draw) {
		g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (y + (tr.getHeight() + gap) * (ca.length + 1) + gap));
		g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
		g2d.fillRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
		g2d.setColor(Color.WHITE);
		g2d.drawString(ts, (float) (x + gap + (maxw - tr.getWidth() + tr.getHeight()) / 2.0), (float) (y + tr.getY() / 2.0 + tr.getHeight()));
	}

	// restore
	g2d.setFont(ftmp);
	g2d.setColor(ctmp);
	return (maxw + 3.0 * gap + tr.getHeight());

}
 
开发者ID:max6cn,项目名称:jmt,代码行数:58,代码来源:QueueDrawer.java

示例12: drawLegend

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * drawing the legend
 * 
 * @param ca
 *            color of the legend
 * @param sa
 *            Comments
 * @param f
 *            font
 * @param x
 *            initial abscissa
 * @param y
 *            initial ordinate
 * @param g2d
 * @return panel lenght 
 */
private double drawLegend(Color[] ca, String[] sa, Font f, double x, double y, Graphics2D g2d, boolean draw) {
	Rectangle2D[] ra = new Rectangle2D[ca.length];
	Rectangle2D[] tba = new Rectangle2D[ca.length];
	double maxw = 0.0, gap = 5.0;
	String ts = "Legenda";
	// backup
	Color ctmp = g2d.getColor();
	Font ftmp = g2d.getFont();

	g2d.setFont(f);
	Rectangle2D tr = f.getStringBounds(ts, g2d.getFontRenderContext());
	maxw = tr.getWidth();
	for (int i = 0; i < ca.length; i++) {
		tba[i] = f.getStringBounds(sa[i], g2d.getFontRenderContext());
		ra[i] = new Rectangle2D.Double(x + gap, y + gap + (tr.getHeight() + gap) * (i + 1), tr.getHeight(), tr.getHeight());
		if (draw) {
			g2d.setColor(ca[i]);
			g2d.fill(ra[i]);
			g2d.setColor(Color.BLACK);
			g2d.draw(ra[i]);
			g2d.drawString(sa[i], (float) (x + gap * 2 + tr.getHeight()), (float) (y + gap + (tr.getHeight() + gap) * (i + 1) + tr.getHeight()
					/ 2.0 - tr.getY() / 2.0));
		}
		if (maxw < tba[i].getWidth()) {
			maxw = tba[i].getWidth();
		}
	}
	if (draw) {
		g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (y + (tr.getHeight() + gap) * (ca.length + 1) + gap));
		g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
		g2d.fillRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
		g2d.setColor(Color.WHITE);
		g2d.drawString(ts, (float) (x + gap + (maxw - tr.getWidth() + tr.getHeight()) / 2.0), (float) (y + tr.getY() / 2.0 + tr.getHeight()));
	}

	// restore
	g2d.setFont(ftmp);
	g2d.setColor(ctmp);
	return (maxw + 3.0 * gap + tr.getHeight());

}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:58,代码来源:QueueDrawer.java

示例13: paintComponent

import java.awt.Graphics2D; //导入方法依赖的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:wintertime,项目名称:FreeCol,代码行数:74,代码来源:Canvas.java

示例14: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g)
{
	Day now = Day.now();

	// Initialisieren
	super.paintComponent(g);

	Graphics2D g2 = (Graphics2D) g;

	int dayWidth = getWidth() / days;
	int hourheight = getHeight() / (hoursPerDay + 1);
	Font defaultFont = g2.getFont();
	Font domFont = new Font(Font.SANS_SERIF, Font.BOLD, 15);
	// Rahmenzeichnen
	g2.setColor(Color.BLACK);
	g2.setStroke(new BasicStroke(3));
	g2.drawLine(0, hourheight, getWidth(), hourheight);

	g2.setColor(TODAY_BACKGROUND_COLOR);
	g2.fillRect(0, hourheight, dayWidth, getHeight());
	g2.setColor(Color.BLACK);

	// X-Achse
	Day tmpDate = null;
	for (int i = 0; i < days; ++i)
	{

		if (0 == i)
			tmpDate = now;
		else
		{
			tmpDate = now.getDateInDays(i);
			g2.drawLine((dayWidth * i), 0, (dayWidth * i), getHeight()); // Tagestrennstriche
		}

		// Day of month
		g2.setFont(domFont);
		int stringWidth = SwingUtilities.computeStringWidth(g2.getFontMetrics(),
				" " + tmpDate.getDate().getDayOfMonth());
		int numberX = (dayWidth * (i + 1)) - stringWidth;
		g2.drawString(tmpDate.getDate().getDayOfMonth() + " ", numberX, (hourheight / 2));

		// Dayname
		g2.setFont(defaultFont);
		g2.drawString(" " + tmpDate.getDayName(), (dayWidth * i), (hourheight / 2));
	}

	g2.setStroke(new BasicStroke(1));

	// Y-Achse
	for (int i = 2; i < (hoursPerDay + 1); ++i)
	{
		g2.drawLine(0, (hourheight * i), getWidth(), (hourheight * i));
	}

}
 
开发者ID:AnonymOnline,项目名称:saveOrganizer,代码行数:58,代码来源:CalendarFrame.java

示例15: DoPaint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
    public void DoPaint(Graphics2D g) {
        super.DoPaint(g);
        Rectangle rec = getArea();
        Color bkpc = g.getColor();

        g.setColor(getBorderColor());

        g.drawRect(rec.x, rec.y, rec.width, rec.height);

        Rectangle bkp = g.getClipBounds();
        g.clipRect(rec.x, rec.y, rec.width, rec.height);

        Font fn = getFont();
        Font font = new Font(fn.getFontName(), fn.getStyle(), fn.getSize() - 2);

        fn = g.getFont();
        g.setFont(font);

        altura = g.getFontMetrics().getHeight() + g.getFontMetrics().getDescent();
        alturaTitulo = altura + altura / 2;

        Composite originalComposite = g.getComposite();
        float alfa = 0.8f;
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa));

        if (getTipo() == TipoLegenda.tpObjetos) {
            altura = Math.max(32, altura);
        }

        int posi = altura + alturaTitulo + rec.y;
        final int lft = rec.x + 2;

        for (ItemDeLegenda it : getItens()) {

            if (it.isSelecionada()) {
                g.setColor(isDisablePainted()? disabledColor : new Color(204, 204, 255, 50));
                g.fillRect(lft, posi - altura - 2, getWidth(), altura + 4);
            }
            g.setColor(isDisablePainted()? disabledColor : it.cor);
            int moveleft;
            switch (getTipo()) {
                case tpLinhas:
                    moveleft = 3 * altura;
                    g.fillRoundRect(lft, posi - (altura / 2) - 2, moveleft - 2, 4, 2, 2);
                    g.setColor(bkpc);
                    g.drawString(it.texto, lft + moveleft, posi - 6);
                    break;
                case tpObjetos:
                    ImageIcon img = Editor.fromControler().getImagemNormal(getMaster().getCassesDoDiagrama()[it.getTag()].getSimpleName());
                    g.drawImage(util.TratadorDeImagens.ReColorBlackImg(img, it.getCor()), lft, posi - altura, null);
                    moveleft = altura + 2;
                    g.drawString(it.texto, lft + moveleft, posi - altura / 2 + 6);
                    break;
                default:
                    moveleft = altura;
                    g.fillRect(lft, posi - altura, altura - 4, altura - 4);
                    g.setColor(bkpc);
                    g.drawRect(lft, posi - altura, altura - 4, altura - 4);
                    g.drawString(it.texto, lft + moveleft, posi - 6);
            }
            it.Area = new Point(posi - altura - 2, altura + 4);
            posi += altura + 4;
        }

        g.setComposite(originalComposite);

//        g.setColor(Color.LIGHT_GRAY);
//        g.drawLine(lft - 1, posi - altura - 2, getLeft() + getWidth() - 1, posi - altura - 2);
        g.setClip(bkp);
        g.setFont(fn);
    }
 
开发者ID:chcandido,项目名称:brModelo,代码行数:73,代码来源:Legenda.java


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