Example usage for java.awt Graphics2D setFont

List of usage examples for java.awt Graphics2D setFont

Introduction

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

Prototype

public abstract void setFont(Font font);

Source Link

Document

Sets this graphics context's font to the specified font.

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;/* w  w  w .ja  v a  2s  .  c  o  m*/
    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:org.apache.fop.render.pcl.PCLRenderer.java

/**
 * {@inheritDoc}/*from   ww w.  ja  v a  2s.com*/
 */
protected void renderText(final TextArea text) {
    renderInlineAreaBackAndBorders(text);

    String fontname = getInternalFontNameForArea(text);
    final int fontsize = text.getTraitAsInteger(Trait.FONT_SIZE);

    //Determine position
    int saveIP = currentIPPosition;
    final int rx = currentIPPosition + text.getBorderAndPaddingWidthStart();
    int bl = currentBPPosition + text.getOffset() + text.getBaselineOffset();

    try {

        final Color col = (Color) text.getTrait(Trait.COLOR);
        boolean pclFont = pclUtil.isAllTextAsBitmaps() ? false
                : HardcodedFonts.setFont(gen, fontname, fontsize, text.getText());
        if (pclFont) {
            //this.currentFill = col;
            if (col != null) {
                //useColor(ct);
                gen.setTransparencyMode(true, false);
                gen.selectGrayscale(col);
            }

            saveGraphicsState();
            graphicContext.translate(rx, bl);
            setCursorPos(0, 0);
            gen.setTransparencyMode(true, true);
            if (text.hasUnderline()) {
                gen.writeCommand("&d0D");
            }
            super.renderText(text); //Updates IPD and renders words and spaces
            if (text.hasUnderline()) {
                gen.writeCommand("&d@");
            }
            restoreGraphicsState();
        } else {
            //Use Java2D to paint different fonts via bitmap
            final Font font = getFontFromArea(text);
            final int baseline = text.getBaselineOffset();

            //for cursive fonts, so the text isn't clipped
            int extraWidth = font.getFontSize() / 3;
            final FontMetricsMapper mapper = (FontMetricsMapper) fontInfo.getMetricsFor(font.getFontName());
            int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000;
            final int additionalBPD = maxAscent - baseline;

            Graphics2DAdapter g2a = getGraphics2DAdapter();
            final Rectangle paintRect = new Rectangle(rx, currentBPPosition + text.getOffset() - additionalBPD,
                    text.getIPD() + extraWidth, text.getBPD() + additionalBPD);
            RendererContext rc = createRendererContext(paintRect.x, paintRect.y, paintRect.width,
                    paintRect.height, null);
            Map atts = new java.util.HashMap();
            atts.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP);
            atts.put(SRC_TRANSPARENCY, "true");
            rc.setProperty(RendererContextConstants.FOREIGN_ATTRIBUTES, atts);

            Graphics2DImagePainter painter = new Graphics2DImagePainter() {

                public void paint(Graphics2D g2d, Rectangle2D area) {
                    g2d.setFont(mapper.getFont(font.getFontSize()));
                    g2d.translate(0, baseline + additionalBPD);
                    g2d.scale(1000, 1000);
                    g2d.setColor(col);
                    Java2DRenderer.renderText(text, g2d, font);
                    renderTextDecoration(g2d, mapper, fontsize, text, 0, 0);
                }

                public Dimension getImageSize() {
                    return paintRect.getSize();
                }

            };
            g2a.paintImage(painter, rc, paintRect.x, paintRect.y, paintRect.width, paintRect.height);
            currentIPPosition = saveIP + text.getAllocIPD();
        }

    } catch (IOException ioe) {
        handleIOTrouble(ioe);
    }
}

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

/**
 * Creates a summary plot for the given set of multi-genome alignment summaries.
 *
 * @param multiGenomeAlignmentSummaries//w  ww.j  a  va  2  s.  co m
 * @param the name of the image file
 * @throws IOException
 */
