Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / javax / swing / DebugGraphics.java
blob074d45114774cc4dd0ae7e9e9cfae617c1ac6cd5
1 /* DebugGraphics.java --
2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.swing;
40 import java.awt.Color;
41 import java.awt.Font;
42 import java.awt.FontMetrics;
43 import java.awt.Graphics;
44 import java.awt.Image;
45 import java.awt.Rectangle;
46 import java.awt.Shape;
47 import java.awt.image.ImageObserver;
48 import java.io.PrintStream;
49 import java.text.AttributedCharacterIterator;
52 /**
53 * DebugGraphics
54 * @author Andrew Selkirk
55 * @version 1.0
57 public class DebugGraphics extends Graphics
59 /**
60 * LOG_OPTION
62 public static final int LOG_OPTION = 1;
64 /**
65 * FLASH_OPTION
67 public static final int FLASH_OPTION = 2;
69 /**
70 * BUFFERED_OPTION
72 public static final int BUFFERED_OPTION = 4;
74 /**
75 * NONE_OPTION
77 public static final int NONE_OPTION = -1;
79 static Color debugFlashColor = Color.RED;
80 static int debugFlashCount = 10;
81 static int debugFlashTime = 1000;
82 static PrintStream debugLogStream = System.out;
84 /**
85 * graphics
87 Graphics graphics;
89 /**
90 * color
92 Color color = Color.BLACK;
94 /**
95 * buffer
97 Image buffer;
99 /**
100 * debugOptions
102 int debugOptions;
105 * graphicsID
107 int graphicsID;
110 * xOffset
112 int xOffset;
115 * yOffset
117 int yOffset;
120 * Creates a <code>DebugGraphics</code> object.
122 public DebugGraphics()
124 // TODO
128 * Creates a <code>DebugGraphics</code> object.
130 * @param graphics The <code>Graphics</code> object to wrap
131 * @param component TODO
133 public DebugGraphics(Graphics graphics, JComponent component)
135 this.graphics = graphics;
136 // FIXME: What shall we do with component ?
140 * Creates a <code>DebugGraphics</code> object.
142 * @param graphics The <code>Graphics</code> object to wrap
144 public DebugGraphics(Graphics graphics)
146 this.graphics = graphics;
150 * Sets the color to draw stuff with.
152 * @param color The color
154 public void setColor(Color color)
156 this.color = color;
160 * Creates a overrides <code>Graphics.create</code> to create a
161 * <code>DebugGraphics</code> object.
163 * @return a new <code>DebugGraphics</code> object.
165 public Graphics create()
167 return new DebugGraphics(graphics.create());
171 * Creates a overrides <code>Graphics.create</code> to create a
172 * <code>DebugGraphics</code> object.
174 * @param x the x coordinate
175 * @param y the y coordinate
176 * @param width the width
177 * @param height the height
179 * @return a new <code>DebugGraphics</code> object.
181 public Graphics create(int x, int y, int width, int height)
183 return new DebugGraphics(graphics.create(x, y, width, height));
187 * flashColor
189 * @return Color
191 public static Color flashColor()
193 return debugFlashColor;
197 * setFlashColor
199 * @param color the color to use for flashing
201 public static void setFlashColor(Color color)
203 debugFlashColor = color;
207 * flashTime
209 * @return The time in milliseconds
211 public static int flashTime()
213 return debugFlashTime;
217 * setFlashTime
219 * @param time The time in milliseconds
221 public static void setFlashTime(int time)
223 debugFlashTime = time;
227 * flashCount
229 * @return The number of flashes
231 public static int flashCount()
233 return debugFlashCount;
237 * setFlashCount
239 * @param count The number of flashes
241 public static void setFlashCount(int count)
243 debugFlashCount = count;
247 * logStream
249 * @return The <code>PrintStream</code> to write logging messages to
251 public static PrintStream logStream()
253 return debugLogStream;
257 * setLogStream
259 * @param stream The currently set <code>PrintStream</code>.
261 public static void setLogStream(PrintStream stream)
263 debugLogStream = stream;
267 * getFont
269 * @return The font
271 public Font getFont()
273 return graphics.getFont();
277 * setFont
279 * @param font The font to use for drawing text
281 public void setFont(Font font)
283 graphics.setFont(font);
287 * Returns the color used for drawing.
289 * @return The color.
291 public Color getColor()
293 return color;
297 * Returns the font metrics of the current font.
299 * @return a <code>FontMetrics</code> object
301 public FontMetrics getFontMetrics()
303 return graphics.getFontMetrics();
307 * Returns the font metrics for a given font.
309 * @param font the font to get the metrics for
311 * @return a <code>FontMetrics</code> object
313 public FontMetrics getFontMetrics(Font font)
315 return graphics.getFontMetrics(font);
319 * translate
321 * @param x the x coordinate
322 * @param y the y coordinate
324 public void translate(int x, int y)
326 graphics.translate(x, y);
330 * setPaintMode
332 public void setPaintMode()
334 graphics.setPaintMode();
338 * setXORMode
340 * @param color the color
342 public void setXORMode(Color color)
344 graphics.setXORMode(color);
348 * getClipBounds
350 * @return Rectangle
352 public Rectangle getClipBounds()
354 return graphics.getClipBounds();
358 * Intersects the current clip region with the given region.
360 * @param x The x-position of the region
361 * @param y The y-position of the region
362 * @param width The width of the region
363 * @param height The height of the region
365 public void clipRect(int x, int y, int width, int height)
367 graphics.clipRect(x, y, width, height);
371 * Sets the clipping region.
373 * @param x The x-position of the region
374 * @param y The y-position of the region
375 * @param width The width of the region
376 * @param height The height of the region
378 public void setClip(int x, int y, int width, int height)
380 graphics.setClip(x, y, width, height);
384 * Returns the current clipping region.
386 * @return Shape
388 public Shape getClip()
390 return graphics.getClip();
394 * Sets the current clipping region
396 * @param shape The clippin region
398 public void setClip(Shape shape)
400 graphics.setClip(shape);
403 private void sleep(int milliseconds)
407 Thread.sleep(milliseconds);
409 catch (InterruptedException e)
411 // Ignore this.
416 * Draws a rectangle.
418 * @param x The x-position of the rectangle
419 * @param y The y-position of the rectangle
420 * @param width The width of the rectangle
421 * @param height The height of the rectangle
423 public void drawRect(int x, int y, int width, int height)
425 for (int index = 0; index < (debugFlashCount - 1); ++index)
427 graphics.setColor(color);
428 graphics.drawRect(x, y, width, height);
429 sleep(debugFlashTime);
431 graphics.setColor(debugFlashColor);
432 graphics.drawRect(x, y, width, height);
433 sleep(debugFlashTime);
436 graphics.setColor(color);
437 graphics.drawRect(x, y, width, height);
441 * Draws a filled rectangle.
443 * @param x The x-position of the rectangle
444 * @param y The y-position of the rectangle
445 * @param width The width of the rectangle
446 * @param height The height of the rectangle
448 public void fillRect(int x, int y, int width, int height)
450 for (int index = 0; index < (debugFlashCount - 1); ++index)
452 graphics.setColor(color);
453 graphics.fillRect(x, y, width, height);
454 sleep(debugFlashTime);
456 graphics.setColor(debugFlashColor);
457 graphics.fillRect(x, y, width, height);
458 sleep(debugFlashTime);
461 graphics.setColor(color);
462 graphics.fillRect(x, y, width, height);
466 * clearRect
468 * @param x The x-position of the rectangle
469 * @param y The y-position of the rectangle
470 * @param width The width of the rectangle
471 * @param height The height of the rectangle
473 public void clearRect(int x, int y, int width, int height)
475 graphics.clearRect(x, y, width, height);
479 * drawRoundRect
481 * @param x The x-position of the rectangle
482 * @param y The y-position of the rectangle
483 * @param width The width of the rectangle
484 * @param height The height of the rectangle
485 * @param arcWidth TODO
486 * @param arcHeight TODO
488 public void drawRoundRect(int x, int y, int width, int height,
489 int arcWidth, int arcHeight)
491 graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
495 * fillRoundRect
497 * @param x The x-position of the rectangle
498 * @param y The y-position of the rectangle
499 * @param width The width of the rectangle
500 * @param height The height of the rectangle
501 * @param arcWidth TODO
502 * @param arcHeight TODO
504 public void fillRoundRect(int x, int y, int width, int height,
505 int arcWidth, int arcHeight)
507 graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
511 * drawLine
513 * @param x1 The x-position of the start
514 * @param y1 The y-position of the start
515 * @param x2 The x-position of the end
516 * @param y2 The y-position of the end
518 public void drawLine(int x1, int y1, int x2, int y2)
520 graphics.drawLine(x1, y1, x2, y2);
524 * draw3DRect
526 * @param x The x-position of the rectangle
527 * @param y The y-position of the rectangle
528 * @param width The width of the rectangle
529 * @param height The height of the rectangle
530 * @param raised TODO
532 public void draw3DRect(int x, int y, int width, int height, boolean raised)
534 graphics.draw3DRect(x, y, width, height, raised);
538 * fill3DRect
540 * @param x The x-position of the rectangle
541 * @param y The y-position of the rectangle
542 * @param width The width of the rectangle
543 * @param height The height of the rectangle
544 * @param raised TODO
546 public void fill3DRect(int x, int y, int width, int height, boolean raised)
548 graphics.fill3DRect(x, y, width, height, raised);
552 * drawOval
554 * @param x the x coordinate
555 * @param y the y coordiante
556 * @param width the width
557 * @param height the height
559 public void drawOval(int x, int y, int width, int height)
561 graphics.drawOval(x, y, width, height);
565 * fillOval
567 * @param x the x coordinate
568 * @param y the y coordinate
569 * @param width the width
570 * @param height the height
572 public void fillOval(int x, int y, int width, int height)
574 graphics.fillOval(x, y, width, height);
578 * drawArc
580 * @param x the x coordinate
581 * @param y the y coordinate
582 * @param width the width
583 * @param height the height
584 * @param startAngle TODO
585 * @param arcAngle TODO
587 public void drawArc(int x, int y, int width, int height,
588 int startAngle, int arcAngle)
590 graphics.drawArc(x, y, width, height, startAngle, arcAngle);
594 * fillArc
596 * @param x the coordinate
597 * @param y the y coordinate
598 * @param width the width
599 * @param height the height
600 * @param startAngle TODO
601 * @param arcAngle TODO
603 public void fillArc(int x, int y, int width, int height,
604 int startAngle, int arcAngle)
606 graphics.fillArc(x, y, width, height, startAngle, arcAngle);
610 * drawPolyline
612 * @param xpoints TODO
613 * @param ypoints TODO
614 * @param npoints TODO
616 public void drawPolyline(int[] xpoints, int[] ypoints, int npoints)
618 graphics.drawPolyline(xpoints, ypoints, npoints);
622 * drawPolygon
624 * @param xpoints TODO
625 * @param ypoints TODO
626 * @param npoints TODO
628 public void drawPolygon(int[] xpoints, int[] ypoints, int npoints)
630 graphics.drawPolygon(xpoints, ypoints, npoints);
634 * fillPolygon
636 * @param xpoints TODO
637 * @param ypoints TODO
638 * @param npoints TODO
640 public void fillPolygon(int[] xpoints, int[] ypoints, int npoints)
642 graphics.fillPolygon(xpoints, ypoints, npoints);
646 * drawString
648 * @param string the string
649 * @param x the x coordinate
650 * @param y the y coordinate
652 public void drawString(String string, int x, int y)
654 graphics.drawString(string, x, y);
658 * drawString
660 * @param iterator TODO
661 * @param x the x coordinate
662 * @param y the y coordinate
664 public void drawString(AttributedCharacterIterator iterator,
665 int x, int y)
667 graphics.drawString(iterator, x, y);
671 * drawBytes
673 * @param data TODO
674 * @param offset TODO
675 * @param length TODO
676 * @param x the x coordinate
677 * @param y the y coordinate
679 public void drawBytes(byte[] data, int offset, int length,
680 int x, int y)
682 graphics.drawBytes(data, offset, length, x, y);
686 * drawChars
688 * @param data array of characters to draw
689 * @param offset offset in array
690 * @param length number of characters in array to draw
691 * @param x x-position
692 * @param y y-position
694 public void drawChars(char[] data, int offset, int length,
695 int x, int y)
697 for (int index = 0; index < (debugFlashCount - 1); ++index)
699 graphics.setColor(color);
700 graphics.drawChars(data, offset, length, x, y);
701 sleep(debugFlashTime);
703 graphics.setColor(debugFlashColor);
704 graphics.drawChars(data, offset, length, x, y);
705 sleep(debugFlashTime);
708 graphics.setColor(color);
709 graphics.drawChars(data, offset, length, x, y);
713 * drawImage
715 * @param image The image to draw
716 * @param x The x position
717 * @param y The y position
718 * @param observer The image observer
719 * @return boolean
721 public boolean drawImage(Image image, int x, int y,
722 ImageObserver observer)
724 return graphics.drawImage(image, x, y, observer);
728 * drawImage
730 * @param image The image to draw
731 * @param x The x position
732 * @param y The y position
733 * @param width The width of the area to draw the image
734 * @param height The height of the area to draw the image
735 * @param observer The image observer
737 * @return boolean
739 public boolean drawImage(Image image, int x, int y, int width,
740 int height, ImageObserver observer)
742 return graphics.drawImage(image, x, y, width, height, observer);
746 * drawImage
748 * @param image The image to draw
749 * @param x The x position
750 * @param y The y position
751 * @param background The color for the background in the opaque regions
752 * of the image
753 * @param observer The image observer
755 * @return boolean
757 public boolean drawImage(Image image, int x, int y,
758 Color background, ImageObserver observer)
760 return graphics.drawImage(image, x, y, background, observer);
764 * drawImage
766 * @param image The image to draw
767 * @param x The x position
768 * @param y The y position
769 * @param width The width of the area to draw the image
770 * @param height The height of the area to draw the image
771 * @param background The color for the background in the opaque regions
772 * of the image
773 * @param observer The image observer
775 * @return boolean
777 public boolean drawImage(Image image, int x, int y, int width, int height,
778 Color background, ImageObserver observer)
780 return graphics.drawImage(image, x, y, width, height, background, observer);
784 * drawImage
786 * @param image The image to draw
787 * @param dx1 TODO
788 * @param dy1 TODO
789 * @param dx2 TODO
790 * @param dy2 TODO
791 * @param sx1 TODO
792 * @param sy1 TODO
793 * @param sx2 TODO
794 * @param sy2 TODO
795 * @param observer The image observer
797 * @return boolean
799 public boolean drawImage(Image image, int dx1, int dy1,
800 int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
801 ImageObserver observer)
803 return graphics.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
807 * drawImage
809 * @param image The image to draw
810 * @param dx1 TODO
811 * @param dy1 TODO
812 * @param dx2 TODO
813 * @param dy2 TODO
814 * @param sx1 TODO
815 * @param sy1 TODO
816 * @param sx2 TODO
817 * @param sy2 TODO
818 * @param background The color for the background in the opaque regions
819 * of the image
820 * @param observer The image observer
822 * @return boolean
824 public boolean drawImage(Image image, int dx1, int dy1,
825 int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
826 Color background, ImageObserver observer)
828 return graphics.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, background, observer);
832 * copyArea
834 * @param x The x position of the source area
835 * @param y The y position of the source area
836 * @param width The width of the area
837 * @param height The height of the area
838 * @param destx The x position of the destination area
839 * @param desty The y posiiton of the destination area
841 public void copyArea(int x, int y, int width, int height,
842 int destx, int desty)
844 graphics.copyArea(x, y, width, height, destx, desty);
848 * Releases all system resources that this <code>Graphics</code> is using.
850 public void dispose()
852 graphics.dispose();
853 graphics = null;
857 * isDrawingBuffer
859 * @return boolean
861 public boolean isDrawingBuffer()
863 return false; // TODO
867 * setDebugOptions
869 * @param options the debug options
871 public void setDebugOptions(int options)
873 debugOptions = options;
877 * getDebugOptions
879 * @return the debug options
881 public int getDebugOptions()
883 return debugOptions;