Changeset 13309 in josm
- Timestamp:
- 2018-01-13T00:52:54+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r13293 r13309 199 199 /** 200 200 * Checks if a map redraw is required and does so if needed. Also updates the status bar. 201 * @param e event, can be null 201 202 * @return true if a repaint is needed 202 203 */ 203 private boolean redrawIfRequired( ) {204 private boolean redrawIfRequired(Object e) { 204 205 updateStatusLine(); 205 206 // repaint required if the helper line is active. … … 236 237 needsRepaint = true; 237 238 } else if (!alt && continueFrom != null && !continueFrom.isSelected()) { 238 currentDataSet.addSelected(continueFrom);239 addSelection(currentDataSet, continueFrom); 239 240 needsRepaint = true; 240 241 } 242 } 243 244 if (!needsRepaint && e instanceof SelectionChangeEvent) { 245 SelectionChangeEvent event = (SelectionChangeEvent) e; 246 needsRepaint = !event.getOldSelection().isEmpty() && event.getSelection().isEmpty(); 241 247 } 242 248 … … 250 256 ds.beginUpdate(); // to prevent the selection listener to screw around with the state 251 257 try { 252 ds.addSelected(toAdd);253 ds.clearSelection(toRemove);258 addSelection(ds, toAdd); 259 clearSelection(ds, toRemove); 254 260 } finally { 255 261 ds.endUpdate(); 256 262 } 263 } 264 265 private static void updatePreservedFlag(OsmPrimitive osm, boolean state) { 266 // Preserves selected primitives and selected way nodes 267 osm.setPreserved(state); 268 if (osm instanceof Way) { 269 for (Node n : ((Way) osm).getNodes()) { 270 n.setPreserved(state); 271 } 272 } 273 } 274 275 private static void setSelection(DataSet ds, Collection<OsmPrimitive> toSet) { 276 toSet.stream().forEach(x -> updatePreservedFlag(x, true)); 277 ds.setSelected(toSet); 278 } 279 280 private static void setSelection(DataSet ds, OsmPrimitive toSet) { 281 updatePreservedFlag(toSet, true); 282 ds.setSelected(toSet); 283 } 284 285 private static void addSelection(DataSet ds, OsmPrimitive toAdd) { 286 updatePreservedFlag(toAdd, true); 287 ds.addSelected(toAdd); 288 } 289 290 private static void clearSelection(DataSet ds, OsmPrimitive toRemove) { 291 ds.clearSelection(toRemove); 292 updatePreservedFlag(toRemove, false); 257 293 } 258 294 … … 303 339 map.statusLine.activateAnglePanel(false); 304 340 305 removeHighlighting(); 341 DataSet ds = getLayerManager().getEditDataSet(); 342 if (ds != null) { 343 ds.getSelected().stream().forEach(x -> updatePreservedFlag(x, false)); 344 } 345 346 removeHighlighting(null); 306 347 map.keyDetector.removeKeyListener(this); 307 348 map.keyDetector.removeModifierExListener(this); … … 317 358 updateKeyModifiersEx(modifiers); 318 359 computeHelperLine(); 319 addHighlighting( );360 addHighlighting(null); 320 361 } 321 362 … … 326 367 snapHelper.setFixedMode(); 327 368 computeHelperLine(); 328 redrawIfRequired( );369 redrawIfRequired(e); 329 370 } 330 371 … … 339 380 snapHelper.unFixOrTurnOff(); 340 381 computeHelperLine(); 341 redrawIfRequired( );382 redrawIfRequired(e); 342 383 } 343 384 … … 351 392 // Make sure helper line is computed later (causes deadlock in selection event chain otherwise) 352 393 SwingUtilities.invokeLater(() -> { 394 event.getOldSelection().stream().forEach(x -> updatePreservedFlag(x, false)); 395 event.getSelection().stream().forEach(x -> updatePreservedFlag(x, true)); 353 396 computeHelperLine(); 354 addHighlighting( );397 addHighlighting(event); 355 398 }); 356 399 } 357 400 358 401 private void tryAgain(MouseEvent e) { 359 getLayerManager().getEditDataSet(). setSelected();402 getLayerManager().getEditDataSet().clearSelection(); 360 403 mouseReleased(e); 361 404 } … … 374 417 // Redraw to remove the helper line stub 375 418 computeHelperLine(); 376 removeHighlighting( );419 removeHighlighting(null); 377 420 } 378 421 … … 445 488 // have to switch modes) 446 489 447 ds.setSelected(n);490 setSelection(ds, n); 448 491 // If we extend/continue an existing way, select it already now to make it obvious 449 492 Way continueFrom = getWayForNode(n); 450 493 if (continueFrom != null) { 451 ds.addSelected(continueFrom);494 addSelection(ds, continueFrom); 452 495 } 453 496 … … 627 670 } 628 671 629 ds.setSelected(newSelection);672 setSelection(ds, newSelection); 630 673 631 674 // "viewport following" mode for tracing long features … … 635 678 } 636 679 computeHelperLine(); 637 removeHighlighting( );680 removeHighlighting(e); 638 681 } 639 682 … … 730 773 (posn0 >= 1 && targetNode.equals(selectedWay.getNode(posn0-1)))) || // previous node 731 774 (posn0 < selectedWay.getNodesCount()-1 && targetNode.equals(selectedWay.getNode(posn0+1)))) { // next node 732 getLayerManager().getEditDataSet().setSelected(targetNode);775 setSelection(getLayerManager().getEditDataSet(), targetNode); 733 776 lastUsedNode = targetNode; 734 777 return true; … … 789 832 790 833 computeHelperLine(); 791 addHighlighting( );834 addHighlighting(e); 792 835 } 793 836 … … 961 1004 mousePos = e.getPoint(); 962 1005 snapHelper.noSnapNow(); 963 boolean repaintIssued = removeHighlighting( );1006 boolean repaintIssued = removeHighlighting(e); 964 1007 // force repaint in case snapHelper needs one. If removeHighlighting 965 1008 // caused one already, don't do it again. … … 1123 1166 * bar both addHighlighting() and repaintIfRequired() are needed, since former fills newHighlights 1124 1167 * and latter processes them into oldHighlights. 1125 */ 1126 private void addHighlighting() { 1168 * @param event event, can be null 1169 */ 1170 private void addHighlighting(Object event) { 1127 1171 newHighlights = new HashSet<>(); 1128 1172 MapView mapView = MainApplication.getMap().mapView; … … 1131 1175 if (ctrl) { 1132 1176 mapView.setNewCursor(cursor, this); 1133 redrawIfRequired( );1177 redrawIfRequired(event); 1134 1178 return; 1135 1179 } … … 1143 1187 mapView.setNewCursor(cursorJoinNode, this); 1144 1188 newHighlights.add(mouseOnExistingNode); 1145 redrawIfRequired( );1189 redrawIfRequired(event); 1146 1190 return; 1147 1191 } … … 1150 1194 if (mouseOnExistingWays.isEmpty()) { 1151 1195 mapView.setNewCursor(cursor, this); 1152 redrawIfRequired( );1196 redrawIfRequired(event); 1153 1197 return; 1154 1198 } … … 1156 1200 mapView.setNewCursor(cursorJoinWay, this); 1157 1201 newHighlights.addAll(mouseOnExistingWays); 1158 redrawIfRequired( );1202 redrawIfRequired(event); 1159 1203 } 1160 1204 1161 1205 /** 1162 1206 * Removes target highlighting from primitives. Issues repaint if required. 1207 * @param event event, can be null 1163 1208 * @return true if a repaint has been issued. 1164 1209 */ 1165 private boolean removeHighlighting( ) {1210 private boolean removeHighlighting(Object event) { 1166 1211 newHighlights = new HashSet<>(); 1167 return redrawIfRequired( );1212 return redrawIfRequired(event); 1168 1213 } 1169 1214 … … 1314 1359 public Collection<? extends OsmPrimitive> getPreservedPrimitives() { 1315 1360 DataSet ds = getLayerManager().getEditDataSet(); 1316 if (ds != null) { 1317 // Preserves selected primitives and selected way nodes 1318 Set<OsmPrimitive> result = new HashSet<>(); 1319 for (Way w : ds.getSelectedWays()) { 1320 result.addAll(w.getNodes()); 1321 } 1322 result.addAll(ds.getSelected()); 1323 return result; 1324 } 1325 return Collections.emptySet(); 1361 return ds != null ? ds.allPreservedPrimitives() : Collections.emptySet(); 1326 1362 } 1327 1363 … … 1368 1404 // select last added node - maybe we will continue drawing from it 1369 1405 if (n != null) { 1370 getLayerManager().getEditDataSet().addSelected(n);1406 addSelection(getLayerManager().getEditDataSet(), n); 1371 1407 } 1372 1408 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r13173 r13309 233 233 * Gets a collection of primitives that should not be hidden by the filter. 234 234 * @return The primitives that the filter should not hide. 235 * @deprecated use {@link org.openstreetmap.josm.data.osm.DataSet#allPreservedPrimitives} 235 236 * @since 11993 236 237 */ 238 @Deprecated 237 239 public Collection<? extends OsmPrimitive> getPreservedPrimitives() { 238 240 return Collections.emptySet(); -
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r12542 r13309 169 169 */ 170 170 protected static final short FLAG_ANNOTATED = 1 << 12; 171 172 /** 173 * Determines if the primitive is preserved from the filter mechanism. 174 */ 175 protected static final short FLAG_PRESERVED = 1 << 13; 171 176 172 177 /** -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r13208 r13309 518 518 519 519 /** 520 * Returns a collection containing all primitives preserved from filtering. 521 * @return A collection containing all primitives preserved from filtering. 522 * @see OsmPrimitive#isPreserved 523 * @since 13309 524 */ 525 public Collection<OsmPrimitive> allPreservedPrimitives() { 526 return getPrimitives(OsmPrimitive::isPreserved); 527 } 528 529 /** 520 530 * Adds a primitive to the dataset. 521 531 * -
trunk/src/org/openstreetmap/josm/data/osm/FilterMatcher.java
r12846 r13309 11 11 import org.openstreetmap.josm.data.osm.search.SearchMode; 12 12 import org.openstreetmap.josm.data.osm.search.SearchParseError; 13 import org.openstreetmap.josm.gui.MainApplication;14 import org.openstreetmap.josm.gui.MapFrame;15 13 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 16 14 … … 225 223 226 224 private static FilterType test(List<FilterInfo> filters, OsmPrimitive primitive, boolean hidden) { 227 MapFrame map = MainApplication.getMap(); 228 if (primitive.isIncomplete() || 229 (map != null && map.mapMode != null && map.mapMode.getPreservedPrimitives().contains(primitive))) 225 if (primitive.isIncomplete() || primitive.isPreserved()) 230 226 return FilterType.NOT_FILTERED; 231 227 -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r13173 r13309 428 428 429 429 /** 430 * Set binary property used internally by the filter mechanism. 431 * @param isPreserved new "preserved" flag value 432 * @since 13309 433 */ 434 public void setPreserved(boolean isPreserved) { 435 updateFlags(FLAG_PRESERVED, isPreserved); 436 } 437 438 /** 430 439 * Replies true, if this primitive is disabled. (E.g. a filter applies) 431 440 * @return {@code true} if this object has the "disabled" flag enabled … … 457 466 public boolean getDisabledType() { 458 467 return (flags & FLAG_DISABLED_TYPE) != 0; 468 } 469 470 /** 471 * Replies true, if this primitive is preserved from filtering. 472 * @return {@code true} if this object has the "preserved" flag enabled 473 * @since 13309 474 */ 475 public boolean isPreserved() { 476 return (flags & FLAG_PRESERVED) != 0; 459 477 } 460 478
Note:
See TracChangeset
for help on using the changeset viewer.