private void createSummaryPlot(Collection<MultiGenomeAlignmentSummary> multiGenomeAlignmentSummaries,
        String imageFilename) throws IOException {
    if (imageFilename == null)
        return;

    int n = multiGenomeAlignmentSummaries.size();
    log.debug("Number of summaries = " + n);

    scaleForPlotWidth();

    int fontHeight = getFontHeight();
    int rowHeight = (int) (fontHeight * ROW_HEIGHT_SCALING_FACTOR);
    int labelOffset = (rowHeight - fontHeight) / 2;
    int rowGap = (int) (fontHeight * ROW_GAP_SCALING_FACTOR);
    int height = (rowHeight + rowGap) * (n + 3);
    int rowSeparation = rowHeight + rowGap;

    BufferedImage image = new BufferedImage(plotWidth, height, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2 = image.createGraphics();

    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setStroke(new BasicStroke(Math.max(1.0f, 0.65f * scaleFactor)));

    g2.setFont(font);

    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, plotWidth, height);
    g2.setColor(Color.BLACK);

    int offset = rowGap + rowHeight - labelOffset;
    int x0 = drawLabels(g2, offset, rowSeparation, multiGenomeAlignmentSummaries);

    long maxSequenceCount = getMaximumSequenceCount(multiGenomeAlignmentSummaries);
    log.debug("Maximum sequence count: " + maxSequenceCount);

    maxSequenceCount = Math.max(maxSequenceCount, minimumSequenceCount);

    long tickInterval = (int) getTickInterval(maxSequenceCount);
    log.debug("Tick interval: " + tickInterval);
    int tickIntervals = (int) (Math.max(1, maxSequenceCount) / tickInterval);
    if (maxSequenceCount % tickInterval != 0)
        tickIntervals += 1;
    maxSequenceCount = tickIntervals * tickInterval;
    log.debug("No. tick intervals: " + tickIntervals);
    log.debug("Maximum sequence count: " + maxSequenceCount);

    int y = rowGap + n * rowSeparation;
    int x1 = drawAxisAndLegend(g2, x0, y, tickIntervals, maxSequenceCount);

    offset = rowGap;
    drawAlignmentBars(g2, offset, rowHeight, rowSeparation, x0, x1, maxSequenceCount,
            multiGenomeAlignmentSummaries);

    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(imageFilename));
    ImageIO.write(image, "png", out);
    out.close();
}

From source file:org.squidy.designer.zoom.impl.VisualizationShape.java

@Override
protected void paintShapeZoomedIn(PPaintContext paintContext) {

    Graphics2D g = paintContext.getGraphics();

    PBounds bounds = getBoundsReference();

    //      PBounds cameraBounds = getBoundsReference();// paintContext.getCamera().getFullBoundsReference();
    //      double cameraX = cameraBounds.getX() - 20;
    //      double cameraY = cameraBounds.getY();
    //      double cameraWidth = cameraBounds.getWidth() + 40;
    //      double cameraHeight = cameraBounds.getHeight();

    //      g.setColor(Color.WHITE);
    //      g.fillRect((int) cameraX, (int) cameraY, (int) cameraWidth, (int) cameraHeight);
    ///*from w w  w .  j  a  va2s .c  om*/
    //      g.setColor(Color.BLACK);
    //      g.fillRect((int) cameraX, (int) (cameraY + cameraHeight / 4), (int) cameraWidth, (int) (cameraHeight / 2));

    g.setFont(fontLables);

    // Paint node labels.
    paintNodeLabels(paintContext);

    super.paintShapeZoomedIn(paintContext);

    // Paint headline.
    if (!isShowNavigation()) {
        paintHeadline(paintContext);
    }

    g.setFont(fontSmall);

    // Translate the current graphics position to 1/4 width and 1/4 height
    // of this shape.
    TRANSLATION.setToTranslation((int) (bounds.getWidth() / 4), (int) (bounds.getHeight() / 4));
    paintContext.pushTransform(TRANSLATION);

    // Scale up visualization are because of int constraints to avoid
    // mathematical round failure.
    int maxWidth = (int) ((bounds.getWidth() / 2) * 10);
    int maxHeight = (int) ((bounds.getHeight() / 2) * 10);

    paintContext.pushTransform(SCALE_TRANSFROM);

    PlotContext plotContext = new PlotContext(paintContext, maxWidth, maxHeight, SCALE_TRANSFORM_SCALING,
            sampleTime);

    long currentTime = System.currentTimeMillis();
    for (IDataContainer dataContainer : DATA_QUEUE) {
        if ((currentTime - dataContainer.getTimestamp()) >= sampleTime) {
            DATA_QUEUE.remove(dataContainer);
            continue;
        }

        // Delegates plot of data to visualization.
        visualizations[visualizationIndex].plotData(plotContext, dataContainer);
    }

    // Paints the grid.
    visualizations[visualizationIndex].paintContextual(paintContext, plotContext);

    paintContext.popTransform(SCALE_TRANSFROM);

    // Pop transform translation.
    paintContext.popTransform(TRANSLATION);

    g.setFont(fontFPS);
    g.drawString("FPS: " + currentFPS, (int) (bounds.getWidth() / 2 - 50), (int) (bounds.getHeight() - 100));

    g.setFont(fontHeadline.deriveFont(18f));
    g.setColor(Color.RED);
    g.fillOval((int) (bounds.getWidth() - 115), (int) (bounds.getHeight() / 2 - 20), 10, 10);
    g.setColor(Color.BLACK);
    g.drawString("x-value", (int) (bounds.getWidth() - 100), (int) (bounds.getHeight() / 2 - 10));

    g.setColor(Color.BLUE);
    g.fillOval((int) (bounds.getWidth() - 115), (int) (bounds.getHeight() / 2 + 20), 10, 10);
    g.setColor(Color.BLACK);
    g.drawString("y-value", (int) (bounds.getWidth() - 100), (int) (bounds.getHeight() / 2 + 30));
}

