Changeset 5025 in josm for trunk/src/org
- Timestamp:
- 2012-02-26T16:10:39+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r4982 r5025 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; … … 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; … … 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 … … 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, … … 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 * … … 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)) { -
trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java
r4191 r5025 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(); -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r4895 r5025 125 125 126 126 private int highlightUpdateCount; 127 128 private boolean uploadDiscouraged = false; 127 129 128 130 private final ReadWriteLock lock = new ReentrantReadWriteLock(); … … 205 207 public void setVersion(String version) { 206 208 this.version = version; 209 } 210 211 public final boolean isUploadDiscouraged() { 212 return uploadDiscouraged; 213 } 214 215 public final void setUploadDiscouraged(boolean uploadDiscouraged) { 216 this.uploadDiscouraged = uploadDiscouraged; 207 217 } 208 218 -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r4701 r5025 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; … … 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; … … 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; … … 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; … … 214 219 } 215 220 221 protected Icon getBaseIcon() { 222 return ImageProvider.get("layer", "osmdata_small"); 223 } 224 216 225 /** 217 226 * TODO: @return Return a dynamic drawn icon of the map data. The icon is … … 219 228 */ 220 229 @Override public Icon getIcon() { 221 return ImageProvider.get("layer", "osmdata_small"); 230 Icon baseIcon = getBaseIcon(); 231 if (isUploadDiscouraged()) { 232 return ImageProvider.overlay(baseIcon, 233 new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(8, 8, Image.SCALE_SMOOTH)), 234 ImageProvider.OverlayPosition.SOUTHEAST); 235 } else { 236 return baseIcon; 237 } 222 238 } 223 239 … … 395 411 396 412 @Override public boolean isMergable(final Layer other) { 397 return other instanceof OsmDataLayer ;413 return other instanceof OsmDataLayer && (isUploadDiscouraged() == ((OsmDataLayer)other).isUploadDiscouraged()); 398 414 } 399 415 … … 457 473 p.add(new JLabel(wayText, ImageProvider.get("data", "way"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 458 474 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")))); 475 p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset"))), GBC.eop().insets(15,0,0,0)); 476 if (isUploadDiscouraged()) { 477 p.add(new JLabel(tr("Upload is discouraged")), GBC.eop().insets(15,0,0,0)); 478 } 460 479 461 480 return p; … … 475 494 SeparatorLayerAction.INSTANCE, 476 495 new LayerListPopup.InfoAction(this)}; 477 return new Action[]{ 496 ArrayList<Action> actions = new ArrayList<Action>(); 497 actions.addAll(Arrays.asList(new Action[]{ 478 498 LayerListDialog.getInstance().createActivateLayerAction(this), 479 499 LayerListDialog.getInstance().createShowHideLayerAction(), … … 486 506 new ConvertToGpxLayerAction(), 487 507 SeparatorLayerAction.INSTANCE, 488 new RenameLayerAction(getAssociatedFile(), this), 508 new RenameLayerAction(getAssociatedFile(), this)})); 509 if (ExpertToggleAction.isExpert() && Main.pref.getBoolean("data.layer.upload_discouragement.menu_item", false)) { 510 actions.add(new ToggleUploadDiscouragedLayerAction(this)); 511 } 512 actions.addAll(Arrays.asList(new Action[]{ 489 513 new ConsistencyTestAction(), 490 514 SeparatorLayerAction.INSTANCE, 491 new LayerListPopup.InfoAction(this)}; 515 new LayerListPopup.InfoAction(this)})); 516 return actions.toArray(new Action[0]); 492 517 } 493 518 … … 702 727 */ 703 728 } 729 730 public final boolean isUploadDiscouraged() { 731 return data.isUploadDiscouraged(); 732 } 733 734 public final void setUploadDiscouraged(boolean uploadDiscouraged) { 735 data.setUploadDiscouraged(uploadDiscouraged); 736 } 704 737 } -
trunk/src/org/openstreetmap/josm/io/OsmExporter.java
r4852 r5025 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 { -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r4856 r5025 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; -
trunk/src/org/openstreetmap/josm/io/OsmWriter.java
r4645 r5025 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 … … 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 } … … 82 90 Collections.sort(result, byIdComparator); 83 91 return result; 92 } 93 94 public void writeLayer(OsmDataLayer layer) { 95 header(!layer.isUploadDiscouraged()); 96 writeDataSources(layer.data); 97 writeContent(layer.data); 98 footer(); 84 99 } 85 100 -
trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
r5014 r5025 221 221 layer.data.getReadLock().lock(); 222 222 try { 223 w.header(); 224 w.writeDataSources(layer.data); 225 w.writeContent(layer.data); 226 w.footer(); 223 w.writeLayer(layer); 227 224 w.flush(); 228 225 } finally {
Note:
See TracChangeset
for help on using the changeset viewer.