Example usage for java.awt Graphics2D drawString

List of usage examples for java.awt Graphics2D drawString

Introduction

In this page you can find the example usage for java.awt Graphics2D drawString.

Prototype

public abstract void drawString(AttributedCharacterIterator iterator, float x, float y);

Source Link

Document

Renders the text of the specified iterator applying its attributes in accordance with the specification of the TextAttribute class.

Usage

From source file:krasa.cpu.CpuUsagePanel.java

@Override
public void paintComponent(final Graphics g) {
    final boolean pressed = getModel().isPressed();
    final boolean stateChanged = myWasPressed != pressed;
    myWasPressed = pressed;//from   w  ww  .j a v  a 2s  .com
    Image bufferedImage = myBufferedImage;

    if (bufferedImage == null || stateChanged) {
        final Dimension size = getSize();
        final Insets insets = getInsets();

        bufferedImage = UIUtil.createImage(g, size.width, size.height, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g2 = (Graphics2D) bufferedImage.getGraphics().create();

        final int max = 100;
        int system = CpuUsageManager.system;
        int process = CpuUsageManager.process;
        final int otherProcesses = system - process;

        final int totalBarLength = size.width - insets.left - insets.right - 3;
        final int processUsageBarLength = totalBarLength * process / max;
        final int otherProcessesUsageBarLength = totalBarLength * otherProcesses / max;
        final int barHeight = Math.max(size.height, getFont().getSize() + 2);
        final int yOffset = (size.height - barHeight) / 2;
        final int xOffset = insets.left;

        // background
        g2.setColor(UIUtil.getPanelBackground());
        g2.fillRect(0, 0, size.width, size.height);

        // gauge (ide)
        g2.setColor(ideColor);
        g2.fillRect(xOffset + 1, yOffset, processUsageBarLength + 1, barHeight);

        // gauge (system)
        g2.setColor(systemColor);
        g2.fillRect(xOffset + processUsageBarLength + 1, yOffset, otherProcessesUsageBarLength + 1, barHeight);

        // label
        g2.setFont(getFont());
        // final String info = CpuUsageBundle.message("cpu.usage.panel.message.text", CpuUsageManager.process,
        // CpuUsageManager.system);
        final String info = fixedLengthString(String.valueOf(process), 3) + "% / "
                + fixedLengthString(String.valueOf(system), 3) + "%";

        final FontMetrics fontMetrics = g.getFontMetrics();
        final int infoWidth = fontMetrics.charsWidth(info.toCharArray(), 0, info.length());
        final int infoHeight = fontMetrics.getAscent();
        UISettings.setupAntialiasing(g2);

        final Color fg = pressed ? UIUtil.getLabelDisabledForeground() : JBColor.foreground();
        g2.setColor(fg);
        g2.drawString(info, xOffset + (totalBarLength - infoWidth) / 2,
                yOffset + infoHeight + (barHeight - infoHeight) / 2 - 1);

        // border
        g2.setStroke(new BasicStroke(1));
        g2.setColor(JBColor.GRAY);
        g2.drawRect(0, 0, size.width - 2, size.height - 1);

        g2.dispose();
        myBufferedImage = bufferedImage;
    }

    draw(g, bufferedImage);
}

From source file:com.fluidops.iwb.deepzoom.ImageLoader.java

private void generateIDCard(URI uri, Map<URI, Set<Value>> facets, String url, File file) {
    int width = 200;
    int height = 200;

    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    Graphics2D ig2 = bi.createGraphics();
    ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    ig2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    /* Special ID card handling for certain entity types */

    /*  TODO: special images based on type
    if(facets.containsKey(RDF.TYPE)) {/*from ww w .j  av  a2 s .co m*/
    Set<Value> facet = facets.get(RDF.TYPE);
            
    for(Value v : facet)
    {
        if(v.equals(Vocabulary.DCAT_DATASET))
        {
            
            Image img = null;
            try
            {
                img = ImageIO.read( new File( "webapps/ROOT/images/rdf.jpg" ) );
            }
            catch (MalformedURLException e)
            {
                logger.error(e.getMessage(), e);
            }
            catch (IOException e)
            {
                logger.error("Could not get image");
            }
            
            ig2.drawImage( img, 0, 0, null );        
            break;
        }
    }
    } */

    String label = EndpointImpl.api().getDataManager().getLabel(uri);
    Font font = new Font(Font.SANS_SERIF, Font.BOLD, 20);
    ig2.setFont(font);

    FontMetrics fontMetrics = ig2.getFontMetrics();
    int labelwidth = fontMetrics.stringWidth(label);
    if (labelwidth >= width) {
        int fontsize = 20 * width / labelwidth;
        font = new Font(Font.SANS_SERIF, Font.BOLD, fontsize);
        ig2.setFont(font);
        fontMetrics = ig2.getFontMetrics();
    }

    int x = (width - fontMetrics.stringWidth(label)) / 2;
    int y = (fontMetrics.getAscent() + (height - (fontMetrics.getAscent() + fontMetrics.getDescent())) / 2);

    ig2.setPaint(Color.black);

    ig2.drawString(label, x, y);

    BufferedOutputStream out;
    try {
        out = new BufferedOutputStream(new FileOutputStream(file));
        ImageIO.write(bi, "PNG", out);
        out.flush();
        out.close();

    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:edworld.pdfreader4humans.PDFReader.java

private void draw(Component component, Graphics2D graphics, Color inkColor, Color backgroundColor,
        boolean showStructure, Map<String, Font> fonts) {
    for (Component child : component.getChildren())
        draw(child, graphics, inkColor, backgroundColor, showStructure, fonts);
    if (component instanceof BoxComponent && showStructure) {
        graphics.setColor(boxColor(backgroundColor));
        graphics.drawRect((int) component.getFromX(), (int) component.getFromY(), (int) component.getWidth(),
                (int) component.getHeight());
        graphics.setColor(inkColor);/*from  ww  w  .  j a v a  2s . c o  m*/
    } else if (component instanceof GroupComponent && showStructure) {
        graphics.setColor(groupColor(backgroundColor));
        graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()),
                Math.round(component.getWidth()), Math.round(component.getHeight()));
        graphics.setColor(inkColor);
    } else if (component instanceof MarginComponent && showStructure) {
        graphics.setColor(marginColor(backgroundColor));
        graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()),
                Math.round(component.getWidth()), Math.round(component.getHeight()));
        graphics.setColor(inkColor);
    } else if (component.getType().equals("line"))
        graphics.drawLine(Math.round(component.getFromX()), Math.round(component.getFromY()),
                Math.round(component.getToX()), Math.round(component.getToY()));
    else if (component.getType().equals("rect"))
        graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()),
                Math.round(component.getWidth()), Math.round(component.getHeight()));
    else if (component instanceof TextComponent) {
        graphics.setFont(font((TextComponent) component, fonts));
        graphics.drawString(((TextComponent) component).getText(), component.getFromX(), component.getToY());
    }
}

