Changeset 1409 in josm for trunk/src


Ignore:
Timestamp:
2009-02-15T18:30:41+01:00 (15 years ago)
Author:
stoecker
Message:

close #1902. Patch by xeen

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r1405 r1409  
    6666    private boolean alt;
    6767    private boolean shift;
    68     private boolean mouseOnExistingNode;
     68    private Node mouseOnExistingNode;
     69    private Set<Way> mouseOnExistingWays = new HashSet<Way>();
     70    private Set<OsmPrimitive> oldHighlights = new HashSet<OsmPrimitive>();
    6971    private boolean drawHelperLine;
    7072    private boolean wayIsFinished = false;
     73    private boolean drawTargetHighlight;
     74    private boolean drawTargetCursor;
    7175    private Point mousePos;
    7276    private Color selectedColor;
     
    9397    }
    9498
     99    /**
     100     * Sets a special cursor to indicate that the next click will automatically join into
     101     * an existing node or way (if feature is enabled)
     102     *
     103     * @param way If true, the cursor will indicate it is joined into a way; node otherwise
     104     */
     105    private void setJoinCursor(boolean way) {
     106        if(!drawTargetCursor) {
     107            resetCursor();
     108            return;
     109        }
     110        try {
     111            Main.map.mapView.setCursor(
     112                    ImageProvider.getCursor("crosshair", (way ? "joinway" : "joinnode"))
     113            );
     114            return;
     115        } catch (Exception e) {
     116            e.printStackTrace();
     117        }
     118        resetCursor();
     119    }
     120
     121    /**
     122     * Resets the cursor to the default cursor for drawing mode (i.e. crosshair)
     123     */
     124    private void resetCursor() {
     125        Main.map.mapView.setCursor(getCursor());
     126    }
     127
     128    /**
     129     * Takes the data from computeHelperLine to determine which ways/nodes should be highlighted
     130     * (if feature enabled). Also sets the target cursor if appropriate.
     131     */
     132    private void addHighlighting() {
     133        // if ctrl key is held ("no join"), don't highlight anything
     134        if (ctrl) {
     135            removeHighlighting();
     136            resetCursor();
     137            return;
     138        }
     139
     140        if (mouseOnExistingNode != null) {
     141            setJoinCursor(false);
     142            // Clean old highlights
     143            removeHighlighting();
     144            if(drawTargetHighlight) {
     145                oldHighlights.add(mouseOnExistingNode);
     146                mouseOnExistingNode.highlighted = true;
     147            }
     148            return;
     149        }
     150
     151        // Insert the node into all the nearby way segments
     152        if(mouseOnExistingWays.size() == 0) {
     153            removeHighlighting();
     154            resetCursor();
     155            return;
     156        }
     157
     158        setJoinCursor(true);
     159        // Clean old highlights
     160        removeHighlighting();
     161
     162        if(!drawTargetHighlight) return;
     163        oldHighlights.addAll(mouseOnExistingWays);
     164        for(Way w : mouseOnExistingWays) {
     165            w.highlighted = true;
     166        }
     167    }
     168
     169    /**
     170     * Removes target highlighting from primitives
     171     */
     172    private void removeHighlighting() {
     173        for(OsmPrimitive prim : oldHighlights) {
     174            prim.highlighted = false;
     175        }
     176    }
     177
    95178    @Override public void enterMode() {
    96179        super.enterMode();
    97180        selectedColor = Main.pref.getColor(marktr("selected"), Color.red);
    98181        drawHelperLine = Main.pref.getBoolean("draw.helper-line", true);
     182        drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true);
     183        drawTargetCursor = Main.pref.getBoolean("draw.target-cursor", true);
    99184        wayIsFinished = false;
    100        
     185
    101186        Main.map.mapView.addMouseListener(this);
    102187        Main.map.mapView.addMouseMotionListener(this);
    103188        Main.map.mapView.addTemporaryLayer(this);
    104189        DataSet.selListeners.add(this);
     190
    105191        try {
    106192            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
     
    110196        // computeHelperLine(false, false, false);
    111197    }
     198
    112199    @Override public void exitMode() {
    113200        super.exitMode();
     
    116203        Main.map.mapView.removeTemporaryLayer(this);
    117204        DataSet.selListeners.remove(this);
     205        removeHighlighting();
    118206        try {
    119207            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
     
    147235        mouseClicked(e);
    148236    }
    149    
     237
    150238    /**
    151239     * If user clicked with the left button, add a node at the current mouse
     
    184272        if (!ctrl)
    185273            n = Main.map.mapView.getNearestNode(mousePos);
    186      
     274
    187275        if (n != null) {
    188276            // user clicked on node
     
    259347            Node selectedNode = null;
    260348            Way selectedWay = null;
    261            
     349
    262350            for (OsmPrimitive p : selection) {
    263351                if (p instanceof Node) {
     
    277365                }
    278366            }
    279            
     367
    280368            // No nodes or ways have been selected, try again with no selection
    281369            // This occurs when a relation has been selected
     
    292380                    n0 = lastUsedNode;
    293381                } else {
    294                     // We have a way selected, but no suitable node to continue from. Start anew. 
     382                    // We have a way selected, but no suitable node to continue from. Start anew.
    295383                    tryAgain(e);
    296384                    return;
     
    326414                }
    327415            }
    328            
     416
    329417            // User clicked last node again, finish way
    330418            if(n0 == n) {
     
    379467            Main.ds.setSelected(way);
    380468        }
    381      
     469
    382470        String title;
    383471        if (!extendedWay) {
     
    404492        if(!wayIsFinished) lastUsedNode = n;
    405493        computeHelperLine();
     494        removeHighlighting();
    406495        Main.map.mapView.repaint();
    407496    }
     
    420509        mousePos = e.getPoint();
    421510
     511        addHighlighting();
    422512        computeHelperLine();
    423513    }
     
    444534        Way selectedWay = null;
    445535        Node currentMouseNode = null;
    446         mouseOnExistingNode = false;
     536        mouseOnExistingNode = null;
     537        mouseOnExistingWays = new HashSet<Way>();
    447538
    448539        Main.map.statusLine.setAngle(-1);
     
    452543        if (!ctrl && mousePos != null) {
    453544            currentMouseNode = Main.map.mapView.getNearestNode(mousePos);
     545        }
     546
     547        // We need this for highlighting and we'll only do so if we actually want to re-use
     548        // *and* there is no node nearby (because nodes beat ways when re-using)
     549        if(!ctrl && currentMouseNode == null) {
     550            List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(mousePos);
     551            for(WaySegment ws : wss)
     552                mouseOnExistingWays.add(ws.way);
    454553        }
    455554
     
    458557            if (selection.isEmpty()) return;
    459558            currentMouseEastNorth = currentMouseNode.eastNorth;
    460             mouseOnExistingNode = true;
     559            mouseOnExistingNode = currentMouseNode;
    461560        } else {
    462561            // no node found in clicked area
     
    511610        updateStatusLine();
    512611
    513         if (!drawHelperLine || wayIsFinished) return;
    514 
     612        if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight) return;
    515613        Main.map.mapView.repaint();
    516614    }
     
    640738
    641739    public void paint(Graphics g, MapView mv) {
    642 
    643         // don't draw line if disabled in prefs
    644         if (!drawHelperLine) return;
     740        if (!drawHelperLine && !drawTargetHighlight) return;
    645741
    646742        // sanity checks
     
    652748
    653749        // don't draw line if we don't know where from or where to
    654         if (currentBaseNode == null) return;
    655         if (currentMouseEastNorth == null) return;
     750        if (currentBaseNode == null || currentMouseEastNorth == null) return;
    656751
    657752        // don't draw line if mouse is outside window
     
    677772        g2.draw(b);
    678773        g2.setStroke(new BasicStroke(1));
    679 
    680774    }
    681775
     
    684778
    685779        if (currentBaseNode != null && !shift) {
    686             if (mouseOnExistingNode) {
     780            if (mouseOnExistingNode != null) {
    687781                if (alt && /* FIXME: way exists */true)
    688782                    rv = tr("Click to create a new way to the existing node.");
     
    704798        return rv.toString();
    705799    }
    706    
     800
    707801    @Override public boolean layerIsSupported(Layer l) {
    708802        return l instanceof OsmDataLayer;
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r1314 r1409  
    123123     */
    124124    public volatile boolean selected = false;
     125   
     126    /**
     127     * If set to true, this object is highlighted. Currently this is only used to
     128     * show which ways/nodes will connect
     129     */
     130    public volatile boolean highlighted = false;
    125131
    126132    /**
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1367 r1409  
    120120        if(osm.mappaintStyle == null && styles != null) {
    121121            osm.mappaintStyle = styles.get(osm);
    122             if(osm instanceof Way)
    123                 osm.isMappaintArea = styles.isArea(osm);
     122            osm.isMappaintArea = styles.isArea(osm);
    124123        }
    125124        return osm.isMappaintArea;
     
    151150        if (nodeStyle != null && isZoomOk(nodeStyle) && showIcons > dist)
    152151            drawNode(n, nodeStyle.icon, nodeStyle.annotate, n.selected);
     152        else if (n.highlighted)
     153            drawNode(n, highlightColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
    153154        else if (n.selected)
    154155            drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
     
    266267            if (tmpWidth > width) width = tmpWidth;
    267268        }
    268         if(w.selected)
     269
     270        if(w.highlighted)
     271            color = highlightColor;
     272        else if(w.selected)
    269273            color = selectedColor;
    270274
     
    11361140                g2d.draw(currentPath);
    11371141            }
    1138            
     1142
    11391143            if(useStrokes > dist)
    11401144                g2d.setStroke(new BasicStroke(1));
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r1289 r1409  
    3737    public final static Color darkgreen = new Color(0,128,0);
    3838    public final static Color teal = new Color(0,128,128);
     39    public final static Color lightteal= new Color(0, 255, 186);
    3940
    4041    /**
     
    6263    protected Color incompleteColor;
    6364    protected Color backgroundColor;
     65    protected Color highlightColor;
    6466    protected boolean showDirectionArrow;
    6567    protected boolean showRelevantDirectionsOnly;
     
    9799        incompleteColor = Main.pref.getColor(marktr("incomplete way"), darkerblue);
    98100        backgroundColor = Main.pref.getColor(marktr("background"), Color.BLACK);
     101        highlightColor = Main.pref.getColor(marktr("highlight"), lightteal);
    99102    }
    100103
     
    132135
    133136        getSettings(virtual);
    134        
    135         if(profiler) 
     137
     138        if(profiler)
    136139        {
    137140            System.out.format("Prepare  : %4dms\n", (java.lang.System.currentTimeMillis()-profilerLast));
    138141            profilerLast = java.lang.System.currentTimeMillis();
    139142        }
    140        
     143
    141144        // draw tagged ways first, then untagged ways. takes
    142145        // time to iterate through list twice, OTOH does not
     
    245248        if (inactive)
    246249            drawNode(n, inactiveColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
     250        else if (n.highlighted)
     251            drawNode(n, highlightColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
    247252        else if (n.selected)
    248253            drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
     
    301306        if (inactive) {
    302307            wayColor = inactiveColor;
     308        } else if(w.highlighted) {
     309            wayColor = highlightColor;
     310        } else if(w.selected) {
     311            wayColor = selectedColor;
    303312        } else if (!w.tagged) {
    304313            wayColor = untaggedWayColor;
     
    312321            for (int orderNumber = 1; it.hasNext(); orderNumber++) {
    313322                Point p = nc.getPoint(it.next().eastNorth);
    314                 drawSegment(lastP, p, w.selected && !inactive ? selectedColor : wayColor,
     323                drawSegment(lastP, p, wayColor,
    315324                    showOnlyHeadArrowOnly ? !it.hasNext() : showThisDirectionArrow);
    316325                if (showOrderNumber)
Note: See TracChangeset for help on using the changeset viewer.