summaryrefslogtreecommitdiff
path: root/NET/worlds/console/ImageCanvas.java
blob: e9cf62ddfa39b4db9383a331b271bb153bad4e25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*     */ 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
 */