/* */ package NET.worlds.console; /* */ /* */ import NET.worlds.network.URL; /* */ import NET.worlds.scape.BGLoaded; /* */ import NET.worlds.scape.BackgroundLoader; /* */ import NET.worlds.scape.Room; /* */ import java.awt.Component; /* */ import java.awt.Dimension; /* */ import java.awt.Graphics; /* */ import java.awt.Image; /* */ import java.awt.MediaTracker; /* */ import java.awt.Toolkit; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class ImageCanvas /* */ extends Component /* */ implements BGLoaded /* */ { /* */ private static final long serialVersionUID = 1687513733496926512L; /* */ protected URL imageURL_; /* */ protected Image image_; /* */ protected boolean loaded_; /* */ protected Dimension dim_; /* 36 */ protected static final URL defaultImageURL = URL.make("home:..\\default.gif"); /* */ /* */ /* */ /* */ public ImageCanvas(URL inURL) /* */ { /* 42 */ setNewImage(inURL); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ protected ImageCanvas() {} /* */ /* */ /* */ /* */ /* */ /* */ /* */ public ImageCanvas(String nm) /* */ { /* 60 */ loadImage(nm); /* */ } /* */ /* */ private Image loadImage(String nm) { /* 64 */ this.imageURL_ = URL.make("home:" + nm); /* 65 */ this.image_ = loadLocalImage(this.imageURL_.unalias()); /* 66 */ if (this.image_ == null) { /* 67 */ this.imageURL_ = URL.make("home:..\\" + nm); /* 68 */ this.image_ = loadLocalImage(this.imageURL_.unalias()); /* */ } /* 70 */ if (this.image_ == null) /* */ { /* 72 */ setNewImage(URL.make(nm)); /* */ } /* */ /* 75 */ return this.image_; /* */ } /* */ /* */ /* */ /* */ /* */ public void setNewImage(URL newImageURL, Graphics g) /* */ { /* 83 */ setNewImage(newImageURL); /* */ } /* */ /* */ public void setNewImage(URL newImageURL) { /* 87 */ this.imageURL_ = newImageURL; /* 88 */ flushImage(); /* 89 */ this.loaded_ = false; /* 90 */ loadRemoteImage(); /* */ } /* */ /* */ protected void flushImage() { /* 94 */ if (this.image_ != null) { /* 95 */ this.image_.flush(); /* 96 */ this.image_ = null; /* */ } /* */ } /* */ /* */ public void update(Graphics g) /* */ { /* 102 */ if (g != null) { /* 103 */ Dimension d = getSize(); /* 104 */ if ((this.image_ == null) || (d.width > this.dim_.width) || /* 105 */ (d.height > this.dim_.height)) /* 106 */ super.update(g); /* 107 */ paint(g); /* */ } /* */ } /* */ /* */ public void paint(Graphics g) /* */ { /* 113 */ if ((this.image_ != null) && (g != null)) /* 114 */ g.drawImage(this.image_, 0, 0, this); /* */ } /* */ /* */ public void paint(Graphics g, int x, int y) { /* 118 */ if ((this.image_ != null) && (g != null)) /* 119 */ g.drawImage(this.image_, x, y, this); /* */ } /* */ /* */ public Dimension imageSize() { /* 123 */ if (this.image_ == null) /* */ { /* 125 */ this.dim_ = new Dimension(0, 0); /* */ } else { /* 127 */ int width = this.image_.getWidth(this); /* 128 */ int height = this.image_.getHeight(this); /* 129 */ if ((width != -1) && (height != -1)) { /* 130 */ this.dim_ = new Dimension(width, height); /* */ } /* */ } /* */ /* 134 */ return this.dim_; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public Object asyncBackgroundLoad(String localName, URL remoteURL) /* */ { /* 148 */ this.image_ = loadLocalImage(localName); /* 149 */ if (getGraphics() != null) { /* 150 */ update(getGraphics()); /* */ } /* 152 */ return localName; /* */ } /* */ /* */ public boolean syncBackgroundLoad(Object obj, URL remoteURL) /* */ { /* 157 */ String localName = (String)obj; /* 158 */ this.image_ = loadLocalImage(localName); /* 159 */ if (getGraphics() != null) { /* 160 */ update(getGraphics()); /* */ } /* 162 */ return false; /* */ } /* */ /* */ public Room getBackgroundLoadRoom() { /* 166 */ return null; /* */ } /* */ /* */ /* */ private void loadRemoteImage() /* */ { /* 172 */ this.image_ = loadLocalImage(defaultImageURL.unalias()); /* */ /* */ /* 175 */ if (this.imageURL_ != defaultImageURL) { /* 176 */ BackgroundLoader.get(this, this.imageURL_); /* */ } /* */ } /* */ /* */ private Image loadLocalImage(String fName) { /* 181 */ Image image = Toolkit.getDefaultToolkit().getImage(fName); /* */ /* 183 */ MediaTracker tracker = new MediaTracker(this); /* 184 */ tracker.addImage(image, 0); /* */ try { /* 186 */ tracker.waitForAll(); /* */ } /* */ catch (InterruptedException localInterruptedException) {} /* */ /* 190 */ if (!tracker.isErrorAny()) { /* 191 */ this.loaded_ = true; /* 192 */ return image; /* */ } /* */ /* 195 */ return null; /* */ } /* */ /* */ public static Image loadImage(URL url, Component comp) { /* 199 */ Image image = Toolkit.getDefaultToolkit().getImage(url.unalias()); /* */ /* */ /* 202 */ MediaTracker tracker = new MediaTracker(comp); /* 203 */ tracker.addImage(image, 0); /* */ try { /* 205 */ tracker.waitForAll(); /* */ } /* */ catch (InterruptedException localInterruptedException) {} /* */ /* 209 */ if (!tracker.isErrorAny()) { /* 210 */ return image; /* */ } /* 212 */ return null; /* */ } /* */ /* */ /* */ public static Image getSystemImage(String name, Component comp) /* */ { /* 218 */ for (int pass = 0; pass < 2; pass++) { /* 219 */ Image image = loadImage(URL.make("home:" + name), comp); /* 220 */ if (image != null) { /* 221 */ return image; /* */ } /* */ /* 224 */ if (pass == 0) /* 225 */ name = "..\\" + name; /* */ } /* 227 */ return null; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public Dimension getPreferredSize() /* */ { /* 244 */ return imageSize(); /* */ } /* */ /* */ public Dimension getMinimumSize() /* */ { /* 249 */ return imageSize(); /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\ImageCanvas.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */