Example usage for java.awt Graphics2D getFont

List of usage examples for java.awt Graphics2D getFont

Introduction

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

Prototype

public abstract Font getFont();

Source Link

Document

Gets the current font.

Usage

From source file:org.prom5.analysis.performance.dottedchart.ui.DottedChartPanel.java

/**
 * convenience method for internal use.//w  w w . ja va2  s .  co  m
 * paints the log lane, with time indicators.
 * @param gOrig
 * @param dMin date on the left boundary
 * @param dMax date on the right boundary
 */
protected void paintComponentLane(Graphics2D g, int width, int hight) {
    g.setFont(g.getFont().deriveFont((float) 10.0));
    // set initial colors
    Color fgColor = null;
    Color bgColor = null;
    Color tmpColor = null;
    fgColor = null;
    bgColor = null;
    // calculate common coordinates
    int unitHeight = hight / getHashMapSize();
    int yTop = 0;
    int yBottom = hight;
    int pixStart = 0;
    String dateStr, timeStr, millisStr = null;

    // calculate area to be painted
    clipL = 0;
    clipR = width;

    // initialze start color
    fgColor = colorLogDark;
    bgColor = colorLogBright;

    // calculate current top
    int currentTop = yTop;

    // paint actual log lane (only the part in the clipping range determined)
    Iterator itr = dcModel.getSortedKeySetList().iterator(); //dcModel.getItemMap().keySet().iterator();
    g.setFont(new Font("Dialog", Font.BOLD, 13));
    int index = 0;
    currentTop = yTop;
    while (itr.hasNext()) {
        String dimName = (String) itr.next();
        if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName))
            continue;
        g.setColor(bgColor);
        g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight);

        g.setColor(fgColor);

        index++;
        currentTop = unit2Cord_buffer(index, hight);

        // swap colors
        tmpColor = fgColor;
        fgColor = bgColor;
        bgColor = tmpColor;
    }

    g.setFont(new Font("Dialog", Font.PLAIN, 12));

    // draw horizontal delimiters
    g.setColor(colorTimeLine);
    g.drawLine(clipL, yTop, clipR, yTop);
    g.drawLine(clipL, yBottom, clipR, yBottom);

    clipLeftTs = coord2timeMillis(clipL);
    clipRightTs = coord2timeMillis(clipR);
}

From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java

/**
 * convenience method for internal use. paints the log lane, with time
 * indicators./*from   ww w.  java  2s. c  o m*/
 * 
 * @param gOrig
 * @param dMin
 *            date on the left boundary
 * @param dMax
 *            date on the right boundary
 */
protected void paintComponentLane(Graphics2D g, int width, int hight) {
    g.setFont(g.getFont().deriveFont((float) 10.0));
    // set initial colors
    Color fgColor = null;
    Color bgColor = null;
    Color tmpColor = null;
    fgColor = null;
    bgColor = null;
    // calculate common coordinates
    int unitHeight = hight / getHashMapSize();
    int yTop = 0;
    int yBottom = hight;
    int pixStart = 0;
    String dateStr, timeStr, millisStr = null;

    // calculate area to be painted
    clipL = 0;
    clipR = width;

    // initialze start color
    fgColor = colorLogDark;
    bgColor = colorLogBright;

    // calculate current top
    int currentTop = yTop;

    // paint actual log lane (only the part in the clipping range
    // determined)
    Iterator itr = dcModel.getSortedKeySetList().iterator(); // dcModel.getItemMap().keySet().iterator();
    g.setFont(new Font("Dialog", Font.BOLD, 13));
    int index = 0;
    currentTop = yTop;
    while (itr.hasNext()) {
        String dimName = (String) itr.next();
        if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName))
            continue;
        g.setColor(bgColor);
        g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight);

        g.setColor(fgColor);

        index++;
        currentTop = unit2Cord_buffer(index, hight);

        // swap colors
        tmpColor = fgColor;
        fgColor = bgColor;
        bgColor = tmpColor;
    }

    g.setFont(new Font("Dialog", Font.PLAIN, 12));

    // draw horizontal delimiters
    g.setColor(colorTimeLine);
    g.drawLine(clipL, yTop, clipR, yTop);
    g.drawLine(clipL, yBottom, clipR, yBottom);

    clipLeftTs = coord2timeMillis(clipL);
    clipRightTs = coord2timeMillis(clipR);
}

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() + ")");
    }// ww w.j  av a 2s .co 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.broad.igv.variant.VariantTrack.java