From source file:org.executequery.gui.erd.ErdTable.java

protected void drawTable(Graphics2D g, int offsetX, int offsetY) {

    if (parent == null) {

        return;/*from  w  w  w .j  a  v a 2 s .  co  m*/
    }

    Font tableNameFont = parent.getTableNameFont();
    Font columnNameFont = parent.getColumnNameFont();

    // set the table value background
    g.setColor(TITLE_BAR_BG_COLOR);
    g.fillRect(offsetX, offsetY, FINAL_WIDTH - 1, TITLE_BAR_HEIGHT);

    // set the table value
    FontMetrics fm = g.getFontMetrics(tableNameFont);
    int lineHeight = fm.getHeight();
    int titleXPosn = (FINAL_WIDTH / 2) - (fm.stringWidth(tableName) / 2) + offsetX;

    g.setColor(Color.BLACK);
    g.setFont(tableNameFont);
    g.drawString(tableName, titleXPosn, lineHeight + offsetY);

    // draw the line separator
    lineHeight = TITLE_BAR_HEIGHT + offsetY - 1;
    g.drawLine(offsetX, lineHeight, offsetX + FINAL_WIDTH - 1, lineHeight);

    // fill the white background
    g.setColor(tableBackground);
    g.fillRect(offsetX, TITLE_BAR_HEIGHT + offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - TITLE_BAR_HEIGHT - 1);

    // add the column names
    fm = g.getFontMetrics(columnNameFont);
    int heightPlusSep = 1 + TITLE_BAR_HEIGHT + offsetY;
    int leftMargin = 5 + offsetX;

    lineHeight = fm.getHeight();
    g.setColor(Color.BLACK);
    g.setFont(columnNameFont);

    int drawCount = 0;
    String value = null;
    if (ArrayUtils.isNotEmpty(columns)) {

        for (int i = 0; i < columns.length; i++) {
            ColumnData column = columns[i];
            if (displayReferencedKeysOnly && !column.isKey()) {
                continue;
            }

            int y = (((drawCount++) + 1) * lineHeight) + heightPlusSep;
            int x = leftMargin;

            // draw the column value string
            value = column.getColumnName();
            g.drawString(value, x, y);

            // draw the data type and size string
            x = leftMargin + dataTypeOffset;
            value = column.getFormattedDataType();
            g.drawString(value, x, y);

            // draw the key label
            if (column.isKey()) {

                if (column.isPrimaryKey() && column.isForeignKey()) {

                    value = PRIMARY + FOREIGN;

                } else if (column.isPrimaryKey()) {

                    value = PRIMARY;

                } else if (column.isForeignKey()) {

                    value = FOREIGN;
                }

                x = leftMargin + dataTypeOffset + keyLabelOffset;
                g.drawString(value, x, y);
            }

        }

    }

    // draw the rectangle border
    double scale = g.getTransform().getScaleX();

    if (selected && scale != ErdPrintable.PRINT_SCALE) {
        g.setStroke(focusBorderStroke);
        g.setColor(Color.BLUE);
    } else {
        g.setColor(Color.BLACK);
    }

    g.drawRect(offsetX, offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - 1);
    //    g.setColor(Color.DARK_GRAY);
    //    g.draw3DRect(offsetX, offsetY, FINAL_WIDTH - 2, FINAL_HEIGHT - 2, true);
}

From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java

