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:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

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

    int cx = getSize().width / 2;
    int cy = getSize().height / 2;

    g2.translate(cx, cy);//from  w w w.  j a v  a2  s. co  m
    g2.rotate(theta * Math.PI / 180);

    Shape oldClip = g2.getClip();
    Shape e = new Ellipse2D.Float(-cx, -cy, cx * 2, cy * 2);
    g2.clip(e);

    Shape c = new Ellipse2D.Float(-cx, -cy, cx * 3 / 4, cy * 2);
    g2.setPaint(new GradientPaint(40, 40, Color.blue, 60, 50, Color.white, true));
    g2.fill(c);

    g2.setPaint(Color.yellow);
    g2.fillOval(cx / 4, 0, cx, cy);

    g2.setClip(oldClip);

    g2.setFont(new Font("Times New Roman", Font.PLAIN, 64));
    g2.setPaint(new GradientPaint(-cx, 0, Color.red, cx, 0, Color.black, false));
    g2.drawString("Hello, 2D!", -cx * 3 / 4, cy / 4);

    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) .75);
    g2.setComposite(ac);

    Shape r = new RoundRectangle2D.Float(0, -cy * 3 / 4, cx * 3 / 4, cy * 3 / 4, 20, 20);
    g2.setStroke(new BasicStroke(4));
    g2.setPaint(Color.magenta);
    g2.fill(r);
    g2.setPaint(Color.green);
    g2.draw(r);

    g2.drawImage(image, -cx / 2, -cy / 2, this);
}

From source file:org.jstockchart.axis.TimeseriesDateAxis.java

protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor, Rectangle2D plotArea,
        Rectangle2D dataArea, RectangleEdge edge) {

    AxisState state = new AxisState(cursor);

    if (isAxisLineVisible()) {
        drawAxisLine(g2, cursor, dataArea, edge);
    }/*from w  w  w  . ja  v  a2s  .  c  om*/

    List ticks = refreshTicks(g2, state, dataArea, edge);
    state.setTicks(ticks);
    g2.setFont(getTickLabelFont());
    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        ValueTick tick = (ValueTick) iterator.next();
        if (isTickLabelsVisible()) {
            g2.setPaint(getTickLabelPaint());
            float[] anchorPoint = calculateAnchorPoint(tick, cursor, dataArea, edge);
            //System.out.println("label:"+tick.getText());
            String tickLabel = tick.getText();
            if (tickLabel == "13:00") {
                TextUtilities.drawRotatedString("/", g2, anchorPoint[0] - 2, anchorPoint[1],
                        tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor());
            }
            if (hideTickLabel != null) {
                if (!hideTickLabel.contains(tickLabel)) {
                    TextUtilities.drawRotatedString(tickLabel, g2, anchorPoint[0], anchorPoint[1],
                            tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor());
                }
            } else {
                TextUtilities.drawRotatedString(tick.getText(), g2, anchorPoint[0], anchorPoint[1],
                        tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor());
            }

        }

        if ((isTickMarksVisible() && tick.getTickType().equals(TickType.MAJOR))
                || (isMinorTickMarksVisible() && tick.getTickType().equals(TickType.MINOR))) {

            double ol = (tick.getTickType().equals(TickType.MINOR)) ? getMinorTickMarkOutsideLength()
                    : getTickMarkOutsideLength();

            double il = (tick.getTickType().equals(TickType.MINOR)) ? getMinorTickMarkInsideLength()
                    : getTickMarkInsideLength();

            float xx = (float) valueToJava2D(tick.getValue(), dataArea, edge);
            Line2D mark = null;
            g2.setStroke(getTickMarkStroke());
            g2.setPaint(getTickMarkPaint());
            if (edge == RectangleEdge.LEFT) {
                mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx);
            } else if (edge == RectangleEdge.RIGHT) {
                mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx);
            } else if (edge == RectangleEdge.TOP) {
                mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il);
            } else if (edge == RectangleEdge.BOTTOM) {
                mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il);
            }
            g2.draw(mark);
        }
    }

    // need to work out the space used by the tick labels...
    // so we can update the cursor...
    double used = 0.0;
    if (isTickLabelsVisible()) {
        if (edge == RectangleEdge.LEFT) {
            used += findMaximumTickLabelWidth(ticks, g2, plotArea, isVerticalTickLabels());
            state.cursorLeft(used);
        } else if (edge == RectangleEdge.RIGHT) {
            used = findMaximumTickLabelWidth(ticks, g2, plotArea, isVerticalTickLabels());
            state.cursorRight(used);
        } else if (edge == RectangleEdge.TOP) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, isVerticalTickLabels());
            state.cursorUp(used);
        } else if (edge == RectangleEdge.BOTTOM) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, isVerticalTickLabels());
            state.cursorDown(used);
        }
    }

    return state;
}