/**
 * Draws the "greenbar" type background.  Also, rather bizarrely, draws the sample names.
 *
 * @param g2D//ww  w .  j  a v  a2 s.  c  o m
 * @param bandRectangle
 * @param visibleRectangle
 * @param type
 */
private void drawBackground(Graphics2D g2D, Rectangle bandRectangle, Rectangle visibleRectangle,
        BackgroundType type) {

    if (getDisplayMode() == DisplayMode.COLLAPSED) {
        return;
    }

    boolean coloredLast = true;
    Rectangle textRectangle = new Rectangle(bandRectangle);
    textRectangle.height--;

    int bandFontSize = Math.min(fontSize, (int) bandRectangle.getHeight() - 1);
    Font font = FontManager.getFont(bandFontSize);
    Font oldFont = g2D.getFont();
    g2D.setFont(font);

    if (grouped) {
        for (Map.Entry<String, List<String>> sampleGroup : samplesByGroups.entrySet()) {
            int y0 = bandRectangle.y;

            List<String> sampleList = sampleGroup.getValue();
            coloredLast = colorBand(g2D, bandRectangle, visibleRectangle, coloredLast, textRectangle,
                    sampleList, type);
            bandRectangle.y += GROUP_BORDER_WIDTH;

            if (type == BackgroundType.NAME && bandRectangle.height < 3) {
                String group = sampleGroup.getKey();
                if (group != null) {
                    g2D.setColor(Color.black);
                    g2D.setFont(oldFont);
                    int y2 = bandRectangle.y;
                    Rectangle textRect = new Rectangle(bandRectangle.x, y0, bandRectangle.width, y2 - y0);
                    GraphicUtils.drawWrappedText(group, textRect, g2D, true);
                }
            }

        }

    } else {
        coloredLast = colorBand(g2D, bandRectangle, visibleRectangle, coloredLast, textRectangle, allSamples,
                type);
    }
    g2D.setFont(oldFont);
}

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

/**
 * Render the background of this GraphPane
 *
 * @param g The graphics object to use/* w  w w  .  j  a va2 s .co  m*/
 */
private void renderBackground(Graphics2D g2, boolean xGridOn, boolean yGridOn) {
    int h = getHeight();
    int w = getWidth();

    // Paint a gradient from top to bottom
    GradientPaint gp0 = new GradientPaint(0, 0, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP), 0,
            h, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM));
    g2.setPaint(gp0);
    g2.fillRect(0, 0, w, h);

    // We don't want the axes stomping on our labels, so make sure the clip excludes them.
    Area clipArea = new Area(new Rectangle(0, 0, w, h));
    Color gridColor = ColourSettings.getColor(ColourKey.AXIS_GRID);

    if (yGridOn) {
        // Smallish font for tick labels.
        Font tickFont = g2.getFont().deriveFont(Font.PLAIN, 9);

        int[] yTicks = MiscUtils.getTickPositions(transformYPixel(getHeight()), transformYPixel(0.0));

        g2.setColor(gridColor);
        g2.setFont(tickFont);
        for (int t : yTicks) {
            double y = transformYPos(t);

            // Skip labels at the top or bottom of the window because they look stupid.
            if (y != 0.0 && y != getHeight()) {
                String s = Integer.toString(t);
                Rectangle2D labelRect = tickFont.getStringBounds(s, g2.getFontRenderContext());
                double baseline = y + labelRect.getHeight() * 0.5 - 2.0;
                g2.drawString(s, 4.0F, (float) baseline);
                clipArea.subtract(new Area(new Rectangle2D.Double(3.0, baseline - labelRect.getHeight() - 1.0,
                        labelRect.getWidth() + 2.0, labelRect.getHeight() + 2.0)));
            }
        }
        g2.setClip(clipArea);
        for (int t2 : yTicks) {
            double y = transformYPos(t2);
            g2.draw(new Line2D.Double(0.0, y, w, y));
        }
    }
    if (xGridOn) {
        Range r = LocationController.getInstance().getRange();
        int[] xTicks = MiscUtils.getTickPositions(r);

        g2.setColor(gridColor);
        for (int t : xTicks) {
            double x = transformXPos(t);
            g2.draw(new Line2D.Double(x, 0, x, h));
        }
    }
    g2.setClip(null);
}

