Ignore:
Timestamp:
2017-08-11T20:16:39+02:00 (7 years ago)
Author:
bastiK
Message:

only one primitive can be highlighted at a time - use Optional

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r12592 r12593  
    181181     * set would have to be checked.
    182182     */
    183     private transient Set<OsmPrimitive> oldHighlights = new HashSet<>();
     183    private transient Optional<OsmPrimitive> currentHighlight = Optional.empty();
    184184
    185185    /**
     
    257257        determineMapMode(c.isPresent());
    258258
    259         Set<OsmPrimitive> newHighlights = new HashSet<>();
     259        Optional<OsmPrimitive> newHighlight = Optional.empty();
    260260
    261261        virtualManager.clear();
     
    267267            mv.setNewCursor(SelectActionCursor.virtual_node.cursor(), this);
    268268            // don't highlight anything else if a virtual node will be
    269             return repaintIfRequired(newHighlights);
     269            return repaintIfRequired(newHighlight);
    270270        }
    271271
     
    274274        // return early if there can't be any highlights
    275275        if (!drawTargetHighlight || mode != Mode.MOVE || !c.isPresent())
    276             return repaintIfRequired(newHighlights);
     276            return repaintIfRequired(newHighlight);
    277277
    278278        // CTRL toggles selection, but if while dragging CTRL means merge
     
    282282            // when clicked. I.e. don't highlight selected elements unless
    283283            // we are in toggle mode.
    284             newHighlights.add(c.get());
    285         }
    286         return repaintIfRequired(newHighlights);
     284            newHighlight = c;
     285        }
     286        return repaintIfRequired(newHighlight);
    287287    }
    288288
     
    354354            ds.clearHighlightedVirtualNodes();
    355355        }
    356         if (oldHighlights.isEmpty())
     356        if (!currentHighlight.isPresent()) {
    357357            return needsRepaint;
    358 
    359         for (OsmPrimitive prim : oldHighlights) {
    360             prim.setHighlighted(false);
    361         }
    362         oldHighlights = new HashSet<>();
     358        } else {
     359            currentHighlight.get().setHighlighted(false);
     360        }
     361        currentHighlight = Optional.empty();
    363362        return true;
    364363    }
    365364
    366     private boolean repaintIfRequired(Set<OsmPrimitive> newHighlights) {
    367         if (!drawTargetHighlight)
     365    private boolean repaintIfRequired(Optional<OsmPrimitive> newHighlight) {
     366        if (!drawTargetHighlight || currentHighlight.equals(newHighlight))
    368367            return false;
    369 
    370         boolean needsRepaint = false;
    371         for (OsmPrimitive x : newHighlights) {
    372             if (oldHighlights.contains(x)) {
    373                 continue;
    374             }
    375             needsRepaint = true;
    376             x.setHighlighted(true);
    377         }
    378         oldHighlights.removeAll(newHighlights);
    379         for (OsmPrimitive x : oldHighlights) {
    380             x.setHighlighted(false);
    381             needsRepaint = true;
    382         }
    383         oldHighlights = newHighlights;
    384         return needsRepaint;
     368        currentHighlight.ifPresent(osm -> osm.setHighlighted(false));
     369        newHighlight.ifPresent(osm -> osm.setHighlighted(true));
     370        currentHighlight = newHighlight;
     371        return true;
    385372    }
    386373
     
    521508            if (p != null) {
    522509                p.setHighlighted(true);
    523                 oldHighlights.add(p);
     510                currentHighlight = Optional.of(p);
    524511                needsRepaint = true;
    525512            }
Note: See TracChangeset for help on using the changeset viewer.