1 36 37 40 41 import java.awt.Graphics ; 42 import java.awt.Image ; 43 import java.awt.image.*; 44 import java.util.StringTokenizer ; 45 import java.net.URL ; 46 import java.net.MalformedURLException ; 47 48 56 class ImageMapArea implements ImageObserver { 57 58 ImageMap parent; 59 60 int X; 61 62 int Y; 63 64 int W; 65 66 int H; 67 71 boolean entered = false; 72 73 boolean active = false; 74 75 80 Image hlImage; 81 82 87 String status; 88 89 98 public void init(ImageMap parent, String args) { 99 this.parent = parent; 100 StringTokenizer st = new StringTokenizer (args, ", "); 101 X = Integer.parseInt(st.nextToken()); 102 Y = Integer.parseInt(st.nextToken()); 103 W = Integer.parseInt(st.nextToken()); 104 H = Integer.parseInt(st.nextToken()); 105 if (st.hasMoreTokens()) { 106 handleArg(st.nextToken(",")); 107 } else { 108 handleArg(null); 109 } 110 makeImages(); 111 } 112 113 119 public void handleArg(String s) { 120 } 121 122 126 public void getMedia() { 127 } 128 129 134 public boolean animate() { 135 return false; 136 } 137 138 142 public void setHighlight(Image img) { 143 hlImage = img; 144 } 145 146 151 public void makeImages() { 152 setHighlight(parent.getHighlight(X, Y, W, H)); 153 } 154 155 159 public void repaint() { 160 parent.repaint(0, X, Y, W, H); 161 } 162 163 169 public boolean inside(int x, int y) { 170 return (x >= X && x < (X + W) && y >= Y && y < (Y + H)); 171 } 172 173 177 public void drawImage(Graphics g, Image img, int imgx, int imgy, 178 int x, int y, int w, int h) { 179 Graphics ng = g.create(); 180 try { 181 ng.clipRect(x, y, w, h); 182 ng.drawImage(img, imgx, imgy, this); 183 } finally { 184 ng.dispose(); 185 } 186 } 187 188 191 public boolean imageUpdate(Image img, int infoflags, 192 int x, int y, int width, int height) { 193 if (img == hlImage) { 194 return parent.imageUpdate(img, infoflags, x + X, y + Y, 195 width, height); 196 } else { 197 return (infoflags & (ALLBITS | ERROR)) == 0; 198 } 199 } 200 201 204 public void showStatus(String msg) { 205 status = msg; 206 parent.newStatus(); 207 } 208 209 216 public String getStatus(String prevmsg) { 217 return (prevmsg == null) ? status : prevmsg; 218 } 219 220 223 public void showDocument(URL u) { 224 parent.getAppletContext().showDocument(u); 225 } 226 227 233 public void highlight(Graphics g) { 234 } 235 236 242 public boolean checkEnter(int x, int y) { 243 if (!entered) { 244 entered = true; 245 enter(x, y); 246 } 247 return isTerminal(); 248 } 249 250 256 public void checkExit() { 257 if (entered) { 258 entered = false; 259 exit(); 260 } 261 } 262 263 269 public boolean isTerminal() { 270 return false; 271 } 272 273 278 public void enter(int x, int y) { 279 enter(); 280 } 281 282 287 public void enter() { 288 } 289 290 293 public void exit() { 294 } 295 296 304 public boolean press(int x, int y) { 305 return press(); 306 } 307 308 315 public boolean press() { 316 return isTerminal(); 317 } 318 319 328 public boolean lift(int x, int y) { 329 return lift(); 330 } 331 332 339 public boolean lift() { 340 return isTerminal(); 341 } 342 343 350 public boolean drag(int x, int y) { 351 return isTerminal(); 352 } 353 354 public String getAppletInfo() { 355 return "Title: ImageArea \nAuthor: Jim Graham \nThis class performs the basic functions that most ImageArea classes will need and delegates specific actions to the subclasses."; 356 } 357 } 358 359 | Popular Tags |