Search in sources :

Example 1 with Rectangle2D

use of com.google.code.appengine.awt.geom.Rectangle2D 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)

Example 2 with Rectangle2D

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

the class ImageMapRenderer method drawLabel.

private static void drawLabel(Graphics2D g2d, BubbleMapMarker marker) {
    Font font = new Font(Font.SANS_SERIF, Font.BOLD, (int) (marker.getRadius() * 2f * 0.8f));
    // measure the bounds of the string so we can center it within
    // the bubble.
    // QUICK FIX: labeling set inappropriately as default for new map layers
    // and no method in UI to turn them off.
    Rectangle2D rect = font.getStringBounds(marker.getLabel(), g2d.getFontRenderContext());
    LineMetrics lm = font.getLineMetrics(marker.getLabel(), g2d.getFontRenderContext());
    g2d.setColor(Color.WHITE);
    g2d.setFont(font);
    g2d.drawString(marker.getLabel(), (int) (marker.getX() - (rect.getWidth() / 2)), (int) (marker.getY() + (lm.getAscent() * 1.25)));
}
Also used : Rectangle2D(com.google.code.appengine.awt.geom.Rectangle2D) LineMetrics(com.google.code.appengine.awt.font.LineMetrics)

Aggregations

LineMetrics (com.google.code.appengine.awt.font.LineMetrics)2 Rectangle2D (com.google.code.appengine.awt.geom.Rectangle2D)2 Font (com.google.code.appengine.awt.Font)1