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:com.alibaba.simpleimage.render.FixDrawTextItem.java

@Override
public void drawText(Graphics2D graphics, int width, int height) {
    if (StringUtils.isBlank(text)) {
        return;//from   w w  w. j av a2  s.c o m
    }

    int x = 0, y = 0;
    int fontsize = 1;
    if (position == Position.CENTER) {
        // ?
        int textLength = (int) (width * textWidthPercent);
        // ??
        fontsize = textLength / text.length();
        // ?.....?
        if (fontsize < minFontSize) {
            return;
        }

        float fsize = (float) fontsize;
        Font font = defaultFont.deriveFont(fsize);
        graphics.setFont(font);
        FontRenderContext context = graphics.getFontRenderContext();
        int sw = (int) font.getStringBounds(text, context).getWidth();

        // ??
        x = (width - sw) / 2;
        y = height / 2 + fontsize / 2;
    } else if (position == Position.TOP_LEFT) {
        fontsize = ((int) (width * textWidthPercent)) / text.length();
        if (fontsize < minFontSize) {
            return;
        }

        float fsize = (float) fontsize;
        Font font = defaultFont.deriveFont(fsize);
        graphics.setFont(font);

        x = fontsize;
        y = fontsize * 2;
    } else if (position == Position.TOP_RIGHT) {
        fontsize = ((int) (width * textWidthPercent)) / text.length();
        if (fontsize < minFontSize) {
            return;
        }

        float fsize = (float) fontsize;
        Font font = defaultFont.deriveFont(fsize);
        graphics.setFont(font);
        FontRenderContext context = graphics.getFontRenderContext();
        int sw = (int) font.getStringBounds(text, context).getWidth();

        x = width - sw - fontsize;
        y = fontsize * 2;
    } else if (position == Position.BOTTOM_LEFT) {
        fontsize = ((int) (width * textWidthPercent)) / text.length();
        if (fontsize < minFontSize) {
            return;
        }

        float fsize = (float) fontsize;
        Font font = defaultFont.deriveFont(fsize);
        graphics.setFont(font);

        x = fontsize / 2;
        y = height - fontsize;
    } else if (position == Position.BOTTOM_RIGHT) {
        fontsize = ((int) (width * textWidthPercent)) / text.length();
        if (fontsize < minFontSize) {
            return;
        }

        float fsize = (float) fontsize;
        Font font = defaultFont.deriveFont(fsize);
        graphics.setFont(font);
        FontRenderContext context = graphics.getFontRenderContext();
        int sw = (int) font.getStringBounds(text, context).getWidth();

        x = width - sw - fontsize;
        y = height - fontsize;
    } else {
        throw new IllegalArgumentException("Unknown position : " + position);
    }

    if (x <= 0 || y <= 0) {
        return;
    }

    if (fontShadowColor != null) {
        graphics.setColor(fontShadowColor);
        graphics.drawString(text, x + getShadowTranslation(fontsize), y + getShadowTranslation(fontsize));
    }

    graphics.setColor(fontColor);
    graphics.drawString(text, x, y);
}

From source file:com.flexoodb.common.FlexUtils.java

static public void createTextBanner(String text, int fontsize, int width, int height, int x, int y,
        String outputfile) throws Exception {
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    img.createGraphics();/*from   ww w .j av  a 2s . c  om*/
    Graphics2D g = (Graphics2D) img.getGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, img.getWidth(), img.getHeight());
    Font font = new Font("Arial", Font.BOLD, fontsize);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    g.setFont(font);
    g.setColor(Color.BLUE.darker());
    g.drawString(text, x, y);
    ImageIO.write(img, "png", new File(outputfile));
}

From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java

