Skip to content

Commit

Permalink
Cleanup and apply final fix for non-instantiable resource frames,
Browse files Browse the repository at this point in the history
everything is working perfect now, also fixed long existing bugs in the
Constants frame as well. Reverting resources and recognizing changes works
100% flawlessly, you can even compile with instantiable and
non-instantiable resources with the changes being recognized without
closing the frame, but you do not lose the ability to revert the frame. It
all works perfect!
  • Loading branch information
RobertBColton committed Oct 1, 2014
1 parent ebf842f commit f7e9c8c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
3 changes: 2 additions & 1 deletion org/lateralgm/subframes/GameInformationFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (C) 2007, 2011 IsmAvatar <IsmAvatar@gmail.com>
* Copyright (C) 2007, 2008 Clam <clamisgood@gmail.com>
* Copyright (C) 2007 Quadduc <quadduc@gmail.com>
* 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.
Expand Down Expand Up @@ -954,5 +954,6 @@ public void revertResource()
{
res.properties.putAll(resOriginal.properties);
setComponents(res);
plf.setMap(res.properties);
}
}
1 change: 1 addition & 0 deletions org/lateralgm/subframes/GameSettingFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
33 changes: 32 additions & 1 deletion org/lateralgm/ui/swing/propertylink/PropertyLinkFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2009 Quadduc <quadduc@gmail.com>
* Copyright (C) 2014 Robert B. Colton
*
* This file is part of LateralGM.
* LateralGM is free software and comes with ABSOLUTELY NO WARRANTY.
Expand All @@ -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;
Expand All @@ -26,9 +29,32 @@

public class PropertyLinkFactory<K extends Enum<K>>
{
private final PropertyMap<K> map;
private PropertyMap<K> 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<PropertyLinkMapListener<K>> mapListeners = new ArrayList<PropertyLinkMapListener<K>>();

public void addLinkMapListener(PropertyLinkMapListener<K> plml) {
mapListeners.add(plml);
}

public void removeLinkMapListener(PropertyLinkMapListener<K> plml) {
mapListeners.remove(plml);
}

public void setMap(PropertyMap<K> m) {
map = m;
for (PropertyLinkMapListener<K> listener : mapListeners) {
listener.mapChanged(map);
}
}

public abstract interface PropertyLinkMapListener<K extends Enum<K>> {
public abstract void mapChanged(PropertyMap<K> m);
}

public PropertyLinkFactory(PropertyMap<K> m, ExceptionListener el)
{
map = m;
Expand All @@ -37,6 +63,11 @@ public PropertyLinkFactory(PropertyMap<K> m, ExceptionListener el)

public <L extends PropertyLink<K,?>>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;
}
Expand Down
19 changes: 17 additions & 2 deletions org/lateralgm/util/PropertyLink.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2009 Quadduc <quadduc@gmail.com>
* Copyright (C) 2014 Robert B. Colton
*
* This file is part of LateralGM.
* LateralGM is free software and comes with ABSOLUTELY NO WARRANTY.
Expand All @@ -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<K extends Enum<K>, V> extends PropertyUpdateListener<K>
public abstract class PropertyLink<K extends Enum<K>, V> extends PropertyUpdateListener<K> implements PropertyLinkMapListener<K>
{
public final PropertyMap<K> map;
public PropertyMap<K> 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<K> factory;

public PropertyLink(PropertyMap<K> m, K k)
{
Expand All @@ -29,7 +36,15 @@ public PropertyLink(PropertyMap<K> m, K k)
public void remove()
{
map.updateSource.removeListener(this);
factory.removeLinkMapListener(this);
}

public void mapChanged(PropertyMap<K> m) {
map.updateSource.removeListener(this);
map = m;
map.getUpdateSource(key).addListener(this);
reset();
}

protected abstract void setComponent(V v);

Expand Down

0 comments on commit f7e9c8c

Please sign in to comment.