From source file:org.esa.s2tbx.dataio.s2.l1b.L1bSceneDescription.java

public BufferedImage createTilePicture(int width) {

    Color[] colors = new Color[] { Color.GREEN, Color.RED, Color.BLUE, Color.YELLOW };

    double scale = width / sceneRectangle.getWidth();
    int height = (int) Math.round(sceneRectangle.getHeight() * scale);

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = image.createGraphics();
    graphics.scale(scale, scale);/*from   w w w . j  a  va2 s .  co  m*/
    graphics.translate(-sceneRectangle.getX(), -sceneRectangle.getY());
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphics.setPaint(Color.WHITE);
    graphics.fill(sceneRectangle);
    graphics.setStroke(new BasicStroke(100F));
    graphics.setFont(new Font("Arial", Font.PLAIN, 800));

    for (int i = 0; i < tileInfos.length; i++) {
        Rectangle rect = tileInfos[i].rectangle;
        graphics.setPaint(addAlpha(colors[i % colors.length].brighter(), 100));
        graphics.fill(rect);
    }
    for (int i = 0; i < tileInfos.length; i++) {
        Rectangle rect = tileInfos[i].rectangle;
        graphics.setPaint(addAlpha(colors[i % colors.length].darker(), 100));
        graphics.draw(rect);
        graphics.setPaint(colors[i % colors.length].darker().darker());
        graphics.drawString("Tile " + (i + 1) + ": " + tileInfos[i].id, rect.x + 1200F, rect.y + 2200F);
    }
    return image;
}

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

/**
 * @param paintContext//w  w w .  j a  va  2  s.  c om
 */
protected void paintHeadline(PPaintContext paintContext) {

    Graphics2D g = paintContext.getGraphics();

    g.setFont(fontHeadline);
    FontMetrics fm = g.getFontMetrics();

    PBounds bounds = getBoundsReference();
    double x = bounds.getX();
    double width = bounds.getWidth();

    int titleWidth = FontUtils.getWidthOfText(fm, getTitle());
    g.drawString(getTitle(), (int) (x + width / 2) - (titleWidth / 2), 100);

    int breadcrumbWidth = FontUtils.getWidthOfText(fm, getBreadcrumb());
    g.drawString(getBreadcrumb(), (int) (x + width / 2) - (breadcrumbWidth / 2), 100 + fm.getHeight());
}

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

/**
 * @param paintContext//from w  w  w  .  ja  v  a  2s  .  c  o m
 */
protected void paintNodeLabels(PPaintContext paintContext) {

    Graphics2D g = paintContext.getGraphics();

    g.setFont(g.getFont().deriveFont(18f));
    FontMetrics fm = g.getFontMetrics();

    PBounds bounds = getBoundsReference();
    double width = bounds.getWidth();
    double height = bounds.getHeight();

    String inputName = pipeShape.getSource().getTitle();
    rotation270.setToRotation(Math.toRadians(270));
    paintContext.pushTransform(rotation270);
    g.setColor(Color.WHITE);
    g.drawString(inputName, (int) -((height / 2) + (FontUtils.getWidthOfText(fm, inputName) / 2)), -25);
    paintContext.popTransform(rotation270);

    String outputName = pipeShape.getTarget().getTitle();
    rotation90.setToRotation(Math.toRadians(90));
    paintContext.pushTransform(rotation90);
    g.setColor(Color.WHITE);
    g.drawString(outputName, (int) ((height / 2) - (FontUtils.getWidthOfText(fm, outputName) / 2)),
            (int) (-width - 30));
    paintContext.popTransform(rotation90);
}