private void updateLegend() {

    int width = DEFAULT_LEGEND_WIDTH;
    int height = DEFAULT_LEGENT_HEIGHT;
    legend = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);
    Graphics2D g = (Graphics2D) legend.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setPaint(UI.colorBlack2);/*w  ww  .  j  av a  2s  .co m*/
    g.fillRoundRect(0, 0, width, height - 12, 5, 5);

    g.setColor(barColorBelow);
    int boxNum = 10;
    g.setStroke(UI.stroke1_5);

    double value;
    for (int i = 0; i < boxNum; i++) {
        value = _minValue + (_maxValue - _minValue) / boxNum * i;

        if (value > disectBound) {
            g.setColor(barColorNormal);
        }

        int h = (height - 12) / boxNum * i;
        g.drawLine(i * width / boxNum, height - 12 - h, (i + 1) * width / boxNum, height - 12 - h);

    }

    g.setColor(Color.BLACK);
    g.setFont(UI.fontMono.deriveFont(10f));
    DecimalFormat format = new DecimalFormat("#.##");
    g.drawString(format.format(_minValue), 2, 23);

    g.setColor(Color.BLACK);
    String maxString = format.format(_maxValue);
    int swidth = g.getFontMetrics().stringWidth(maxString);
    g.drawString(maxString, width - 2 - swidth, 23);
    g.dispose();
}

From source file:org.broad.igv.variant.VariantTrack.java

/**
 * Render the name panel./*w  w w .  j  a v  a  2  s.  c om*/
 * <p/>
 * NOTE:  The sample names are actually drawn in the drawBackground method!
 *
 * @param g2D
 * @param trackRectangle
 * @param visibleRectangle
 */
@Override
public void renderName(Graphics2D g2D, Rectangle trackRectangle, Rectangle visibleRectangle) {

    top = trackRectangle.y;

    Rectangle rect = new Rectangle(trackRectangle);
    g2D.setFont(FontManager.getFont(fontSize));
    g2D.setColor(BAND2_COLOR);

    g2D.setColor(Color.black);
    rect.height = getVariantsHeight();
    if (rect.intersects(visibleRectangle)) {
        GraphicUtils.drawWrappedText(getName(), rect, g2D, false);
    }

    rect.y += rect.height;
    rect.height = getGenotypeBandHeight();
    if (areFeaturesStacked()) {
        // The sample bounds list will get reset when  the names are drawn.
        sampleBounds.clear();
        drawBackground(g2D, rect, visibleRectangle, BackgroundType.NAME);
    }

    renderBoundaryLines(g2D, trackRectangle, visibleRectangle);

}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java

/**
 * Make the plot/*from   ww  w.  j a  v  a  2 s  .c  o m*/
 *
 * @return The plot_
 */
