1 package demo.notification.whiteboard; 2 3 4 5 import java.awt.Color ; 6 7 import org.apache.log.Logger; 8 9 import org.apache.log.Hierarchy; 10 11 12 13 20 21 22 23 public class BrushSizePixelImage extends PixelImage { 24 25 26 27 Logger logger_ = Hierarchy.getDefaultHierarchy().getLoggerFor("PixelImage"); 28 29 30 31 int brushSize = 1; 32 33 boolean brush = true; 34 35 int width, height; 36 37 38 39 public void setBrushSize(int x) { 40 41 brushSize = x; 42 43 } 44 45 46 47 public int getBrushSize() { 48 49 return brushSize; 50 51 } 52 53 54 55 public BrushSizePixelImage(int width, int height) { 56 57 super(width, height); 58 59 60 61 logger_.debug("init"); 62 63 64 65 this.width = width; 66 67 this.height = height; 68 69 } 70 71 72 73 public void setArea(int x, int y, int r, int g, int b) { 74 75 for ( int xi = x - brushSize; xi <= x+brushSize; xi++ ) 76 77 for ( int yi = y - brushSize; yi<=y+brushSize; yi++) { 78 79 if ( xi >= 0 && yi >= 0 && xi < width && yi < height) 80 81 super.setPixel(xi,yi,r,g,b); 82 83 } 84 85 } 86 87 88 89 public void setPixel(int x, int y, int red, int green, int blue) { 90 91 Color color = new Color (red,green,blue); 92 93 if (brush) { 94 95 setArea(x,y,red,green,blue); 96 97 } else { 98 99 super.setPixel(x,y,red,green,blue); 100 101 } 102 103 } 104 105 106 107 public void clearAll() { 108 109 for(int x=0;x<width;x++) { 110 111 for(int y=0;y<height;y++) { 112 113 super.setPixel(x,y,0,0,0); 114 115 } 116 117 } 118 119 } 120 121 } 123 | Popular Tags |