From source file:com.neophob.sematrix.generator.Textwriter.java

/**
 * create image.//from w w w .  ja v a2  s . c om
 *
 * @param text the text
 */
public void createTextImage(String text) {
    //only load if needed
    if (StringUtils.equals(text, this.text)) {
        return;
    }

    this.text = text;

    BufferedImage img = new BufferedImage(TEXT_BUFFER_X_SIZE, internalBufferYSize, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2 = img.createGraphics();
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout layout = new TextLayout(text, font, frc);
    Rectangle2D rect = layout.getBounds();

    int h = (int) (0.5f + rect.getHeight());
    maxXPos = (int) (0.5f + rect.getWidth()) + 5;
    ypos = internalBufferYSize - (internalBufferYSize - h) / 2;

    img = new BufferedImage(maxXPos, internalBufferYSize, BufferedImage.TYPE_INT_RGB);
    g2 = img.createGraphics();

    g2.setColor(color);
    g2.setFont(font);
    g2.setClip(0, 0, maxXPos, internalBufferYSize);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);

    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);

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

    g2.drawString(text, xpos, ypos);
    DataBufferInt dbi = (DataBufferInt) img.getRaster().getDataBuffer();
    textBuffer = dbi.getData();
    g2.dispose();

    wait = 0;
    xofs = 0;
    scrollRight = false;
}

From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java

/**
 * Note:  assumption is that featureList is sorted by pStart position.
 *
 * @param featureList/*from   w  ww. j  a  v  a  2  s . com*/
 * @param context
 * @param trackRectangle
 * @param track
 */