public void drawString(Graphics g, String text, RectangularShape bounds, Align align, double angle,
        boolean multiline) {
    Graphics2D g2 = (Graphics2D) g;
    Font font = g2.getFont();//from   w ww.  j a v  a  2 s . co m
    if (angle != 0) {
        g2.setFont(font.deriveFont(AffineTransform.getRotateInstance(Math.toRadians(angle))));
    }

    Rectangle2D sSize = g2.getFontMetrics().getStringBounds(text, g2);
    Point2D pos = getPoint(bounds, align);
    double x = pos.getX();
    double y = pos.getY() + sSize.getHeight();

    switch (align) {
    case TopCenter:
    case BottomCenter:
    case Center:
        x -= (sSize.getWidth() / 2);
        break;
    case TopRight:
    case MiddleRight:
    case BottomRight:
        x -= (sSize.getWidth());
        break;
    case BottomLeft:
    case MiddleLeft:
    case TopLeft:
        break;
    }
    if (multiline) {
        // Create a new LineBreakMeasurer from the paragraph.
        // It will be cached and re-used.
        //if (lineMeasurer == null) {
        AttributedCharacterIterator paragraph = new AttributedString(text).getIterator();
        paragraphStart = paragraph.getBeginIndex();
        paragraphEnd = paragraph.getEndIndex();
        FontRenderContext frc = g2.getFontRenderContext();
        lineMeasurer = new LineBreakMeasurer(paragraph, frc);
        //}

        // Set break width to width of Component.
        float breakWidth = (float) bounds.getWidth();
        float drawPosY = (float) y;
        // Set position to the index of the first character in the paragraph.
        lineMeasurer.setPosition(paragraphStart);

        // Get lines until the entire paragraph has been displayed.
        while (lineMeasurer.getPosition() < paragraphEnd) {

            // Retrieve next layout. A cleverer program would also cache
            // these layouts until the component is re-sized.
            TextLayout layout = lineMeasurer.nextLayout(breakWidth);

            // Compute pen x position. If the paragraph is right-to-left we
            // will align the TextLayouts to the right edge of the panel.
            // Note: this won't occur for the English text in this sample.
            // Note: drawPosX is always where the LEFT of the text is placed.
            float drawPosX = layout.isLeftToRight() ? (float) x : (float) x + breakWidth - layout.getAdvance();

            // Move y-coordinate by the ascent of the layout.
            drawPosY += layout.getAscent();

            // Draw the TextLayout at (drawPosX, drawPosY).
            layout.draw(g2, drawPosX, drawPosY);

            // Move y-coordinate in preparation for next layout.
            drawPosY += layout.getDescent() + layout.getLeading();
        }
    } else {
        g2.drawString(text, (float) x, (float) y);
    }
    g2.setFont(font);
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private static void drawString(final int i, final double x, final double y, final Graphics2D g) {
    g.drawString(String.valueOf(i), (int) (x + 0.5), (int) (y + 0.5));
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private static void drawString(final String str, final double x, final double y, final Graphics2D g) {
    g.drawString(str, (int) (x + 0.5), (int) (y + 0.5));
}

From source file:spinworld.gui.RadarPlot.java

/**
 * Draws the label for one axis./*  www .j a  v a  2 s. com*/
 *
 * @param g2  the graphics device.
 * @param plotArea  whole plot drawing area (e.g. including space for labels)
 * @param plotDrawingArea  the plot drawing area (just spanning of axis)
 * @param value  the value of the label (ignored).
 * @param cat  the category (zero-based index).
 * @param startAngle  the starting angle.
 * @param extent  the extent of the arc.
 */
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, Rectangle2D plotDrawingArea, double value,
        int cat, double startAngle, double extent) {
    FontRenderContext frc = g2.getFontRenderContext();

    String label = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        // if series are in rows, then the categories are the column keys
        label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
    } else {
        // if series are in columns, then the categories are the row keys
        label = this.labelGenerator.generateRowLabel(this.dataset, cat);
    }

    double angle = normalize(startAngle);

    Font font = getLabelFont();
    Point2D labelLocation;
    do {
        Rectangle2D labelBounds = font.getStringBounds(label, frc);
        LineMetrics lm = font.getLineMetrics(label, frc);
        double ascent = lm.getAscent();

        labelLocation = calculateLabelLocation(labelBounds, ascent, plotDrawingArea, startAngle);

        boolean leftOut = angle > 90 && angle < 270 && labelLocation.getX() < plotArea.getX();
        boolean rightOut = (angle < 90 || angle > 270)
                && labelLocation.getX() + labelBounds.getWidth() > plotArea.getX() + plotArea.getWidth();

        if (leftOut || rightOut) {
            font = font.deriveFont(font.getSize2D() - 1);
        } else {
            break;
        }
    } while (font.getSize() > 8);

    Composite saveComposite = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    g2.setPaint(getLabelPaint());
    g2.setFont(font);
    g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY());
    g2.setComposite(saveComposite);
}

