mirror of
https://github.com/OMGeeky/ATCS.git
synced 2025-12-26 23:57:25 +01:00
fix oversight, where changes would call the wrong event
This commit is contained in:
@@ -8,13 +8,24 @@ import java.util.List;
|
||||
public interface ListenerListModel<E> extends ListModel<E> {
|
||||
List<ListDataListener> getListeners();
|
||||
|
||||
default void notifyListeners(int event, int index0, int index1) {
|
||||
default void notifyListeners(ChangeType event, int index0, int index1) {
|
||||
notifyListeners(this, event, index0, index1);
|
||||
}
|
||||
|
||||
default void notifyListeners(Object source, int event, int index0, int index1) {
|
||||
default void notifyListeners(Object source, ChangeType event, int index0, int index1) {
|
||||
int eventCode = switch (event) {
|
||||
case CHANGED -> ListDataEvent.CONTENTS_CHANGED;
|
||||
case ADDED -> ListDataEvent.INTERVAL_ADDED;
|
||||
case REMOVED -> ListDataEvent.INTERVAL_REMOVED;
|
||||
};
|
||||
|
||||
for (ListDataListener l : getListeners()) {
|
||||
l.intervalRemoved(new ListDataEvent(source, event, index0, index1));
|
||||
ListDataEvent e = new ListDataEvent(source, eventCode, index0, index1);
|
||||
switch (event) {
|
||||
case CHANGED -> l.contentsChanged(e);
|
||||
case ADDED -> l.intervalAdded(e);
|
||||
case REMOVED -> l.intervalRemoved(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +38,12 @@ public interface ListenerListModel<E> extends ListModel<E> {
|
||||
}
|
||||
|
||||
default void fireListChanged() {
|
||||
notifyListeners(ListDataEvent.CONTENTS_CHANGED, 0, getSize() - 1);
|
||||
notifyListeners(this, ChangeType.CHANGED, 0, getSize() - 1);
|
||||
}
|
||||
|
||||
enum ChangeType {
|
||||
CHANGED,
|
||||
ADDED,
|
||||
REMOVED,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,13 +74,13 @@ public class NotificationsPane extends JList {
|
||||
|
||||
@Override
|
||||
public void onNewNotification(Notification n) {
|
||||
notifyListeners(NotificationsPane.this, ListDataEvent.INTERVAL_ADDED, Notification.notifs.size() - 1, Notification.notifs.size() - 1);
|
||||
notifyListeners(NotificationsPane.this, ChangeType.ADDED, Notification.notifs.size() - 1, Notification.notifs.size() - 1);
|
||||
NotificationsPane.this.ensureIndexIsVisible(Notification.notifs.indexOf(n));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListCleared(int i) {
|
||||
notifyListeners(NotificationsPane.this, ListDataEvent.INTERVAL_REMOVED, 0, i);
|
||||
notifyListeners(NotificationsPane.this, ChangeType.REMOVED, 0, i);
|
||||
}
|
||||
|
||||
private List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract class OrderedListenerListModel<S, E> implements ListenerCollecti
|
||||
}
|
||||
getItems().add(item);
|
||||
int index = getItems().indexOf(item);
|
||||
notifyListeners(ListDataEvent.INTERVAL_ADDED, index, index);
|
||||
notifyListeners(ChangeType.ADDED, index, index);
|
||||
}
|
||||
|
||||
public void removeObject(E item) {
|
||||
@@ -57,7 +57,7 @@ public abstract class OrderedListenerListModel<S, E> implements ListenerCollecti
|
||||
if (getSize() == 0) {
|
||||
setItems(null);
|
||||
}
|
||||
notifyListeners(ListDataEvent.INTERVAL_REMOVED, index, index);
|
||||
notifyListeners(this, ChangeType.REMOVED, index, index);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public abstract class OrderedListenerListModel<S, E> implements ListenerCollecti
|
||||
E exchanged = getElementAt(index + direction);
|
||||
setElementAt(index, exchanged);
|
||||
setElementAt(index + direction, item);
|
||||
notifyListeners(ListDataEvent.CONTENTS_CHANGED, index + direction, index);
|
||||
notifyListeners(this, ChangeType.CHANGED, index + direction, index);
|
||||
}
|
||||
|
||||
public void objectChanged(E item) {
|
||||
@@ -83,10 +83,10 @@ public abstract class OrderedListenerListModel<S, E> implements ListenerCollecti
|
||||
|
||||
public void itemChanged(E item) {
|
||||
int index = getItems().indexOf(item);
|
||||
notifyListeners(ListDataEvent.CONTENTS_CHANGED, index, index);
|
||||
notifyListeners(this, ChangeType.CHANGED, index, index);
|
||||
}
|
||||
|
||||
private List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
|
||||
private final List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
|
||||
|
||||
public List<ListDataListener> getListeners() {
|
||||
return listeners;
|
||||
|
||||
@@ -1020,20 +1020,20 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
|
||||
|
||||
public void objectChanged(tiled.core.MapLayer layer) {
|
||||
int index = map.tmxMap.getLayerIndex(layer);
|
||||
notifyListeners(ListDataEvent.CONTENTS_CHANGED, index, index);
|
||||
notifyListeners(ChangeType.CHANGED, index, index);
|
||||
|
||||
}
|
||||
|
||||
public void addObject(tiled.core.MapLayer layer) {
|
||||
map.addLayer(layer);
|
||||
int index = map.tmxMap.getLayerIndex(layer);
|
||||
notifyListeners(ListDataEvent.INTERVAL_ADDED, index, index);
|
||||
notifyListeners(ChangeType.ADDED, index, index);
|
||||
}
|
||||
|
||||
public void removeObject(tiled.core.MapLayer layer) {
|
||||
int index = map.tmxMap.getLayerIndex(layer);
|
||||
map.removeLayer(layer);
|
||||
notifyListeners(ListDataEvent.INTERVAL_REMOVED, index, index);
|
||||
notifyListeners(ChangeType.REMOVED, index, index);
|
||||
}
|
||||
|
||||
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
|
||||
|
||||
Reference in New Issue
Block a user