From source file:savant.view.swing.GraphPane.java

@Override
protected void paintComponent(Graphics g) {
    if (tracks != null && tracks.length > 0) {
        LOG.trace("GraphPane.paintComponent(" + tracks[0].getName() + ")");
    }/*from w  w  w. java  2  s  .c  o  m*/
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    boolean trueRender = render(g2);

    GraphPaneController gpc = GraphPaneController.getInstance();
    int h = getHeight();

    // Aiming adjustments.
    if (gpc.isAiming() && mouseInside) {
        g2.setColor(Color.BLACK);
        Font thickfont = g2.getFont().deriveFont(Font.BOLD, 15.0F);
        g2.setFont(thickfont);
        int genomeX = gpc.getMouseXPosition();
        double genomeY = gpc.getMouseYPosition();
        String target = "";
        target += "X: " + MiscUtils.numToString(genomeX);
        if (!Double.isNaN(genomeY)) {
            target += " Y: " + MiscUtils.numToString(genomeY);
        }

        g2.drawLine(mouseX, 0, mouseX, h);
        if (genomeY != -1) {
            g.drawLine(0, mouseY, this.getWidth(), mouseY);
        }
        g2.drawString(target, mouseX + 5, mouseY - 5);
    }

    double x1 = transformXPos(gpc.getMouseClickPosition());
    double x2 = transformXPos(gpc.getMouseReleasePosition());

    double width = x1 - x2;

    selectionRect = new Rectangle2D.Double(width < 0 ? x1 : x2, 0.0, Math.max(2.0, Math.abs(width)), h);

    if (gpc.isPanning()) {
        // Panning adjustments (none).
    } else if (gpc.isZooming() || gpc.isSelecting()) {
        // Zooming adjustments.
        Rectangle2D rectangle = new Rectangle2D.Double(selectionRect.getX(), selectionRect.getY() - 10.0,
                selectionRect.getWidth(), selectionRect.getHeight() + 10.0);
        g2.setColor(Color.gray);
        g2.setStroke(
                new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3f, new float[] { 4f }, 4f));
        g2.draw(rectangle);

        if (gpc.isZooming()) {
            g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_ZOOM_FILL));
        } else if (gpc.isSelecting()) {
            g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_SELECTION_FILL));
        }
        g2.fill(selectionRect);
    }

    // Plumbing adjustments.
    Range xRange = getXRange();
    if (gpc.isPlumbing()) {
        g2.setColor(Color.BLACK);
        double spos = transformXPos(gpc.getMouseXPosition());
        g2.draw(new Line2D.Double(spos, 0, spos, h));
        double rpos = transformXPos(gpc.getMouseXPosition() + 1);
        g2.draw(new Line2D.Double(rpos, 0, rpos, h));
    }

    // Spotlight
    if (gpc.isSpotlight() && !gpc.isZooming()) {

        int center = gpc.getMouseXPosition();
        int left = center - gpc.getSpotlightSize() / 2;
        int right = left + gpc.getSpotlightSize();

        g2.setColor(new Color(0, 0, 0, 200));

        // draw left of spotlight
        if (left >= xRange.getFrom()) {
            g2.fill(new Rectangle2D.Double(0.0, 0.0, transformXPos(left), h));
        }
        // draw right of spotlight
        if (right <= xRange.getTo()) {
            double pix = transformXPos(right);
            g2.fill(new Rectangle2D.Double(pix, 0, getWidth() - pix, h));
        }
    }

    if (isLocked()) {
        drawMessage((Graphics2D) g, "Locked");
    }
    if (trueRender) {
        gpc.delistRenderingGraphpane(this);
    }
}

