Changeset 16673 in josm


Ignore:
Timestamp:
2020-06-17T21:47:19+02:00 (3 weeks ago)
Author:
simon04
Message:

fix #19381 - Upload dialog: warn about large bounding box

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/BBox.java

    r16553 r16673  
    216216
    217217    /**
     218     * Gets the area of the bbox.
     219     * @return the area computed from {@link #width()} and {@link #height()}
     220     */
     221    public double area() {
     222        return width() * height();
     223    }
     224
     225    /**
    218226     * Tests, whether the bbox {@code b} lies completely inside this bbox.
    219227     * @param b bounding box
  • trunk/src/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanel.java

    r16672 r16673  
    2424import javax.swing.JLabel;
    2525import javax.swing.JPanel;
     26import javax.swing.JTextField;
    2627import javax.swing.event.AncestorEvent;
    2728import javax.swing.event.AncestorListener;
     
    3132
    3233import org.openstreetmap.josm.data.osm.Changeset;
     34import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3335import org.openstreetmap.josm.gui.MainApplication;
     36import org.openstreetmap.josm.gui.io.UploadTextComponentValidator.UploadAreaValidator;
    3437import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
    3538import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
     
    6972    /** the checkbox to request feedback from other users */
    7073    private final JCheckBox cbRequestReview = new JCheckBox(tr("I would like someone to review my edits."));
     74    private final JLabel areaValidatorFeedback = new JLabel();
     75    private final UploadAreaValidator areaValidator = new UploadAreaValidator(new JTextField(), areaValidatorFeedback);
    7176    /** the changeset comment model */
    7277    private final transient ChangesetCommentModel changesetCommentModel;
     
    200205            cbRequestReview.addItemListener(e -> changesetReviewModel.setReviewRequested(e.getStateChange() == ItemEvent.SELECTED));
    201206        }
     207        JPanel pnl = new JPanel(new GridBagLayout());
     208        pnl.add(areaValidatorFeedback, GBC.eol().fill(GBC.HORIZONTAL));
     209        add(pnl);
    202210    }
    203211
     
    274282    }
    275283
     284    void setUploadedPrimitives(List<OsmPrimitive> primitives) {
     285        areaValidator.computeArea(primitives);
     286    }
     287
    276288    /**
    277289     * Returns the panel that displays a summary of data the user is about to upload.
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r16672 r16673  
    253253            return;
    254254        }
     255        pnlBasicUploadSettings.setUploadedPrimitives(toUpload.getPrimitives());
    255256        pnlUploadedObjects.setUploadedPrimitives(
    256257                toUpload.getPrimitivesToAdd(),
  • trunk/src/org/openstreetmap/josm/gui/io/UploadTextComponentValidator.java

    r16672 r16673  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.util.Collection;
    67import java.util.Collections;
    78
     
    910import javax.swing.text.JTextComponent;
    1011
     12import org.openstreetmap.josm.data.osm.BBox;
     13import org.openstreetmap.josm.data.osm.IPrimitive;
    1114import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
     15import org.openstreetmap.josm.spi.preferences.Config;
    1216import org.openstreetmap.josm.tools.Utils;
    1317
     
    111115        }
    112116    }
     117
     118    /**
     119     * Validator for the changeset area
     120     */
     121    static class UploadAreaValidator extends UploadTextComponentValidator {
     122        private double area = Double.NaN;
     123
     124        UploadAreaValidator(JTextComponent tc, JLabel feedback) {
     125            super(tc, feedback);
     126        }
     127
     128        void computeArea(Collection<? extends IPrimitive> primitives) {
     129            this.area = primitives.stream()
     130                    .map(IPrimitive::getBBox)
     131                    .reduce((b1, b2) -> {
     132                        b1.add(b2);
     133                        return b1;
     134                    }).map(BBox::area)
     135                    .orElse(Double.NaN);
     136            validate();
     137        }
     138
     139        @Override
     140        public void validate() {
     141            if (Double.isFinite(area) && area <= Config.getPref().getDouble("upload.max-area", 3.)) {
     142                feedbackValid(null);
     143            } else {
     144                feedbackWarning(tr("The bounding box of this changeset is very large – please consider splitting your changes!"));
     145            }
     146        }
     147    }
    113148}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/BBoxTest.java

    r15877 r16673  
    166166
    167167    /**
    168      * Unit test of {@link BBox#height} and {@link BBox#width} methods.
     168     * Unit test of {@link BBox#height} and {@link BBox#width} and {@link BBox#area} methods.
    169169     */
    170170    @Test
    171     public void testHeightWidth() {
     171    public void testHeightWidthArea() {
    172172        BBox b1 = new BBox(1, 2, 3, 5);
    173173        assertEquals(2, b1.width(), 1e-7);
    174174        assertEquals(3, b1.height(), 1e-7);
     175        assertEquals(6, b1.area(), 1e-7);
    175176        BBox b2 = new BBox();
    176177        assertEquals(0, b2.width(), 1e-7);
    177178        assertEquals(0, b2.height(), 1e-7);
     179        assertEquals(0, b2.area(), 1e-7);
    178180    }
    179181
Note: See TracChangeset for help on using the changeset viewer.