Changeset 16673 in josm
- Timestamp:
- 2020-06-17T21:47:19+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/BBox.java
r16553 r16673 216 216 217 217 /** 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 /** 218 226 * Tests, whether the bbox {@code b} lies completely inside this bbox. 219 227 * @param b bounding box -
trunk/src/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanel.java
r16672 r16673 24 24 import javax.swing.JLabel; 25 25 import javax.swing.JPanel; 26 import javax.swing.JTextField; 26 27 import javax.swing.event.AncestorEvent; 27 28 import javax.swing.event.AncestorListener; … … 31 32 32 33 import org.openstreetmap.josm.data.osm.Changeset; 34 import org.openstreetmap.josm.data.osm.OsmPrimitive; 33 35 import org.openstreetmap.josm.gui.MainApplication; 36 import org.openstreetmap.josm.gui.io.UploadTextComponentValidator.UploadAreaValidator; 34 37 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 35 38 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; … … 69 72 /** the checkbox to request feedback from other users */ 70 73 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); 71 76 /** the changeset comment model */ 72 77 private final transient ChangesetCommentModel changesetCommentModel; … … 200 205 cbRequestReview.addItemListener(e -> changesetReviewModel.setReviewRequested(e.getStateChange() == ItemEvent.SELECTED)); 201 206 } 207 JPanel pnl = new JPanel(new GridBagLayout()); 208 pnl.add(areaValidatorFeedback, GBC.eol().fill(GBC.HORIZONTAL)); 209 add(pnl); 202 210 } 203 211 … … 274 282 } 275 283 284 void setUploadedPrimitives(List<OsmPrimitive> primitives) { 285 areaValidator.computeArea(primitives); 286 } 287 276 288 /** 277 289 * 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 253 253 return; 254 254 } 255 pnlBasicUploadSettings.setUploadedPrimitives(toUpload.getPrimitives()); 255 256 pnlUploadedObjects.setUploadedPrimitives( 256 257 toUpload.getPrimitivesToAdd(), -
trunk/src/org/openstreetmap/josm/gui/io/UploadTextComponentValidator.java
r16672 r16673 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Collection; 6 7 import java.util.Collections; 7 8 … … 9 10 import javax.swing.text.JTextComponent; 10 11 12 import org.openstreetmap.josm.data.osm.BBox; 13 import org.openstreetmap.josm.data.osm.IPrimitive; 11 14 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator; 15 import org.openstreetmap.josm.spi.preferences.Config; 12 16 import org.openstreetmap.josm.tools.Utils; 13 17 … … 111 115 } 112 116 } 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 } 113 148 } -
trunk/test/unit/org/openstreetmap/josm/data/osm/BBoxTest.java
r15877 r16673 166 166 167 167 /** 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. 169 169 */ 170 170 @Test 171 public void testHeightWidth () {171 public void testHeightWidthArea() { 172 172 BBox b1 = new BBox(1, 2, 3, 5); 173 173 assertEquals(2, b1.width(), 1e-7); 174 174 assertEquals(3, b1.height(), 1e-7); 175 assertEquals(6, b1.area(), 1e-7); 175 176 BBox b2 = new BBox(); 176 177 assertEquals(0, b2.width(), 1e-7); 177 178 assertEquals(0, b2.height(), 1e-7); 179 assertEquals(0, b2.area(), 1e-7); 178 180 } 179 181
Note:
See TracChangeset
for help on using the changeset viewer.