From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java

/**
 * Render the pie chart with the given height
 * //  www.  ja v a  2  s  .c o  m
 * @param height
 *          The height of the resulting image
 * @return The pie chart rendered as an image
 */
public BufferedImage render(int height) {
    BufferedImage image = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    g2.scale(zoom, zoom);
    // fill background to white
    g2.setColor(Color.WHITE);
    g2.fill(new Rectangle(totalWidth, totalHeight));
    // prepare render hints
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    // draw shadow image
    g2.drawImage(pieShadow.getImage(), 0, 0, pieShadow.getImageObserver());

    double start = 0;
    List<Arc2D> pies = new ArrayList<>();
    // pie segmente erzeugen und fuellen
    if (total == 0) {
        g2.setColor(BRIGHT_GRAY);
        g2.fillOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius);
        g2.setColor(Color.WHITE);
        g2.drawOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius);
    } else {
        for (Segment s : segments) {
            double portionDegrees = s.getPortion() / total;
            Arc2D pie = paintPieSegment(g2, start, portionDegrees, s.getColor());
            if (withSubSegments) {
                double smallRadius = radius * s.getSubSegmentRatio();
                paintPieSegment(g2, start, portionDegrees, smallRadius, s.getColor().darker());
            }
            start += portionDegrees;
            // portion degree jetzt noch als String (z.B. "17.3%" oder "20%" zusammenbauen)
            String p = String.format(Locale.ENGLISH, "%.1f", Math.rint(portionDegrees * 1000) / 10.0);
            p = removeSuffix(p, ".0"); // evtl. ".0" bei z.B. "25.0" abschneiden (-> "25")
            s.setPercent(p + "%");
            pies.add(pie);
        }
        // weissen Rahmen um die pie segmente zeichen
        g2.setColor(Color.WHITE);
        for (Arc2D pie : pies) {
            g2.draw(pie);
        }
    }
    // Legende zeichnen
    renderLegend(g2);
    // "xx%" Label direkt auf die pie segmente zeichen
    g2.setColor(Color.WHITE);
    float fontSize = 32f;
    g2.setFont(NORMALFONT.deriveFont(fontSize).deriveFont(Font.BOLD));
    start = 0;
    for (Segment s : segments) {
        if (s.getPortion() < 1E-6) {
            continue; // ignore segments with portions that are extremely small
        }
        double portionDegrees = s.getPortion() / total;
        double angle = start + portionDegrees / 2; // genau in der Mitte des Segments
        double xOffsetForCenteredTxt = 8 * s.getPercent().length(); // assume roughly 8px per char
        int x = (int) (centerX + 0.6 * radius * Math.sin(2 * Math.PI * angle) - xOffsetForCenteredTxt);
        int y = (int) (centerY - 0.6 * radius * Math.cos(2 * Math.PI * angle) + fontSize / 2);
        g2.drawString(s.getPercent(), x, y);
        start += portionDegrees;
    }
    return image;
}

From source file:paquete.HollywoodUI.java

