1 7 package java.awt; 8 9 import java.io.*; 10 import java.lang.*; 11 import java.util.*; 12 import java.awt.image.ImageObserver ; 13 import java.text.AttributedCharacterIterator ; 14 15 87 public abstract class Graphics { 88 89 101 protected Graphics() { 102 } 103 104 110 public abstract Graphics create(); 111 112 146 public Graphics create(int x, int y, int width, int height) { 147 Graphics g = create(); 148 if (g == null) return null; 149 g.translate(x, y); 150 g.clipRect(0, 0, width, height); 151 return g; 152 } 153 154 165 public abstract void translate(int x, int y); 166 167 173 public abstract Color getColor(); 174 175 183 public abstract void setColor(Color c); 184 185 192 public abstract void setPaintMode(); 193 194 209 public abstract void setXORMode(Color c1); 210 211 217 public abstract Font getFont(); 218 219 229 public abstract void setFont(Font font); 230 231 239 public FontMetrics getFontMetrics() { 240 return getFontMetrics(getFont()); 241 } 242 243 251 public abstract FontMetrics getFontMetrics(Font f); 252 253 254 271 public abstract Rectangle getClipBounds(); 272 273 292 public abstract void clipRect(int x, int y, int width, int height); 293 294 309 public abstract void setClip(int x, int y, int width, int height); 310 311 327 public abstract Shape getClip(); 328 329 345 public abstract void setClip(Shape clip); 346 347 366 public abstract void copyArea(int x, int y, int width, int height, 367 int dx, int dy); 368 369 378 public abstract void drawLine(int x1, int y1, int x2, int y2); 379 380 399 public abstract void fillRect(int x, int y, int width, int height); 400 401 417 public void drawRect(int x, int y, int width, int height) { 418 if ((width < 0) || (height < 0)) { 419 return; 420 } 421 422 if (height == 0 || width == 0) { 423 drawLine(x, y, x + width, y + height); 424 } else { 425 drawLine(x, y, x + width - 1, y); 426 drawLine(x + width, y, x + width, y + height - 1); 427 drawLine(x + width, y + height, x + 1, y + height); 428 drawLine(x, y + height, x, y + 1); 429 } 430 } 431 432 451 public abstract void clearRect(int x, int y, int width, int height); 452 453 469 public abstract void drawRoundRect(int x, int y, int width, int height, 470 int arcWidth, int arcHeight); 471 472 488 public abstract void fillRoundRect(int x, int y, int width, int height, 489 int arcWidth, int arcHeight); 490 491 510 public void draw3DRect(int x, int y, int width, int height, 511 boolean raised) { 512 Color c = getColor(); 513 Color brighter = c.brighter(); 514 Color darker = c.darker(); 515 516 setColor(raised ? brighter : darker); 517 drawLine(x, y, x, y + height); 518 drawLine(x + 1, y, x + width - 1, y); 519 setColor(raised ? darker : brighter); 520 drawLine(x + 1, y + height, x + width, y + height); 521 drawLine(x + width, y, x + width, y + height - 1); 522 setColor(c); 523 } 524 525 540 public void fill3DRect(int x, int y, int width, int height, 541 boolean raised) { 542 Color c = getColor(); 543 Color brighter = c.brighter(); 544 Color darker = c.darker(); 545 546 if (!raised) { 547 setColor(darker); 548 } 549 fillRect(x+1, y+1, width-2, height-2); 550 setColor(raised ? brighter : darker); 551 drawLine(x, y, x, y + height - 1); 552 drawLine(x + 1, y, x + width - 2, y); 553 setColor(raised ? darker : brighter); 554 drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1); 555 drawLine(x + width - 1, y, x + width - 1, y + height - 2); 556 setColor(c); 557 } 558 559 576 public abstract void drawOval(int x, int y, int width, int height); 577 578 589 public abstract void fillOval(int x, int y, int width, int height); 590 591 628 public abstract void drawArc(int x, int y, int width, int height, 629 int startAngle, int arcAngle); 630 631 667 public abstract void fillArc(int x, int y, int width, int height, 668 int startAngle, int arcAngle); 669 670 682 public abstract void drawPolyline(int xPoints[], int yPoints[], 683 int nPoints); 684 685 704 public abstract void drawPolygon(int xPoints[], int yPoints[], 705 int nPoints); 706 707 714 public void drawPolygon(Polygon p) { 715 drawPolygon(p.xpoints, p.ypoints, p.npoints); 716 } 717 718 738 public abstract void fillPolygon(int xPoints[], int yPoints[], 739 int nPoints); 740 741 750 public void fillPolygon(Polygon p) { 751 fillPolygon(p.xpoints, p.ypoints, p.npoints); 752 } 753 754 765 public abstract void drawString(String str, int x, int y); 766 767 779 public abstract void drawString(AttributedCharacterIterator iterator, 780 int x, int y); 781 782 795 public void drawChars(char data[], int offset, int length, int x, int y) { 796 drawString(new String (data, offset, length), x, y); 797 } 798 799 812 public void drawBytes(byte data[], int offset, int length, int x, int y) { 813 drawString(new String (data, 0, offset, length), x, y); 814 } 815 816 848 public abstract boolean drawImage(Image img, int x, int y, 849 ImageObserver observer); 850 851 887 public abstract boolean drawImage(Image img, int x, int y, 888 int width, int height, 889 ImageObserver observer); 890 891 929 public abstract boolean drawImage(Image img, int x, int y, 930 Color bgcolor, 931 ImageObserver observer); 932 933 974 public abstract boolean drawImage(Image img, int x, int y, 975 int width, int height, 976 Color bgcolor, 977 ImageObserver observer); 978 979 1029 public abstract boolean drawImage(Image img, 1030 int dx1, int dy1, int dx2, int dy2, 1031 int sx1, int sy1, int sx2, int sy2, 1032 ImageObserver observer); 1033 1034 1090 public abstract boolean drawImage(Image img, 1091 int dx1, int dy1, int dx2, int dy2, 1092 int sx1, int sy1, int sx2, int sy2, 1093 Color bgcolor, 1094 ImageObserver observer); 1095 1096 1123 public abstract void dispose(); 1124 1125 1129 public void finalize() { 1130 dispose(); 1131 } 1132 1133 1138 public String toString() { 1139 return getClass().getName() + "[font=" + getFont() + ",color=" + getColor() + "]"; 1140 } 1141 1142 1149 @Deprecated 1150 public Rectangle getClipRect() { 1151 return getClipBounds(); 1152 } 1153 1154 1180 public boolean hitClip(int x, int y, int width, int height) { 1181 Rectangle clipRect = getClipBounds(); 1185 if (clipRect == null) { 1186 return true; 1187 } 1188 return clipRect.intersects(x, y, width, height); 1189 } 1190 1191 1207 public Rectangle getClipBounds(Rectangle r) { 1208 Rectangle clipRect = getClipBounds(); 1212 if (clipRect != null) { 1213 r.x = clipRect.x; 1214 r.y = clipRect.y; 1215 r.width = clipRect.width; 1216 r.height = clipRect.height; 1217 } else if (r == null) { 1218 throw new NullPointerException ("null rectangle parameter"); 1219 } 1220 return r; 1221 } 1222} 1223 | Popular Tags |