Ticket #4043: patch2.diff
| File patch2.diff, 15.7 KB (added by , 14 years ago) |
|---|
-
core/src/org/openstreetmap/josm/actions/ToggleUploadDiscouragedLayerAction.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.actions; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.event.ActionEvent; 7 8 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 9 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 10 11 public class ToggleUploadDiscouragedLayerAction extends JosmAction { 12 13 private OsmDataLayer layer; 14 15 public ToggleUploadDiscouragedLayerAction(OsmDataLayer layer) { 16 super(tr("Encourage/discourage upload"), null, null, null, false); 17 this.layer = layer; 18 } 19 20 @Override 21 public void actionPerformed(ActionEvent e) { 22 layer.setUploadDiscouraged(!layer.isUploadDiscouraged()); 23 LayerListDialog.getInstance().repaint(); 24 } 25 } -
core/src/org/openstreetmap/josm/actions/UploadAction.java
4 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.awt.Image; 7 8 import java.awt.event.ActionEvent; 8 9 import java.awt.event.KeyEvent; 9 10 import java.util.LinkedList; 10 11 12 import javax.swing.Icon; 13 import javax.swing.ImageIcon; 11 14 import javax.swing.JOptionPane; 12 15 import javax.swing.SwingUtilities; 13 16 … … 18 21 import org.openstreetmap.josm.actions.upload.ValidateUploadHook; 19 22 import org.openstreetmap.josm.data.APIDataSet; 20 23 import org.openstreetmap.josm.data.conflict.ConflictCollection; 24 import org.openstreetmap.josm.gui.ExtendedDialog; 21 25 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 22 26 import org.openstreetmap.josm.gui.help.HelpUtil; 23 27 import org.openstreetmap.josm.gui.io.UploadDialog; 24 28 import org.openstreetmap.josm.gui.io.UploadPrimitivesTask; 25 29 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 30 import org.openstreetmap.josm.tools.ImageProvider; 26 31 import org.openstreetmap.josm.tools.Shortcut; 27 32 28 33 /** … … 103 108 return checkPreUploadConditions(layer, new APIDataSet(layer.data)); 104 109 } 105 110 106 protected void alertUnresolvedConflicts(OsmDataLayer layer) {111 protected static void alertUnresolvedConflicts(OsmDataLayer layer) { 107 112 HelpAwareOptionPane.showOptionDialog( 108 113 Main.parent, 109 114 tr("<html>The data to be uploaded participates in unresolved conflicts of layer ''{0}''.<br>" … … 114 119 HelpUtil.ht("/Action/Upload#PrimitivesParticipateInConflicts") 115 120 ); 116 121 } 122 123 /** 124 * returns true if the user wants to cancel, false if they 125 * want to continue 126 */ 127 public static final boolean warnUploadDiscouraged(OsmDataLayer layer) { 128 ExtendedDialog dlg = new ExtendedDialog(Main.parent, 129 tr("Upload discouraged"), 130 new String[] {tr("Cancel"), tr("Continue")}); 131 dlg.setContent("<html>" + 132 tr("You are about to upload data from the layer ''{0}''.<br /><br />"+ 133 "Sending data from this layer is <b>strongly discouraged</b>. If you continue,<br />"+ 134 "it may require you subsequently have to revert your changes, or force other contributors to.<br /><br />"+ 135 "Are you sure you want to continue?", layer.getName())+ 136 "</html>"); 137 dlg.setButtonIcons(new Icon[] { 138 ImageProvider.get("cancel"), 139 ImageProvider.overlay( 140 ImageProvider.get("upload"), 141 new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(10 , 10, Image.SCALE_SMOOTH)), 142 ImageProvider.OverlayPosition.SOUTHEAST)}); 143 dlg.setToolTipTexts(new String[] { 144 tr("Cancel"), 145 tr("Ignore this hint and upload anyway")}); 146 dlg.setIcon(JOptionPane.WARNING_MESSAGE); 147 dlg.setCancelButton(1); 148 return dlg.showDialog().getValue() != 2; 149 } 117 150 118 151 /** 119 152 * Check whether the preconditions are met to upload data in <code>apiData</code>. 120 * Makes sure primitives in <code>apiData</code> don't participate in conflicts and153 * Makes sure upload is allowed, primitives in <code>apiData</code> don't participate in conflicts and 121 154 * runs the installed {@see UploadHook}s. 122 155 * 123 156 * @param layer the source layer of the data to be uploaded … … 125 158 * @return true, if the preconditions are met; false, otherwise 126 159 */ 127 160 public boolean checkPreUploadConditions(OsmDataLayer layer, APIDataSet apiData) { 161 if (layer.isUploadDiscouraged()) { 162 if (warnUploadDiscouraged(layer)) { 163 return false; 164 } 165 } 128 166 ConflictCollection conflicts = layer.getConflicts(); 129 167 if (apiData.participatesInConflict(conflicts)) { 130 168 alertUnresolvedConflicts(layer); -
core/src/org/openstreetmap/josm/actions/UploadSelectionAction.java
87 87 public void actionPerformed(ActionEvent e) { 88 88 if (!isEnabled()) 89 89 return; 90 if (getEditLayer().isUploadDiscouraged()) { 91 if (UploadAction.warnUploadDiscouraged(getEditLayer())) { 92 return; 93 } 94 } 90 95 UploadHullBuilder builder = new UploadHullBuilder(); 91 96 UploadSelectionDialog dialog = new UploadSelectionDialog(); 92 97 Collection<OsmPrimitive> modifiedCandidates = getModifiedPrimitives(getEditLayer().data.getSelected()); -
core/src/org/openstreetmap/josm/data/osm/DataSet.java
124 124 private final List<AbstractDatasetChangedEvent> cachedEvents = new ArrayList<AbstractDatasetChangedEvent>(); 125 125 126 126 private int highlightUpdateCount; 127 128 private boolean uploadDiscouraged = false; 127 129 128 130 private final ReadWriteLock lock = new ReentrantReadWriteLock(); 129 131 private final Object selectionLock = new Object(); … … 206 208 this.version = version; 207 209 } 208 210 211 public final boolean isUploadDiscouraged() { 212 return uploadDiscouraged; 213 } 214 215 public final void setUploadDiscouraged(boolean uploadDiscouraged) { 216 this.uploadDiscouraged = uploadDiscouraged; 217 } 218 209 219 /* 210 220 * Holding bin for changeset tag information, to be applied when or if this is ever uploaded. 211 221 */ -
core/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
12 12 import java.awt.Composite; 13 13 import java.awt.Graphics2D; 14 14 import java.awt.GridBagLayout; 15 import java.awt.Image; 15 16 import java.awt.Point; 16 17 import java.awt.Rectangle; 17 18 import java.awt.TexturePaint; … … 20 21 import java.awt.image.BufferedImage; 21 22 import java.io.File; 22 23 import java.util.ArrayList; 24 import java.util.Arrays; 23 25 import java.util.Collection; 24 26 import java.util.HashMap; 25 27 import java.util.HashSet; … … 29 31 import javax.swing.AbstractAction; 30 32 import javax.swing.Action; 31 33 import javax.swing.Icon; 34 import javax.swing.ImageIcon; 32 35 import javax.swing.JLabel; 33 36 import javax.swing.JOptionPane; 34 37 import javax.swing.JPanel; … … 36 39 import javax.swing.JTextArea; 37 40 38 41 import org.openstreetmap.josm.Main; 42 import org.openstreetmap.josm.actions.ExpertToggleAction; 39 43 import org.openstreetmap.josm.actions.RenameLayerAction; 44 import org.openstreetmap.josm.actions.ToggleUploadDiscouragedLayerAction; 40 45 import org.openstreetmap.josm.data.Bounds; 41 46 import org.openstreetmap.josm.data.SelectionChangedListener; 42 47 import org.openstreetmap.josm.data.conflict.Conflict; … … 218 223 * updated by a background thread to not disturb the running programm. 219 224 */ 220 225 @Override public Icon getIcon() { 221 return ImageProvider.get("layer", "osmdata_small"); 226 Icon baseIcon = ImageProvider.get("layer", "osmdata_small"); 227 if (isUploadDiscouraged()) { 228 return ImageProvider.overlay(baseIcon, 229 new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(8, 8, Image.SCALE_SMOOTH)), 230 ImageProvider.OverlayPosition.SOUTHEAST); 231 } else { 232 return baseIcon; 233 } 222 234 } 223 235 224 236 /** … … 394 406 395 407 396 408 @Override public boolean isMergable(final Layer other) { 397 return other instanceof OsmDataLayer ;409 return other instanceof OsmDataLayer && (isUploadDiscouraged() == ((OsmDataLayer)other).isUploadDiscouraged()); 398 410 } 399 411 400 412 @Override public void visitBoundingBox(final BoundingXYVisitor v) { … … 456 468 p.add(new JLabel(nodeText, ImageProvider.get("data", "node"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 457 469 p.add(new JLabel(wayText, ImageProvider.get("data", "way"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 458 470 p.add(new JLabel(relationText, ImageProvider.get("data", "relation"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 459 p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset")))); 471 p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset"))), GBC.eop().insets(15,0,0,0)); 472 if (isUploadDiscouraged()) { 473 p.add(new JLabel(tr("Upload is discouraged")), GBC.eop().insets(15,0,0,0)); 474 } 460 475 461 476 return p; 462 477 } … … 474 489 new ConsistencyTestAction(), 475 490 SeparatorLayerAction.INSTANCE, 476 491 new LayerListPopup.InfoAction(this)}; 477 return new Action[]{ 492 ArrayList<Action> actions = new ArrayList<Action>(); 493 actions.addAll(Arrays.asList(new Action[]{ 478 494 LayerListDialog.getInstance().createActivateLayerAction(this), 479 495 LayerListDialog.getInstance().createShowHideLayerAction(), 480 496 LayerListDialog.getInstance().createDeleteLayerAction(), … … 485 501 new LayerGpxExportAction(this), 486 502 new ConvertToGpxLayerAction(), 487 503 SeparatorLayerAction.INSTANCE, 488 new RenameLayerAction(getAssociatedFile(), this), 504 new RenameLayerAction(getAssociatedFile(), this)})); 505 if (ExpertToggleAction.isExpert()) { 506 actions.add(new ToggleUploadDiscouragedLayerAction(this)); 507 } 508 actions.addAll(Arrays.asList(new Action[]{ 489 509 new ConsistencyTestAction(), 490 510 SeparatorLayerAction.INSTANCE, 491 new LayerListPopup.InfoAction(this)}; 511 new LayerListPopup.InfoAction(this)})); 512 return actions.toArray(new Action[0]); 492 513 } 493 514 494 515 public static GpxData toGpxData(DataSet data, File file) { … … 701 722 * change listener and already got notified. 702 723 */ 703 724 } 725 726 public final boolean isUploadDiscouraged() { 727 return data.isUploadDiscouraged(); 728 } 729 730 public final void setUploadDiscouraged(boolean uploadDiscouraged) { 731 data.setUploadDiscouraged(uploadDiscouraged); 732 } 704 733 } -
core/src/org/openstreetmap/josm/io/OsmExporter.java
73 73 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, layer.data.getVersion()); 74 74 layer.data.getReadLock().lock(); 75 75 try { 76 w.header(); 77 w.writeDataSources(layer.data); 78 w.writeContent(layer.data); 79 w.footer(); 76 w.writeLayer(layer); 80 77 w.close(); 81 78 } finally { 82 79 layer.data.getReadLock().unlock(); -
core/src/org/openstreetmap/josm/io/OsmReader.java
116 116 throwException(tr("Unsupported version: {0}", v)); 117 117 } 118 118 ds.setVersion(v); 119 String upload = parser.getAttributeValue(null, "upload"); 120 if (upload != null) { 121 ds.setUploadDiscouraged(!Boolean.parseBoolean(upload)); 122 } 119 123 String generator = parser.getAttributeValue(null, "generator"); 120 124 Long uploadChangesetId = null; 121 125 if (parser.getAttributeValue(null, "upload-changeset") != null) { -
core/src/org/openstreetmap/josm/io/OsmWriter.java
25 25 import org.openstreetmap.josm.data.osm.Tagged; 26 26 import org.openstreetmap.josm.data.osm.Way; 27 27 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 28 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 28 29 import org.openstreetmap.josm.tools.DateUtils; 29 30 30 31 /** … … 61 62 } 62 63 63 64 public void header() { 65 header(null); 66 } 67 public void header(Boolean upload) { 64 68 out.println("<?xml version='1.0' encoding='UTF-8'?>"); 65 69 out.print("<osm version='"); 66 70 out.print(version); 71 if (upload != null) { 72 out.print("' upload='"); 73 out.print(upload); 74 } 67 75 out.println("' generator='JOSM'>"); 68 76 } 69 77 public void footer() { … … 82 90 Collections.sort(result, byIdComparator); 83 91 return result; 84 92 } 93 94 public void writeLayer(OsmDataLayer layer) { 95 header(!layer.isUploadDiscouraged()); 96 writeDataSources(layer.data); 97 writeContent(layer.data); 98 footer(); 99 } 85 100 86 101 public void writeContent(DataSet ds) { 87 102 for (OsmPrimitive n : sortById(ds.getNodes())) { -
core/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
221 221 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, layer.data.getVersion()); 222 222 layer.data.getReadLock().lock(); 223 223 try { 224 w.header(); 225 w.writeDataSources(layer.data); 226 w.writeContent(layer.data); 227 w.footer(); 224 w.writeLayer(layer); 228 225 w.flush(); 229 226 } finally { 230 227 layer.data.getReadLock().unlock();