From source file:org.n52.v3d.terrainserver.povraywts.WebTerrainServlet.java

private void addAnnotations(BufferedImage pImage, int pHeight, int pWidth, double pPitch, double pYaw,
        boolean pDrawNorthArrow) {
    if (mCopyrightTextContent.length() > 0) {
        Graphics2D g = pImage.createGraphics();
        g.drawImage(pImage, 0, 0, null);
        g.setColor(new java.awt.Color(mCopyrightTextColor.getRed(), mCopyrightTextColor.getGreen(),
                mCopyrightTextColor.getBlue()));

        // 1. Copyright-Vermerk
        // Etwas unschn: Durch JPEG-Komprimierung wird Text (insb. bei kleiner Font-Gre) wird unscharf...
        // TODO: Abhilfe evtl. durch Hintergrund?
        Font font = new Font(mCopyrightTextFont, Font.BOLD /* Style als int, siehe ggf. API-Dok.*/,
                mCopyrightTextSize);//w  ww  .  jav a2s.c o  m
        g.setFont(font);
        // mehrzeilige Copyright-Texte erlauben:
        StringTokenizer str = new StringTokenizer(mCopyrightTextContent, "\n");
        int spacePerRow = mCopyrightTextSize;
        int rows = str.countTokens();
        int startPos = spacePerRow * rows;
        int currRow = 0;
        while (str.hasMoreTokens()) {
            int yPos = pHeight - (startPos - (currRow * spacePerRow)) + spacePerRow / 2;
            g.drawString(str.nextToken().trim(), 5, yPos);
            currRow++;
        }

        // 2. Nordpfeil
        if (pDrawNorthArrow) {
            // Zeichenparameter:
            double radius = 35.;
            double phi = 15.;
            // Symbolkonstruktion:
            int rx = (int) radius;
            int ry = (int) Math.round(radius * Math.sin(-pPitch * Math.PI / 180.));
            int mx = pWidth - rx - 5;
            int my = pHeight - ry - 5;
            int dx = (int) (radius * Math.sin(pYaw * Math.PI / 180.));
            int dy = (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos(pYaw * Math.PI / 180.));
            int px = mx - dx, py = my - dy; // Pfeilspitze
            int qlx = mx + (int) (radius * Math.sin((pYaw + phi) * Math.PI / 180.));
            int qly = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.)
                    * Math.cos((pYaw + phi) * Math.PI / 180.));
            int qrx = mx + (int) (radius * Math.sin((pYaw - phi) * Math.PI / 180.));
            int qry = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.)
                    * Math.cos((pYaw - phi) * Math.PI / 180.));
            // Ellipse zeichnen:
            g.setStroke(new BasicStroke(2.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
            g.drawOval(mx - rx, my - ry, 2 * rx, 2 * ry);
            // Striche fr Pfeil zeichnen:

            g.setStroke(new BasicStroke(1.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));

            boolean fillArrow = true;
            if (fillArrow)
                g.fill(new Polygon(new int[] { px, qlx, qrx }, new int[] { py, qly, qry }, 3));
            else {
                g.drawLine(px, py, qlx, qly);
                g.drawLine(px, py, qrx, qry);
                g.drawLine(qlx, qly, qrx, qry);
            }
        }

        g.dispose();
    }
}

