Changeset 12495 in josm for trunk/src/org
- Timestamp:
- 2017-07-23T01:09:45+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Changeset.java
r12494 r12495 23 23 * @since 625 24 24 */ 25 public final class Changeset implements Tagged {25 public final class Changeset implements Tagged, Comparable<Changeset> { 26 26 27 27 /** The maximum changeset tag length allowed by API 0.6 **/ … … 120 120 * a value greater than {@code 0} if {@code getId() > other.getId()} 121 121 */ 122 @Override 122 123 public int compareTo(Changeset other) { 123 124 return Integer.compare(getId(), other.getId()); -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java
r11713 r12495 635 635 public void actionPerformed(ActionEvent e) { 636 636 Window parent = GuiHelper.getWindowAncestorFor(e); 637 JosmUserIdentityManager im = JosmUserIdentityManager.getInstance(); 638 if (im.isAnonymous()) { 637 try { 638 ChangesetQuery query = ChangesetQuery.forCurrentUser(); 639 if (!GraphicsEnvironment.isHeadless()) { 640 ChangesetCacheManager.getInstance().runDownloadTask(new ChangesetQueryTask(parent, query)); 641 } 642 } catch (IllegalStateException ex) { 639 643 alertAnonymousUser(parent); 640 return; 641 } 642 ChangesetQuery query = new ChangesetQuery(); 643 if (im.isFullyIdentified()) { 644 query = query.forUser(im.getUserId()); 645 } else { 646 query = query.forUser(im.getUserName()); 647 } 648 if (!GraphicsEnvironment.isHeadless()) { 649 ChangesetCacheManager.getInstance().runDownloadTask(new ChangesetQueryTask(parent, query)); 644 Main.trace(ex); 650 645 } 651 646 } … … 695 690 696 691 /** 692 * Returns the changeset cache model. 693 * @return the changeset cache model 694 * @since 12495 695 */ 696 public ChangesetCacheManagerModel getModel() { 697 return model; 698 } 699 700 /** 697 701 * Selects the changesets in <code>changests</code>, provided the 698 702 * respective changesets are already present in the local changeset cache. -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java
r12297 r12495 139 139 140 140 @Override 141 public Object getValueAt(int row, int column) {141 public Changeset getValueAt(int row, int column) { 142 142 return data.get(row); 143 143 } -
trunk/src/org/openstreetmap/josm/gui/download/BookmarkList.java
r10627 r12495 5 5 6 6 import java.awt.Component; 7 import java.awt.GraphicsEnvironment; 7 8 import java.util.ArrayList; 8 9 import java.util.Arrays; 9 10 import java.util.Collection; 10 11 import java.util.Collections; 12 import java.util.Comparator; 11 13 import java.util.LinkedList; 12 14 import java.util.List; … … 15 17 16 18 import javax.swing.DefaultListModel; 19 import javax.swing.ImageIcon; 17 20 import javax.swing.JLabel; 18 21 import javax.swing.JList; … … 21 24 22 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.actions.downloadtasks.ChangesetQueryTask; 23 27 import org.openstreetmap.josm.data.Bounds; 28 import org.openstreetmap.josm.data.coor.LatLon; 29 import org.openstreetmap.josm.data.osm.Changeset; 30 import org.openstreetmap.josm.data.osm.UserInfo; 31 import org.openstreetmap.josm.data.preferences.IntegerProperty; 32 import org.openstreetmap.josm.data.projection.Projection; 33 import org.openstreetmap.josm.data.projection.Projections; 34 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 35 import org.openstreetmap.josm.gui.MapViewState; 36 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetCacheManager; 37 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; 38 import org.openstreetmap.josm.gui.util.GuiHelper; 39 import org.openstreetmap.josm.io.ChangesetQuery; 24 40 import org.openstreetmap.josm.tools.ImageProvider; 41 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; 25 42 26 43 /** … … 31 48 32 49 /** 50 * The maximum number of changeset bookmarks to maintain in list. 51 * @since 12495 52 */ 53 public static final IntegerProperty MAX_CHANGESET_BOOKMARKS = new IntegerProperty("bookmarks.changesets.max-entries", 15); 54 55 /** 33 56 * Class holding one bookmarkentry. 34 57 */ … … 36 59 private String name; 37 60 private Bounds area; 61 private ImageIcon icon; 38 62 39 63 /** … … 48 72 if (array.size() < 5) 49 73 throw new IllegalArgumentException(tr("Wrong number of arguments for bookmark")); 74 icon = ImageProvider.get("dialogs", "bookmark"); 50 75 name = array.get(0); 51 76 area = new Bounds(Double.parseDouble(array.get(1)), Double.parseDouble(array.get(2)), … … 57 82 */ 58 83 public Bookmark() { 59 area = null; 60 name = null; 84 this(null, null); 61 85 } 62 86 … … 66 90 */ 67 91 public Bookmark(Bounds area) { 92 this(null, area); 93 } 94 95 /** 96 * Constructs a new {@code Bookmark} for the given name and area. 97 * @param name The bookmark name 98 * @param area The bookmark area 99 * @since 12495 100 */ 101 protected Bookmark(String name, Bounds area) { 102 this.icon = ImageProvider.get("dialogs", "bookmark"); 103 this.name = name; 68 104 this.area = area; 69 105 } 70 106 71 @Override public String toString() { 107 @Override 108 public String toString() { 72 109 return name; 73 110 } … … 89 126 Bookmark bookmark = (Bookmark) obj; 90 127 return Objects.equals(name, bookmark.name) && 91 128 Objects.equals(area, bookmark.area); 92 129 } 93 130 … … 122 159 public void setArea(Bounds area) { 123 160 this.area = area; 161 } 162 163 /** 164 * Returns the bookmark icon. 165 * @return the bookmark icon 166 * @since 12495 167 */ 168 public ImageIcon getIcon() { 169 return icon; 170 } 171 172 /** 173 * Sets the bookmark icon. 174 * @param icon the bookmark icon 175 * @since 12495 176 */ 177 public void setIcon(ImageIcon icon) { 178 this.icon = icon; 179 } 180 } 181 182 /** 183 * A specific optional bookmark for the "home location" configured on osm.org website. 184 * @since 12495 185 */ 186 public static class HomeLocationBookmark extends Bookmark { 187 /** 188 * Constructs a new {@code HomeLocationBookmark}. 189 */ 190 public HomeLocationBookmark() { 191 setName(tr("Home location")); 192 setIcon(ImageProvider.get("help", "home", ImageSizes.SMALLICON)); 193 UserInfo info = JosmUserIdentityManager.getInstance().getUserInfo(); 194 if (info == null) { 195 throw new IllegalStateException("User not identified"); 196 } 197 LatLon home = info.getHome(); 198 if (home == null) { 199 throw new IllegalStateException("User home location not set"); 200 } 201 int zoom = info.getHomeZoom(); 202 if (zoom <= 3) { 203 // 3 is the default zoom level in OSM database, but the real zoom level was not correct 204 // for a long time, see https://github.com/openstreetmap/openstreetmap-website/issues/1592 205 zoom = 12; 206 } 207 Projection mercator = Projections.getProjectionByCode("EPSG:3857"); 208 setArea(MapViewState.createDefaultState(430, 400) // Size of map on osm.org user profile settings 209 .usingProjection(mercator) 210 .usingScale(Selector.GeneralSelector.level2scale(zoom) / 100) 211 .usingCenter(mercator.latlon2eastNorth(home)) 212 .getViewArea() 213 .getLatLonBoundsBox()); 214 } 215 } 216 217 /** 218 * A specific optional bookmark for the boundaries of recent changesets. 219 * @since 12495 220 */ 221 public static class ChangesetBookmark extends Bookmark { 222 /** 223 * Constructs a new {@code ChangesetBookmark}. 224 * @param cs changeset 225 */ 226 public ChangesetBookmark(Changeset cs) { 227 setName(String.format("%d - %tF - %s", cs.getId(), cs.getCreatedAt(), cs.getComment())); 228 setIcon(ImageProvider.get("data", "changeset", ImageSizes.SMALLICON)); 229 setArea(cs.getBounds()); 124 230 } 125 231 } … … 136 242 137 243 /** 138 * Loads the bookmarks from file. 244 * Loads the home location bookmark from OSM API, 245 * the manual bookmarks from preferences file, 246 * the changeset bookmarks from changeset cache. 139 247 */ 140 248 public final void load() { 141 DefaultListModel<Bookmark> model = (DefaultListModel<Bookmark>) getModel();249 final DefaultListModel<Bookmark> model = (DefaultListModel<Bookmark>) getModel(); 142 250 model.removeAllElements(); 251 JosmUserIdentityManager im = JosmUserIdentityManager.getInstance(); 252 // Add home location bookmark first, if user fully identified 253 if (im.isFullyIdentified()) { 254 try { 255 model.addElement(new HomeLocationBookmark()); 256 } catch (IllegalStateException e) { 257 Main.info(e.getMessage()); 258 Main.trace(e); 259 } 260 } 261 // Then add manual bookmarks previously saved in local preferences 143 262 Collection<Collection<String>> args = Main.pref.getArray("bookmarks", null); 144 263 if (args != null) { … … 156 275 } 157 276 } 158 } 159 160 /** 161 * Saves all bookmarks to the preferences file 277 // Finally add recent changeset bookmarks, if user name is known 278 final int n = MAX_CHANGESET_BOOKMARKS.get(); 279 if (n > 0 && !im.isAnonymous()) { 280 final ChangesetCacheManager ccm = ChangesetCacheManager.getInstance(); 281 final int userId = im.getUserInfo().getId(); 282 int found = 0; 283 for (int i = 0; i < ccm.getModel().getRowCount() && found < n; i++) { 284 Changeset cs = ccm.getModel().getValueAt(i, 0); 285 if (cs.getUser().getId() == userId && cs.getBounds() != null) { 286 model.addElement(new ChangesetBookmark(cs)); 287 found++; 288 } 289 } 290 } 291 } 292 293 /** 294 * Saves all manual bookmarks to the preferences file. 162 295 */ 163 296 public final void save() { 164 297 List<Collection<String>> coll = new LinkedList<>(); 165 298 for (Object o : ((DefaultListModel<Bookmark>) getModel()).toArray()) { 299 if (o instanceof HomeLocationBookmark || o instanceof ChangesetBookmark) { 300 continue; 301 } 166 302 String[] array = new String[5]; 167 303 Bookmark b = (Bookmark) o; … … 177 313 } 178 314 315 /** 316 * Refreshes the changeset bookmarks. 317 * @since 12495 318 */ 319 public void refreshChangesetBookmarks() { 320 final int n = MAX_CHANGESET_BOOKMARKS.get(); 321 if (n > 0) { 322 final DefaultListModel<Bookmark> model = (DefaultListModel<Bookmark>) getModel(); 323 for (int i = model.getSize() - 1; i >= 0; i--) { 324 if (model.get(i) instanceof ChangesetBookmark) { 325 model.remove(i); 326 } 327 } 328 ChangesetQuery query = ChangesetQuery.forCurrentUser(); 329 if (!GraphicsEnvironment.isHeadless()) { 330 final ChangesetQueryTask task = new ChangesetQueryTask(this, query); 331 ChangesetCacheManager.getInstance().runDownloadTask(task); 332 Main.worker.submit(() -> { 333 if (task.isCanceled() || task.isFailed()) 334 return; 335 GuiHelper.runInEDT(() -> task.getDownloadedData().stream() 336 .filter(cs -> cs.getBounds() != null) 337 .sorted(Comparator.reverseOrder()) 338 .limit(n) 339 .forEachOrdered(cs -> model.addElement(new ChangesetBookmark(cs)))); 340 }); 341 } 342 } 343 } 344 179 345 static class BookmarkCellRenderer extends JLabel implements ListCellRenderer<BookmarkList.Bookmark> { 180 346 … … 184 350 BookmarkCellRenderer() { 185 351 setOpaque(true); 186 setIcon(ImageProvider.get("dialogs", "bookmark"));187 352 } 188 353 … … 200 365 Bounds area = b.getArea(); 201 366 StringBuilder sb = new StringBuilder(128); 202 sb.append("<html>min[latitude,longitude]=<strong>[") 203 .append(area.getMinLat()).append(',').append(area.getMinLon()).append("]</strong>"+ 204 "<br>max[latitude,longitude]=<strong>[") 205 .append(area.getMaxLat()).append(',').append(area.getMaxLon()).append("]</strong>"+ 206 "</html>"); 367 if (area != null) { 368 sb.append("<html>min[latitude,longitude]=<strong>[") 369 .append(area.getMinLat()).append(',').append(area.getMinLon()).append("]</strong>"+ 370 "<br>max[latitude,longitude]=<strong>[") 371 .append(area.getMaxLat()).append(',').append(area.getMaxLon()).append("]</strong>"+ 372 "</html>"); 373 } 207 374 return sb.toString(); 208 375 } … … 212 379 boolean cellHasFocus) { 213 380 renderColor(isSelected); 381 setIcon(value.getIcon()); 214 382 setText(value.getName()); 215 383 setToolTipText(buildToolTipText(value)); -
trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java
r10634 r12495 24 24 import org.openstreetmap.josm.Main; 25 25 import org.openstreetmap.josm.data.Bounds; 26 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 26 27 import org.openstreetmap.josm.gui.download.BookmarkList.Bookmark; 27 28 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; … … 69 70 bookmarks.addListSelectionListener(renameAction); 70 71 pnl.add(new JButton(renameAction), gc); 72 73 gc.gridy = 2; 74 RefreshAction refreshAction = new RefreshAction(); 75 pnl.add(new JButton(refreshAction), gc); 71 76 72 77 gc.fill = GridBagConstraints.BOTH; … … 278 283 } 279 284 285 class RefreshAction extends AbstractAction { 286 /** 287 * Constructs a new {@code RefreshAction}. 288 */ 289 RefreshAction() { 290 putValue(SMALL_ICON, ImageProvider.get("dialogs/changeset", "downloadchangeset")); 291 putValue(SHORT_DESCRIPTION, tr("Download bookmarks for my {0} last changesets", BookmarkList.MAX_CHANGESET_BOOKMARKS.get())); 292 setEnabled(!JosmUserIdentityManager.getInstance().isAnonymous()); 293 } 294 295 @Override 296 public void actionPerformed(ActionEvent e) { 297 bookmarks.refreshChangesetBookmarks(); 298 } 299 } 300 280 301 class DoubleClickAdapter extends MouseAdapter { 281 302 @Override -
trunk/src/org/openstreetmap/josm/io/ChangesetQuery.java
r12470 r12495 19 19 import org.openstreetmap.josm.data.Bounds; 20 20 import org.openstreetmap.josm.data.coor.LatLon; 21 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 21 22 import org.openstreetmap.josm.tools.CheckParameterUtil; 22 23 import org.openstreetmap.josm.tools.Utils; … … 61 62 public static ChangesetQuery buildFromUrlQuery(String query) throws ChangesetQueryUrlException { 62 63 return new ChangesetQueryUrlParser().parse(query); 64 } 65 66 /** 67 * Replies a changeset query object restricted to the current user, if known. 68 * @return a changeset query object restricted to the current user, if known 69 * @throws IllegalStateException if current user is anonymous 70 * @since 12495 71 */ 72 public static ChangesetQuery forCurrentUser() { 73 JosmUserIdentityManager im = JosmUserIdentityManager.getInstance(); 74 if (im.isAnonymous()) { 75 throw new IllegalStateException("anonymous user"); 76 } 77 ChangesetQuery query = new ChangesetQuery(); 78 if (im.isFullyIdentified()) { 79 return query.forUser(im.getUserId()); 80 } else { 81 return query.forUser(im.getUserName()); 82 } 63 83 } 64 84 -
trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java
r10212 r12495 153 153 throwException(tr("Illegal value for attribute ''{0}''. Got ''{1}''.", "max_lat", maxLatStr)); 154 154 } 155 current.setMax(new LatLon(maxL on, maxLat));155 current.setMax(new LatLon(maxLat, maxLon)); 156 156 } 157 157
Note:
See TracChangeset
for help on using the changeset viewer.