KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > web > TextGraphics2D


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.web;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Composite JavaDoc;
25 import java.awt.Font JavaDoc;
26 import java.awt.FontMetrics JavaDoc;
27 import java.awt.Graphics JavaDoc;
28 import java.awt.Graphics2D JavaDoc;
29 import java.awt.GraphicsConfiguration JavaDoc;
30 import java.awt.Image JavaDoc;
31 import java.awt.Paint JavaDoc;
32 import java.awt.Rectangle JavaDoc;
33 import java.awt.RenderingHints JavaDoc;
34 import java.awt.Shape JavaDoc;
35 import java.awt.Stroke JavaDoc;
36 import java.awt.font.FontRenderContext JavaDoc;
37 import java.awt.font.GlyphVector JavaDoc;
38 import java.awt.geom.AffineTransform JavaDoc;
39 import java.awt.image.BufferedImage JavaDoc;
40 import java.awt.image.BufferedImageOp JavaDoc;
41 import java.awt.image.ImageObserver JavaDoc;
42 import java.awt.image.RenderedImage JavaDoc;
43 import java.awt.image.renderable.RenderableImage JavaDoc;
44 import java.text.AttributedCharacterIterator JavaDoc;
45 import java.util.Map JavaDoc;
46
47
48 /** Renders all drawString(...) into StringBuffer.
49  *
50  * @author Martin.Schovanek@sun.com
51  */

