home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / frei / vnc-java.arj / VNC-JAVA.ZIP / animatedMemoryImageSource.java next >
Encoding:
Java Source  |  1998-01-15  |  2.0 KB  |  79 lines

  1. //
  2. //  Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
  3. //
  4. //  This is free software; you can redistribute it and/or modify
  5. //  it under the terms of the GNU General Public License as published by
  6. //  the Free Software Foundation; either version 2 of the License, or
  7. //  (at your option) any later version.
  8. //
  9. //  This software is distributed in the hope that it will be useful,
  10. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //  GNU General Public License for more details.
  13. //
  14. //  You should have received a copy of the GNU General Public License
  15. //  along with this software; if not, write to the Free Software
  16. //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  17. //  USA.
  18. //
  19.  
  20. //
  21. // animatedMemoryImageSource.java
  22. //
  23.  
  24. import java.awt.image.*;
  25.  
  26. class animatedMemoryImageSource implements ImageProducer {
  27.   int width;
  28.   int height;
  29.   ColorModel cm;
  30.   byte[] pixels;
  31.   ImageConsumer ic;
  32.  
  33.   animatedMemoryImageSource(int w, int h, ColorModel c, byte[] p) {
  34.     width = w;
  35.     height = h;
  36.     cm = c;
  37.     pixels = p;
  38.   }
  39.  
  40.   public void addConsumer(ImageConsumer c) {
  41.     if (ic == c)
  42.       return;
  43.  
  44.     if (ic != null) {
  45.       ic.imageComplete(ImageConsumer.IMAGEERROR);
  46.     }
  47.  
  48.     ic = c;
  49.     ic.setDimensions(width, height);
  50.     ic.setColorModel(cm);
  51.     ic.setHints(ImageConsumer.RANDOMPIXELORDER);
  52.     ic.setPixels(0, 0, width, height, cm, pixels, 0, width);
  53.     ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
  54.   }
  55.  
  56.   public boolean isConsumer(ImageConsumer c) {
  57.     return (ic == c);
  58.   }
  59.  
  60.   public void removeConsumer(ImageConsumer c) {
  61.     if (ic == c)
  62.       ic = null;
  63.   }
  64.  
  65.   public void requestTopDownLeftRightResend(ImageConsumer c) {
  66.   }
  67.  
  68.   public void startProduction(ImageConsumer c) {
  69.     addConsumer(c);
  70.   }
  71.  
  72.   void newPixels(int x, int y, int w, int h) {
  73.     if (ic != null) {
  74.       ic.setPixels(x, y, w, h, cm, pixels, width * y + x, width);
  75.       ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
  76.     }
  77.   }
  78. }
  79.