Changeset 637 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2008-05-13T00:02:14+02:00 (16 years ago)
Author:
framm
Message:
  • fixed more NPEs
File:
1 edited

Legend:

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

    r627 r637  
    6565        protected GeneralPath currentPath = new GeneralPath();
    6666
    67         private Rectangle screen;
    6867        Rectangle bbox = new Rectangle();
    6968
     
    171170                int y = (p1.y+p2.y)/2 + 4;
    172171
    173                 if (screen.contains(x,y)) {
     172                if (isSegmentVisible(p1, p2)) {
    174173                        Color c = g.getColor();
    175174                        g.setColor(backgroundColor);
     
    188187        public void drawNode(Node n, Color color) {
    189188                Point p = nc.getPoint(n.eastNorth);
    190                 g.setColor(color);
    191 
    192                 if (screen.contains(p.x, p.y))
    193                         if (n.tagged) {
    194                                 g.drawRect(p.x, p.y, 0, 0);
    195                                 g.drawRect(p.x-2, p.y-2, 4, 4);
    196                         } else {
    197                                 g.drawRect(p.x-1, p.y-1, 2, 2);
    198                         }
     189        if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;
     190
     191        g.setColor(color);
     192
     193        if (n.tagged) {
     194            g.drawRect(p.x, p.y, 0, 0);
     195            g.drawRect(p.x-2, p.y-2, 4, 4);
     196        } else {
     197            g.drawRect(p.x-1, p.y-1, 2, 2);
     198        }
    199199        }
    200200
     
    206206                if (col != currentColor) displaySegments(col);
    207207               
    208                 if (onScreen(p1, p2)) {
     208                if (isSegmentVisible(p1, p2)) {
    209209                        currentPath.moveTo(p1.x, p1.y);
    210210                        currentPath.lineTo(p2.x, p2.y);
     
    219219        }
    220220       
    221         private boolean onScreen(Point p1, Point p2) {
    222                 bbox.setBounds(p1.x, p1.y, 0, 0);
    223                 bbox.add(p2);
    224                 if (bbox.height + bbox.width < 1) return false;
    225                 bbox.width++;
    226                 bbox.height++;
    227                 return screen.intersects(bbox);
    228         }
     221    private boolean isSegmentVisible(Point p1, Point p2) {
     222        if ((p1.x < 0) && (p2.x < 0)) return false;
     223        if ((p1.y < 0) && (p2.y < 0)) return false;
     224        if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false;
     225        if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false;
     226        return true;
     227    }
    229228       
    230229        public void setGraphics(Graphics g) {
    231230                this.g = g;
    232                 screen = g.getClipBounds();
    233231        }
    234232
Note: See TracChangeset for help on using the changeset viewer.