From source file:ImageOps.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    int w = getSize().width;
    int h = getSize().height;

    g2.setColor(Color.black);//  w  w w  .j a  v a  2 s. c om
    float[][] data = { { 0.1f, 0.1f, 0.1f, // low-pass filter
            0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f }, SHARPEN3x3_3 };

    String theDesc[] = { "Convolve LowPass", "Convolve Sharpen", "LookupOp", "RescaleOp" };
    for (int i = 0; i < bi.length; i++) {
        int iw = bi[i].getWidth(this);
        int ih = bi[i].getHeight(this);
        int x = 0, y = 0;

        AffineTransform at = new AffineTransform();
        at.scale((w - 14) / 2.0 / iw, (h - 34) / 2.0 / ih);

        BufferedImageOp biop = null;
        BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);

        switch (i) {
        case 0:
        case 1:
            x = i == 0 ? 5 : w / 2 + 3;
            y = 15;
            Kernel kernel = new Kernel(3, 3, data[i]);
            ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
            cop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
            break;
        case 2:
            x = 5;
            y = h / 2 + 15;
            byte chlut[] = new byte[256];
            for (int j = 0; j < 200; j++)
                chlut[j] = (byte) (256 - j);
            ByteLookupTable blut = new ByteLookupTable(0, chlut);
            LookupOp lop = new LookupOp(blut, null);
            lop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
            break;
        case 3:
            x = w / 2 + 3;
            y = h / 2 + 15;
            RescaleOp rop = new RescaleOp(1.1f, 20.0f, null);
            rop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
        }
        g2.drawImage(bimg, biop, x, y);
        TextLayout tl = new TextLayout(theDesc[i], g2.getFont(), g2.getFontRenderContext());
        tl.draw(g2, (float) x, (float) y - 4);
    }
}

From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java

/**
 * Renders this image//  w  w  w.ja v a 2  s.  c  om
 * 
 * @return The image data
 */
private final byte[] render() throws IOException {
    Graphics2D gfx = (Graphics2D) this.image.getGraphics();
    if (config.isFontAntialiasing())
        gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int curWidth = config.getTextMarginLeft();
    FontRenderContext ctx = new FontRenderContext(null, config.isFontAntialiasing(), false);
    for (int i = 0; i < charAttsList.size(); i++) {
        CharAttributes cf = (CharAttributes) charAttsList.get(i);
        TextLayout text = new TextLayout(cf.getChar() + "", getFont(cf.getName()), ctx); //gfx.getFontRenderContext());
        AffineTransform textAt = new AffineTransform();
        textAt.translate(curWidth, this.height - cf.getRise());
        if (cf.getRotation() != 0) {
            textAt.rotate(cf.getRotation());
        }
        if (cf.getShearX() > 0.0)
            textAt.shear(cf.getShearX(), cf.getShearY());
        Shape shape = text.getOutline(textAt);
        curWidth += shape.getBounds().getWidth() + config.getTextSpacing();
        if (config.isUseImageBackground())
            gfx.setColor(Color.BLACK);
        else
            gfx.setXORMode(Color.BLACK);
        gfx.fill(shape);
    }
    if (config.isEffectsNoise()) {
        noiseEffects(gfx, image);
    }
    if (config.isUseTimestamp()) {
        if (config.isEffectsNoise())
            gfx.setColor(Color.WHITE);
        else
            gfx.setColor(Color.BLACK);

        TimeZone tz = TimeZone.getTimeZone(config.getTimestampTZ());
        Calendar cal = new GregorianCalendar(tz);
        SimpleDateFormat formatter;
        if (config.isUseTimestamp24hr())
            formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z");
        else
            formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a, z");
        formatter.setTimeZone(tz);
        Font font = gfx.getFont();
        Font newFont = new Font(font.getName(), font.getStyle(), config.getTimestampFontSize());
        gfx.setFont(newFont);
        gfx.drawString(formatter.format(cal.getTime()), config.getTextMarginLeft() * 4, this.height - 1);
    }

    return toImageData(image);
}

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