From source file:forseti.JUtil.java

public static synchronized Image generarImagenMensaje(String mensaje, String nombreFuente, int tamanioFuente) {
    Frame f = new Frame();
    f.addNotify();/*from w  w  w .  j a v  a2  s . c  om*/
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    env.getAvailableFontFamilyNames();
    Font fuente = new Font(nombreFuente, Font.PLAIN, tamanioFuente);
    FontMetrics medidas = f.getFontMetrics(fuente);
    int anchoMensaje = medidas.stringWidth(mensaje);
    int lineaBaseX = anchoMensaje / 10;
    int ancho = anchoMensaje + 2 * (lineaBaseX + tamanioFuente);
    int alto = tamanioFuente * 7 / 2;
    int lineaBaseY = alto * 8 / 10;
    Image imagenMensaje = f.createImage(ancho, alto);
    Graphics2D g2d = (Graphics2D) imagenMensaje.getGraphics();
    g2d.setFont(fuente);
    g2d.translate(lineaBaseX, lineaBaseY);
    g2d.setPaint(Color.lightGray);
    AffineTransform origTransform = g2d.getTransform();
    g2d.shear(-0.95, 0);
    g2d.scale(1, 3);
    g2d.drawString(mensaje, 0, 0);
    g2d.setTransform(origTransform);
    g2d.setPaint(Color.black);
    g2d.drawString(mensaje, 0, 0);

    return (imagenMensaje);
}

From source file:org.cruk.mga.CreateReport.java

/**
 * Draws the x-axis for the number of sequences and the legend.
 *
 * @param g2//w w w  . jav  a  2  s  . c om
 * @param x0
 * @param y
 * @param tickIntervals
 * @param maxSequenceCount
 * @return
 */
