Ticket #7503: only_repaint_if_changed.patch

File only_repaint_if_changed.patch, 4.1 KB (added by xeen, 14 years ago)
  • src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

     
    251251     * @return true if a repaint is required
    252252     */
    253253    private boolean removeHighlighting() {
     254        System.out.println("removing highlights");
    254255        boolean needsRepaint = false;
    255256        DataSet ds = getCurrentDataSet();
    256257        if(ds != null && !ds.getHighlightedVirtualNodes().isEmpty()) {
     
    267268        return true;
    268269    }
    269270
     271    private boolean repaintIfRequired(HashSet<OsmPrimitive> newHighlights) {
     272        if(!drawTargetHighlight)
     273            return false;
     274
     275        boolean needsRepaint = false;
     276        for(OsmPrimitive x : newHighlights) {
     277            if(oldHighlights.contains(x)) {
     278                continue;
     279            }
     280            needsRepaint = true;
     281            x.setHighlighted(true);
     282        }
     283        oldHighlights.removeAll(newHighlights);
     284        for(OsmPrimitive x : oldHighlights) {
     285            x.setHighlighted(false);
     286            needsRepaint = true;
     287        }
     288        oldHighlights = newHighlights;
     289        if(needsRepaint) {
     290            System.out.println("repainting" + System.currentTimeMillis());
     291        }
     292        return needsRepaint;
     293    }
     294
    270295    /**
    271296     * handles adding highlights and updating the cursor for the given mouse event.
    272297     * Please note that the highlighting for merging while moving is handled via mouseDragged.
     
    285310     * @return true if repaint is required
    286311     */
    287312    private boolean giveUserFeedback(MouseEvent e, int modifiers) {
    288         boolean needsRepaint = false;
    289 
    290313        Collection<OsmPrimitive> c = MapView.asColl(
    291314                mv.getNearestNodeOrWay(e.getPoint(), OsmPrimitive.isSelectablePredicate, true));
    292315
    293316        updateKeyModifiers(modifiers);
    294317        determineMapMode(!c.isEmpty());
    295318
    296         if(drawTargetHighlight) {
    297             needsRepaint = removeHighlighting();
    298         }
     319        HashSet<OsmPrimitive> newHighlights = new HashSet<OsmPrimitive>();
    299320
    300321        virtualWays.clear();
    301322        virtualNode = null;
    302323        if(mode == Mode.move && setupVirtual(e)) {
    303324            DataSet ds = getCurrentDataSet();
    304             if (ds != null) {
    305                 if(drawTargetHighlight) ds.setHighlightedVirtualNodes(virtualWays);
     325            if (ds != null && drawTargetHighlight) {
     326                ds.setHighlightedVirtualNodes(virtualWays);
    306327            }
    307328            mv.setNewCursor(SelectActionCursor.virtual_node.cursor(), this);
    308329            // don't highlight anything else if a virtual node will be
    309             return drawTargetHighlight; // if no highlighting, repaint is not needed
     330            return repaintIfRequired(newHighlights);
    310331        }
    311332
    312333        mv.setNewCursor(getCursor(c), this);
    313334
    314335        // return early if there can't be any highlights
    315336        if(!drawTargetHighlight || mode != Mode.move || c.isEmpty())
    316             return needsRepaint;
     337            return repaintIfRequired(newHighlights);
    317338
    318339        // CTRL toggles selection, but if while dragging CTRL means merge
    319340        final boolean isToggleMode = ctrl && !dragInProgress();
     
    322343            // when clicked. I.e. don't highlight selected elements unless
    323344            // we are in toggle mode.
    324345            if(isToggleMode || !x.isSelected()) {
    325                 x.setHighlighted(true);
    326                 oldHighlights.add(x);
     346                newHighlights.add(x);
    327347            }
    328348        }
    329         return needsRepaint || !oldHighlights.isEmpty();
     349        return repaintIfRequired(newHighlights);
    330350    }
    331351
    332352    /**
     
    445465                return;
    446466
    447467            Command c = !Main.main.undoRedo.commands.isEmpty()
    448                     ? Main.main.undoRedo.commands.getLast() : null;
     468            ? Main.main.undoRedo.commands.getLast() : null;
    449469            if (c instanceof SequenceCommand) {
    450470                c = ((SequenceCommand) c).getLastCommand();
    451471            }