1 // Copyright 2000-2006, FreeHEP
2 package org.freehep.graphicsio;
3
4 import java.awt.Color;
5 import java.awt.Dimension;
6 import java.awt.Font;
7 import java.awt.GradientPaint;
8 import java.awt.Graphics;
9 import java.awt.GraphicsConfiguration;
10 import java.awt.Paint;
11 import java.awt.Rectangle;
12 import java.awt.Shape;
13 import java.awt.TexturePaint;
14 import java.awt.geom.AffineTransform;
15 import java.awt.image.RenderedImage;
16 import java.io.IOException;
17
18 import org.freehep.graphics2d.VectorGraphics;
19
20 /**
21 * This class provides a dummy Graphics2D class, which issues warnings for all
22 * non implemented methods. It also describes how to implement these methods. It
23 * serves as an example to start the implementation for a new output format.
24 *
25 * @author Mark Donszelmann
26 * @version $Id: DummyGraphics2D.java 8584 2006-08-10 23:06:37Z duns $
27 */
28 public class DummyGraphics2D extends AbstractVectorGraphicsIO {
29 /*
30 * ================================================================================
31 * Table of Contents: ------------------ 1. Constructors & Factory Methods
32 * 2. Document Settings 3. Header, Trailer, Multipage & Comments 3.1 Header &
33 * Trailer 3.2 MultipageDocument methods 4. Create & Dispose 5. Drawing
34 * Methods 5.1. shapes (draw/fill) 5.1.1. lines, rectangles, round
35 * rectangles 5.1.2. polylines, polygons 5.1.3. ovals, arcs 5.1.4. shapes
36 * 5.2. Images 5.3. Strings 6. Transformations 7. Clipping 8. Graphics State /
37 * Settings 8.1. stroke/linewidth 8.2. paint/color 8.3. font 8.4. rendering
38 * hints 9. Auxiliary 10. Private/Utility Methos
39 * ================================================================================
40 */
41
42 /*
43 * ================================================================================
44 * 1. Constructors & Factory Methods
45 * ================================================================================
46 */
47 public DummyGraphics2D(Dimension size, boolean doRestoreOnDispose) {
48 super(size, doRestoreOnDispose);
49 // Create a graphics context with given imageBounds.
50 // This constructor is used by the user to create the initial graphics
51 // context.
52 // doRestoreOnDispose is used to call writeGraphicsRestore(),
53 // when the graphics context is being disposed off.
54 }
55
56 protected DummyGraphics2D(AbstractVectorGraphicsIO graphics,
57 boolean doRestoreOnDispose) {
58 super(graphics, doRestoreOnDispose);
59 // Create a graphics context from a given graphics context.
60 // This constructor is used by the system to clone a given graphics
61 // context.
62 // doRestoreOnDispose is used to call writeGraphicsRestore(),
63 // when the graphics context is being disposed off.
64 }
65
66 /*
67 * ================================================================================ |
68 * 2. Document Settings
69 * ================================================================================
70 */
71
72 /*
73 * ================================================================================ |
74 * 3. Header, Trailer, Multipage & Comments
75 * ================================================================================
76 */
77 /* 3.1 Header & Trailer */
78 public void writeHeader() throws IOException {
79 writeWarning(getClass() + ": writeHeader() not implemented.");
80 // Write out the header to the output stream.
81 }
82
83 public void writeBackground() throws IOException {
84 writeWarning(getClass() + ": writeBackground() not implemented.");
85 // Write out the background to the output stream.
86 }
87
88 public void writeTrailer() throws IOException {
89 writeWarning(getClass() + ": writeTrailer() not implemented.");
90 // Write out the trailer to the output stream.
91 }
92
93 public void closeStream() throws IOException {
94 writeWarning(getClass() + ": closeStream() not implemented.");
95 // Close the output stream.
96 }
97
98 /* 3.2 MultipageDocument methods */
99
100 /*
101 * ================================================================================
102 * 4. Create & Dispose
103 * ================================================================================
104 */
105
106 public Graphics create() {
107 // Create a new graphics context from the current one.
108 try {
109 // Save the current context for restore later.
110 writeGraphicsSave();
111 } catch (IOException e) {
112 }
113 // The correct graphics context should be created.
114 return new DummyGraphics2D(this, true);
115 }
116
117 public Graphics create(double x, double y, double width, double height) {
118 // Create a new graphics context from the current one.
119 try {
120 // Save the current context for restore later.
121 writeGraphicsSave();
122 } catch (IOException e) {
123 }
124 // The correct graphics context should be created.
125 VectorGraphics graphics = new DummyGraphics2D(this, true);
126 graphics.clipRect(x, y, width, height);
127 return graphics;
128 }
129
130 protected void writeGraphicsSave() throws IOException {
131 writeWarning(getClass() + ": writeGraphicsSave() not implemented.");
132 // Write a graphics context save.
133 // If the output format does not support this, keep a stack yourself.
134 }
135
136 protected void writeGraphicsRestore() throws IOException {
137 writeWarning(getClass() + ": writeGraphicsRestore() not implemented.");
138 // Write a graphics context restore.
139 // If the output format does not support this, keep a stack yourself.
140 }
141
142 /*
143 * ================================================================================ |
144 * 5. Drawing Methods
145 * ================================================================================
146 */
147 /* 5.1.4. shapes */
148
149 public void draw(Shape shape) {
150 writeWarning(getClass() + ": draw(Shape) not implemented.");
151 // Write out the stroke of the shape.
152 }
153
154 public void fill(Shape shape) {
155 writeWarning(getClass() + ": fill(Shape) not implemented.");
156 // Write out the fill of the shape.
157 }
158
159 public void fillAndDraw(Shape shape, Color fillColor) {
160 writeWarning(getClass()
161 + ": fillAndDraw(Shape, Color) not implemented.");
162 // Write out the fill with fillColor and stroke of the shape in
163 // getColor().
164 }
165
166 /* 5.2. Images */
167 public void copyArea(int x, int y, int width, int height, int dx, int dy) {
168 writeWarning(getClass()
169 + ": copyArea(int, int, int, int, int, int) not implemented.");
170 // Mostly unimplemented.
171 }
172
173 protected void writeImage(RenderedImage image, AffineTransform xform,
174 Color bkg) throws IOException {
175 writeWarning(getClass()
176 + ": writeImage(RenderedImage, AffineTransform, Color) not implemented.");
177 // Write out the image.
178 }
179
180 /* 5.3. Strings */
181 protected void writeString(String string, double x, double y)
182 throws IOException {
183 writeWarning(getClass()
184 + ": drawString(String, double, double) not implemented.");
185 // Write out the string.
186 }
187
188 /*
189 * ================================================================================ |
190 * 6. Transformations
191 * ================================================================================
192 */
193 protected void writeTransform(AffineTransform t) throws IOException {
194 writeWarning(getClass()
195 + ": writeTransform(AffineTransform) not implemented.");
196 // Write out the transform to be applied to the internal transform of
197 // the output
198 // format.
199 // You can also use the currentTransform.
200 }
201
202 protected void writeSetTransform(AffineTransform t) throws IOException {
203 writeWarning(getClass()+": writeTransform(AffineTransform) not implemented.");
204 // Clear the currentTransform and write out the transform to
205 // be applied to the internal transform of the output format.
206 }
207
208 /*
209 * ================================================================================ |
210 * 7. Clipping
211 * ================================================================================
212 */
213 protected void writeClip(Shape s) throws IOException {
214 writeWarning(getClass() + ": writeClip(Shape) not implemented.");
215 // Write out the clip shape.
216 }
217
218 protected void writeSetClip(Shape s) throws IOException {
219 writeWarning(getClass()+": writeSetClip(Shape) not implemented.");
220 // Write out the clip shape.
221 }
222
223 /*
224 * ================================================================================ |
225 * 8. Graphics State
226 * ================================================================================
227 */
228 /* 8.1. stroke/linewidth */
229 protected void writeWidth(float width) throws IOException {
230 writeWarning(getClass() + ": writeWidth(float) not implemented.");
231 // Write out the stroke width.
232 }
233
234 protected void writeCap(int cap) throws IOException {
235 writeWarning(getClass() + ": writeCap(int) not implemented.");
236 // Write out the stroke cap.
237 }
238
239 protected void writeJoin(int join) throws IOException {
240 writeWarning(getClass() + ": writeJoin(int) not implemented.");
241 // Write out the stroke join.
242 }
243
244 protected void writeMiterLimit(float limit) throws IOException {
245 writeWarning(getClass() + ": writeMiterLimit(float) not implemented.");
246 // Write out the stroke miter limit.
247 }
248
249 protected void writeDash(float[] dash, float phase) throws IOException {
250 writeWarning(getClass()
251 + ": writeDash(float[], float) not implemented.");
252 // Write out the stroke dash.
253 }
254
255 /* 8.2. paint/color */
256 public void setPaintMode() {
257 writeWarning(getClass() + ": setPaintMode() not implemented.");
258 // Mostly unimplemented.
259 }
260
261 public void setXORMode(Color c1) {
262 writeWarning(getClass() + ": setXORMode(Color) not implemented.");
263 // Mostly unimplemented.
264 }
265
266 protected void writePaint(Color p) throws IOException {
267 writeWarning(getClass() + ": writePaint(Color) not implemented.");
268 // Write out the color paint.
269 }
270
271 protected void writePaint(GradientPaint p) throws IOException {
272 writeWarning(getClass()
273 + ": writePaint(GradientPaint) not implemented.");
274 // Write out the gradient paint.
275 }
276
277 protected void writePaint(TexturePaint p) throws IOException {
278 writeWarning(getClass() + ": writePaint(TexturePaint) not implemented.");
279 // Write out the texture paint.
280 }
281
282 protected void writePaint(Paint p) throws IOException {
283 writeWarning(getClass() + ": writePaint(Paint) not implemented for "
284 + p.getClass());
285 // Write out the paint.
286 }
287
288 /* 8.3. font */
289 protected void writeFont(Font font) throws IOException {
290 writeWarning(getClass() + ": writeFont(Font) not implemented.");
291 }
292
293 /* 8.4. rendering hints */
294
295 /*
296 * ================================================================================ |
297 * 9. Auxiliary
298 * ================================================================================
299 */
300 public GraphicsConfiguration getDeviceConfiguration() {
301 writeWarning(getClass() + ": getDeviceConfiguration() not implemented.");
302 // Mostly unimplemented
303 return null;
304 }
305
306 public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
307 writeWarning(getClass()
308 + ": hit(Rectangle, Shape, boolean) not implemented.");
309 // Mostly unimplemented
310 return false;
311 }
312
313 public void writeComment(String comment) throws IOException {
314 writeWarning(getClass() + ": writeComment(String) not implemented.");
315 // Write out the comment.
316 }
317
318 public String toString() {
319 return "DummyGraphics";
320 }
321 }