ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/DBReporter/GraphMaker.java
Revision: 1.1
Committed: Mon Dec 11 16:31:58 2000 UTC (25 years ago) by pjm2
Branch: MAIN
Log Message:
Used to create and ultimately output a gif image.  This class accepts a
PlotData object in the constructor, yet has the filename, size,
etc. passed in a separate method - this is so that the same PlotData can
easily be used to create several graphs of differing filenames, sizes,
etc.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2
3 //---IMPORTS---
4
5 import java.io.*;
6 import java.awt.*;
7 import java.awt.image.*;
8
9 import Acme.JPM.Encoders.*;
10
11 /**
12 * GraphMaker - Used to create and ultimately output a gif image.
13 * This class accepts a PlotData object in the constructor, yet has
14 * the filename, size, etc. passed in a separate method - this is so
15 * that the same PlotData can easily be used to create several graphs
16 * of differing filenames, sizes, etc...
17 *
18 * @author $Author: pjm2 $
19 * @version $Id: $
20 */
21 public class GraphMaker {
22
23 //---FINAL ATTRIBUTES---
24
25 /**
26 * The current CVS revision of this class
27 */
28 public final String REVISION = "$Revision: $";
29
30 private final int _fg = 0; // black
31 private final int _bg = 16777215; // white
32 private final int _gradeColour = 13421823; // i-scream blue ;)
33
34 //---STATIC METHODS---
35
36 //---CONSTRUCTORS---
37
38 public GraphMaker(PlotData pd){
39 _pd = pd;
40 }
41
42
43 //---PUBLIC METHODS---
44
45 public void writeGraph(String filename, int width, int height, int grade){
46
47 //Uncomment this to find out the integer values for certain colours.
48 //int rgb = 0*256*256 + 0*256 + 0;
49 //System.out.println ((rgb & 0xff00ff00) | ((rgb & 0xff0000) >> 16) | ((rgb & 0xff) << 16));
50
51 BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
52
53 _pd.drawGraph(img, width, height, grade, _fg, _bg, _gradeColour);
54
55 try {
56 FileOutputStream fos = new FileOutputStream(new File(filename));
57 GifEncoder encoder = new GifEncoder(img, fos);
58
59 encoder.encode();
60
61 fos.flush();
62 fos.close();
63
64 System.out.println(" - Written "+width+"x"+height+" graph file");
65 }
66 catch(Exception e){
67 System.out.println("Could not write the .gif file.");
68 }
69
70 //g.dispose();
71 //frame.dispose();
72
73 }
74
75 /**
76 * Overrides the {@link java.lang.Object#toString() Object.toString()}
77 * method to provide clean logging (every class should have this).
78 *
79 * @return the name of this class and its CVS revision
80 */
81 public String toString() {
82 return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
83 }
84
85 //---PRIVATE METHODS---
86
87 //---ACCESSOR/MUTATOR METHODS---
88
89 //---ATTRIBUTES---
90
91 private PlotData _pd;
92
93 //---STATIC ATTRIBUTES---
94
95 }