- Timestamp:
- 2009-12-12T15:09:44+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapView.java
r2512 r2617 381 381 382 382 Graphics2D tempG = offscreenBuffer.createGraphics(); 383 tempG.setClip(g.getClip()); 383 384 tempG.setColor(Main.pref.getColor("background", Color.BLACK)); 384 385 tempG.fillRect(0, 0, getWidth(), getHeight()); -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r2606 r2617 564 564 gc.fill = GridBagConstraints.NONE; 565 565 gc.weightx = gc.weighty = 0.0; 566 yLayer. loadThumbs = Main.pref.getBoolean("geoimage.showThumbs", false);567 JCheckBox cbShowThumbs = new JCheckBox(tr("Show Thumbnail images on the map"), yLayer. loadThumbs);566 yLayer.useThumbs = Main.pref.getBoolean("geoimage.showThumbs", false); 567 JCheckBox cbShowThumbs = new JCheckBox(tr("Show Thumbnail images on the map"), yLayer.useThumbs); 568 568 panelTf.add(cbShowThumbs, gc); 569 569 … … 635 635 } 636 636 637 yLayer. loadThumbs = cbShowThumbs.isSelected();637 yLayer.useThumbs = cbShowThumbs.isSelected(); 638 638 639 639 Main.pref.put("geoimage.doublegpstimezone", Double.toString(gpstimezone)); 640 640 Main.pref.put("geoimage.gpstimezone", Long.toString(- ((long) gpstimezone))); 641 641 Main.pref.put("geoimage.delta", Long.toString(delta * 1000)); 642 Main.pref.put("geoimage.showThumbs", yLayer. loadThumbs);642 Main.pref.put("geoimage.showThumbs", yLayer.useThumbs); 643 643 isOk = true; 644 644 645 if (yLayer. loadThumbs) {646 yLayer.thumbsloader = new ThumbsLoader(yLayer .data);645 if (yLayer.useThumbs) { 646 yLayer.thumbsloader = new ThumbsLoader(yLayer); 647 647 Thread t = new Thread(yLayer.thumbsloader); 648 648 t.setPriority(Thread.MIN_PRIORITY); -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r2606 r2617 9 9 import static org.openstreetmap.josm.tools.I18n.trn; 10 10 11 import java.awt.AlphaComposite; 12 import java.awt.Color; 11 13 import java.awt.Component; 14 import java.awt.Composite; 15 import java.awt.Dimension; 12 16 import java.awt.Graphics2D; 13 17 import java.awt.Image; … … 19 23 import java.awt.event.MouseEvent; 20 24 import java.awt.image.BufferedImage; 25 import java.beans.PropertyChangeListener; 26 import java.beans.PropertyChangeEvent; 21 27 import java.io.File; 22 28 import java.io.IOException; … … 56 62 import com.drew.metadata.exif.GpsDirectory; 57 63 58 public class GeoImageLayer extends Layer {64 public class GeoImageLayer extends Layer implements PropertyChangeListener { 59 65 60 66 List<ImageEntry> data; … … 71 77 public long timeoffset = 0; 72 78 73 boolean loadThumbs;79 boolean useThumbs = false; 74 80 ThumbsLoader thumbsloader; 81 private BufferedImage offscreenBuffer; 82 boolean updateOffscreenBuffer = true; 75 83 76 84 /* … … 295 303 Collections.sort(data); 296 304 this.data = data; 305 Main.map.mapView.addPropertyChangeListener(this); 297 306 } 298 307 … … 375 384 376 385 setName(l.getName()); 377 386 } 387 388 private Dimension scaledDimension(Image thumb) { 389 final double d = Main.map.mapView.getDist100Pixel(); 390 final double size = 40 /*meter*/; /* size of the photo on the map */ 391 double s = size * 100 /*px*/ / d; 392 393 final double sMin = ThumbsLoader.minSize; 394 final double sMax = ThumbsLoader.maxSize; 395 396 if (s < sMin) { 397 s = sMin; 398 } 399 if (s > sMax) { 400 s = sMax; 401 } 402 final double f = s / sMax; /* scale factor */ 403 404 if (thumb == null) 405 return null; 406 407 return new Dimension( 408 (int) Math.round(f * thumb.getWidth(null)), 409 (int) Math.round(f * thumb.getHeight(null))); 378 410 } 379 411 380 412 @Override 381 413 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 382 383 for (ImageEntry e : data) { 414 int width = Main.map.mapView.getWidth(); 415 int height = Main.map.mapView.getHeight(); 416 Rectangle clip = g.getClipBounds(); 417 if (useThumbs) { 418 if (null == offscreenBuffer || offscreenBuffer.getWidth() != width // reuse the old buffer if possible 419 || offscreenBuffer.getHeight() != height) { 420 offscreenBuffer = new BufferedImage(width, height, 421 BufferedImage.TYPE_INT_ARGB); 422 updateOffscreenBuffer = true; 423 } 424 425 if (updateOffscreenBuffer) { 426 Graphics2D tempG = offscreenBuffer.createGraphics(); 427 tempG.setColor(new Color(0,0,0,0)); 428 Composite saveComp = tempG.getComposite(); 429 tempG.setComposite(AlphaComposite.Clear); // remove the old images 430 tempG.fillRect(0, 0, width, height); 431 tempG.setComposite(saveComp); 432 433 for (ImageEntry e : data) { 434 if (e.pos == null) 435 continue; 436 Point p = mv.getPoint(e.pos); 437 if (e.thumbnail != null) { 438 Dimension d = scaledDimension(e.thumbnail); 439 Rectangle target = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); 440 if (clip.intersects(target)) { 441 tempG.drawImage(e.thumbnail, target.x, target.y, target.width, target.height, null); 442 } 443 } 444 else { // thumbnail not loaded yet 445 icon.paintIcon(mv, tempG, 446 p.x - icon.getIconWidth() / 2, 447 p.y - icon.getIconHeight() / 2); 448 } 449 } 450 updateOffscreenBuffer = false; 451 } 452 g.drawImage(offscreenBuffer, 0, 0, null); 453 } 454 else { 455 for (ImageEntry e : data) { 456 if (e.pos == null) 457 continue; 458 Point p = mv.getPoint(e.pos); 459 icon.paintIcon(mv, g, 460 p.x - icon.getIconWidth() / 2, 461 p.y - icon.getIconHeight() / 2); 462 } 463 } 464 465 if (currentPhoto >= 0 && currentPhoto < data.size()) { 466 ImageEntry e = data.get(currentPhoto); 467 384 468 if (e.pos != null) { 385 469 Point p = mv.getPoint(e.pos); 386 if (e.thumbnail != null && e.thumbnail.getWidth(null) > 0 && e.thumbnail.getHeight(null) > 0) { 387 g.drawImage(e.thumbnail, 388 p.x - e.thumbnail.getWidth(null) / 2, 389 p.y - e.thumbnail.getHeight(null) / 2, null); 390 } 391 else { 392 icon.paintIcon(mv, g, 393 p.x - icon.getIconWidth() / 2, 394 p.y - icon.getIconHeight() / 2); 395 } 396 } 397 } 398 399 // Draw the selection on top of the other pictures. 400 if (currentPhoto >= 0 && currentPhoto < data.size()) { 401 ImageEntry e = data.get(currentPhoto); 402 403 if (e.pos != null) { 404 Point p = mv.getPoint(e.pos); 405 406 Rectangle r = new Rectangle(p.x - selectedIcon.getIconWidth() / 2, 407 p.y - selectedIcon.getIconHeight() / 2, 408 selectedIcon.getIconWidth(), 409 selectedIcon.getIconHeight()); 410 selectedIcon.paintIcon(mv, g, r.x, r.y); 470 471 if (e.thumbnail != null) { 472 Dimension d = scaledDimension(e.thumbnail); 473 g.setColor(new Color(128, 0, 0, 122)); 474 g.fillRect(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); 475 } else { 476 selectedIcon.paintIcon(mv, g, 477 p.x - selectedIcon.getIconWidth() / 2, 478 p.y - selectedIcon.getIconHeight() / 2); 479 } 411 480 } 412 481 } … … 500 569 501 570 public void checkPreviousNextButtons() { 502 System.err.println("check:" + currentPhoto);571 // System.err.println("showing image " + currentPhoto); 503 572 ImageViewerDialog.setNextEnabled(currentPhoto < data.size() - 1); 504 573 ImageViewerDialog.setPreviousEnabled(currentPhoto > 0); … … 517 586 } 518 587 } 588 updateOffscreenBuffer = true; 519 589 Main.main.map.repaint(); 520 590 } … … 534 604 535 605 @Override public void mouseReleased(MouseEvent ev) { 536 537 606 if (ev.getButton() != MouseEvent.BUTTON1) { 538 607 return; … … 541 610 return; 542 611 } 543 544 ImageViewerDialog d = ImageViewerDialog.getInstance();545 612 546 613 for (int i = data.size() - 1; i >= 0; --i) { … … 549 616 continue; 550 617 Point p = Main.map.mapView.getPoint(e.pos); 551 Rectangle r = new Rectangle(p.x - icon.getIconWidth() / 2, 552 p.y - icon.getIconHeight() / 2, 553 icon.getIconWidth(), 554 icon.getIconHeight()); 618 Rectangle r; 619 if (e.thumbnail != null) { 620 Dimension d = scaledDimension(e.thumbnail); 621 r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); 622 } else { 623 r = new Rectangle(p.x - icon.getIconWidth() / 2, 624 p.y - icon.getIconHeight() / 2, 625 icon.getIconWidth(), 626 icon.getIconHeight()); 627 } 555 628 if (r.contains(ev.getPoint())) { 556 629 currentPhoto = i; … … 560 633 } 561 634 } 562 Main.map.mapView.repaint();563 635 } 564 636 }; … … 577 649 public void layerRemoved(Layer oldLayer) { 578 650 if (oldLayer == GeoImageLayer.this) { 651 if (thumbsloader != null) { 652 thumbsloader.stop = true; 653 } 579 654 Main.map.mapView.removeMouseListener(mouseAdapter); 580 655 currentPhoto = -1; … … 585 660 }); 586 661 } 587 588 @Override 589 public void destroy() { 590 if (thumbsloader != null) { 591 thumbsloader.stop = true; 662 663 public void propertyChange(PropertyChangeEvent evt) { 664 if ("center".equals(evt.getPropertyName()) || "scale".equals(evt.getPropertyName())) { 665 updateOffscreenBuffer = true; 592 666 } 593 667 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r2602 r2617 201 201 public void displayImage(GeoImageLayer layer, ImageEntry entry) { 202 202 synchronized(this) { 203 if (currentLayer == layer && currentEntry == entry) {204 repaint();205 return;206 } 203 // if (currentLayer == layer && currentEntry == entry) { 204 // repaint(); 205 // return; 206 // } TODO: pop up image dialog but don't load image again 207 207 208 208 if (centerView && Main.map != null && entry != null && entry.pos != null) { -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java
r2606 r2617 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.awt.MediaTracker;8 7 import java.awt.Graphics2D; 9 8 import java.awt.Image; 9 import java.awt.MediaTracker; 10 import java.awt.Rectangle; 10 11 import java.awt.Toolkit; 11 12 import java.awt.image.BufferedImage; … … 19 20 20 21 public class ThumbsLoader implements Runnable { 22 public static final int maxSize = 120; 23 public static final int minSize = 22; 21 24 volatile boolean stop = false; 22 25 List<ImageEntry> data; 26 GeoImageLayer layer; 23 27 MediaTracker tracker; 24 28 CacheFiles cache; 25 29 boolean cacheOff = Main.pref.getBoolean("geoimage.noThumbnailCache", false); 26 27 public ThumbsLoader(List<ImageEntry> data) { 28 this.data = new ArrayList<ImageEntry>(data); 30 31 public ThumbsLoader(GeoImageLayer layer) { 32 this.layer = layer; 33 this.data = new ArrayList<ImageEntry>(layer.data); 29 34 if (!cacheOff) { 30 35 cache = new CacheFiles("geoimage-thumbnails", false); … … 39 44 for (int i = 0; i < data.size(); i++) { 40 45 if (stop) return; 46 41 47 System.err.print("fetching image "+i); 48 42 49 data.get(i).thumbnail = loadThumb(data.get(i)); 50 43 51 if (Main.map != null && Main.map.mapView != null) { 52 try { 53 layer.updateOffscreenBuffer = true; 54 } catch (Exception e) {} 44 55 Main.map.mapView.repaint(); 45 56 } 46 57 } 47 (new Thread() { 58 try { 59 layer.updateOffscreenBuffer = true; 60 } catch (Exception e) {} 61 Main.map.mapView.repaint(); 62 (new Thread() { // clean up the garbage - shouldn't hurt 48 63 public void run() { 49 64 try { … … 56 71 57 72 } 58 73 59 74 private BufferedImage loadThumb(ImageEntry entry) { 60 final int size = 16; 61 final String cacheIdent = entry.file.toString()+":"+size; 62 75 final String cacheIdent = entry.file.toString()+":"+maxSize; 76 63 77 if (!cacheOff) { 64 78 BufferedImage cached = cache.getImg(cacheIdent); 65 79 if(cached != null) { 66 System.err.println(" from cache"); 80 System.err.println(" from cache"); 67 81 return cached; 68 82 } 69 83 } 70 84 71 85 Image img = Toolkit.getDefaultToolkit().createImage(entry.file.getPath()); 72 86 tracker.addImage(img, 0); … … 77 91 return null; 78 92 } 79 BufferedImage scaledBI = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); 93 if (tracker.isErrorID(1) || img.getWidth(null) <= 0 || img.getHeight(null) <= 0) { 94 System.err.println(" Invalid image"); 95 return null; 96 } 97 Rectangle targetSize = ImageDisplay.calculateDrawImageRectangle( 98 new Rectangle(0, 0, img.getWidth(null), img.getHeight(null)), 99 new Rectangle(0, 0, maxSize, maxSize)); 100 BufferedImage scaledBI = new BufferedImage(targetSize.width, targetSize.height, BufferedImage.TYPE_INT_RGB); 80 101 Graphics2D g = scaledBI.createGraphics(); 81 while (!g.drawImage(img, 0, 0, 16, 16, null))102 while (!g.drawImage(img, 0, 0, targetSize.width, targetSize.height, null)) 82 103 { 83 104 try { 84 105 Thread.sleep(10); 85 } catch(InterruptedException ie) {} //FIXME: timeout?106 } catch(InterruptedException ie) {} 86 107 } 87 108 g.dispose(); 88 109 tracker.removeImage(img); 89 90 if (!cacheOff && scaledBI != null && scaledBI.getWidth() > 0) { 110 111 if (scaledBI == null || scaledBI.getWidth() <= 0 || scaledBI.getHeight() <= 0) { 112 System.err.println(" Invalid image"); 113 return null; 114 } 115 116 if (!cacheOff) { 91 117 cache.saveImg(cacheIdent, scaledBI); 92 118 } 93 119 94 120 System.err.println(""); 95 121 return scaledBI;
Note:
See TracChangeset
for help on using the changeset viewer.