public void dibujarAristas() {
    Graphics2D g = grafico.createGraphics();
    g.setFont(new Font("SansSerif", Font.BOLD, 11));
    adyaTemp = new ArrayList<>(this.HollyUniverseGraph.getEdges());
    for (Actor temp_actor : actoresArray) {
        for (Arista temp_arista : adyaTemp) {
            g.setColor(Color.BLACK);
            g.drawLine(temp_actor.getX(), temp_actor.getY(), temp_arista.getNext().getX(),
                    temp_arista.getNext().getY());
            int nx = (temp_actor.getX() + temp_arista.getNext().getX()) / 2;
            int ny = (temp_actor.getY() + temp_arista.getNext().getY()) / 2;
            g.setColor(Color.ORANGE);
            if (temp_arista.getRelacion().equals("Amistad")) {
                g.setColor(Color.BLUE);
                g.drawString(temp_arista.getRelacion() + "", nx + 10, ny - 3);
            } else if (temp_arista.getRelacion().equals("Noviazgo")) {
                g.setColor(Color.GREEN);
                g.drawString(temp_arista.getRelacion() + "", nx + 10, ny + 23);
            } else if (temp_arista.getRelacion().equals("Matrimonio")) {
                g.setColor(Color.RED);
                g.drawString(temp_arista.getRelacion() + "", nx - 15, ny - 5);
            } else if (temp_arista.getRelacion().equals("Familia")) {
                g.setColor(Color.YELLOW);
                g.drawString(temp_arista.getRelacion() + "", nx - 15, ny - 5);
            }//from  ww  w .j a va 2  s  . c o m
        }
    }
    Image img;
    img = Toolkit.getDefaultToolkit().createImage(grafico.getSource()).getScaledInstance(800, 600, 0);
    label_grafico.setIcon(new ImageIcon(img));
}

From source file:paquete.HollywoodUI.java

