Changeset 12343 in josm


Ignore:
Timestamp:
2017-06-08T01:20:59+02:00 (2 years ago)
Author:
michael2402
Message:

Add the ability to listen to NoteData changes and use it to repaint notes layer.

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

Legend:

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

    r11821 r12343  
    1616import org.openstreetmap.josm.data.notes.NoteComment;
    1717import org.openstreetmap.josm.gui.JosmUserIdentityManager;
     18import org.openstreetmap.josm.tools.ListenerList;
    1819
    1920/**
     
    2223public class NoteData {
    2324
     25    /**
     26     * A listener that can be informed on note data changes.
     27     * @author Michael Zangl
     28     * @since 12343
     29     */
     30    public interface NoteDataUpdateListener {
     31        /**
     32         * Called when the note data is updated
     33         * @param data The data that was changed
     34         */
     35        void noteDataUpdated(NoteData data);
     36
     37        /**
     38         * The selected node was changed
     39         * @param noteData The data of which the selected node was changed
     40         */
     41        void selectedNoteChanged(NoteData noteData);
     42    }
     43
    2444    private long newNoteId = -1;
    2545
     
    2747    private Note selectedNote;
    2848    private Comparator<Note> comparator = Note.DEFAULT_COMPARATOR;
     49
     50    private final ListenerList<NoteDataUpdateListener> listeners = ListenerList.create();
    2951
    3052    /**
     
    7799        if (Main.map != null) {
    78100            Main.map.noteDialog.selectionChanged();
    79             Main.map.mapView.repaint();
    80         }
     101        }
     102        listeners.fireEvent(l -> l.selectedNoteChanged(this));
    81103    }
    82104
     
    213235        if (Main.isDisplayingMapView()) {
    214236            Main.map.noteDialog.setNotes(getSortedNotes());
    215             Main.map.mapView.repaint();
    216         }
     237        }
     238        listeners.fireEvent(l -> l.noteDataUpdated(this));
    217239    }
    218240
     
    256278        dataUpdated();
    257279    }
     280
     281    /**
     282     * Adds a listener that listens to node data changes
     283     * @param listener The listener
     284     */
     285    public void addNoteDataUpdateListener(NoteDataUpdateListener listener) {
     286        listeners.addListener(listener);
     287    }
     288
     289    /**
     290     * Removes a listener that listens to node data changes
     291     * @param listener The listener
     292     */
     293    public void removeNoteDataUpdateListener(NoteDataUpdateListener listener) {
     294        listeners.removeListener(listener);
     295    }
    258296}
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r12206 r12343  
    3030import org.openstreetmap.josm.data.notes.NoteComment;
    3131import org.openstreetmap.josm.data.osm.NoteData;
     32import org.openstreetmap.josm.data.osm.NoteData.NoteDataUpdateListener;
    3233import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    3334import org.openstreetmap.josm.gui.MapView;
     
    4950 * @since 7522
    5051 */
    51 public class NoteLayer extends AbstractModifiableLayer implements MouseListener {
     52public class NoteLayer extends AbstractModifiableLayer implements MouseListener, NoteDataUpdateListener {
    5253
    5354    private final NoteData noteData;
     
    6162        super(name);
    6263        noteData = new NoteData(notes);
     64        noteData.addNoteDataUpdateListener(this);
    6365    }
    6466
     
    7173    public void hookUpMapView() {
    7274        Main.map.mapView.addMouseListener(this);
     75    }
     76
     77    @Override
     78    public synchronized void destroy() {
     79        Main.map.mapView.removeMouseListener(this);
     80        noteData.removeNoteDataUpdateListener(this);
     81        super.destroy();
    7382    }
    7483
     
    260269        }
    261270        noteData.setSelectedNote(closestNote);
    262         invalidate();
    263271    }
    264272
     
    292300        // Do nothing
    293301    }
     302
     303    @Override
     304    public void noteDataUpdated(NoteData data) {
     305        invalidate();
     306    }
     307
     308    @Override
     309    public void selectedNoteChanged(NoteData noteData) {
     310        invalidate();
     311    }
    294312}
Note: See TracChangeset for help on using the changeset viewer.