Ticket #6773: 6773.patch
| File 6773.patch, 20.2 KB (added by , 14 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/HistoryInfoAction.java
diff --git a/src/org/openstreetmap/josm/actions/HistoryInfoAction.java b/src/org/openstreetmap/josm/actions/HistoryInfoAction.java index 928335d..4d97f0b 100644
a b 1 1 //License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 import java.awt.event.ActionEvent; 6 5 import java.awt.event.KeyEvent; 6 import java.util.Collection; 7 7 8 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.data.osm.DataSet; 9 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 import org.openstreetmap.josm. data.osm.OsmPrimitiveType;11 import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager; 11 12 import org.openstreetmap.josm.tools.Shortcut; 13 14 import static org.openstreetmap.josm.tools.I18n.tr; 12 15 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 13 16 14 public class HistoryInfoAction extends AbstractInfoAction { 15 16 public HistoryInfoAction() { 17 super(tr("Object history"), "about", 18 tr("Display history information about OSM ways, nodes, or relations."), 19 Shortcut.registerShortcut("core:history", 20 tr("Object history"), KeyEvent.VK_H, Shortcut.GROUP_HOTKEY), false); 21 putValue("help", ht("/Action/ObjectHistory")); 22 putValue("toolbar", "action/historyinfo"); 23 Main.toolbar.register(this); 24 } 25 26 @Override 27 protected String createInfoUrl(Object infoObject) { 28 OsmPrimitive primitive = (OsmPrimitive)infoObject; 29 return getBaseBrowseUrl() + "/" + OsmPrimitiveType.from(primitive).getAPIName() + "/" + primitive.getId() + "/history"; 30 } 17 public class HistoryInfoAction extends JosmAction { 18 19 public HistoryInfoAction() { 20 super(tr("History"), "about", 21 tr("Display history information about OSM ways, nodes, or relations."), 22 Shortcut.registerShortcut("core:historyinfo", 23 tr("History"), KeyEvent.VK_H, Shortcut.GROUP_HOTKEY), false); 24 putValue("help", ht("/Action/ObjectHistory")); 25 putValue("toolbar", "action/historyinfo"); 26 Main.toolbar.register(this); 27 } 28 29 @Override 30 public void actionPerformed(ActionEvent ae) { 31 DataSet set = getCurrentDataSet(); 32 if (set != null) { 33 HistoryBrowserDialogManager.getInstance().showHistory(set.getSelected()); 34 } 35 } 36 37 @Override 38 public void updateEnabledState() { 39 if (getCurrentDataSet() == null) { 40 setEnabled(false); 41 } else { 42 updateEnabledState(getCurrentDataSet().getSelected()); 43 } 44 } 45 46 @Override 47 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 48 setEnabled(!selection.isEmpty()); 49 } 31 50 } -
deleted file src/org/openstreetmap/josm/actions/HistoryInfoWebbrowserAction.java
diff --git a/src/org/openstreetmap/josm/actions/HistoryInfoWebbrowserAction.java b/src/org/openstreetmap/josm/actions/HistoryInfoWebbrowserAction.java deleted file mode 100644 index aca7ffe..0000000
+ - 1 //License: GPL. Copyright 2007 by Immanuel Scholz and others2 package org.openstreetmap.josm.actions;3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 6 import java.awt.event.KeyEvent;7 8 import org.openstreetmap.josm.Main;9 import org.openstreetmap.josm.data.osm.OsmPrimitive;10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;11 import org.openstreetmap.josm.tools.Shortcut;12 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;13 14 public class HistoryInfoWebbrowserAction extends AbstractInfoAction {15 16 public HistoryInfoWebbrowserAction() {17 super(tr("History (web)"), "about",18 tr("Display history information about OSM ways, nodes, or relations in web browser."),19 Shortcut.registerShortcut("core:historybrowser",20 tr("Object history (web browser)"), KeyEvent.VK_H, Shortcut.GROUP_HOTKEY, Shortcut.SHIFT_DEFAULT), false);21 putValue("help", ht("/Action/ObjectHistory"));22 putValue("toolbar", "action/historybrowserinfo");23 Main.toolbar.register(this);24 }25 26 @Override27 protected String createInfoUrl(Object infoObject) {28 OsmPrimitive primitive = (OsmPrimitive) infoObject;29 return getBaseBrowseUrl() + "/" + OsmPrimitiveType.from(primitive).getAPIName() + "/" + primitive.getId() + "/history";30 }31 } -
src/org/openstreetmap/josm/actions/InfoAction.java
diff --git a/src/org/openstreetmap/josm/actions/InfoAction.java b/src/org/openstreetmap/josm/actions/InfoAction.java index d89a70e..27d5c66 100644
a b 1 1 //License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.actions; 3 3 4 import java.awt.event.ActionEvent; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 6 7 7 8 import java.awt.event.KeyEvent; 8 9 10 import java.util.Collection; 9 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.osm.DataSet; 10 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 import org.openstreetmap.josm. data.osm.OsmPrimitiveType;14 import org.openstreetmap.josm.gui.dialogs.InspectPrimitiveDialog; 12 15 import org.openstreetmap.josm.tools.Shortcut; 13 16 14 public class InfoAction extends AbstractInfoAction {17 public class InfoAction extends JosmAction { 15 18 16 19 public InfoAction() { 17 super(tr(" Info about Element"), "about",18 tr("Display object information about OSM nodes, ways, or relations."),19 Shortcut.registerShortcut("core:info rmation",20 tr("Info about Element"), KeyEvent.VK_I, Shortcut.GROUP_HOTKEY), false);20 super(tr("Advanced info"), "about", 21 tr("Display advanced object information about OSM nodes, ways, or relations."), 22 Shortcut.registerShortcut("core:info", 23 tr("Advanced info"), KeyEvent.VK_I, Shortcut.GROUP_HOTKEY), false); 21 24 putValue("help", ht("/Action/InfoAboutElements")); 22 25 putValue("toolbar", "action/info"); 23 26 Main.toolbar.register(this); 24 27 } 25 28 26 29 @Override 27 protected String createInfoUrl(Object infoObject) { 28 OsmPrimitive primitive = (OsmPrimitive)infoObject; 29 return getBaseBrowseUrl() + "/" + OsmPrimitiveType.from(primitive).getAPIName() + "/" + primitive.getId(); 30 public void actionPerformed(ActionEvent ae) { 31 DataSet set = getCurrentDataSet(); 32 if (set != null) { 33 new InspectPrimitiveDialog(set.getSelected(), Main.map.mapView.getEditLayer()).showDialog(); 34 } 35 } 36 37 @Override 38 public void updateEnabledState() { 39 if (getCurrentDataSet() == null) { 40 setEnabled(false); 41 } else { 42 updateEnabledState(getCurrentDataSet().getSelected()); 43 } 44 } 45 46 @Override 47 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 48 setEnabled(!selection.isEmpty()); 30 49 } 31 50 } -
src/org/openstreetmap/josm/gui/MainMenu.java
diff --git a/src/org/openstreetmap/josm/gui/MainMenu.java b/src/org/openstreetmap/josm/gui/MainMenu.java index 311f8d3..f3c3306 100644
a b import org.openstreetmap.josm.actions.FullscreenToggleAction; 38 38 import org.openstreetmap.josm.actions.GpxExportAction; 39 39 import org.openstreetmap.josm.actions.HelpAction; 40 40 import org.openstreetmap.josm.actions.HistoryInfoAction; 41 import org.openstreetmap.josm.actions.HistoryInfoWebAction; 41 42 import org.openstreetmap.josm.actions.InfoAction; 43 import org.openstreetmap.josm.actions.InfoWebAction; 42 44 import org.openstreetmap.josm.actions.JoinAreasAction; 43 45 import org.openstreetmap.josm.actions.JoinNodeWayAction; 44 46 import org.openstreetmap.josm.actions.JosmAction; … … public class MainMenu extends JMenuBar { 142 144 public final WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction(); 143 145 public final JosmAction toggleGPXLines = new ToggleGPXLinesAction(); 144 146 public final InfoAction info = new InfoAction(); 147 public final InfoWebAction infoweb = new InfoWebAction(); 145 148 public final HistoryInfoAction historyinfo = new HistoryInfoAction(); 149 public final HistoryInfoWebAction historyinfoweb = new HistoryInfoWebAction(); 146 150 147 151 /* Tools menu */ 148 152 public final JosmAction splitWay = new SplitWayAction(); … … public class MainMenu extends JMenuBar { 316 320 } 317 321 viewMenu.addSeparator(); 318 322 add(viewMenu, info); 323 add(viewMenu, infoweb); 319 324 add(viewMenu, historyinfo); 325 add(viewMenu, historyinfoweb); 320 326 321 327 add(presetsMenu, presetSearchAction); 322 328 -
src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
diff --git a/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java b/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java index ba08b87..d781c54 100644
a b import javax.swing.JComponent; 21 21 import javax.swing.JLabel; 22 22 import javax.swing.JTable; 23 23 import javax.swing.ListSelectionModel; 24 import javax.swing.SwingUtilities;25 24 import javax.swing.event.ListSelectionEvent; 26 25 import javax.swing.event.ListSelectionListener; 27 26 import javax.swing.table.DefaultTableCellRenderer; … … import org.openstreetmap.josm.data.SelectionChangedListener; 35 34 import org.openstreetmap.josm.data.osm.DataSet; 36 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; 37 36 import org.openstreetmap.josm.data.osm.PrimitiveId; 38 import org.openstreetmap.josm.data.osm.history.History;39 37 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 40 38 import org.openstreetmap.josm.data.osm.history.HistoryDataSetListener; 41 39 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … import org.openstreetmap.josm.gui.SideButton; 43 41 import org.openstreetmap.josm.gui.help.HelpUtil; 44 42 import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager; 45 43 import org.openstreetmap.josm.gui.history.HistoryLoadTask; 46 import org.openstreetmap.josm.tools.BugReportExceptionHandler;47 44 import org.openstreetmap.josm.tools.ImageProvider; 48 45 import org.openstreetmap.josm.tools.Shortcut; 49 46 … … public class HistoryDialog extends ToggleDialog implements HistoryDataSetListene 289 286 public void mouseClicked(MouseEvent e) { 290 287 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { 291 288 int row = historyTable.rowAtPoint(e.getPoint()); 292 new ShowHistoryAction().showHistory(Collections.singletonList(model.getPrimitive(row)));289 HistoryBrowserDialogManager.getInstance().showHistory(Collections.singletonList(model.getPrimitive(row))); 293 290 } 294 291 } 295 292 } … … public class HistoryDialog extends ToggleDialog implements HistoryDataSetListene 305 302 updateEnabledState(); 306 303 } 307 304 308 protected List<OsmPrimitive> filterPrimitivesWithUnloadedHistory(Collection<OsmPrimitive> primitives) {309 ArrayList<OsmPrimitive> ret = new ArrayList<OsmPrimitive>(primitives.size());310 HistoryDataSet hds = HistoryDataSet.getInstance();311 for (OsmPrimitive p: primitives) {312 if (hds.getHistory(p.getPrimitiveId()) == null) {313 // reload if the history is not in the cache yet314 ret.add(p);315 } else if (!p.isNew() && hds.getHistory(p.getPrimitiveId()).getByVersion(p.getUniqueId()) == null) {316 // reload if the history object of the selected object is not in the cache317 // yet318 ret.add(p);319 }320 }321 return ret;322 }323 324 public void showHistory(final List<OsmPrimitive> primitives) {325 List<OsmPrimitive> toLoad = filterPrimitivesWithUnloadedHistory(primitives);326 if (!toLoad.isEmpty()) {327 HistoryLoadTask task = new HistoryLoadTask();328 task.add(primitives);329 Main.worker.submit(task);330 }331 332 Runnable r = new Runnable() {333 public void run() {334 try {335 for (OsmPrimitive p : primitives) {336 History h = HistoryDataSet.getInstance().getHistory(p.getPrimitiveId());337 if (h == null) {338 continue;339 }340 HistoryBrowserDialogManager.getInstance().show(h);341 }342 } catch (final Exception e) {343 SwingUtilities.invokeLater(new Runnable() {344 public void run() {345 BugReportExceptionHandler.handleException(e);346 }347 });348 }349 350 }351 };352 Main.worker.submit(r);353 }354 355 305 public void actionPerformed(ActionEvent e) { 356 306 int [] rows = historyTable.getSelectedRows(); 357 307 if (rows == null || rows.length == 0) return; 358 showHistory(model.getPrimitives(rows));308 HistoryBrowserDialogManager.getInstance().showHistory(model.getPrimitives(rows)); 359 309 } 360 310 361 311 protected void updateEnabledState() { -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
diff --git a/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java b/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java index 1a9ff34..cf0a19b 100644
a b import java.util.Arrays; 16 16 import java.util.Collection; 17 17 import java.util.Collections; 18 18 import java.util.Comparator; 19 import java.util.HashMap;20 19 import java.util.HashSet; 21 20 import java.util.LinkedList; 22 21 import java.util.List; … … import java.util.Set; 25 24 import javax.swing.AbstractAction; 26 25 import javax.swing.AbstractListModel; 27 26 import javax.swing.DefaultListSelectionModel; 28 import javax.swing.JButton;29 27 import javax.swing.JList; 30 28 import javax.swing.JMenuItem; 31 29 import javax.swing.JPopupMenu; … … public class SelectionListDialog extends ToggleDialog { 87 85 private SetRelationSelection actSetRelationSelection; 88 86 private EditRelationSelection actEditRelationSelection; 89 87 private DownloadSelectedIncompleteMembersAction actDownloadSelectedIncompleteMembers; 90 private InspectAction actInspect;91 88 92 89 /** 93 90 * Builds the content panel for this dialog … … public class SelectionListDialog extends ToggleDialog { 147 144 actDownloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction(); 148 145 lstPrimitives.getSelectionModel().addListSelectionListener(actDownloadSelectedIncompleteMembers); 149 146 150 actInspect = new InspectAction();151 lstPrimitives.getSelectionModel().addListSelectionListener(actInspect);152 153 147 lstPrimitives.addMouseListener(new SelectionPopupMenuLauncher()); 154 148 lstPrimitives.addMouseListener(new DblClickHandler()); 155 149 } … … public class SelectionListDialog extends ToggleDialog { 220 214 add(actEditRelationSelection); 221 215 addSeparator(); 222 216 add(actDownloadSelectedIncompleteMembers); 223 addSeparator();224 add(actInspect);225 217 } 226 218 } 227 219 … … public class SelectionListDialog extends ToggleDialog { 850 842 } 851 843 } 852 844 853 class InspectAction extends AbstractAction implements ListSelectionListener {854 public InspectAction() {855 putValue(SHORT_DESCRIPTION, tr("Get detailed information on the internal state of the objects."));856 putValue(NAME, tr("Inspect"));857 updateEnabledState();858 }859 860 public void actionPerformed(ActionEvent e) {861 Collection<OsmPrimitive> sel = model.getSelected();862 if (sel.isEmpty()) return;863 InspectPrimitiveDialog inspectDialog = new InspectPrimitiveDialog(sel, Main.map.mapView.getEditLayer());864 inspectDialog.showDialog();865 }866 867 public void updateEnabledState() {868 setEnabled(!model.getSelected().isEmpty());869 }870 871 public void valueChanged(ListSelectionEvent e) {872 updateEnabledState();873 }874 }875 876 845 /** Quicker comparator, comparing just by type and ID's */ 877 846 static private class OsmPrimitiveQuickComparator implements Comparator<OsmPrimitive> { 878 847 -
src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java
diff --git a/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java b/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java index 5d24dd8..e285a2d 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.history; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.awt.Dimension; 5 7 import java.awt.Point; 6 8 import java.util.ArrayList; 9 import java.util.Collection; 7 10 import java.util.HashMap; 8 11 import java.util.Map; 12 import javax.swing.JOptionPane; 13 import javax.swing.SwingUtilities; 9 14 10 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 17 import org.openstreetmap.josm.data.osm.history.History; 18 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 12 19 import org.openstreetmap.josm.gui.MapView; 13 20 import org.openstreetmap.josm.gui.layer.Layer; 21 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 22 import org.openstreetmap.josm.tools.Predicate; 23 import org.openstreetmap.josm.tools.Utils; 14 24 import org.openstreetmap.josm.tools.WindowGeometry; 15 25 16 26 public class HistoryBrowserDialogManager implements MapView.LayerChangeListener { … … public class HistoryBrowserDialogManager implements MapView.LayerChangeListener 122 132 hideAll(); 123 133 } 124 134 } 135 136 public void showHistory(final Collection<OsmPrimitive> primitives) { 137 final Collection<OsmPrimitive> notNewPrimitives = Utils.filter(primitives, notNewPredicate); 138 if (notNewPrimitives.isEmpty()) { 139 JOptionPane.showMessageDialog( 140 Main.parent, 141 tr("Please select at least one already uploaded node, way, or relation."), 142 tr("Warning"), 143 JOptionPane.WARNING_MESSAGE); 144 return; 145 } 146 Collection<OsmPrimitive> toLoad = Utils.filter(primitives, unloadedHistoryPredicate); 147 if (!toLoad.isEmpty()) { 148 HistoryLoadTask task = new HistoryLoadTask(); 149 task.add(notNewPrimitives); 150 Main.worker.submit(task); 151 } 152 153 Runnable r = new Runnable() { 154 155 @Override 156 public void run() { 157 try { 158 for (OsmPrimitive p : notNewPrimitives) { 159 History h = HistoryDataSet.getInstance().getHistory(p.getPrimitiveId()); 160 if (h == null) { 161 continue; 162 } 163 show(h); 164 } 165 } catch (final Exception e) { 166 SwingUtilities.invokeLater(new Runnable() { 167 168 @Override 169 public void run() { 170 BugReportExceptionHandler.handleException(e); 171 } 172 }); 173 } 174 175 } 176 }; 177 Main.worker.submit(r); 178 } 179 180 private final Predicate<OsmPrimitive> unloadedHistoryPredicate = new Predicate<OsmPrimitive>() { 181 182 HistoryDataSet hds = HistoryDataSet.getInstance(); 183 184 @Override 185 public boolean evaluate(OsmPrimitive p) { 186 if (hds.getHistory(p.getPrimitiveId()) == null) { 187 // reload if the history is not in the cache yet 188 return true; 189 } else if (!p.isNew() && hds.getHistory(p.getPrimitiveId()).getByVersion(p.getUniqueId()) == null) { 190 // reload if the history object of the selected object is not in the cache yet 191 return true; 192 } else { 193 return false; 194 } 195 } 196 }; 197 198 private final Predicate<OsmPrimitive> notNewPredicate = new Predicate<OsmPrimitive>() { 199 200 @Override 201 public boolean evaluate(OsmPrimitive p) { 202 return !p.isNew(); 203 } 204 }; 205 125 206 } -
src/org/openstreetmap/josm/tools/Utils.java
diff --git a/src/org/openstreetmap/josm/tools/Utils.java b/src/org/openstreetmap/josm/tools/Utils.java index 20f07ce..ae24092 100644
a b public class Utils { 54 54 } 55 55 return null; 56 56 } 57 58 public static <T> Collection<T> filter(Collection<? extends T> collection, Predicate<? super T> predicate) { 59 return new FilteredCollection<T>(collection, predicate); 60 } 57 61 58 62 /** 59 63 * Filter a collection by (sub)class.