public void printActores() {
    this.actoresArray = new ArrayList<>(this.HollyUniverseGraph.getVertices());
    try {/*from  w w w .j a  v a 2 s . com*/
        int cant_actores = 0;
        grafico = ImageIO.read(new File("./src/sources/hollywoodUniverseV2.jpg"));
        Graphics2D g = grafico.createGraphics();
        Actor a = null;
        for (Actor temp_actor : actoresArray) {
            a = temp_actor;
            g.setColor(Color.GREEN);
            g.setFont(new Font("SansSerif", Font.BOLD, 11));
            if (cant_actores == 0) {
                g.drawImage(temp_actor.getFoto_actor(), null, 150, 25);
                grafico.setRGB(150 + temp_actor.getFoto_actor().getWidth() / 2,
                        25 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB());
                a.setArea(150, 150 + temp_actor.getFoto_actor().getWidth(), 25,
                        25 + temp_actor.getFoto_actor().getHeight());
                g.drawString(a.getNombre(), 150 - 20, 20);
                a.setLocation(150 + temp_actor.getFoto_actor().getWidth() / 2,
                        25 + temp_actor.getFoto_actor().getHeight() / 2);
            } else {
                if (cant_actores == 1) {
                    g.drawImage(temp_actor.getFoto_actor(), null, 300, 85);
                    grafico.setRGB(300 + temp_actor.getFoto_actor().getWidth() / 2,
                            85 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB());
                    a.setArea(300, 300 + temp_actor.getFoto_actor().getWidth(), 85,
                            85 + temp_actor.getFoto_actor().getHeight());
                    g.drawString(a.getNombre(), 300, 80);
                    a.setLocation(300 + temp_actor.getFoto_actor().getWidth() / 2,
                            85 + temp_actor.getFoto_actor().getHeight() / 2);
                } else {
                    if (cant_actores == 2) {
                        g.drawImage(temp_actor.getFoto_actor(), null, 475, 25);
                        grafico.setRGB(475 + temp_actor.getFoto_actor().getWidth() / 2,
                                25 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB());
                        a.setArea(475, 475 + temp_actor.getFoto_actor().getWidth(), 25,
                                25 + temp_actor.getFoto_actor().getHeight());
                        g.drawString(a.getNombre(), 475, 25);
                        a.setLocation(475 + temp_actor.getFoto_actor().getWidth() / 2,
                                25 + temp_actor.getFoto_actor().getHeight() / 2);
                    } else if (cant_actores == 3) {
                        g.drawImage(temp_actor.getFoto_actor(), null, 50, 225);
                        grafico.setRGB(50 + temp_actor.getFoto_actor().getWidth() / 2,
                                225 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB());
                        a.setArea(50, 50 + temp_actor.getFoto_actor().getWidth(), 225,
                                225 + temp_actor.getFoto_actor().getHeight());
                        g.drawString(a.getNombre(), 50, 220);
                        a.setLocation(50 + temp_actor.getFoto_actor().getWidth() / 2,
                                225 + temp_actor.getFoto_actor().getHeight() / 2);

                    } else if (cant_actores == 4) {
                        g.drawImage(temp_actor.getFoto_actor(), null, 300, 200);
                        grafico.setRGB(300 + temp_actor.getFoto_actor().getWidth() / 2,
                                200 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB());
                        a.setArea(300, 300 + temp_actor.getFoto_actor().getWidth(), 200,
                                200 + temp_actor.getFoto_actor().getHeight());
                        g.drawString(a.getNombre(), 300, 195);
                        a.setLocation(300 + temp_actor.getFoto_actor().getWidth() / 2,
                                200 + temp_actor.getFoto_actor().getHeight() / 2);

                    } else if (cant_actores == 5) {
                        g.drawImage(temp_actor.getFoto_actor(), null, 575, 225);
                        grafico.setRGB(575 + temp_actor.getFoto_actor().getWidth() / 2,
                                225 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB());
                        a.setArea(575, 575 + temp_actor.getFoto_actor().getWidth(), 225,
                                225 + temp_actor.getFoto_actor().getHeight());
                        g.drawString(a.getNombre(), 575, 220);
                        a.setLocation(575 + temp_actor.getFoto_actor().getWidth() / 2,
                                225 + temp_actor.getFoto_actor().getHeight() / 2);

                    } else if (cant_actores == 6) {
                        g.drawImage(temp_actor.getFoto_actor(), null, 150, 415);
                        grafico.setRGB(150 + temp_actor.getFoto_actor().getWidth() / 2,
                                415 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB());
                        g.drawString(a.getNombre(), 150, 410);
                        a.setArea(150, 150 + temp_actor.getFoto_actor().getWidth(), 425,
                                415 + temp_actor.getFoto_actor().getHeight());
                        a.setLocation(150 + temp_actor.getFoto_actor().getWidth() / 2,
                                415 + temp_actor.getFoto_actor().getHeight() / 2);

                    } else if (cant_actores == 7) {
                        g.drawImage(temp_actor.getFoto_actor(), null, 300, 350);
                        grafico.setRGB(300 + temp_actor.getFoto_actor().getWidth() / 2,
                                350 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB());
                        a.setArea(300, 300 + temp_actor.getFoto_actor().getWidth(), 350,
                                350 + temp_actor.getFoto_actor().getHeight());
                        g.drawString(a.getNombre(), 300, 345);
                        a.setLocation(300 + temp_actor.getFoto_actor().getWidth() / 2,
                                350 + temp_actor.getFoto_actor().getHeight() / 2);

                    } else if (cant_actores == 8) {
                        g.drawImage(temp_actor.getFoto_actor(), null, 475, 415);
                        grafico.setRGB(475 + temp_actor.getFoto_actor().getWidth() / 2,
                                415 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB());
                        a.setArea(475, 475 + temp_actor.getFoto_actor().getWidth(), 415,
                                415 + temp_actor.getFoto_actor().getHeight());
                        g.drawString(a.getNombre(), 475, 410);
                        a.setLocation(475 + temp_actor.getFoto_actor().getWidth() / 2,
                                415 + temp_actor.getFoto_actor().getHeight() / 2);

                    }
                }
            }
            cant_actores++;
        }

    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "Ocurrio un error inesperado en el sistema", "ERROR",
                JOptionPane.ERROR_MESSAGE);
    }
    dibujarAristas();
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void drawTitle(Graphics2D g2) {
    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Color oldColor = g2.getColor();
    final Font oldFont = g2.getFont();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final Font titleFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() * 1.5f);

    final int margin = 5;

    final FontMetrics titleFontMetrics = g2.getFontMetrics(titleFont);
    final FontMetrics oldFontMetrics = g2.getFontMetrics(oldFont);
    final java.text.NumberFormat numberFormat = java.text.NumberFormat.getInstance();
    numberFormat.setMaximumFractionDigits(2);
    numberFormat.setMinimumFractionDigits(2);

    final double totalInvestValue = this.investmentFlowChartJDialog.getTotalInvestValue();
    final double totalROIValue = this.investmentFlowChartJDialog.getTotalROIValue();

    final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace();

    final String invest = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace,
            totalInvestValue);/*from ww  w . j  a v a 2  s. c o m*/
    final String roi = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalROIValue);
    final double gain = totalROIValue - totalInvestValue;
    final double percentage = totalInvestValue > 0.0 ? gain / totalInvestValue * 100.0 : 0.0;
    final String gain_str = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, gain);
    final String percentage_str = numberFormat.format(percentage);

    final String SELECTED = this.investmentFlowChartJDialog.getCurrentSelectedString();
    final String INVEST = GUIBundle.getString("InvestmentFlowLayerUI_Invest");
    final String RETURN = GUIBundle.getString("InvestmentFlowLayerUI_Return");
    final String GAIN = (SELECTED.length() > 0 ? SELECTED + " " : "")
            + GUIBundle.getString("InvestmentFlowLayerUI_Gain");
    final String LOSS = (SELECTED.length() > 0 ? SELECTED + " " : "")
            + GUIBundle.getString("InvestmentFlowLayerUI_Loss");

    final int string_width = oldFontMetrics.stringWidth(INVEST + ": ")
            + titleFontMetrics.stringWidth(invest + " ") + oldFontMetrics.stringWidth(RETURN + ": ")
            + titleFontMetrics.stringWidth(roi + " ")
            + oldFontMetrics.stringWidth((gain >= 0 ? GAIN : LOSS) + ": ")
            + titleFontMetrics.stringWidth(gain_str + " (" + percentage_str + "%)");

    int x = (int) (this.investmentFlowChartJDialog.getChartPanel().getWidth() - string_width) >> 1;
    final int y = margin + titleFontMetrics.getAscent();

    g2.setFont(oldFont);
    g2.drawString(INVEST + ": ", x, y);
    x += oldFontMetrics.stringWidth(INVEST + ": ");
    g2.setFont(titleFont);
    g2.drawString(invest + " ", x, y);
    x += titleFontMetrics.stringWidth(invest + " ");
    g2.setFont(oldFont);
    g2.drawString(RETURN + ": ", x, y);
    x += oldFontMetrics.stringWidth(RETURN + ": ");
    g2.setFont(titleFont);
    g2.drawString(roi + " ", x, y);
    x += titleFontMetrics.stringWidth(roi + " ");
    g2.setFont(oldFont);
    if (gain >= 0) {
        if (gain > 0) {
            if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) {
                g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor());
            } else {
                g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor());
            }
        }
        g2.drawString(GAIN + ": ", x, y);
        x += oldFontMetrics.stringWidth(GAIN + ": ");
    } else {
        if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) {
            g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor());
        } else {
            g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor());
        }
        g2.drawString(LOSS + ": ", x, y);
        x += oldFontMetrics.stringWidth(LOSS + ": ");
    }
    g2.setFont(titleFont);
    g2.drawString(gain_str + " (" + percentage_str + "%)", x, y);

    g2.setColor(oldColor);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    g2.setFont(oldFont);
}