daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public final class IndirectCanvas extends PixelCanvas implements ImageProducer, ImageObserver {
  2.     private ColorModel model;
  3.     private ImageConsumer consumer;
  4.  
  5.     public synchronized void addConsumer(ImageConsumer ic) {
  6.         consumer = ic;
  7.         ic.setDimensions(width, height);
  8.         ic.setProperties(null);
  9.         ic.setColorModel(model);
  10.         ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES | ImageConsumer.SINGLEPASS);
  11.     }
  12.  
  13.     public synchronized boolean isConsumer(ImageConsumer ic) {
  14.         return ic == consumer;
  15.     }
  16.  
  17.     public synchronized void notifyConsumer(int x, int y, int w, int h) {
  18.         if(consumer != null) {
  19.             consumer.setPixels(x, y, w, h, model, pixels, 0, width);
  20.             consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
  21.         }
  22.     }
  23.  
  24.     public synchronized void notifyConsumer() {
  25.         if(consumer != null) {
  26.             consumer.setPixels(0, 0, width, height, model, pixels, 0, width);
  27.             consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
  28.         }
  29.     }
  30.  
  31.     public synchronized void removeConsumer(ImageConsumer ic) {
  32.         if(ic == consumer)
  33.             consumer = null;
  34.     }
  35.  
  36.     public void draw(Graphics graphics, int x, int y, int w, int h) {
  37.         notifyConsumer(x, y, w, h);
  38.         Shape old_clip = graphics.getClip();
  39.         graphics.clipRect(x, y, w, h);
  40.         graphics.drawImage(render, 0, 0, this);
  41.         graphics.setClip(old_clip);
  42.     }
  43.  
  44.     public void draw(Graphics graphics, int x, int y) {
  45.         notifyConsumer();
  46.         graphics.drawImage(render, x, y, this);
  47.     }
  48.  
  49.     public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
  50.         return true;
  51.     }
  52.  
  53.     public void prepare(Component c, int w, int h) {
  54.         width = w;
  55.         height = h;
  56.         pixels = new int[w * h + 1];
  57.         model = new DirectColorModel(32, 0xff0000, 0xff00, 0xff);
  58.         render = c.createImage(this);
  59.  
  60.         // I still have noi idea why this is done 3 times...
  61.         notifyConsumer();
  62.         c.prepareImage(render, this);
  63.         notifyConsumer();
  64.         c.prepareImage(render, this);
  65.         notifyConsumer();
  66.         c.prepareImage(render, this);
  67.         // initDrawingArea();
  68.     }
  69.  
  70.     public void requestTopDownLeftRightResend(ImageConsumer ic) {
  71.     }
  72.  
  73.     public void startProduction(ImageConsumer ic) {
  74.         addConsumer(ic);
  75.     }
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top