@Override
public void render(List<IGVFeature> featureList, RenderContext context, Rectangle trackRectangle, Track track) {

    double origin = context.getOrigin();
    double locScale = context.getScale();

    // TODO -- use enum instead of string "Color"
    if ((featureList != null) && !featureList.isEmpty()) {

        // Create a graphics object to draw font names.  Graphics are not cached
        // by font, only by color, so its neccessary to create a new one to prevent
        // affecting other tracks.
        Font font = FontManager.getFont(track.getFontSize());
        Graphics2D fontGraphics = (Graphics2D) context.getGraphic2DForColor(Color.BLACK).create();

        if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) {
            fontGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

        }
        fontGraphics.setFont(font);

        //determine whether to show flanking regions
        PreferenceManager prefs = PreferenceManager.getInstance();
        boolean shouldShowFlankingRegions = prefs
                .getAsBoolean(PreferenceManager.SAM_SHOW_JUNCTION_FLANKINGREGIONS);

        // Track coordinates
        double trackRectangleX = trackRectangle.getX();
        double trackRectangleMaxX = trackRectangle.getMaxX();

        SpliceJunctionFeature selectedFeature = (SpliceJunctionFeature) ((FeatureTrack) track)
                .getSelectedFeature();

        // Start of Roche-Tessella modification
        if (track.getAutoScale()) {
            Frequency f = new Frequency();
            List<Integer> scores = new ArrayList<Integer>();

            for (IGVFeature feature : featureList) {
                SpliceJunctionFeature junctionFeature = (SpliceJunctionFeature) feature;
                f.addValue(junctionFeature.getScore());
                scores.add((int) junctionFeature.getScore());
            }

            Collections.sort(scores);
            Collections.reverse(scores);
            for (int s : scores) {
                if (f.getCumPct(s) < 0.99) {
                    maxDepth = s;
                    break;
                }
            }

        }
        // End of Roche-Tessella modification

        for (IGVFeature feature : featureList) {
            SpliceJunctionFeature junctionFeature = (SpliceJunctionFeature) feature;
            //if same junction as selected feature, highlight
            boolean shouldHighlight = false;
            if (selectedFeature != null && selectedFeature.isSameJunction(junctionFeature)) {
                setHighlightFeature(junctionFeature);
                shouldHighlight = true;
            }

            // Get the pStart and pEnd of the entire feature.  at extreme zoom levels the
            // virtual pixel value can be too large for an int, so the computation is
            // done in double precision and cast to an int only when its confirmed its
            // within the field of view.
            int flankingStart = junctionFeature.getStart();
            int flankingEnd = junctionFeature.getEnd();

            int junctionStart = junctionFeature.getJunctionStart();
            int junctionEnd = junctionFeature.getJunctionEnd();

            double virtualPixelStart = Math.round((flankingStart - origin) / locScale);
            double virtualPixelEnd = Math.round((flankingEnd - origin) / locScale);

            double virtualPixelJunctionStart = Math.round((junctionStart - origin) / locScale);
            double virtualPixelJunctionEnd = Math.round((junctionEnd - origin) / locScale);

            // If the any part of the feature fits in the
            // Track rectangle draw it
            if ((virtualPixelEnd >= trackRectangleX) && (virtualPixelStart <= trackRectangleMaxX)) {

                //
                int displayPixelEnd = (int) Math.min(trackRectangleMaxX, virtualPixelEnd);
                int displayPixelStart = (int) Math.max(trackRectangleX, virtualPixelStart);

                float depth = junctionFeature.getJunctionDepth();
                Color color = feature.getColor();

                drawFeature((int) virtualPixelStart, (int) virtualPixelEnd, (int) virtualPixelJunctionStart,
                        (int) virtualPixelJunctionEnd, depth, trackRectangle, context, feature.getStrand(),
                        junctionFeature, shouldHighlight, color, shouldShowFlankingRegions);
            }
        }

        //draw a central horizontal line
        Graphics2D g2D = context.getGraphic2DForColor(COLOR_CENTERLINE);
        g2D.drawLine((int) trackRectangleX, (int) trackRectangle.getCenterY(), (int) trackRectangleMaxX,
                (int) trackRectangle.getCenterY());

    }
}

From source file:main.MapKit.java

@Override
public void paintWaypoint(Graphics2D g, JXMapViewer viewer, MyWaypoint w) {
    g = (Graphics2D) g.create();/*w  ww  .j a  va 2  s.com*/

    Point2D point = viewer.getTileFactory().geoToPixel(w.getPosition(), viewer.getZoom());
    int x = (int) point.getX();
    int y = (int) point.getY();

    if (w.amount == -1) { //means it's an original data point
        int fontSize = 28 - viewer.getZoom() * 2; //font size is larger when zoom in
        if (fontSize < 6)
            fontSize = 6;
        g.setFont(new Font("Arial", Font.PLAIN, fontSize));
        g.setColor(w.color);
        g.drawString("x", x - fontSize / 2, y + fontSize / 2);
        g.dispose();
        return;
    }

    if (origImage == null) {
        return;
    }

    BufferedImage myImg = map.get(w.color);

    if (myImg == null) {
        myImg = convert(origImage, w.color);
        map.put(w.color, myImg);
    }

    g.drawImage(myImg, x - myImg.getWidth() / 2, y - myImg.getHeight(), null);

    String label = String.valueOf(w.amount);

    //      g.setFont(font);
    FontMetrics metrics = g.getFontMetrics();
    int tw = metrics.stringWidth(label);
    int th = 1 + metrics.getAscent();

    //      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.drawString(label, x - tw / 2, y + th);

    g.dispose();
}

From source file:net.sf.mzmine.modules.visualization.metamsecorrelate.visual.pseudospectra.PseudoSpectraRenderer.java

