Ignore:
Timestamp:
2011-12-26T12:57:26+01:00 (12 years ago)
Author:
bastiK
Message:

fixed NPE from [4695] (see #7153)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r4604 r4710  
    7070
    7171    public MarkerLayer(GpxData indata, String name, File associatedFile, GpxLayer fromLayer) {
    72 
     72        this(indata, name, associatedFile, fromLayer, true);
     73    }
     74
     75    public MarkerLayer(GpxData indata, String name, File associatedFile, GpxLayer fromLayer, boolean addMouseHandlerInConstructor) {
    7376        super(name);
    7477        this.setAssociatedFile(associatedFile);
     
    8891        }
    8992
    90         SwingUtilities.invokeLater(new Runnable(){
    91             public void run() {
    92                 Main.map.mapView.addMouseListener(new MouseAdapter() {
    93                     @Override public void mousePressed(MouseEvent e) {
    94                         if (e.getButton() != MouseEvent.BUTTON1)
    95                             return;
    96                         boolean mousePressedInButton = false;
    97                         if (e.getPoint() != null) {
    98                             for (Marker mkr : data) {
    99                                 if (mkr.containsPoint(e.getPoint())) {
    100                                     mousePressedInButton = true;
    101                                     break;
    102                                 }
    103                             }
    104                         }
    105                         if (! mousePressedInButton)
    106                             return;
    107                         mousePressed  = true;
    108                         if (isVisible()) {
    109                             Main.map.mapView.repaint();
     93        if (addMouseHandlerInConstructor) {
     94            SwingUtilities.invokeLater(new Runnable(){
     95                public void run() {
     96                    addMouseHandler();
     97                }
     98            });
     99        }
     100    }
     101
     102    public void addMouseHandler() {
     103        Main.map.mapView.addMouseListener(new MouseAdapter() {
     104            @Override public void mousePressed(MouseEvent e) {
     105                if (e.getButton() != MouseEvent.BUTTON1)
     106                    return;
     107                boolean mousePressedInButton = false;
     108                if (e.getPoint() != null) {
     109                    for (Marker mkr : data) {
     110                        if (mkr.containsPoint(e.getPoint())) {
     111                            mousePressedInButton = true;
     112                            break;
    110113                        }
    111114                    }
    112                     @Override public void mouseReleased(MouseEvent ev) {
    113                         if (ev.getButton() != MouseEvent.BUTTON1 || ! mousePressed)
    114                             return;
    115                         mousePressed = false;
    116                         if (!isVisible())
    117                             return;
    118                         if (ev.getPoint() != null) {
    119                             for (Marker mkr : data) {
    120                                 if (mkr.containsPoint(ev.getPoint())) {
    121                                     mkr.actionPerformed(new ActionEvent(this, 0, null));
    122                                 }
    123                             }
     115                }
     116                if (! mousePressedInButton)
     117                    return;
     118                mousePressed  = true;
     119                if (isVisible()) {
     120                    Main.map.mapView.repaint();
     121                }
     122            }
     123            @Override public void mouseReleased(MouseEvent ev) {
     124                if (ev.getButton() != MouseEvent.BUTTON1 || ! mousePressed)
     125                    return;
     126                mousePressed = false;
     127                if (!isVisible())
     128                    return;
     129                if (ev.getPoint() != null) {
     130                    for (Marker mkr : data) {
     131                        if (mkr.containsPoint(ev.getPoint())) {
     132                            mkr.actionPerformed(new ActionEvent(this, 0, null));
    124133                        }
    125                         Main.map.mapView.repaint();
    126134                    }
    127                 });
     135                }
     136                Main.map.mapView.repaint();
    128137            }
    129138        });
Note: See TracChangeset for help on using the changeset viewer.