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