ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/DBReporter/GraphMaker.java
(Generate patch)

Comparing projects/cms/source/reports/DBReporter/GraphMaker.java (file contents):
Revision 1.3 by pjm2, Fri Dec 15 09:39:17 2000 UTC vs.
Revision 1.13 by pjm2, Thu Jan 11 19:03:04 2001 UTC

# Line 1 | Line 1
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$
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 gradeX, int gradeY){
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, gradeX, gradeY, _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 <    
1 > //---PACKAGE DECLARATION---
2  
3 +
4  
5 + //---IMPORTS---
6  
7 +
8  
9 + import java.io.*;
10  
11 + import java.awt.*;
12  
13 + import java.awt.image.*;
14  
15 +
16  
17 + import Acme.JPM.Encoders.*;
18  
19 +
20  
21 + /**
22  
23 + * GraphMaker - Used to create and ultimately output a gif image.
24  
25 + * This class accepts a PlotData object in the constructor, yet has
26  
27 + * the filename, size, etc. passed in a separate method - this is so
28  
29 + * that the same PlotData can easily be used to create several graphs
30  
31 + * of differing filenames, sizes, etc...
32  
33 + *
34  
35 + * @author  $Author$
36  
37 + * @version $Id$
38  
39 + */
40  
41 + public class GraphMaker {
42  
43 +
44  
45 + //---FINAL ATTRIBUTES---
46  
47 +
48  
49 +    /**
50  
51 +     * The current CVS revision of this class
52  
53 +     */
54  
55 +    public final String REVISION = "$Revision$";
56  
57 +    
58  
59 +
60  
61 + //---STATIC METHODS---
62  
63 +
64  
65 + //---CONSTRUCTORS---
66  
67 +
68  
69 +    public GraphMaker(PlotData pd){
70  
71 +        _pd = pd;
72  
73 +    }
74  
75 +
76  
77 +
78  
79 + //---PUBLIC METHODS---
80  
81 +
82  
83 +    public void writeGraph(String filename, int width, int height, int gradeX, int gradeY){
84  
85 +        
86  
87 +        BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
88  
89 +
90  
91 +        _pd.drawGraph(img, width, height, gradeX, gradeY);
92  
93 +  
94  
95 +        try {
96  
97 +            FileOutputStream fos = new FileOutputStream(new File(filename));
98  
99 +            GifEncoder encoder = new GifEncoder(img, fos);
100  
101 +            
102  
103 +            encoder.encode();
104  
105 +
106  
107 +            fos.flush();
108  
109 +            fos.close();
110  
111 +            
112  
113 +            System.out.println("            - Written "+width+"x"+height+" graph file");
114  
115 +        }
116  
117 +        catch(Exception e){
118  
119 +            System.out.println("Could not write the .gif file.");
120  
121 +        }
122  
123 +
124  
125 +        //g.dispose();
126  
127 +        //frame.dispose();
128  
129 +        
130  
131 +    }
132  
133 +    
134  
135 +    /**
136  
137 +     * Overrides the {@link java.lang.Object#toString() Object.toString()}
138  
139 +     * method to provide clean logging (every class should have this).
140  
141 +     *
142  
143 +     * @return the name of this class and its CVS revision
144  
145 +     */
146  
147 +    public String toString() {
148  
149 +        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
150  
151 +    }
152  
153 +    
154  
155 + //---PRIVATE METHODS---
156  
157 +
158  
159 + //---ACCESSOR/MUTATOR METHODS---
160  
161 +
162  
163 + //---ATTRIBUTES---
164  
165 +
166  
167 +    private PlotData _pd;
168  
169 +
170  
171 + //---STATIC ATTRIBUTES---
172  
173 +    
174  
175   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines