Ignore:
Timestamp:
2007-09-24T01:36:24+02:00 (17 years ago)
Author:
framm
Message:

This commit is a manual merge of all changes that have been made to
the intermediate "core_0.5" branch on the main OSM repository,
bevore JOSM was moved to openstreetmap.de.

Changes incorporated here:

r4464@svn.openstreetmap.org
r4466@svn.openstreetmap.org
r4468@svn.openstreetmap.org
r4469@svn.openstreetmap.org
r4479@svn.openstreetmap.org

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r319 r329  
    44import java.awt.Color;
    55import java.awt.Graphics;
    6 import java.awt.Graphics2D;
    76import java.awt.Point;
    87import java.awt.Rectangle;
    9 import java.awt.geom.GeneralPath;
    108import java.awt.geom.Line2D;
    119
    1210import org.openstreetmap.josm.Main;
    1311import org.openstreetmap.josm.data.osm.DataSet;
     12import org.openstreetmap.josm.data.osm.Relation;
    1413import org.openstreetmap.josm.data.osm.Node;
    1514import org.openstreetmap.josm.data.osm.OsmPrimitive;
    16 import org.openstreetmap.josm.data.osm.Segment;
    1715import org.openstreetmap.josm.data.osm.Way;
    1816import org.openstreetmap.josm.gui.NavigatableComponent;
     
    3028        public final static Color darkblue = new Color(0,0,128);
    3129        public final static Color darkgreen = new Color(0,128,0);
    32        
     30
    3331        /**
    3432         * The environment to paint to.
     
    4139       
    4240        public boolean inactive;
    43        
     41
    4442        protected static final double PHI = Math.toRadians(20);
    4543
    46         /**
    47          * Preferences
    48          */
    49         protected Color inactiveColor;
    50         protected Color selectedColor;
    51         protected Color nodeColor;
    52         protected Color segmentColor;
    53         protected Color dfltWayColor;
    54         protected Color incompleteColor;
    55         protected Color backgroundColor;
    56         protected boolean showDirectionArrow;
    57         protected boolean showOrderNumber;
    58        
    59         /**
    60          * Draw subsequent segments of same color as one Path
    61          */
    62         protected Color currentColor = null;
    63         protected GeneralPath currrentPath = new GeneralPath();
    64        
    6544        public void visitAll(DataSet data) {
    66                 inactiveColor = getPreferencesColor("inactive", Color.DARK_GRAY);
    67                 selectedColor = getPreferencesColor("selected", Color.WHITE);
    68                 nodeColor = getPreferencesColor("node", Color.RED);
    69                 segmentColor = getPreferencesColor("segment", darkgreen);
    70                 dfltWayColor = getPreferencesColor("way", darkblue);
    71                 incompleteColor = getPreferencesColor("incomplete way", darkerblue);
    72                 backgroundColor = getPreferencesColor("background", Color.BLACK);
    73                 showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
    74                 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number");
    75                
    76                 for (final OsmPrimitive osm : data.segments)
    77                         if (!osm.deleted && !osm.selected)
    78                                 osm.visit(this);
    7945                for (final OsmPrimitive osm : data.ways)
    8046                        if (!osm.deleted && !osm.selected)
    8147                                osm.visit(this);
    82                 displaySegments(null);  // Flush segment cache before nodes
    8348                for (final OsmPrimitive osm : data.nodes)
    8449                        if (!osm.deleted && !osm.selected)
     
    8752                        if (!osm.deleted)
    8853                                osm.visit(this);
    89                 displaySegments(null);
    9054        }
    9155
     
    9963                Color color = null;
    10064                if (inactive)
    101                         color = inactiveColor;
     65                        color = getPreferencesColor("inactive", Color.DARK_GRAY);
    10266                else if (n.selected)
    103                         color = selectedColor;
     67                        color = getPreferencesColor("selected", Color.WHITE);
    10468                else
    105                         color = nodeColor;
     69                        color = getPreferencesColor("node", Color.RED);
    10670                drawNode(n, color);
    107         }
    108 
    109         /**
    110          * Draw just a line between the points.
    111          * White if selected (as always) or green otherwise.
    112          */
    113         public void visit(Segment ls) {
    114                 Color color;
    115                 if (inactive)
    116                         color = inactiveColor;
    117                 else if (ls.selected)
    118                         color = selectedColor;
    119                 else
    120                         color = segmentColor;
    121                 drawSegment(ls, color, showDirectionArrow);
    12271        }
    12372
     
    12978                Color wayColor;
    13079                if (inactive)
    131                         wayColor = inactiveColor;
     80                        wayColor = getPreferencesColor("inactive", Color.DARK_GRAY);
    13281                else {
    133                         wayColor = dfltWayColor;
    134                         for (Segment ls : w.segments) {
    135                                 if (ls.incomplete) {
    136                                         wayColor = incompleteColor;
    137                                         break;
    138                                 }
    139                         }
     82                        wayColor = getPreferencesColor("way", darkblue);
    14083                }
    14184
     85                boolean showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
     86                boolean showOrderNumber = Main.pref.getBoolean("draw.segment.order_number");
    14287                int orderNumber = 0;
    143                 for (Segment ls : w.segments) {
     88                Node lastN = null;
     89                for (Node n : w.nodes) {
     90                        if (lastN == null) {
     91                                lastN = n;
     92                                continue;
     93                        }
    14494                        orderNumber++;
    145                         if (!ls.selected) // selected already in good color
    146                                 drawSegment(ls, w.selected && !inactive ? selectedColor : wayColor, showDirectionArrow);
    147                         if (!ls.incomplete && showOrderNumber)
    148                                 drawOrderNumber(ls, orderNumber);
     95                        drawSegment(lastN, n, w.selected && !inactive ? getPreferencesColor("selected", Color.WHITE) : wayColor, showDirectionArrow);
     96                        if (showOrderNumber)
     97                                drawOrderNumber(lastN, n, orderNumber);
     98                        lastN = n;
    14999                }
    150100        }
    151101
     102        public void visit(Relation e) {
     103                // relations are not drawn.
     104        }
    152105        /**
    153          * Draw an number of the order of the segment within the parents way
     106         * Draw an number of the order of the two consecutive nodes within the
     107         * parents way
    154108         */
    155         protected void drawOrderNumber(Segment ls, int orderNumber) {
     109        protected void drawOrderNumber(Node n1, Node n2, int orderNumber) {
    156110                int strlen = (""+orderNumber).length();
    157                 Point p1 = nc.getPoint(ls.from.eastNorth);
    158                 Point p2 = nc.getPoint(ls.to.eastNorth);
     111                Point p1 = nc.getPoint(n1.eastNorth);
     112                Point p2 = nc.getPoint(n2.eastNorth);
    159113                int x = (p1.x+p2.x)/2 - 4*strlen;
    160114                int y = (p1.y+p2.y)/2 + 4;
     
    163117                if (screen.contains(x,y)) {
    164118                        Color c = g.getColor();
    165                         g.setColor(backgroundColor);
     119                        g.setColor(getPreferencesColor("background", Color.BLACK));
    166120                        g.fillRect(x-1, y-12, 8*strlen+1, 14);
    167121                        g.setColor(c);
     
    188142         * Draw a line with the given color.
    189143         */
    190         protected void drawSegment(Segment ls, Color col, boolean showDirection) {
    191                 if (ls.incomplete)
    192                         return;
    193                 if (col != currentColor) {
    194                         displaySegments(col);
    195                 }
     144        protected void drawSegment(Node n1, Node n2, Color col, boolean showDirection) {
     145                g.setColor(col);
     146                Point p1 = nc.getPoint(n1.eastNorth);
     147                Point p2 = nc.getPoint(n2.eastNorth);
    196148               
    197                 Point p1 = nc.getPoint(ls.from.eastNorth);
    198                 Point p2 = nc.getPoint(ls.to.eastNorth);
    199                
    200                 Rectangle screen = g.getClipBounds();           
     149                Rectangle screen = g.getClipBounds();
    201150                Line2D line = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
    202151                if (screen.contains(p1.x, p1.y, p2.x, p2.y) || screen.intersectsLine(line))
    203152                {
    204                         currrentPath.moveTo(p1.x, p1.y);
    205                         currrentPath.lineTo(p2.x, p2.y);
     153                        g.drawLine(p1.x, p1.y, p2.x, p2.y);
    206154       
    207155                        if (showDirection) {
    208156                                double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
    209                                 currrentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
    210                                 currrentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
    211                                 currrentPath.lineTo(p2.x, p2.y);                        }
    212                 }
    213         }
    214        
    215         protected void displaySegments(Color newColor) {
    216                 if (currrentPath != null) {
    217                         g.setColor(currentColor);
    218                         ((Graphics2D) g).draw(currrentPath);
    219                         currrentPath = new GeneralPath();
    220                         currentColor = newColor;
     157                        g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
     158                        g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
     159                        }
    221160                }
    222161        }
Note: See TracChangeset for help on using the changeset viewer.