52 public class TextGraphics2D extends Graphics2D JavaDoc {
53     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
54     Component JavaDoc dummy;
55     Font JavaDoc font;
56     
57     /**
58      * Creates a new instance of TextGraphics2D
59      */

60     public TextGraphics2D(Component JavaDoc component) {
61         dummy = component;
62     }
63     
64     public TextGraphics2D() {
65         this(null);
66     }
67     
68     public String JavaDoc getText() {
69         return buf.toString();
70     }
71     
72     public void setText(CharSequence JavaDoc text){
73         buf.append(text);
74     }
75     
76     public String JavaDoc getTextUni() {
77         String JavaDoc str;
78         int start;
79         StringBuffer JavaDoc buf = new StringBuffer JavaDoc().append(this.buf);
80         while ((start=buf.indexOf(" ")) > -1) {
81             buf.deleteCharAt(start);
82         }
83         str = buf.toString();
84         // remove '...' ussually rendered when the left epression is too long
85
str = str.replaceAll("[.]{3} ?", "");
86         return str;
87     }
88     
89     public void clearRect(int param, int param1, int param2, int param3) {
90     }
91     
92     public void clipRect(int param, int param1, int param2, int param3) {
93     }
94     
95     public void copyArea(int param, int param1, int param2, int param3,
96             int param4, int param5) {
97     }
98     
99     public Graphics JavaDoc create() {
100         return new TextGraphics2D(dummy);
101     }
102     
103     public void dispose() {
104     }
105     
106     public void drawArc(int param, int param1, int param2, int param3,
107             int param4, int param5) {
108     }
109     
110     public boolean drawImage(Image JavaDoc image, int param, int param2,
111             ImageObserver JavaDoc imageObserver) {
112         return true;
113     }
114     
115     public boolean drawImage(Image JavaDoc image, int param, int param2, Color JavaDoc color,
116             ImageObserver JavaDoc imageObserver) {
117         return true;
118     }
119     
120     public boolean drawImage(Image JavaDoc image, int param, int param2, int param3,
121             int param4, ImageObserver JavaDoc imageObserver) {
122         return true;
123     }
124     
125     public boolean drawImage(Image JavaDoc image, int param, int param2, int param3,
126             int param4, Color JavaDoc color, ImageObserver JavaDoc imageObserver) {
127         return true;
128     }
129     
130     public boolean drawImage(Image JavaDoc image, int param, int param2, int param3,
131             int param4, int param5, int param6, int param7, int param8,
132             ImageObserver JavaDoc imageObserver) {
133         return true;
134     }
135     
136     public boolean drawImage(Image JavaDoc image, int param, int param2, int param3,
137             int param4, int param5, int param6, int param7, int param8,
138             Color JavaDoc color, ImageObserver JavaDoc imageObserver) {
139         return true;
140     }
141     
142     public void drawLine(int param, int param1, int param2, int param3) {
143     }
144     
145     public void drawOval(int param, int param1, int param2, int param3) {
146     }
147     
148     public void drawPolygon(int[] values, int[] values1, int param) {
149     }
150     
151     public void drawPolyline(int[] values, int[] values1, int param) {
152     }
153     
154     public void drawRoundRect(int param, int param1, int param2, int param3,
155             int param4, int param5) {
156     }
157     
158     public void drawString(String JavaDoc str, int x, int y) {
159         drawString(str, (float) x, (float) y);
160     }
161     
162     public void drawString(AttributedCharacterIterator JavaDoc iterator, int x, int y) {
163         drawString(iterator, (float) x, (float) y);
164     }
165     
166     public void fillArc(int param, int param1, int param2, int param3, int param4,
167             int param5) {
168     }
169     
170     public void fillOval(int param, int param1, int param2, int param3) {
171     }
172     
173     public void fillPolygon(int[] values, int[] values1, int param) {
174     }
175     
176     public void fillRect(int param, int param1, int param2, int param3) {
177     }
178     
179     public void fillRoundRect(int param, int param1, int param2, int param3,
180             int param4, int param5) {
181     }
182     
183     public Shape JavaDoc getClip() {
184         return new Rectangle JavaDoc();
185     }
186     
187     public Rectangle JavaDoc getClipBounds() {
188         return new Rectangle JavaDoc();
189     }
190     
191     public Color JavaDoc getColor() {
192         return Color.WHITE;
193     }
194     
195     public Font JavaDoc getFont() {
196         if(font != null) return font;
197         if (dummy == null) return null;
198         return dummy.getFont();
199     }
200     
201     public FontMetrics JavaDoc getFontMetrics(Font JavaDoc font) {
202         if (dummy == null) return null;
203         return dummy.getFontMetrics(dummy.getFont());
204     }
205     
206     public void setClip(Shape JavaDoc shape) {
207     }
208     
209     public void setClip(int param, int param1, int param2, int param3) {
210     }
211     
212     public void setColor(Color JavaDoc color) {
213     }
214     
215     public void setFont(Font JavaDoc font) {
216         this.font=font;
217     }
218     
219     public void setPaintMode() {
220     }
221     
222     public void setXORMode(Color JavaDoc color) {
223     }
224     
225     public void translate(int param, int param1) {
226     }
227     
228     public void addRenderingHints(Map JavaDoc map) {
229     }
230     
231     public void clip(Shape JavaDoc shape) {
232     }
233     
234     public void draw(Shape JavaDoc shape) {
235     }
236     
237     public void drawGlyphVector(GlyphVector JavaDoc glyphVector, float param,
238             float param2) {
239     }
240     
241     public boolean drawImage(Image JavaDoc image, AffineTransform JavaDoc affineTransform,
242             ImageObserver JavaDoc imageObserver) {
243         return true;
244     }
245     
246     public void drawImage(BufferedImage JavaDoc bufferedImage,
247             BufferedImageOp JavaDoc bufferedImageOp, int param, int param3) {
248     }
249     
250     public void drawRenderableImage(RenderableImage JavaDoc renderableImage,
251             AffineTransform JavaDoc affineTransform) {
252     }
253     
254     public void drawRenderedImage(RenderedImage JavaDoc renderedImage,
255             AffineTransform JavaDoc affineTransform) {
256     }
257     
258     public void drawString(String JavaDoc str, float x, float y) {
259         if (buf.length()>0 && buf.charAt(buf.length()-1) != ' ') {
260             buf.append(' ');
261         }
262         buf.append(str);
263     }
264     
265     public void drawString(AttributedCharacterIterator JavaDoc iterator,
266             float x, float y) {
267         if (buf.length()>0 && buf.charAt(buf.length()-1)!=' ') {
268             buf.append(' ');
269         }
270         for (char c=iterator.first(); c != iterator.DONE; c=iterator.next()) {
271             buf.append(c);
272         }
273     }
274     
275     public void fill(Shape JavaDoc shape) {
276     }
277     
278     public Color JavaDoc getBackground() {
279         if (dummy == null) return null;
280         return dummy.getBackground();
281     }
282     
283     public Composite JavaDoc getComposite() {
284         return null;
285     }
286     
287     public GraphicsConfiguration JavaDoc getDeviceConfiguration() {
288         return null;
289     }
290     
291     public FontRenderContext JavaDoc getFontRenderContext() {
292         if (dummy == null) return null;
293         Graphics2D JavaDoc graphics = (Graphics2D JavaDoc) dummy.getGraphics();
294         if (graphics == null) return null;
295         return graphics.getFontRenderContext();
296     }
297     
298     public Paint JavaDoc getPaint() {
299         return null;
300     }
301     
302     public Object JavaDoc getRenderingHint(RenderingHints.Key JavaDoc key) {
303         return null;
304     }
305     
306     public RenderingHints JavaDoc getRenderingHints() {
307         return null;
308     }
309     
310     public Stroke JavaDoc getStroke() {
311         return null;
312     }
313     
314     public AffineTransform JavaDoc getTransform() {
315         return null;
316     }
317     
318     public boolean hit(Rectangle JavaDoc rectangle, Shape JavaDoc shape, boolean param) {
319         return true;
320     }
321     
322     public void rotate(double param) {
323     }
324     
325     public void rotate(double param, double param1, double param2) {
326     }
327     
328     public void scale(double param, double param1) {
329     }
330     
331     public void setBackground(Color JavaDoc color) {
332     }
333     
334     public void setComposite(Composite JavaDoc composite) {
335     }
336     
337     public void setPaint(Paint JavaDoc paint) {
338     }
339     
340     public void setRenderingHint(RenderingHints.Key JavaDoc key, Object JavaDoc obj) {
341     }
342     
343     public void setRenderingHints(Map JavaDoc map) {
344     }
345     
346     public void setStroke(Stroke JavaDoc stroke) {
347     }
348     
349     public void setTransform(AffineTransform JavaDoc affineTransform) {
350     }
351     
352     public void shear(double param, double param1) {
353     }
354     
355     public void transform(AffineTransform JavaDoc affineTransform) {
356     }
357     
358     public void translate(double param, double param1) {
359     }
360 }
361
Popular Tags