- Timestamp:
- 2011-09-08T00:08:02+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java
r4139 r4408 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 {17 public class HistoryInfoAction extends JosmAction { 15 18 16 17 super(tr("Object history"), "about",18 19 Shortcut.registerShortcut("core:history",20 tr("Object history"), KeyEvent.VK_H, Shortcut.GROUP_HOTKEY), false);21 22 23 24 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 } 25 28 26 @Override 27 protected String createInfoUrl(Object infoObject) { 28 OsmPrimitive primitive = (OsmPrimitive)infoObject; 29 return getBaseBrowseUrl() + "/" + OsmPrimitiveType.from(primitive).getAPIName() + "/" + primitive.getId() + "/history"; 30 } 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 } -
trunk/src/org/openstreetmap/josm/actions/InfoAction.java
r4139 r4408 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; … … 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"); … … 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 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r4380 r4408 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; … … 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 */ … … 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); -
trunk/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
r4363 r4408 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; … … 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; … … 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; … … 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 } … … 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 -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r4357 r4408 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; … … 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; … … 88 86 private EditRelationSelection actEditRelationSelection; 89 87 private DownloadSelectedIncompleteMembersAction actDownloadSelectedIncompleteMembers; 90 private InspectAction actInspect;91 88 92 89 /** … … 147 144 actDownloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction(); 148 145 lstPrimitives.getSelectionModel().addListSelectionListener(actDownloadSelectedIncompleteMembers); 149 150 actInspect = new InspectAction();151 lstPrimitives.getSelectionModel().addListSelectionListener(actInspect);152 146 153 147 lstPrimitives.addMouseListener(new SelectionPopupMenuLauncher()); … … 221 215 addSeparator(); 222 216 add(actDownloadSelectedIncompleteMembers); 223 addSeparator();224 add(actInspect);225 217 } 226 218 } … … 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> { -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java
r3083 r4408 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.history; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 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 … … 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 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r4403 r4408 58 58 return null; 59 59 } 60 61 public static <T> Collection<T> filter(Collection<? extends T> collection, Predicate<? super T> predicate) { 62 return new FilteredCollection<T>(collection, predicate); 63 } 60 64 61 65 /**
Note:
See TracChangeset
for help on using the changeset viewer.