private int drawAxisAndLegend(Graphics2D g2, int x0, int y, int tickIntervals, long maxSequenceCount) {
    g2.setColor(Color.BLACK);
    g2.setFont(axisFont);

    boolean millions = maxSequenceCount / tickIntervals >= 1000000;
    long largestTickValue = maxSequenceCount;
    if (millions)
        largestTickValue /= 1000000;
    int w = g2.getFontMetrics().stringWidth(Long.toString(largestTickValue));
    int x1 = plotWidth - (w / 2) - gapSize;
    g2.drawLine(x0, y, x1, y);

    int tickFontHeight = g2.getFontMetrics().getAscent();
    int tickHeight = tickFontHeight / 2;
    for (int i = 0; i <= tickIntervals; i++) {
        int x = x0 + i * (x1 - x0) / tickIntervals;
        g2.drawLine(x, y, x, y + tickHeight);
        long tickValue = i * maxSequenceCount / tickIntervals;
        if (millions)
            tickValue /= 1000000;
        String s = Long.toString(tickValue);
        int xs = x - g2.getFontMetrics().stringWidth(s) / 2 + 1;
        int ys = y + tickHeight + tickFontHeight + 1;
        g2.drawString(s, xs, ys);
    }

    g2.setFont(font);
    int fontHeight = g2.getFontMetrics().getAscent();
    String s = "Number of sequences";
    if (millions)
        s += " (millions)";
    int xs = x0 + (x1 - x0 - g2.getFontMetrics().stringWidth(s)) / 2;
    int ys = y + tickHeight + tickFontHeight + fontHeight + fontHeight / 3;
    g2.drawString(s, xs, ys);

    int yl = ys + fontHeight * 2;
    int xl = x0;

    int barHeight = (int) (fontHeight * 0.7f);
    int barWidth = 3 * barHeight;
    int yb = yl + (int) (fontHeight * 0.3f);
    int gap = (int) (fontHeight * 0.4f);

    g2.setColor(Color.GREEN);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    g2.setFont(axisFont);
    String label = "Sequenced species/genome";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(Color.ORANGE);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Control";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(Color.RED);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Contaminant";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(ADAPTER_COLOR);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Adapter";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Unmapped";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(Color.GRAY);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Unknown";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);

    return x1;
}

From source file:it.unibo.alchemist.boundary.gui.effects.DrawShape.java

@SuppressFBWarnings("ES_COMPARING_STRINGS_WITH_EQ")
@Override// ww  w .j  av a2s  . c  o m
public void apply(final Graphics2D g, final Node<?> n, final int x, final int y) {
    if (molString != molStringCached // NOPMD: pointer comparison is wanted here
            || incarnation == null || curIncarnation != prevIncarnation) { // NOPMD: pointer comparison is wanted here
        molStringCached = molString;
        prevIncarnation = curIncarnation;
        incarnation = SupportedIncarnations.get(curIncarnation.getCurrent()).get();
        /*
         * Process in a separate thread: if it fails, does not kill EDT.
         */
        final Thread th = new Thread(() -> molecule = incarnation.createMolecule(molString));
        th.start();
        try {
            th.join();
        } catch (final InterruptedException e) {
            L.error("Bug.", e);
        }
    }
    if (!molFilter || (molecule != null && n.contains(molecule))) {
        final double ks = (scaleFactor.getVal() - MIN_SCALE) * 2 / (double) (SCALE_DIFF);
        final int sizex = size.getVal();
        final int startx = x - sizex / 2;
        final int sizey = (int) Math.ceil(sizex * ks);
        final int starty = y - sizey / 2;
        final Color toRestore = g.getColor();
        colorCache = new Color(red.getVal(), green.getVal(), blue.getVal(), alpha.getVal());
        Color newcolor = colorCache;
        if (molPropertyFilter && molecule != null) {
            final int minV = (int) (minprop.getVal() * FastMath.pow(PROPERTY_SCALE, propoom.getVal()));
            final int maxV = (int) (maxprop.getVal() * FastMath.pow(PROPERTY_SCALE, propoom.getVal()));
            if (minV < maxV) {
                @SuppressWarnings({ "rawtypes", "unchecked" })
                double propval = incarnation.getProperty((Node) n, molecule, property);
                if (isWritingPropertyValue()) {
                    g.setColor(colorCache);
                    g.drawString(Double.toString(propval), startx + sizex, starty + sizey);
                }
                propval = Math.min(Math.max(propval, minV), maxV);
                propval = (propval - minV) / (maxV - minV);
                if (reverse) {
                    propval = 1f - propval;
                }
                newcolor = c.alter(newcolor, (float) propval);
            }
        }
        g.setColor(newcolor);
        switch (mode) {
        case FillEllipse:
            g.fillOval(startx, starty, sizex, sizey);
            break;
        case DrawEllipse:
            g.drawOval(startx, starty, sizex, sizey);
            break;
        case DrawRectangle:
            g.drawRect(startx, starty, sizex, sizey);
            break;
        case FillRectangle:
            g.fillRect(startx, starty, sizex, sizey);
            break;
        default:
            g.fillOval(startx, starty, sizex, sizey);
        }
        g.setColor(toRestore);
    }
}

