Changeset 31838 in osm for applications/editors/josm/plugins
- Timestamp:
- 2015-12-16T17:17:00+01:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryDataListener.java
r31787 r31838 13 13 * Fired when any image is added to the database. 14 14 */ 15 publicvoid imagesAdded();15 void imagesAdded(); 16 16 17 17 /** … … 24 24 * New selected {@link MapillaryAbstractImage} 25 25 */ 26 publicvoid selectedImageChanged(MapillaryAbstractImage oldImage,26 void selectedImageChanged(MapillaryAbstractImage oldImage, 27 27 MapillaryAbstractImage newImage); 28 28 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java
r31811 r31838 97 97 98 98 @Override 99 public void selectedImageChanged(MapillaryAbstractImage oldImage, 100 MapillaryAbstractImage newImage) { 101 if (newImage != null) 102 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getWalkMenu(), true); 103 else 104 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getWalkMenu(), false); 99 public void selectedImageChanged(MapillaryAbstractImage oldImage, MapillaryAbstractImage newImage) { 100 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getWalkMenu(), newImage != null); 105 101 } 106 102 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkListener.java
r31787 r31838 16 16 * @param thread The thread executing the walk. 17 17 */ 18 publicvoid walkStarted(WalkThread thread);18 void walkStarted(WalkThread thread); 19 19 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java
r31797 r31838 23 23 private final int interval; 24 24 private final MapillaryData data; 25 private boolean end = false;25 private boolean end; 26 26 private final boolean waitForFullQuality; 27 27 private final boolean followSelected; 28 28 private final boolean goForward; 29 29 private BufferedImage lastImage; 30 private volatile boolean paused = false;30 private volatile boolean paused; 31 31 32 32 /** … … 61 61 // Predownload next 10 thumbnails. 62 62 for (int i = 0; i < 10; i++) { 63 if (image.next() == null) 63 if (image.next() == null) { 64 64 break; 65 } 65 66 image = image.next(); 66 CacheUtils.downloadPicture((MapillaryImage) image, 67 CacheUtils.PICTURE.THUMBNAIL); 67 CacheUtils.downloadPicture((MapillaryImage) image, CacheUtils.PICTURE.THUMBNAIL); 68 68 } 69 69 if (this.waitForFullQuality) 70 70 // Start downloading 3 next full images. 71 71 for (int i = 0; i < 3; i++) { 72 if (image.next() == null) 72 if (image.next() == null) { 73 73 break; 74 } 74 75 image = image.next(); 75 CacheUtils.downloadPicture((MapillaryImage) image, 76 CacheUtils.PICTURE.FULL_IMAGE); 76 CacheUtils.downloadPicture((MapillaryImage) image, CacheUtils.PICTURE.FULL_IMAGE); 77 77 } 78 78 } … … 80 80 synchronized (this) { 81 81 // Waits for full quality picture. 82 final BufferedImage displayImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay.getImage(); 82 83 if (this.waitForFullQuality && image instanceof MapillaryImage) { 83 while (MapillaryMainDialog.getInstance().mapillaryImageDisplay 84 .getImage() == this.lastImage 85 || MapillaryMainDialog.getInstance().mapillaryImageDisplay 86 .getImage() == null 87 || MapillaryMainDialog.getInstance().mapillaryImageDisplay 88 .getImage().getWidth() < 2048) 84 while ( displayImage == this.lastImage || displayImage == null || displayImage.getWidth() < 2048) { 89 85 wait(100); 86 } 90 87 } 91 88 // Waits for thumbnail. 92 89 else { 93 while (MapillaryMainDialog.getInstance().mapillaryImageDisplay 94 .getImage() == this.lastImage 95 || MapillaryMainDialog.getInstance().mapillaryImageDisplay 96 .getImage() == null 97 || MapillaryMainDialog.getInstance().mapillaryImageDisplay 98 .getImage().getWidth() < 320) 90 while (displayImage == this.lastImage || displayImage == null || displayImage.getWidth() < 320) { 99 91 wait(100); 92 } 100 93 } 101 while (this.paused) 94 while (this.paused) { 102 95 wait(100); 96 } 103 97 wait(this.interval); 104 while (this.paused) 98 while (this.paused) { 105 99 wait(100); 100 } 106 101 } 107 this.lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay 108 .getImage(); 102 this.lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay.getImage(); 109 103 synchronized (this) { 110 if (this.goForward) 104 if (this.goForward) { 111 105 this.data.selectNext(this.followSelected); 112 else106 } else { 113 107 this.data.selectPrevious(this.followSelected); 108 } 114 109 } 115 110 } catch (InterruptedException e) { … … 118 113 } 119 114 } catch (NullPointerException e) { 115 // TODO: Avoid NPEs instead of waiting until they are thrown and then catching them 120 116 return; 121 117 } … … 129 125 130 126 @Override 131 public void selectedImageChanged(MapillaryAbstractImage oldImage, 132 MapillaryAbstractImage newImage) { 127 public void selectedImageChanged(MapillaryAbstractImage oldImage, MapillaryAbstractImage newImage) { 133 128 if (newImage != oldImage.next()) { 134 129 end(); … … 155 150 */ 156 151 public void stopWalk() { 157 if (!SwingUtilities.isEventDispatchThread()) { 152 if (SwingUtilities.isEventDispatchThread()) { 153 end(); 154 this.interrupt(); 155 } else { 158 156 SwingUtilities.invokeLater(new Runnable() { 159 157 @Override … … 162 160 } 163 161 }); 164 } else {165 end();166 this.interrupt();167 162 } 168 163 } … … 172 167 */ 173 168 public void end() { 174 if (!SwingUtilities.isEventDispatchThread()) { 169 if (SwingUtilities.isEventDispatchThread()) { 170 this.end = true; 171 this.data.removeListener(this); 172 MapillaryMainDialog.getInstance().setMode(MapillaryMainDialog.MODE.NORMAL); 173 } else { 175 174 SwingUtilities.invokeLater(new Runnable() { 176 175 @Override … … 179 178 } 180 179 }); 181 } else {182 this.end = true;183 this.data.removeListener(this);184 MapillaryMainDialog.getInstance()185 .setMode(MapillaryMainDialog.MODE.NORMAL);186 180 } 187 181 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java
r31833 r31838 308 308 }); 309 309 } else if (this.image != null) { 310 StringBuilder title = new StringBuilder(tr(BASE_TITLE)); 310 311 if (this.image instanceof MapillaryImage) { 311 312 MapillaryImage mapillaryImage = (MapillaryImage) this.image; 312 String title = tr(BASE_TITLE);313 313 if (mapillaryImage.getUser() != null) 314 title += " -- " + mapillaryImage.getUser();314 title.append(" — ").append(mapillaryImage.getUser()); 315 315 if (mapillaryImage.getCapturedAt() != 0) 316 title += " -- " + mapillaryImage.getDate();317 setTitle(title );316 title.append(" — ").append(mapillaryImage.getDate()); 317 setTitle(title.toString()); 318 318 } else if (this.image instanceof MapillaryImportedImage) { 319 319 MapillaryImportedImage mapillaryImportedImage = (MapillaryImportedImage) this.image; 320 String title = tr(BASE_TITLE); 321 title += " -- " + mapillaryImportedImage.getFile().getName(); 322 title += " -- " + mapillaryImportedImage.getDate(); 323 setTitle(title); 320 title.append(" — ").append(mapillaryImportedImage.getFile().getName()); 321 title.append(" — ").append(mapillaryImportedImage.getDate()); 322 setTitle(title.toString()); 324 323 } 325 324 } … … 518 517 } else if (data != null && result == LoadResult.SUCCESS) { 519 518 try { 520 BufferedImage img = ImageIO.read(new ByteArrayInputStream(data 521 .getContent())); 522 if (img == null) 519 BufferedImage img = ImageIO.read(new ByteArrayInputStream(data.getContent())); 520 if (img == null) { 523 521 return; 524 if (this.mapillaryImageDisplay.getImage() == null) 522 } 523 if (this.mapillaryImageDisplay.getImage() == null) { 525 524 this.mapillaryImageDisplay.setImage(img); 526 else if (img.getHeight() > this.mapillaryImageDisplay.getImage() 527 .getHeight()) { 525 } else if (img.getHeight() > this.mapillaryImageDisplay.getImage().getHeight()) { 528 526 this.mapillaryImageDisplay.setImage(img); 529 527 } … … 563 561 panel.add(this.buttonsPanel, BorderLayout.NORTH); 564 562 createLayout(panel, true, null); 565 } else 563 } else { 566 564 createLayout(panel, true, buttons); 565 } 567 566 this.add(this.titleBar, BorderLayout.NORTH); 568 567 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java
r31836 r31838 15 15 import java.util.Date; 16 16 import java.util.List; 17 import java.util.Locale; 17 18 18 19 import javax.swing.SwingUtilities; … … 163 164 * @throws ParseException 164 165 */ 165 public static long getEpoch(String date, String format) 166 throws ParseException { 167 SimpleDateFormat formatter = new SimpleDateFormat(format); 166 public static long getEpoch(String date, String format) throws ParseException { 167 SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.UK); 168 168 Date dateTime = formatter.parse(date); 169 169 return dateTime.getTime(); … … 460 460 */ 461 461 public static void updateHelpText() { 462 String ret = ""; 463 if (PluginState.isDownloading()) 464 ret += tr("Downloading Mapillary images"); 465 else if (MapillaryLayer.getInstance().getData().size() > 0) 466 ret += tr("Total Mapillary images: {0}", 467 MapillaryLayer.getInstance().getData().size()); 468 else 469 ret += tr("No images found"); 470 if (MapillaryLayer.getInstance().mode != null) 471 ret += " -- " + tr(MapillaryLayer.getInstance().mode.toString()); 472 if (PluginState.isUploading()) 473 ret += " -- " + PluginState.getUploadString(); 462 StringBuilder ret = new StringBuilder(); 463 if (PluginState.isDownloading()) { 464 ret .append(tr("Downloading Mapillary images")); 465 } else if (MapillaryLayer.getInstance().getData().size() > 0) { 466 ret.append(tr("Total Mapillary images: {0}", MapillaryLayer.getInstance().getData().size())); 467 } else { 468 ret.append(tr("No images found")); 469 } 470 if (MapillaryLayer.getInstance().mode != null) { 471 ret.append(" — ").append(tr(MapillaryLayer.getInstance().mode.toString())); 472 } 473 if (PluginState.isUploading()) { 474 ret.append(" — ").append(PluginState.getUploadString()); 475 } 474 476 synchronized (MapillaryUtils.class) { 475 Main.map.statusLine.setHelpText(ret );477 Main.map.statusLine.setHelpText(ret.toString()); 476 478 } 477 479 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/PluginState.java
r31787 r31838 17 17 public class PluginState { 18 18 19 private static int runningDownloads = 0;19 private static int runningDownloads; 20 20 /** Images that have to be uploaded. */ 21 protected static int imagesToUpload = 0;21 protected static int imagesToUpload; 22 22 /** Images that have been uploaded. */ 23 public static int imagesUploaded = 0; 23 public static int imagesUploaded; 24 25 private PluginState() { 26 // Empty constructor to avoid instantiation 27 } 24 28 25 29 /** … … 77 81 public static void imageUploaded() { 78 82 imagesUploaded++; 79 if (imagesToUpload == imagesUploaded) { 80 if (Main.main != null) 83 if (imagesToUpload == imagesUploaded && Main.main != null) { 81 84 finishedUploadDialog(); 82 85 } … … 85 88 private static void finishedUploadDialog() { 86 89 if (!SwingUtilities.isEventDispatchThread()) { 90 JOptionPane pane = new JOptionPane(); 91 pane.setMessage(new FinishedUploadDialog()); 92 JDialog dlg = pane.createDialog(Main.parent, tr("Finished upload")); 93 dlg.setVisible(true); 94 } else { 87 95 SwingUtilities.invokeLater(new Runnable() { 88 96 @Override … … 91 99 } 92 100 }); 93 } else {94 JOptionPane pane = new JOptionPane();95 pane.setMessage(new FinishedUploadDialog());96 JDialog dlg = pane.createDialog(Main.parent, tr("Finished upload"));97 dlg.setVisible(true);98 101 } 99 102 } … … 105 108 */ 106 109 public static String getUploadString() { 107 return tr("Uploading: {0}", "(" + imagesUploaded + "/" + imagesToUpload 108 + ")"); 110 return tr("Uploading: {0}", "(" + imagesUploaded + "/" + imagesToUpload + ")"); 109 111 } 110 112 }
Note:
See TracChangeset
for help on using the changeset viewer.