private void renderRange(LongRange pRange, LongRange pStartRange, LongRange pArriveRange, boolean pIsStartRange,
        boolean pIsArriveRange, Graphics2D pG2D, TimeSpan pSpanForRange, HashMap<String, Object> pPopupInfo) {
    int rangeStart = 0;
    int rangeWidth = 0;

    if (pRange.overlapsRange(pStartRange)) {
        //start range rendering
        long startDelta = pStartRange.getMinimumLong();
        rangeStart = Math.round((pRange.getMinimumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE);
        // int rangeEnd = Math.round((pRange.getMaximumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE);
        rangeWidth = Math/*w ww .  j av a  2 s  .  c o  m*/
                .round((pRange.getMaximumLong() - pRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE);
    } else if (pRange.overlapsRange(pArriveRange)) {
        //end range rendering
        long startDelta = pStartRange.getMinimumLong();
        rangeStart = Math.round((pRange.getMinimumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE);
        // int rangeEnd = Math.round((pRange.getMaximumLong() - arriveDelta) / DateUtils.MILLIS_PER_MINUTE);
        rangeWidth = Math
                .round((pRange.getMaximumLong() - pRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE);
    }
    //correct small widths
    if (rangeWidth == 0) {
        rangeWidth = 5;
    }

    long max = Math.round(
            (pArriveRange.getMaximumLong() - pStartRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE);

    if (rangeStart > max) {
        return;
    }

    SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
    String labelString = "";
    if (pSpanForRange != null) {
        labelString = pSpanForRange.toString();
    } else {
        labelString = f.format(new Date(pRange.getMinimumLong())) + " bis "
                + f.format(new Date(pRange.getMaximumLong()));
    }
    Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(labelString, pG2D);
    if (pIsStartRange) {
        pG2D.setColor(Color.RED);
        pG2D.fillRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.BLACK);
        pG2D.drawRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.RED);
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 14.0f));
        pG2D.drawString(labelString, rangeStart, (int) labelBounds.getHeight());
    } else if (pIsArriveRange) {
        pG2D.setColor(Color.GREEN.darker());
        pG2D.fillRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.BLACK);
        pG2D.drawRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.GREEN.darker());
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 14.0f));
        pG2D.drawString(labelString, rangeStart, (int) labelBounds.getHeight() + 40);
    } else {
        pG2D.fillRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.BLACK);
        pG2D.drawRect(rangeStart, 20, rangeWidth, 20);
        Point loc = getMousePosition();
        if (loc != null && new Rectangle(rangeStart, 20, rangeWidth, 20).contains(loc)) {
            pPopupInfo.put("popup.location", loc);
            pPopupInfo.put("popup.label", labelString);
            pPopupInfo.put("active.range", pRange);
            pPopupInfo.put("span.for.range", pSpanForRange);

        }
    }
}

From source file:org.viafirma.util.QRCodeUtil.java

/**
 * Genera codigo de firma para impresin formado por el texto, el cdigo qr
 * del texto y un cdigo de barras con el cdigo de firma.
 * /*  w  w  w.j a va 2s. c o m*/
 * @param text
 * @param codFirma
 * @return
 * @throws ExcepcionErrorInterno
 */
