Search in sources :

Example 1 with Font

use of com.google.code.appengine.awt.Font in project activityinfo by bedatadriven.

the class PolygonLegendRenderer method createImage.

public ItextGraphic createImage(ImageCreator creator) {
    ItextGraphic result = creator.create(width, height);
    Graphics2D g2d = result.getGraphics();
    int y = 0;
    for (PolygonLegend.ColorClass clazz : legend.getClasses()) {
        y += PADDING;
        g2d.setColor(ColorUtil.colorFromString(clazz.getColor()));
        g2d.fillRect(PADDING, y, SWATCH_WIDTH, SWATCH_HEIGHT);
        g2d.setColor(Color.BLACK);
        g2d.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, LABEL_HEIGHT));
        g2d.drawString(formatLabel(clazz), PADDING + SWATCH_WIDTH + PADDING, y + SWATCH_HEIGHT - (LABEL_HEIGHT / 2));
        y += SWATCH_HEIGHT;
    }
    return result;
}
Also used : PolygonLegend(org.activityinfo.legacy.shared.reports.content.PolygonLegend) ColorClass(org.activityinfo.legacy.shared.reports.content.PolygonLegend.ColorClass) Font(com.google.code.appengine.awt.Font) Graphics2D(com.google.code.appengine.awt.Graphics2D)

Example 2 with Font

use of com.google.code.appengine.awt.Font in project activityinfo by bedatadriven.

the class BubbleLegendRenderer method drawBubbleLegendLabel.

private void drawBubbleLegendLabel(Graphics2D g2d, int x, int y, double value) {
    Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 10);
    String label = labelFormat.format(value);
    LineMetrics metrics = font.getLineMetrics(label, g2d.getFontRenderContext());
    Rectangle2D bounds = font.getStringBounds(label, g2d.getFontRenderContext());
    x -= bounds.getWidth() / 2d;
    y += metrics.getAscent();
    g2d.setColor(Color.BLACK);
    g2d.setFont(font);
    g2d.drawString(label, x, y);
}
Also used : Rectangle2D(com.google.code.appengine.awt.geom.Rectangle2D) LineMetrics(com.google.code.appengine.awt.font.LineMetrics) Font(com.google.code.appengine.awt.Font)

Aggregations

Font (com.google.code.appengine.awt.Font)2 Graphics2D (com.google.code.appengine.awt.Graphics2D)1 LineMetrics (com.google.code.appengine.awt.font.LineMetrics)1 Rectangle2D (com.google.code.appengine.awt.geom.Rectangle2D)1 PolygonLegend (org.activityinfo.legacy.shared.reports.content.PolygonLegend)1 ColorClass (org.activityinfo.legacy.shared.reports.content.PolygonLegend.ColorClass)1