home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.image;
-
- import java.awt.image.ImageObserver;
- import java.awt.image.ImageProducer;
- import java.util.Enumeration;
- import java.util.Hashtable;
-
- public abstract class Image extends java.awt.Image {
- ImageProducer source;
- InputStreamImageSource src;
- ImageInfoGrabber info;
- private int width = -1;
- private int height = -1;
- private Hashtable properties;
- private int availinfo;
- Hashtable representations = new Hashtable();
-
- protected Image() {
- }
-
- protected Image(int w, int h) {
- OffScreenImageSource osis = new OffScreenImageSource(w, h);
- this.source = osis;
- this.width = w;
- this.height = h;
- this.availinfo |= 3;
- ImageRepresentation ir = this.getImageRep(-1, -1);
- this.representations.put(w + "x" + h, ir);
- this.representations.put("-1x-1", ir);
- ir.setDimensions(w, h);
- ir.offscreenInit();
- osis.setImageRep(ir);
- }
-
- protected Image(ImageProducer is) {
- this.source = is;
- if (is instanceof InputStreamImageSource) {
- this.src = (InputStreamImageSource)is;
- }
-
- this.info = new ImageInfoGrabber(this);
- this.info.setupConsumer();
- }
-
- public ImageProducer getSource() {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- return this.source;
- }
-
- public int getWidth() {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if ((this.availinfo & 1) == 0) {
- this.reconstruct(1);
- }
-
- return this.width;
- }
-
- public synchronized int getWidth(ImageObserver iw) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if ((this.availinfo & 1) == 0) {
- this.addWatcher(iw, true);
- return -1;
- } else {
- return this.width;
- }
- }
-
- public int getHeight() {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if ((this.availinfo & 2) == 0) {
- this.reconstruct(2);
- }
-
- return this.height;
- }
-
- public synchronized int getHeight(ImageObserver iw) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if ((this.availinfo & 2) == 0) {
- this.addWatcher(iw, true);
- return -1;
- } else {
- return this.height;
- }
- }
-
- public Object getProperty(String name, ImageObserver observer) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if (this.properties == null) {
- this.addWatcher(observer, true);
- return null;
- } else {
- Object o = this.properties.get(name);
- if (o == null) {
- o = java.awt.Image.UndefinedProperty;
- }
-
- return o;
- }
- }
-
- public boolean hasError() {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- return (this.availinfo & 64) != 0;
- }
-
- public int check(ImageObserver iw) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if ((this.availinfo & 64) == 0 && (~this.availinfo & 7) != 0) {
- this.addWatcher(iw, false);
- }
-
- return this.availinfo;
- }
-
- public void preload(ImageObserver iw) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if ((this.availinfo & 32) == 0) {
- this.addWatcher(iw, true);
- }
-
- }
-
- private synchronized void addWatcher(ImageObserver iw, boolean load) {
- if ((this.availinfo & 64) != 0) {
- if (iw != null) {
- iw.imageUpdate(this, 192, -1, -1, -1, -1);
- }
-
- } else {
- if (this.info == null) {
- this.info = new ImageInfoGrabber(this);
- this.info.setupConsumer();
- }
-
- this.info.addWatcher(iw);
- if (load) {
- this.info.getInfo();
- }
-
- }
- }
-
- private synchronized void reconstruct(int flags) {
- if ((flags & ~this.availinfo) != 0) {
- if ((this.availinfo & 64) != 0) {
- return;
- }
-
- if (this.info == null) {
- this.info = new ImageInfoGrabber(this);
- }
-
- this.info.getInfo();
-
- while((flags & ~this.availinfo) != 0) {
- try {
- this.wait();
- } catch (InterruptedException var2) {
- Thread.currentThread().interrupt();
- return;
- }
-
- if ((this.availinfo & 64) != 0) {
- return;
- }
- }
- }
-
- }
-
- synchronized void addInfo(int newinfo) {
- this.availinfo |= newinfo;
- this.notifyAll();
- if ((~this.availinfo & 7) == 0) {
- this.info.stopInfo();
- }
-
- }
-
- void setDimensions(int w, int h) {
- this.width = w;
- this.height = h;
- this.addInfo(3);
- }
-
- void setProperties(Hashtable props) {
- if (props == null) {
- props = new Hashtable();
- }
-
- this.properties = props;
- this.addInfo(4);
- }
-
- synchronized void infoDone(int status) {
- if (status != 1 && (~this.availinfo & 3) == 0) {
- if ((this.availinfo & 4) == 0) {
- this.setProperties((Hashtable)null);
- }
-
- } else {
- this.addInfo(64);
- }
- }
-
- public void flush() {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if (!(this.source instanceof OffScreenImageSource)) {
- synchronized(this){}
-
- Enumeration enum;
- try {
- this.availinfo &= -65;
- enum = this.representations.elements();
- this.representations = new Hashtable();
- if (this.source instanceof InputStreamImageSource) {
- ((InputStreamImageSource)this.source).flush();
- }
- } catch (Throwable var4) {
- throw var4;
- }
-
- while(enum.hasMoreElements()) {
- ImageRepresentation ir = (ImageRepresentation)enum.nextElement();
- ir.abort();
- }
- }
-
- }
-
- protected ImageRepresentation getImageRep(int w, int h) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- String key = w + "x" + h;
- ImageRepresentation ir = (ImageRepresentation)this.representations.get(key);
- if (ir == null) {
- synchronized(this){}
-
- try {
- ir = (ImageRepresentation)this.representations.get(key);
- if (ir == null) {
- ir = new ImageRepresentation(this, w, h, 0);
- if (this.source instanceof OffScreenImageSource) {
- ir.offscreen = true;
- } else {
- this.representations.put(key, ir);
- }
- }
- } catch (Throwable var7) {
- throw var7;
- }
- }
-
- return ir;
- }
- }
-