@Override
protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot,
        XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) {
    //super.drawItemLabel(g2, dataset, series, item, plot, generator, bar, negative);  

    if (generator != null) {
        String label = generator.generateLabel(dataset, series, item);

        if (label != null) {
            Font labelFont = getItemLabelFont(series, item);
            Paint paint = getItemLabelPaint(series, item);
            g2.setFont(labelFont);
            g2.setPaint(paint);/*  w w w  .  ja v  a  2s.  c  o m*/

            // get the label position..
            ItemLabelPosition position;
            if (!negative) {
                position = getPositiveItemLabelPosition(series, item);
            } else {
                position = getNegativeItemLabelPosition(series, item);
            }

            // work out the label anchor point...
            Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar,
                    plot.getOrientation());

            // split by \n
            String symbol = "\n";
            String[] splitted = label.split(symbol);

            if (splitted.length > 1) {
                FontRenderContext frc = g2.getFontRenderContext();
                GlyphVector gv = g2.getFont().createGlyphVector(frc, "Fg,");
                int height = 4 + (int) gv.getPixelBounds(null, 0, 0).getHeight();
                // draw more than one row
                for (int i = 0; i < splitted.length; i++) {
                    int offset = -height * (splitted.length - i - 1);
                    TextUtilities.drawRotatedString(splitted[i], g2, (float) anchorPoint.getX(),
                            (float) anchorPoint.getY() + offset, position.getTextAnchor(), position.getAngle(),
                            position.getRotationAnchor());
                }
            } else {
                // one row 
                TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(),
                        (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(),
                        position.getRotationAnchor());
            }
        }
    }

}

From source file:org.pentaho.platform.plugin.action.chartbeans.ChartAction.java

/**
 * Called to process the chart definition and data set to produce a usable chart.
 *
 * @throws ChartBootException//  w  w  w.ja  v  a 2 s .  co  m
 * @throws ChartProcessingException
 * @throws ResourceException
 * @throws InvalidChartDefinition
 * @throws IOException
 * @throws PersistenceException
 * @see org.pentaho.platform.api.action.IAction#execute()
 */
