org/sonews/web/MemoryBitmapChart.java
author chris <chris@marvin>
Wed, 01 Jul 2009 10:48:22 +0200
changeset 2 1090e2141798
parent 1 6fceb66e1ad7
permissions -rw-r--r--
sonews/0.5.1 fixes merged
     1 /*
     2  *   SONEWS News Server
     3  *   see AUTHORS for the list of contributors
     4  *
     5  *   This program is free software: you can redistribute it and/or modify
     6  *   it under the terms of the GNU General Public License as published by
     7  *   the Free Software Foundation, either version 3 of the License, or
     8  *   (at your option) any later version.
     9  *
    10  *   This program is distributed in the hope that it will be useful,
    11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *   GNU General Public License for more details.
    14  *
    15  *   You should have received a copy of the GNU General Public License
    16  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 
    19 package org.sonews.web;
    20 
    21 import info.monitorenter.gui.chart.Chart2D;
    22 import info.monitorenter.gui.chart.IAxis.AxisTitle;
    23 import java.awt.Color;
    24 import java.awt.image.BufferedImage;
    25 import java.io.ByteArrayOutputStream;
    26 import java.io.IOException;
    27 import javax.imageio.ImageIO;
    28 
    29 /**
    30  * A chart rendered to a memory bitmap.
    31  * @author Christian Lins
    32  * @since sonews/0.5.0
    33  */
    34 class MemoryBitmapChart extends Chart2D
    35 {
    36 
    37   public MemoryBitmapChart()
    38   {
    39     setGridColor(Color.LIGHT_GRAY);
    40     getAxisX().setPaintGrid(true);
    41     getAxisY().setPaintGrid(true);
    42     getAxisX().setAxisTitle(new AxisTitle("time of day"));
    43     getAxisY().setAxisTitle(new AxisTitle("processed news"));
    44   }
    45   
    46   public String getContentType()
    47   {
    48     return "image/png";
    49   }
    50   
    51   public byte[] getRawData(final int width, final int height)
    52     throws IOException
    53   {
    54     setSize(width, height);
    55     BufferedImage img = snapShot(width, height);
    56     ByteArrayOutputStream out = new ByteArrayOutputStream();
    57     ImageIO.write(img, "png", out);
    58     return out.toByteArray();
    59   }
    60   
    61 }