| 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: pjm2 $ |
| 36 |
|
| 37 |
* @version $Id: GraphMaker.java,v 1.13 2001/01/11 19:03:04 pjm2 Exp $ |
| 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: 1.13 $"; |
| 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 |
} |