public void execute() throws Exception {

    //
    // Runtime value validation is now part of the execute operation
    //
    validate();

    if (bootException != null) {
        throw new ChartBootException(bootException);
    }

    // Transform IPentahoResultSet to an object array

    Object[][] data = processChartData(chartData, valueColumn);

    if (chartModel.getTheme() != null) {
        AbstractChartThemeFactory chartThemeFactory = new AbstractChartThemeFactory() {
            protected List<File> getThemeFiles() {
                ArrayList<File> themeFiles = new ArrayList<File>();
                themeFiles.add(new File(PentahoSystem.getApplicationContext()
                        .getSolutionPath("system/chartbeans/themes/Theme1.xml"))); //$NON-NLS-1$
                themeFiles.add(new File(PentahoSystem.getApplicationContext()
                        .getSolutionPath("system/chartbeans/themes/Theme2.xml"))); //$NON-NLS-1$
                themeFiles.add(new File(PentahoSystem.getApplicationContext()
                        .getSolutionPath("system/chartbeans/themes/Theme3.xml"))); //$NON-NLS-1$
                themeFiles.add(new File(PentahoSystem.getApplicationContext()
                        .getSolutionPath("system/chartbeans/themes/Theme4.xml"))); //$NON-NLS-1$
                themeFiles.add(new File(PentahoSystem.getApplicationContext()
                        .getSolutionPath("system/chartbeans/themes/Theme5.xml"))); //$NON-NLS-1$
                themeFiles.add(new File(PentahoSystem.getApplicationContext()
                        .getSolutionPath("system/chartbeans/themes/Theme6.xml"))); //$NON-NLS-1$
                return themeFiles;
            }
        };

        if (!(chartModel.getPlot() instanceof DialPlot)) {
            Theme chartTheme = chartThemeFactory.getTheme(chartModel.getTheme());
            if (chartTheme != null) {
                chartTheme.applyTo(chartModel);
            }
        }
    }

    // Make sure chart engine is loaded
    loadChartEngine();
    // Set chart engine on chartModel for the ChartFactory to use
    chartModel.setChartEngineId(chartEngine);

    InputStream is = null;

    try {
        IChartLinkGenerator chartLinkGenerator = contentLinkingTemplate == null ? null
                : new ChartLinkGenerator(contentLinkingTemplate);
        is = ChartBeanFactory.createChart(data, scalingFactor, convertNullsToZero, valueColumn, seriesColumn,
                categoryColumn, chartModel, chartLinkGenerator, chartWidth, chartHeight, getOutputType());
        // Wrap output as necessary
        if (OpenFlashChartPlugin.PLUGIN_ID.equals(chartEngine)) {
            // Convert stream to string, insert into HTML fragment and re-stream it
            StringBuilder sb = new StringBuilder();
            int c = 0;

            // Build string
            while ((c = is.read()) >= 0) {
                sb.append((char) c);
            }

            IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
            String contextPath = requestContext.getContextPath();

            String flashContent = ChartBeansGeneratorUtil.mergeOpenFlashChartHtmlTemplate(
                    sb.toString().replaceAll("\"", "\\\\\""), //$NON-NLS-1$ //$NON-NLS-2$
                    contextPath + "/" + this.getSwfPath() + "/" + getSwfName()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$

            is = new ByteArrayInputStream(flashContent.getBytes("utf-8")); //$NON-NLS-1$
        }

        int val = 0;

        // TODO: Buffer for more efficiency
        while ((val = is.read()) != -1) {
            chartContentStream.write(val);
        }
    } catch (NoChartDataException ex) {
        if (JFreeChartPlugin.PLUGIN_ID.equals(chartEngine)) {
            BufferedImage image = new BufferedImage(chartWidth, chartHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D graphics = image.createGraphics();
            graphics.setFont(new Font("serif", Font.BOLD, 14)); //$NON-NLS-1$
            graphics.setColor(Color.BLACK);
            graphics.drawString("The chart data query returned no data.", 5, 5); //$NON-NLS-1$
            String outputType = getMimeType(null).equals("image/jpg") ? "jpeg" : "png"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            ImageIO.write(image, outputType, chartContentStream);
        } else {
            String flashContent = ChartBeansGeneratorUtil
                    .buildEmptyOpenFlashChartHtmlFragment("The chart data query returned no data."); //$NON-NLS-1$
            is = new ByteArrayInputStream(flashContent.getBytes("utf-8")); //$NON-NLS-1$
            int val = 0;
            // TODO: Buffer for more efficiency
            while ((val = is.read()) != -1) {
                chartContentStream.write(val);
            }
        }
    } catch (ChartDataOverflowException ex) {
        if (JFreeChartPlugin.PLUGIN_ID.equals(chartEngine)) {
            BufferedImage image = new BufferedImage(chartWidth, chartHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D graphics = image.createGraphics();
            graphics.setFont(new Font("serif", Font.BOLD, 14)); //$NON-NLS-1$
            graphics.setColor(Color.BLACK);
            graphics.drawString(Messages.getInstance().getErrorString("ChartAction.TOO_MANY_DATA_POINTS"), 5,
                    5); //$NON-NLS-1$
            graphics.drawString(Messages.getInstance().getErrorString("ChartAction.MAX_ALLOWED_DATA_POINTS",
                    Integer.toString(ex.getMaxAllowedDataPoints())), 5, 25); //$NON-NLS-1$

            String outputType = getMimeType(null).equals("image/jpg") ? "jpeg" : "png"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            ImageIO.write(image, outputType, chartContentStream);
        } else {
            String flashContent = ChartBeansGeneratorUtil.buildEmptyOpenFlashChartHtmlFragment(
                    Messages.getInstance().getErrorString("ChartAction.TOO_MANY_DATA_POINTS_HTML", //$NON-NLS-1$
                            Integer.toString(ex.getMaxAllowedDataPoints())));
            is = new ByteArrayInputStream(flashContent.getBytes("utf-8")); //$NON-NLS-1$
            int val = 0;
            // TODO: Buffer for more efficiency
            while ((val = is.read()) != -1) {
                chartContentStream.write(val);
            }
        }
    }
}