diff --git a/org/lateralgm/subframes/GameInformationFrame.java b/org/lateralgm/subframes/GameInformationFrame.java index f60a1acf9..bf170ff39 100644 --- a/org/lateralgm/subframes/GameInformationFrame.java +++ b/org/lateralgm/subframes/GameInformationFrame.java @@ -3,7 +3,7 @@ * Copyright (C) 2007, 2011 IsmAvatar * Copyright (C) 2007, 2008 Clam * Copyright (C) 2007 Quadduc - * Copyright (C) 2013 Robert B. Colton + * Copyright (C) 2013, 2014 Robert B. Colton * * This file is part of LateralGM. * LateralGM is free software and comes with ABSOLUTELY NO WARRANTY. @@ -954,5 +954,6 @@ public void revertResource() { res.properties.putAll(resOriginal.properties); setComponents(res); + plf.setMap(res.properties); } } diff --git a/org/lateralgm/subframes/GameSettingFrame.java b/org/lateralgm/subframes/GameSettingFrame.java index 763019e8c..8e7dd78d0 100644 --- a/org/lateralgm/subframes/GameSettingFrame.java +++ b/org/lateralgm/subframes/GameSettingFrame.java @@ -960,6 +960,7 @@ public void revertResource() if (frameListener != null) frameListener.revertResource(); res.properties.putAll(resOriginal.properties); setComponents(res); + plf.setMap(res.properties); imagesChanged = false; } diff --git a/org/lateralgm/ui/swing/propertylink/PropertyLinkFactory.java b/org/lateralgm/ui/swing/propertylink/PropertyLinkFactory.java index 5ac20cd9a..51d8c6428 100644 --- a/org/lateralgm/ui/swing/propertylink/PropertyLinkFactory.java +++ b/org/lateralgm/ui/swing/propertylink/PropertyLinkFactory.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Quadduc + * Copyright (C) 2014 Robert B. Colton * * This file is part of LateralGM. * LateralGM is free software and comes with ABSOLUTELY NO WARRANTY. @@ -9,6 +10,8 @@ package org.lateralgm.ui.swing.propertylink; import java.beans.ExceptionListener; +import java.util.ArrayList; +import java.util.List; import javax.swing.AbstractButton; import javax.swing.BoundedRangeModel; @@ -26,9 +29,32 @@ public class PropertyLinkFactory> { - private final PropertyMap map; + private PropertyMap map; private final ExceptionListener exceptionListener; + /* This is a map used to inform all property links that the factory that created them has changed maps + * and they should thus update their controls. + */ + private List> mapListeners = new ArrayList>(); + + public void addLinkMapListener(PropertyLinkMapListener plml) { + mapListeners.add(plml); + } + + public void removeLinkMapListener(PropertyLinkMapListener plml) { + mapListeners.remove(plml); + } + + public void setMap(PropertyMap m) { + map = m; + for (PropertyLinkMapListener listener : mapListeners) { + listener.mapChanged(map); + } + } + public abstract interface PropertyLinkMapListener> { + public abstract void mapChanged(PropertyMap m); + } + public PropertyLinkFactory(PropertyMap m, ExceptionListener el) { map = m; @@ -37,6 +63,11 @@ public PropertyLinkFactory(PropertyMap m, ExceptionListener el) public >L init(L l) { + /* This should probably be moved into PropertyLink itself, but either way the PropertyLink needs to know the plf that created it + * so it knows when to add and remove itself as a listener to revert when the PLF decides to changes its map. + */ + l.factory = this; + addLinkMapListener(l); l.setExceptionListener(exceptionListener); return l; } diff --git a/org/lateralgm/util/PropertyLink.java b/org/lateralgm/util/PropertyLink.java index fc40f8d74..864a7ca7e 100644 --- a/org/lateralgm/util/PropertyLink.java +++ b/org/lateralgm/util/PropertyLink.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Quadduc + * Copyright (C) 2014 Robert B. Colton * * This file is part of LateralGM. * LateralGM is free software and comes with ABSOLUTELY NO WARRANTY. @@ -10,14 +11,20 @@ import java.beans.ExceptionListener; +import org.lateralgm.ui.swing.propertylink.PropertyLinkFactory; +import org.lateralgm.ui.swing.propertylink.PropertyLinkFactory.PropertyLinkMapListener; import org.lateralgm.util.PropertyMap.PropertyUpdateEvent; import org.lateralgm.util.PropertyMap.PropertyUpdateListener; -public abstract class PropertyLink, V> extends PropertyUpdateListener +public abstract class PropertyLink, V> extends PropertyUpdateListener implements PropertyLinkMapListener { - public final PropertyMap map; + public PropertyMap map; public final K key; private ExceptionListener exceptionListener; + /* + * We keep a reference to our plf so that we can tell it to install/uninstall us as a listener. + */ + public PropertyLinkFactory factory; public PropertyLink(PropertyMap m, K k) { @@ -29,7 +36,15 @@ public PropertyLink(PropertyMap m, K k) public void remove() { map.updateSource.removeListener(this); + factory.removeLinkMapListener(this); } + + public void mapChanged(PropertyMap m) { + map.updateSource.removeListener(this); + map = m; + map.getUpdateSource(key).addListener(this); + reset(); + } protected abstract void setComponent(V v);