Changeset 3828 in osm for applications/editors


Ignore:
Timestamp:
2007-07-29T01:01:21+02:00 (17 years ago)
Author:
christofd
Message:

add calculated route to layer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorLayer.java

    r3749 r3828  
    44package at.dallermassl.josm.plugin.navigator;
    55
     6import java.awt.BasicStroke;
     7import java.awt.Color;
    68import java.awt.Component;
    79import java.awt.Graphics;
     10import java.awt.Graphics2D;
    811import java.awt.Point;
     12import java.awt.Rectangle;
     13import java.awt.geom.Line2D;
    914import java.util.List;
    1015
     
    1621import org.openstreetmap.josm.gui.MapView;
    1722import org.openstreetmap.josm.gui.layer.Layer;
     23import org.openstreetmap.josm.tools.ColorHelper;
    1824import org.openstreetmap.josm.tools.ImageProvider;
    1925
     
    2531 */
    2632public class NavigatorLayer extends Layer {
     33    private static final String KEY_ROUTE_COLOR = "color.navigator.route";
     34    private static final String KEY_ROUTE_WIDTH = "navigator.route.width";
     35    private static final String KEY_ROUTE_SELECT = "navigator.route.select";
     36    protected static final double ARROW_PHI = Math.toRadians(20);
    2737    private NavigatorModel navigatorNodeModel;
    2838    private Icon startIcon;
     
    137147            endIcon.paintIcon(mv, g, screen.x, screen.y - endIcon.getIconHeight());
    138148        }
    139        
    140         List<Segment> path = navigatorNodeModel.getSegmentPath();
    141         if(path != null) {
    142             synchronized(path) {
    143                 // TODO paint path
     149
     150        Main.pref.hasKey(KEY_ROUTE_COLOR);
     151        String selectString = Main.pref.get(KEY_ROUTE_SELECT);
     152        if(selectString.length() == 0) {
     153            selectString = "true";
     154            Main.pref.put(KEY_ROUTE_SELECT, selectString);
     155        }
     156       
     157        if(Boolean.parseBoolean(selectString)) {
     158            List<Segment> path = navigatorNodeModel.getSegmentPath();
     159            if(path != null) {
     160                synchronized(path) {
     161                    Main.ds.setSelected(path);
     162//                  Main.map.mapView.repaint();
     163                }
    144164            }
    145165        }
    146     }
     166       
     167        String colorString = Main.pref.get(KEY_ROUTE_COLOR);
     168        if(colorString.length() == 0) {
     169            colorString = ColorHelper.color2html(Color.GREEN);
     170            // FIXXME add after good color is found: Main.pref.put(KEY_ROUTE_COLOR, colorString);
     171        }
     172        Color color = ColorHelper.html2color(colorString);
     173
     174        String widthString = Main.pref.get(KEY_ROUTE_WIDTH);
     175        if(widthString.length() == 0) {
     176            widthString = "5";
     177            // FIXXME add after good width is found: Main.pref.put(KEY_ROUTE_WIDTH, widthString);
     178        }
     179        int width = Integer.parseInt(widthString);
     180
     181        List<SegmentEdge>edgePath = navigatorNodeModel.getEdgePath();
     182        if(edgePath != null) {
     183            for(SegmentEdge edge : edgePath) {
     184                drawSegmentEdge(g, mv, edge, color, width, true);
     185            }
     186        }
     187    }
     188   
     189    /**
     190     * Draw a line with the given color.
     191     */
     192    protected void drawSegmentEdge(Graphics g, MapView mv, SegmentEdge edge, Color col, int width, boolean showDirection) {
     193        g.setColor(col);
     194        Point from;
     195        Point to;
     196        if(!edge.isInverted()) {
     197            from = mv.getPoint(edge.getSegment().from.eastNorth);
     198            to = mv.getPoint(edge.getSegment().to.eastNorth);
     199        } else {
     200            from = mv.getPoint(edge.getSegment().to.eastNorth);
     201            to = mv.getPoint(edge.getSegment().from.eastNorth);           
     202        }
     203       
     204        Rectangle screen = g.getClipBounds();
     205        Line2D line = new Line2D.Double(from.x, from.y, to.x, to.y);
     206        if (screen.contains(from.x, from.y, to.x, to.y) || screen.intersectsLine(line))
     207        {
     208            Graphics2D g2d = (Graphics2D)g;
     209            g2d.setStroke(new BasicStroke(width)); // thickness
     210            g.drawLine(from.x, from.y, to.x, to.y);
     211            if (showDirection) {
     212                double t = Math.atan2(to.y-from.y, to.x-from.x) + Math.PI;
     213                g.drawLine(to.x,to.y, (int)(to.x + 10*Math.cos(t-ARROW_PHI)), (int)(to.y + 10*Math.sin(t-ARROW_PHI)));
     214                g.drawLine(to.x,to.y, (int)(to.x + 10*Math.cos(t+ARROW_PHI)), (int)(to.y + 10*Math.sin(t+ARROW_PHI)));
     215            }
     216        }
     217    }
     218
    147219
    148220    /*
Note: See TracChangeset for help on using the changeset viewer.