public Plot doMakePlot() {

    IdvPreferenceManager pref = control.getControlContext().getIdv().getPreferenceManager();
    TimeZone timeZone = pref.getDefaultTimeZone();
    NumberAxis valueAxis = new FixedWidthNumberAxis("");
    final SimpleDateFormat sdf = new SimpleDateFormat(
            ((dateFormat != null) ? dateFormat : pref.getDefaultDateFormat()));
    sdf.setTimeZone(timeZone);
    DateAxis timeAxis = new DateAxis("Time (" + timeZone.getID() + ")", timeZone) {

        protected List xxxxxrefreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

            List ticks = super.refreshTicksHorizontal(g2, dataArea, edge);

            List<Tick> result = new java.util.ArrayList<Tick>();

            Font tickLabelFont = getTickLabelFont();
            g2.setFont(tickLabelFont);

            if (isAutoTickUnitSelection()) {
                selectAutoTickUnit(g2, dataArea, edge);
            }

            DateTickUnit unit = getTickUnit();
            Date tickDate = calculateLowestVisibleTickValue(unit);
            Date upperDate = getMaximumDate();

            Date firstDate = null;
            while (tickDate.before(upperDate)) {

                if (!isHiddenValue(tickDate.getTime())) {
                    // work out the value, label and position
                    String tickLabel;
                    DateFormat formatter = getDateFormatOverride();
                    if (firstDate == null) {
                        if (formatter != null) {
                            tickLabel = formatter.format(tickDate);
                        } else {
                            tickLabel = getTickUnit().dateToString(tickDate);
                        }
                        firstDate = tickDate;
                    } else {
                        double msdiff = tickDate.getTime() - firstDate.getTime();
                        int hours = (int) (msdiff / 1000 / 60 / 60);
                        tickLabel = hours + "H";
                    }
                    //                tickLabel = tickLabel;
                    TextAnchor anchor = null;
                    TextAnchor rotationAnchor = null;
                    double angle = 0.0;
                    if (isVerticalTickLabels()) {
                        anchor = TextAnchor.CENTER_RIGHT;
                        rotationAnchor = TextAnchor.CENTER_RIGHT;
                        if (edge == RectangleEdge.TOP) {
                            angle = Math.PI / 2.0;
                        } else {
                            angle = -Math.PI / 2.0;
                        }
                    } else {
                        if (edge == RectangleEdge.TOP) {
                            anchor = TextAnchor.BOTTOM_CENTER;
                            rotationAnchor = TextAnchor.BOTTOM_CENTER;
                        } else {
                            anchor = TextAnchor.TOP_CENTER;
                            rotationAnchor = TextAnchor.TOP_CENTER;
                        }
                    }

                    Tick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle);
                    result.add(tick);
                    tickDate = unit.addToDate(tickDate, getTimeZone());
                } else {
                    tickDate = unit.rollDate(tickDate, getTimeZone());

                    continue;
                }

                // could add a flag to make the following correction optional...
                switch (unit.getUnit()) {

                case (DateTickUnit.MILLISECOND):
                case (DateTickUnit.SECOND):
                case (DateTickUnit.MINUTE):
                case (DateTickUnit.HOUR):
                case (DateTickUnit.DAY):
                    break;

                case (DateTickUnit.MONTH):
                    tickDate = calculateDateForPositionX(new Month(tickDate, getTimeZone()),
                            getTickMarkPosition());

                    break;

                case (DateTickUnit.YEAR):
                    tickDate = calculateDateForPositionX(new Year(tickDate, getTimeZone()),
                            getTickMarkPosition());

                    break;

                default:
                    break;

                }

            }

            return result;

        }

        private Date calculateDateForPositionX(RegularTimePeriod period, DateTickMarkPosition position) {

            if (position == null) {
                throw new IllegalArgumentException("Null 'position' argument.");
            }
            Date result = null;
            if (position == DateTickMarkPosition.START) {
                result = new Date(period.getFirstMillisecond());
            } else if (position == DateTickMarkPosition.MIDDLE) {
                result = new Date(period.getMiddleMillisecond());
            } else if (position == DateTickMarkPosition.END) {
                result = new Date(period.getLastMillisecond());
            }

            return result;

        }

    };
    timeAxis.setDateFormatOverride(sdf);

    final XYPlot[] xyPlotHolder = { null };

    xyPlotHolder[0] = new MyXYPlot(new TimeSeriesCollection(), timeAxis, valueAxis, null) {
        public void drawBackground(Graphics2D g2, Rectangle2D area) {
            super.drawBackground(g2, area);
            drawSunriseSunset(g2, xyPlotHolder[0], area);
        }
    };

    if (animationTimeAnnotation != null) {
        xyPlotHolder[0].addAnnotation(animationTimeAnnotation);
    }

    return xyPlotHolder[0];

}

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

private void addHints(BufferedImage pImage, VgElevationGrid pTerrain, double pDistance, double pYaw,
        double pExaggeration) {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');
    DecimalFormat df = new DecimalFormat("0.0", dfs);

    String deltaX = df.format(pTerrain.getGeometry().envelope().getExtentX() / 1000.);
    String deltaY = df.format(pTerrain.getGeometry().envelope().getExtentY() / 1000.);

    String hint = "DIST: " + df.format(pDistance) + ", EXAGG: " + pExaggeration + ", YAW: " + pYaw + ", BBOX: "
            + deltaX + " x " + deltaY + ", DZ: " + df.format(pTerrain.elevationDifference());

    Graphics2D g = pImage.createGraphics();
    g.drawImage(pImage, 0, 0, null);//from w  ww  .j a  v  a  2 s  .c o m
    g.setColor(new java.awt.Color(mCopyrightTextColor.getRed(), mCopyrightTextColor.getGreen(),
            mCopyrightTextColor.getBlue()));
    Font font = new Font(mCopyrightTextFont, Font.BOLD /* Style als int, siehe ggf. API-Dok.*/,
            mCopyrightTextSize);
    g.setFont(font);
    g.drawString(hint, 5, mCopyrightTextSize + 5);
    g.dispose();
}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialValueIndicator.java

/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted).
 *///from   ww  w  .  j  a  va2s  .co m
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(), this.getRadius());
    Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();

    // calculate the bounds of the template value
    FontMetrics fm = g2.getFontMetrics(this.getFont());
    String s = this.getNumberFormat().format(this.getTemplateValue());
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(),
            pt.getY(), this.getFrameAnchor());

    // add the insets
    Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.getBackgroundPaint());
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.getOutlineStroke());
    g2.setPaint(this.getOutlinePaint());
    g2.draw(fb);

    // now find the text anchor point
    String valueStr = this.getNumberFormat()
            .format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale));
    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor());
    g2.setPaint(this.getPaint());
    g2.setFont(this.getFont());
    TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.getTextAnchor());

}