001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.test.web;
043:
044: import java.awt.Color;
045: import java.awt.Component;
046: import java.awt.Composite;
047: import java.awt.Font;
048: import java.awt.FontMetrics;
049: import java.awt.Graphics;
050: import java.awt.Graphics2D;
051: import java.awt.GraphicsConfiguration;
052: import java.awt.Image;
053: import java.awt.Paint;
054: import java.awt.Rectangle;
055: import java.awt.RenderingHints;
056: import java.awt.Shape;
057: import java.awt.Stroke;
058: import java.awt.font.FontRenderContext;
059: import java.awt.font.GlyphVector;
060: import java.awt.geom.AffineTransform;
061: import java.awt.image.BufferedImage;
062: import java.awt.image.BufferedImageOp;
063: import java.awt.image.ImageObserver;
064: import java.awt.image.RenderedImage;
065: import java.awt.image.renderable.RenderableImage;
066: import java.text.AttributedCharacterIterator;
067: import java.util.Map;
068:
069: /** Renders all drawString(...) into StringBuffer.
070: *
071: * @author Martin.Schovanek@sun.com
072: */
073: public class TextGraphics2D extends Graphics2D {
074: StringBuffer buf = new StringBuffer();
075: Component dummy;
076: Font font;
077:
078: /**
079: * Creates a new instance of TextGraphics2D
080: */
081: public TextGraphics2D(Component component) {
082: dummy = component;
083: }
084:
085: public TextGraphics2D() {
086: this (null);
087: }
088:
089: public String getText() {
090: return buf.toString();
091: }
092:
093: public String getTextUni() {
094: String str;
095: int start;
096: StringBuffer buf = new StringBuffer().append(this .buf);
097: while ((start = buf.indexOf(" ")) > -1) {
098: buf.deleteCharAt(start);
099: }
100: str = buf.toString();
101: // remove '...' ussually rendered when the left epression is too long
102: str = str.replaceAll("[.]{3} ?", "");
103: return str;
104: }
105:
106: public void clearRect(int param, int param1, int param2, int param3) {
107: }
108:
109: public void clipRect(int param, int param1, int param2, int param3) {
110: }
111:
112: public void copyArea(int param, int param1, int param2, int param3,
113: int param4, int param5) {
114: }
115:
116: public Graphics create() {
117: return new TextGraphics2D(dummy);
118: }
119:
120: public void dispose() {
121: }
122:
123: public void drawArc(int param, int param1, int param2, int param3,
124: int param4, int param5) {
125: }
126:
127: public boolean drawImage(Image image, int param, int param2,
128: ImageObserver imageObserver) {
129: return true;
130: }
131:
132: public boolean drawImage(Image image, int param, int param2,
133: Color color, ImageObserver imageObserver) {
134: return true;
135: }
136:
137: public boolean drawImage(Image image, int param, int param2,
138: int param3, int param4, ImageObserver imageObserver) {
139: return true;
140: }
141:
142: public boolean drawImage(Image image, int param, int param2,
143: int param3, int param4, Color color,
144: ImageObserver imageObserver) {
145: return true;
146: }
147:
148: public boolean drawImage(Image image, int param, int param2,
149: int param3, int param4, int param5, int param6, int param7,
150: int param8, ImageObserver imageObserver) {
151: return true;
152: }
153:
154: public boolean drawImage(Image image, int param, int param2,
155: int param3, int param4, int param5, int param6, int param7,
156: int param8, Color color, ImageObserver imageObserver) {
157: return true;
158: }
159:
160: public void drawLine(int param, int param1, int param2, int param3) {
161: }
162:
163: public void drawOval(int param, int param1, int param2, int param3) {
164: }
165:
166: public void drawPolygon(int[] values, int[] values1, int param) {
167: }
168:
169: public void drawPolyline(int[] values, int[] values1, int param) {
170: }
171:
172: public void drawRoundRect(int param, int param1, int param2,
173: int param3, int param4, int param5) {
174: }
175:
176: public void drawString(String str, int x, int y) {
177: drawString(str, (float) x, (float) y);
178: }
179:
180: public void drawString(AttributedCharacterIterator iterator, int x,
181: int y) {
182: drawString(iterator, (float) x, (float) y);
183: }
184:
185: public void fillArc(int param, int param1, int param2, int param3,
186: int param4, int param5) {
187: }
188:
189: public void fillOval(int param, int param1, int param2, int param3) {
190: }
191:
192: public void fillPolygon(int[] values, int[] values1, int param) {
193: }
194:
195: public void fillRect(int param, int param1, int param2, int param3) {
196: }
197:
198: public void fillRoundRect(int param, int param1, int param2,
199: int param3, int param4, int param5) {
200: }
201:
202: public Shape getClip() {
203: return new Rectangle();
204: }
205:
206: public Rectangle getClipBounds() {
207: return new Rectangle();
208: }
209:
210: public Color getColor() {
211: return Color.WHITE;
212: }
213:
214: public Font getFont() {
215: if (font != null)
216: return font;
217: if (dummy == null)
218: return null;
219: return dummy.getFont();
220: }
221:
222: public FontMetrics getFontMetrics(Font font) {
223: if (dummy == null)
224: return null;
225: return dummy.getFontMetrics(dummy.getFont());
226: }
227:
228: public void setClip(Shape shape) {
229: }
230:
231: public void setClip(int param, int param1, int param2, int param3) {
232: }
233:
234: public void setColor(Color color) {
235: }
236:
237: public void setFont(Font font) {
238: this .font = font;
239: }
240:
241: public void setPaintMode() {
242: }
243:
244: public void setXORMode(Color color) {
245: }
246:
247: public void translate(int param, int param1) {
248: }
249:
250: public void addRenderingHints(Map map) {
251: }
252:
253: public void clip(Shape shape) {
254: }
255:
256: public void draw(Shape shape) {
257: }
258:
259: public void drawGlyphVector(GlyphVector glyphVector, float param,
260: float param2) {
261: }
262:
263: public boolean drawImage(Image image,
264: AffineTransform affineTransform, ImageObserver imageObserver) {
265: return true;
266: }
267:
268: public void drawImage(BufferedImage bufferedImage,
269: BufferedImageOp bufferedImageOp, int param, int param3) {
270: }
271:
272: public void drawRenderableImage(RenderableImage renderableImage,
273: AffineTransform affineTransform) {
274: }
275:
276: public void drawRenderedImage(RenderedImage renderedImage,
277: AffineTransform affineTransform) {
278: }
279:
280: public void drawString(String str, float x, float y) {
281: if (buf.length() > 0 && buf.charAt(buf.length() - 1) != ' ') {
282: buf.append(' ');
283: }
284: buf.append(str);
285: }
286:
287: public void drawString(AttributedCharacterIterator iterator,
288: float x, float y) {
289: if (buf.length() > 0 && buf.charAt(buf.length() - 1) != ' ') {
290: buf.append(' ');
291: }
292: for (char c = iterator.first(); c != iterator.DONE; c = iterator
293: .next()) {
294: buf.append(c);
295: }
296: }
297:
298: public void fill(Shape shape) {
299: }
300:
301: public Color getBackground() {
302: if (dummy == null)
303: return null;
304: return dummy.getBackground();
305: }
306:
307: public Composite getComposite() {
308: return null;
309: }
310:
311: public GraphicsConfiguration getDeviceConfiguration() {
312: return null;
313: }
314:
315: public FontRenderContext getFontRenderContext() {
316: if (dummy == null)
317: return null;
318: Graphics2D graphics = (Graphics2D) dummy.getGraphics();
319: if (graphics == null)
320: return null;
321: return graphics.getFontRenderContext();
322: }
323:
324: public Paint getPaint() {
325: return null;
326: }
327:
328: public Object getRenderingHint(RenderingHints.Key key) {
329: return null;
330: }
331:
332: public RenderingHints getRenderingHints() {
333: return null;
334: }
335:
336: public Stroke getStroke() {
337: return null;
338: }
339:
340: public AffineTransform getTransform() {
341: return null;
342: }
343:
344: public boolean hit(Rectangle rectangle, Shape shape, boolean param) {
345: return true;
346: }
347:
348: public void rotate(double param) {
349: }
350:
351: public void rotate(double param, double param1, double param2) {
352: }
353:
354: public void scale(double param, double param1) {
355: }
356:
357: public void setBackground(Color color) {
358: }
359:
360: public void setComposite(Composite composite) {
361: }
362:
363: public void setPaint(Paint paint) {
364: }
365:
366: public void setRenderingHint(RenderingHints.Key key, Object obj) {
367: }
368:
369: public void setRenderingHints(Map map) {
370: }
371:
372: public void setStroke(Stroke stroke) {
373: }
374:
375: public void setTransform(AffineTransform affineTransform) {
376: }
377:
378: public void shear(double param, double param1) {
379: }
380:
381: public void transform(AffineTransform affineTransform) {
382: }
383:
384: public void translate(double param, double param1) {
385: }
386: }
|