public byte[] generate(String text, String url, String textoQR, String codFirma) throws ExcepcionErrorInterno {
    // Comprobamos el tamao del texto. No recomendamos textos de mas de 120
    // caracteres
    if (textoQR.length() > MAX_TEXT_SIZE) {
        log.warn("El tamao del texto '" + text + "' ha excedido el tamao mximo. " + text.length() + ">"
                + MAX_TEXT_SIZE);
        textoQR = textoQR.substring(textoQR.lastIndexOf(" "));
        log.warn("El texto sera recortado: '" + textoQR + "'");
    }

    // Generamos la sufperficie de dibujo
    BufferedImage imagenQR = new BufferedImage(ANCHO_ETIQUETA, ALTO_ETIQUETA, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = imagenQR.createGraphics();
    // El fondo es blanco
    g.setBackground(Color.WHITE);
    g.clearRect(0, 0, ANCHO_ETIQUETA, ALTO_ETIQUETA);
    g.setColor(Color.BLACK);
    g.setStroke(new BasicStroke(2f));
    // Pintamos la caja de borde
    g.draw(new java.awt.Rectangle(MARGEN_CAJA, MARGEN_CAJA, ANCHO_ETIQUETA - MARGEN_CAJA * 2,
            ALTO_ETIQUETA - MARGEN_CAJA * 2));
    g.draw(new java.awt.Rectangle(MARGEN_CAJA + 3, MARGEN_CAJA + 3, ANCHO_ETIQUETA - MARGEN_CAJA * 2 - 6,
            ALTO_ETIQUETA - MARGEN_CAJA * 2 - 6));

    // Generamos el cdigo QR
    Qrcode x = new Qrcode();
    x.setQrcodeErrorCorrect('L');
    x.setQrcodeEncodeMode('B'); // Modo Binario
    byte[] d = textoQR.getBytes();
    // Generamos el cdigo QR
    boolean[][] s = x.calQrcode(d);
    for (int i = 0; i < s.length; i++) {
        for (int j = 0; j < s.length; j++) {
            if (s[j][i]) {
                g.fillRect(j * SIZE_QR + MARGEN, i * SIZE_QR + MARGEN, SIZE_QR, SIZE_QR);
            }
        }
    }
    int marjenSeparador = MARGEN + SIZE_QR * s.length + MARGEN_CAJA;
    int marjenTexto = marjenSeparador + MARGEN_CAJA;
    // Linea de separacin entre el QR cdigo y el texto
    g.drawLine(marjenSeparador - 3, MARGEN_CAJA + 3, marjenSeparador - 3, ALTO_ETIQUETA - MARGEN_CAJA - 3);
    g.drawLine(marjenSeparador, MARGEN_CAJA + 3, marjenSeparador, ALTO_ETIQUETA - MARGEN_CAJA - 3);

    // Linea de separacin entre texto y cdigo de barras.
    int marjenCodigoBarras = MARGEN + MAX_ROWS * FONT_SIZE;
    // Pintamos una pequea linea de separacin
    g.drawLine(marjenSeparador, marjenCodigoBarras, ANCHO_ETIQUETA - MARGEN_CAJA - 3, marjenCodigoBarras);
    g.drawLine(marjenSeparador, marjenCodigoBarras - 3, ANCHO_ETIQUETA - MARGEN_CAJA - 3,
            marjenCodigoBarras - 3);

    // Escribimos el texto
    List<String> parrafos = split(text);

    g.setFont(new Font(g.getFont().getName(), Font.BOLD, FONT_SIZE));

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    for (int i = 0; i < parrafos.size(); i++) {
        String linea = parrafos.get(i);
        // Pintamos la nueva linea de texto
        g.drawString(linea, marjenTexto, MARGEN + 3 + (FONT_SIZE * i + 1));
    }

    g.setFont(new Font(g.getFont().getName(), Font.BOLD, FONT_SIZE - 4));
    // Pintamos el texto final de una sola lnea( Generalmente el MD5 )
    //if(url.length())
    if (!url.equals("")) {
        g.drawString("Custodia del documento: ", marjenTexto, marjenCodigoBarras - 10 * 2);
        g.drawString(url, marjenTexto, marjenCodigoBarras - 6);
    }
    marjenCodigoBarras += MARGEN_CAJA;
    // Generamos el cdigo de barras
    try {
        // int marjenCodigoBarras=MARGEN+MAX_ROWS*FONT_SIZE;
        BarcodeFactory.createCode39(codFirma, true).draw(g, marjenTexto, marjenCodigoBarras);
    } catch (Exception e1) { // TODO
        e1.printStackTrace();
    }
    // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    // RenderingHints.VALUE_ANTIALIAS_OFF);

    // Finalizamos la superficie de dibujo
    g.dispose();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // Generamos la imagen
    try {
        ImageIO.write(imagenQR, "png", out);
        // ImageIO.write(imagenQR, "png", new
        // FileOutputStream("/tmp/imagen.png"));
        out.close();
    } catch (Exception e) {
        throw new ExcepcionErrorInterno(CodigoError.ERROR_INTERNO, e);
    }

    return out.toByteArray();
}

From source file:org.earthtime.UPb_Redux.dateInterpretation.WeightedMeanGraphPanel.java

private void drawAxesAndTicks(Graphics2D g2d, double rangeX, double rangeY) {

    // oct 2014 new tic logic
    // reset the clip bounds to paint axis and numbers
    g2d.setClip(0, 0, getWidth(), getHeight());

    g2d.setFont(new Font("Monospaced", Font.BOLD, 14));
    g2d.setPaint(Color.BLACK);/*from   w w  w. ja  v a 2  s  .c  om*/
    g2d.setStroke(new BasicStroke(2.0f));

    // determine the axis ticks
    BigDecimal[] tics = TicGeneratorForAxes.generateTics(getMinY_Display(), getMaxY_Display(), 12);
    // trap for bad plot
    if (tics.length <= 1) {
        tics = new BigDecimal[0];
    }
    double minXDisplay = 0.0;
    int yAxisTicWidth = 8;
    int yTicLabelFrequency = 2;
    int labeledTicCountYAxis = 0;

    g2d.setPaint(Color.black);
    for (int i = 0; i < tics.length; i++) {

        double y = tics[i].doubleValue();

        if ((y > getMinY_Display()) // dont print across mappedX axis
                && (y < getMaxY_Display())) // dont print across top border
        {
            try {
                Shape ticMark = new Line2D.Double( //
                        mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth),
                        mapY(y, getMaxY_Display(), rangeY, graphHeight),
                        mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) + 7,
                        mapY(y, getMaxY_Display(), rangeY, graphHeight));
                g2d.draw(ticMark);

                String intString = "00000" + tics[i].toPlainString().replace(".", "");
                int lastPlace = Integer.parseInt(intString.substring(intString.length() - 4));

                if (lastPlace % yTicLabelFrequency == 0) {
                    if (labeledTicCountYAxis % yTicLabelFrequency == 0) {

                        TextLayout mLayout = //
                                new TextLayout(tics[i].toPlainString(), g2d.getFont(),
                                        g2d.getFontRenderContext());

                        Rectangle2D bounds = mLayout.getBounds();

                        //if (isyAxisHorizontalTicLabels()) {
                        //                            g2d.drawString(tics[i].toPlainString(),//
                        //                                    (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
                        //                                    (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f);
                        //                            } else {
                        float yLabelCenterOffset = (float) mLayout.getBounds().getWidth() / 2f;

                        g2d.rotate(-Math.PI / 2.0,
                                (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
                                (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset);
                        g2d.drawString(tics[i].toPlainString(),
                                (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
                                (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset);
                        g2d.rotate(Math.PI / 2.0,
                                (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
                                (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset);
                    }

                    labeledTicCountYAxis++;
                } else {

                    if (labeledTicCountYAxis > 0) {
                        labeledTicCountYAxis++;
                    }
                }
            } catch (Exception e) {
            }
        }
    }

    ////        // reset the clip bounds to paint axis and numbers
    ////        g2d.setClip(0, 0, getWidth(), getHeight());
    ////
    ////        g2d.setFont(new Font("Monospaced", Font.BOLD, 14));
    ////        g2d.setPaint(Color.BLACK);
    ////        g2d.setStroke(new BasicStroke(2.0f));
    ////
    ////        // determine the axis ticks
    ////        double minYtick = Math.ceil(getMinY_Display() * 100) / 100;
    ////        double maxYtick = Math.floor(getMaxY_Display() * 100) / 100;
    ////
    ////        int count = 0;
    ////        double deltay = Math.rint((maxYtick - minYtick) * 10 + 0.5);
    ////        double stepYtick = deltay / 100;
    ////
    ////        for (double y = minYtick; y
    ////                < maxYtick; y
    ////                += stepYtick) {
    ////            Line2D line = new Line2D.Double(
    ////                    mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth),
    ////                    mapY(y, getMaxY_Display(), rangeY, graphHeight),
    ////                    mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) + 7,
    ////                    mapY(y, getMaxY_Display(), rangeY, graphHeight));
    ////            g2d.draw(line);
    ////
    ////            if ((count % 2) == 1) {
    ////                NumberFormat yFormat = null;
    ////                String temp = null;
    ////
    ////                yFormat
    ////                        = new DecimalFormat("0.00");
    ////                temp
    ////                        = yFormat.format(y);
    ////
    ////                g2d.setPaint(Color.black);
    ////                g2d.rotate(
    ////                        -Math.PI / 2.0,
    ////                        (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
    ////                        (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f);
    ////                g2d.drawString(
    ////                        temp,
    ////                        (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
    ////                        (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f);
    ////                g2d.rotate(
    ////                        Math.PI / 2.0,
    ////                        (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
    ////                        (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f);
    ////
    ////            }
    ////
    ////            count++;
    ////
    ////        }
    // draw and label axes
    g2d.setFont(new Font("Monospaced", Font.BOLD, 20));
    g2d.drawRect(getLeftMargin(), getTopMargin(), getGraphWidth() - 1, getGraphHeight() - 1);

}