Files
ATCS/src/com/gpl/rpg/atcontentstudio/Notification.java
Zukero 940996aa30 Some refactoring. Replaced all "listeners" list by instances of
CopyOnWriteArrayList, to allow listeners to unregister themselves due to
an event while preventing ConcurrentModificationExceptions.
Modified all GameDataElement.elementChanged concrete implementation to
remove the backlink from the oldOne.An element pointed by an altered
element will not show the game source element in its backlink list
anymore.
2017-03-02 13:53:24 +01:00

92 lines
2.2 KiB
Java

package com.gpl.rpg.atcontentstudio;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class Notification {
public static List<Notification> notifs = new ArrayList<Notification>();
private static List<NotificationListener> listeners = new CopyOnWriteArrayList<NotificationListener>();
public static boolean showS = true, showI = true, showW = true, showE = true;
static {
boolean[] config = ConfigCache.getNotifViewConfig();
showS = config[0];
showI = config[1];
showW = config[2];
showE = config[3];
}
public static enum Type {
SUCCESS,
INFO,
WARN,
ERROR
}
public Type type;
public String text;
public Notification(Type type, String text) {
this.type = type;
this.text = text;
}
public String toString() {
return "["+type.toString()+"] "+text;
}
public static void clear() {
int i = notifs.size();
notifs.clear();
for (NotificationListener l : listeners) {
l.onListCleared(i);
}
}
public static void addSuccess(String text) {
if (!showS) return;
Notification n = new Notification(Notification.Type.SUCCESS, text);
notifs.add(n);
for (NotificationListener l : listeners) {
l.onNewNotification(n);
}
}
public static void addInfo(String text) {
if (!showI) return;
Notification n = new Notification(Notification.Type.INFO, text);
notifs.add(n);
for (NotificationListener l : listeners) {
l.onNewNotification(n);
}
}
public static void addWarn(String text) {
if (!showW) return;
Notification n = new Notification(Notification.Type.WARN, text);
notifs.add(n);
for (NotificationListener l : listeners) {
l.onNewNotification(n);
}
}
public static void addError(String text) {
if (!showE) return;
Notification n = new Notification(Notification.Type.ERROR, text);
notifs.add(n);
for (NotificationListener l : listeners) {
l.onNewNotification(n);
}
}
public static void addNotificationListener(NotificationListener l) {
listeners.add(l);
}
public static void removeNotificationListener(NotificationListener l) {
listeners.remove(l);
}
}