| 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: GraphMaker.java,v 1.3 2000/12/15 09:39:17 pjm2 Exp $ |
| 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: 1.3 $"; |
| 29 |
|
| 30 |
|
| 31 |
//---STATIC METHODS--- |
| 32 |
|
| 33 |
//---CONSTRUCTORS--- |
| 34 |
|
| 35 |
public GraphMaker(PlotData pd){ |
| 36 |
_pd = pd; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
//---PUBLIC METHODS--- |
| 41 |
|
| 42 |
public void writeGraph(String filename, int width, int height, int gradeX, int gradeY){ |
| 43 |
|
| 44 |
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
| 45 |
|
| 46 |
_pd.drawGraph(img, width, height, gradeX, gradeY); |
| 47 |
|
| 48 |
try { |
| 49 |
FileOutputStream fos = new FileOutputStream(new File(filename)); |
| 50 |
GifEncoder encoder = new GifEncoder(img, fos); |
| 51 |
|
| 52 |
encoder.encode(); |
| 53 |
|
| 54 |
fos.flush(); |
| 55 |
fos.close(); |
| 56 |
|
| 57 |
System.out.println(" - Written "+width+"x"+height+" graph file"); |
| 58 |
} |
| 59 |
catch(Exception e){ |
| 60 |
System.out.println("Could not write the .gif file."); |
| 61 |
} |
| 62 |
|
| 63 |
//g.dispose(); |
| 64 |
//frame.dispose(); |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
| 70 |
* method to provide clean logging (every class should have this). |
| 71 |
* |
| 72 |
* @return the name of this class and its CVS revision |
| 73 |
*/ |
| 74 |
public String toString() { |
| 75 |
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
| 76 |
} |
| 77 |
|
| 78 |
//---PRIVATE METHODS--- |
| 79 |
|
| 80 |
//---ACCESSOR/MUTATOR METHODS--- |
| 81 |
|
| 82 |
//---ATTRIBUTES--- |
| 83 |
|
| 84 |
private PlotData _pd; |
| 85 |
|
| 86 |
//---STATIC ATTRIBUTES--- |
| 87 |
|
| 88 |
} |