chris@1: /* chris@1: * SONEWS News Server chris@1: * see AUTHORS for the list of contributors chris@1: * chris@1: * This program is free software: you can redistribute it and/or modify chris@1: * it under the terms of the GNU General Public License as published by chris@1: * the Free Software Foundation, either version 3 of the License, or chris@1: * (at your option) any later version. chris@1: * chris@1: * This program is distributed in the hope that it will be useful, chris@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of chris@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@1: * GNU General Public License for more details. chris@1: * chris@1: * You should have received a copy of the GNU General Public License chris@1: * along with this program. If not, see . chris@1: */ chris@1: chris@1: package org.sonews.web; chris@1: chris@1: import info.monitorenter.gui.chart.Chart2D; chris@1: import info.monitorenter.gui.chart.IAxis.AxisTitle; chris@1: import java.awt.Color; chris@1: import java.awt.image.BufferedImage; chris@1: import java.io.ByteArrayOutputStream; chris@1: import java.io.IOException; chris@1: import javax.imageio.ImageIO; chris@1: chris@1: /** chris@1: * A chart rendered to a memory bitmap. chris@1: * @author Christian Lins chris@1: * @since sonews/0.5.0 chris@1: */ chris@1: class MemoryBitmapChart extends Chart2D chris@1: { chris@1: chris@1: public MemoryBitmapChart() chris@1: { chris@1: setGridColor(Color.LIGHT_GRAY); chris@1: getAxisX().setPaintGrid(true); chris@1: getAxisY().setPaintGrid(true); chris@1: getAxisX().setAxisTitle(new AxisTitle("time of day")); chris@1: getAxisY().setAxisTitle(new AxisTitle("processed news")); chris@1: } chris@1: chris@1: public String getContentType() chris@1: { chris@1: return "image/png"; chris@1: } chris@1: chris@1: public byte[] getRawData(final int width, final int height) chris@1: throws IOException chris@1: { chris@1: setSize(width, height); chris@1: BufferedImage img = snapShot(width, height); chris@1: ByteArrayOutputStream out = new ByteArrayOutputStream(); chris@1: ImageIO.write(img, "png", out); chris@1: return out.toByteArray(); chris@1: } chris@1: chris@1: }