From source file:org.apache.fop.afp.svg.AFPTextHandler.java

/**
 * Add a text string to the current data object of the AFP datastream.
 * The text is painted using text operations.
 *
 * {@inheritDoc}//from w w  w  .  j  a va 2s  .  co  m
 */
@Override
public void drawString(Graphics2D g, String str, float x, float y) {
    if (log.isDebugEnabled()) {
        log.debug("drawString() str=" + str + ", x=" + x + ", y=" + y);
    }
    if (g instanceof AFPGraphics2D) {
        AFPGraphics2D g2d = (AFPGraphics2D) g;
        GraphicsObject graphicsObj = g2d.getGraphicsObject();
        Color color = g2d.getColor();

        // set the color
        AFPPaintingState paintingState = g2d.getPaintingState();
        if (paintingState.setColor(color)) {
            graphicsObj.setColor(color);
        }

        // set the character set
        int fontReference = 0;
        int fontSize;
        String internalFontName;
        AFPPageFonts pageFonts = paintingState.getPageFonts();
        if (overrideFont != null) {
            internalFontName = overrideFont.getFontName();
            fontSize = overrideFont.getFontSize();
            if (log.isDebugEnabled()) {
                log.debug("  with overriding font: " + internalFontName + ", " + fontSize);
            }
        } else {
            java.awt.Font awtFont = g2d.getFont();
            Font fopFont = fontInfo.getFontInstanceForAWTFont(awtFont);
            if (log.isDebugEnabled()) {
                log.debug("  with font: " + fopFont);
            }
            internalFontName = fopFont.getFontName();
            fontSize = fopFont.getFontSize();
        }
        fontSize = (int) Math.round(g2d.convertToAbsoluteLength(fontSize));
        fontReference = registerPageFont(pageFonts, internalFontName, fontSize);
        // TODO: re-think above registerPageFont code...
        AFPFont afpFont = (AFPFont) fontInfo.getFonts().get(internalFontName);
        final CharacterSet charSet = afpFont.getCharacterSet(fontSize);
        // Work-around for InfoPrint's AFP which loses character set state
        // over Graphics Data
        // boundaries.
        graphicsObj.setCharacterSet(fontReference);
        // add the character string
        graphicsObj.addString(str, Math.round(x), Math.round(y), charSet);
    } else {
        //Inside Batik's SVG filter operations, you won't get an AFPGraphics2D
        g.drawString(str, x, y);
    }
}

From source file:processing.app.Base.java

/**
 * Show the About box./*from   w  w w  . j a  v  a2s. c o  m*/
 */
@SuppressWarnings("serial")
public void handleAbout() {
    final Image image = Theme.getLibImage("about", activeEditor, Theme.scale(475), Theme.scale(300));
    final Window window = new Window(activeEditor) {
        public void paint(Graphics graphics) {
            Graphics2D g = Theme.setupGraphics2D(graphics);
            g.drawImage(image, 0, 0, null);

            Font f = new Font("SansSerif", Font.PLAIN, Theme.scale(11));
            g.setFont(f);
            g.setColor(new Color(0, 151, 156));
            g.drawString(BaseNoGui.VERSION_NAME_LONG, Theme.scale(33), Theme.scale(20));
        }
    };
    window.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            window.dispose();
        }
    });
    int w = image.getWidth(activeEditor);
    int h = image.getHeight(activeEditor);
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    window.setBounds((screen.width - w) / 2, (screen.height - h) / 2, w, h);
    window.setLocationRelativeTo(activeEditor);
    window.setVisible(true);
}