Skip to content

Commit

Permalink
Property Link Factory Context (#551)
Browse files Browse the repository at this point in the history
Replace references to individual property links with factory reference. Also document some of the property link factory methods. This produces cleaner code since the factories already know the links they created in order to clear them when the frames close. Consequentially resolves the concurrency regressions with document links.
  • Loading branch information
RobertBColton committed Mar 30, 2021
1 parent 284ab76 commit 4ef7256
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 114 deletions.
2 changes: 1 addition & 1 deletion org/lateralgm/main/LGM.java
Expand Up @@ -128,7 +128,7 @@

public final class LGM
{
public static final String version = "1.8.228"; //$NON-NLS-1$
public static final String version = "1.8.229"; //$NON-NLS-1$

// TODO: This list holds the class loader for any loaded plugins which should be
// cleaned up and closed when the application closes.
Expand Down
23 changes: 11 additions & 12 deletions org/lateralgm/subframes/FontFrame.java
Expand Up @@ -64,11 +64,9 @@
import org.lateralgm.resources.Font.PFont;
import org.lateralgm.resources.sub.CharacterRange;
import org.lateralgm.resources.sub.CharacterRange.PCharacterRange;
import org.lateralgm.ui.swing.propertylink.FormattedLink;
import org.lateralgm.ui.swing.propertylink.PropertyLinkFactory;
import org.lateralgm.ui.swing.propertylink.ComboBoxLink.IndexComboBoxConversion;
import org.lateralgm.ui.swing.util.ArrayListModel;
import org.lateralgm.util.PropertyLink;
import org.lateralgm.util.PropertyMap.PropertyUpdateEvent;
import org.lateralgm.util.PropertyMap.PropertyUpdateListener;

Expand All @@ -82,7 +80,7 @@ public class FontFrame extends InstantiableResourceFrame<Font,PFont> implements
public JCheckBox italic, bold;
public JComboBox<String> aa;
public NumberField charMin, charMax;
private FormattedLink<PCharacterRange> minLink, maxLink;
private PropertyLinkFactory<PCharacterRange> rplf;
public JEditorPane previewText;
public JTextArea previewRange;
private JMenuItem cutItem, copyItem, pasteItem, selAllItem;
Expand All @@ -107,6 +105,9 @@ public FontFrame(Font res, ResNode node)
this.getRootPane().setDefaultButton(save);
((JComponent) getContentPane()).setBorder(new EmptyBorder(4,4,4,4));

rplf = new PropertyLinkFactory<PCharacterRange>(null,this);
this.addSecondaryPropertyLinkFactory(rplf);

propUpdateListener = new PropertyUpdateListener<PFont>()
{
public void updated(PropertyUpdateEvent<PFont> e)
Expand Down Expand Up @@ -591,15 +592,13 @@ public void fireRangeUpdate()
CharacterRange cr = rangeList.getSelectedValue();
if (lastRange == cr) return;
lastRange = cr;
PropertyLink.removeAll(minLink,maxLink);
if (cr != null)
{
PropertyLinkFactory<PCharacterRange> rplf = new PropertyLinkFactory<PCharacterRange>(
cr.properties,this);
this.addSecondaryPropertyLinkFactory(rplf);
minLink = rplf.make(charMin,PCharacterRange.RANGE_MIN);
maxLink = rplf.make(charMax,PCharacterRange.RANGE_MAX);
}

rplf.removeAllLinks();
if (cr == null) return;
rplf.setMap(cr.properties);

rplf.make(charMin,PCharacterRange.RANGE_MIN);
rplf.make(charMax,PCharacterRange.RANGE_MAX);
}

public void updated(UpdateEvent e)
Expand Down
30 changes: 11 additions & 19 deletions org/lateralgm/subframes/PathFrame.java
Expand Up @@ -47,10 +47,8 @@
import org.lateralgm.resources.Room;
import org.lateralgm.resources.sub.PathPoint;
import org.lateralgm.resources.sub.PathPoint.PPathPoint;
import org.lateralgm.ui.swing.propertylink.FormattedLink;
import org.lateralgm.ui.swing.propertylink.PropertyLinkFactory;
import org.lateralgm.ui.swing.util.ArrayListModel;
import org.lateralgm.util.PropertyLink;
import org.lateralgm.util.PropertyMap.PropertyUpdateEvent;
import org.lateralgm.util.PropertyMap.PropertyUpdateListener;

Expand All @@ -75,6 +73,8 @@ public PathFrame(Path res, ResNode node)
pathEditor.properties.updateSource.addListener(pepl);
peplf = new PropertyLinkFactory<PPathEditor>(pathEditor.properties,this);
this.addSecondaryPropertyLinkFactory(peplf);
ppplf = new PropertyLinkFactory<PPathPoint>(null,null);
this.addSecondaryPropertyLinkFactory(ppplf);

GroupLayout layout = new GroupLayout(getContentPane())
{
Expand Down Expand Up @@ -308,7 +308,7 @@ public void actionPerformed(ActionEvent e)
super.actionPerformed(e);
}

FormattedLink<PPathPoint> ltx, lty, ltsp;
private PropertyLinkFactory<PPathPoint> ppplf;

private class PathEditorPropertyListener extends PropertyUpdateListener<PPathEditor>
{
Expand All @@ -318,23 +318,15 @@ public void updated(PropertyUpdateEvent<PPathEditor> e)
switch (e.key)
{
case SELECTED_POINT:
PropertyLink.removeAll(ltx,lty,ltsp);
PathPoint pp = e.map.get(e.key);
if (pp != null)
{
PropertyLinkFactory<PPathPoint> ppplf = new PropertyLinkFactory<PPathPoint>(
pp.properties,null);
PathFrame.this.addSecondaryPropertyLinkFactory(ppplf);
ltx = ppplf.make(tx,PPathPoint.X);
lty = ppplf.make(ty,PPathPoint.Y);
ltsp = ppplf.make(tsp,PPathPoint.SPEED);
}
else
{
ltx = null;
lty = null;
ltsp = null;
}

ppplf.removeAllLinks();
if (pp == null) return;
ppplf.setMap(pp.properties);

ppplf.make(tx,PPathPoint.X);
ppplf.make(ty,PPathPoint.Y);
ppplf.make(tsp,PPathPoint.SPEED);
break;
default:
break;
Expand Down
155 changes: 74 additions & 81 deletions org/lateralgm/subframes/RoomFrame.java
Expand Up @@ -131,13 +131,9 @@
import org.lateralgm.resources.sub.View;
import org.lateralgm.resources.sub.View.PView;
import org.lateralgm.subframes.CodeFrame.CodeHolder;
import org.lateralgm.ui.swing.propertylink.ButtonModelLink;
import org.lateralgm.ui.swing.propertylink.DocumentLink;
import org.lateralgm.ui.swing.propertylink.FormattedLink;
import org.lateralgm.ui.swing.propertylink.PropertyLinkFactory;
import org.lateralgm.ui.swing.util.ArrayListModel;
import org.lateralgm.util.ActiveArrayList;
import org.lateralgm.util.PropertyLink;
import org.lateralgm.util.PropertyMap.PropertyUpdateEvent;
import org.lateralgm.util.PropertyMap.PropertyUpdateListener;

Expand All @@ -160,19 +156,15 @@ public class RoomFrame extends InstantiableResourceFrame<Room,PRoom> implements

//Objects
public JCheckBox oUnderlying, oLocked;
private ButtonModelLink<PInstance> loLocked;
public JList<Instance> oList;
private Instance lastObj = null; //non-guaranteed copy of oList.getLastSelectedValue()
private PropertyLinkFactory<PInstance> iplf;
private JButton addObjectButton, deleteObjectButton;
public ResourceMenu<GmObject> oNew, oSource;
private PropertyLink<PInstance,ResourceReference<GmObject>> loSource;
private JTextField objectName;
public NumberField objectHorizontalPosition, objectVerticalPosition, objectScaleX, objectScaleY,
objectRotation, objectAlpha;
public ColorSelect objectColor;
public PropertyLink<PInstance,Color> loColour;
private FormattedLink<PInstance> loX, loY, loScaleX, loScaleY, loRotation, loAlpha;
private DocumentLink<PInstance> loName;
private JButton oCreationCode;

//Settings
Expand All @@ -189,42 +181,35 @@ public class RoomFrame extends InstantiableResourceFrame<Room,PRoom> implements
Vector<Integer> layers = new Vector<Integer>();
private JButton addLayer, deleteLayer, changeLayer;
public JCheckBox tUnderlying, tLocked, tHideOtherLayers, tEditOtherLayers;
private ButtonModelLink<PTile> ltLocked;
public TileSelector tSelect;
private JScrollPane tScroll;
public JList<Tile> tList;
private Tile lastTile = null; //non-guaranteed copy of tList.getLastSelectedValue()
private PropertyLinkFactory<PTile> tplf;
private JButton deleteTileButton;
public ResourceMenu<Background> taSource, teSource;
private PropertyLink<PTile,ResourceReference<Background>> ltSource;
public NumberField tsX, tsY, tileHorizontalPosition, tileVerticalPosition, teDepth;
private FormattedLink<PTile> ltsX, ltsY, ltX, ltY, ltDepth;

//Backgrounds
private JCheckBox bDrawColor, bVisible, bForeground, bTileH, bTileV, bStretch;
private ButtonModelLink<PBackgroundDef> lbVisible, lbForeground, lbTileH, lbTileV, lbStretch;
private ColorSelect bColor;
private JList<JLabel> bList;
/**Guaranteed valid version of bList.getLastSelectedIndex()*/
private int lastValidBack = -1;
private PropertyLinkFactory<PBackgroundDef> bdplf;
private ResourceMenu<Background> bSource;
private PropertyLink<PBackgroundDef,ResourceReference<Background>> lbSource;
private NumberField bX, bY, bH, bV;
private FormattedLink<PBackgroundDef> lbX, lbY, lbH, lbV;
private final BgDefPropertyListener bdpl = new BgDefPropertyListener();
//Views
private JCheckBox vEnabled, vVisible;
private ButtonModelLink<PView> lvVisible;
private JList<JLabel> vList;
/**Guaranteed valid version of vList.getLastSelectedIndex()*/
private int lastValidView = -1;
private PropertyLinkFactory<PView> vplf;
private NumberField vRX, vRY, vRW, vRH;
private NumberField vPX, vPY, vPW, vPH;
private FormattedLink<PView> lvRX, lvRY, lvRW, lvRH, lvPX, lvPY, lvPW, lvPH;
private ResourceMenu<GmObject> vObj;
private PropertyLink<PView,ResourceReference<GmObject>> lvObj;
private NumberField vOHBor, vOVBor, vOHSp, vOVSp;
private FormattedLink<PView> lvOHBor, lvOVBor, lvOHSp, lvOVSp;
private final ViewPropertyListener vpl = new ViewPropertyListener();

private final PropertyLinkFactory<PRoomEditor> prelf;
Expand Down Expand Up @@ -1905,6 +1890,10 @@ public RoomFrame(Room res, ResNode node)
editor = new RoomEditor(res,this);
prelf = new PropertyLinkFactory<PRoomEditor>(editor.properties,null);
this.addSecondaryPropertyLinkFactory(prelf);
iplf = new PropertyLinkFactory<PInstance>(null,null);
this.addSecondaryPropertyLinkFactory(iplf);
tplf = new PropertyLinkFactory<PTile>(null,null);
this.addSecondaryPropertyLinkFactory(tplf);

GroupLayout layout = new GroupLayout(getContentPane())
{
Expand Down Expand Up @@ -2732,24 +2721,21 @@ public void fireObjUpdate()
Instance selectedInstance = oList.getSelectedValue();
if (lastObj == selectedInstance) return;
lastObj = selectedInstance;
PropertyLink.removeAll(loLocked,loSource,loName,loX,loY,loScaleX,loScaleY,loColour,loRotation,loAlpha);

if (selectedInstance != null)
{
PropertyLinkFactory<PInstance> iplf = new PropertyLinkFactory<PInstance>(
selectedInstance.properties,this);
this.addSecondaryPropertyLinkFactory(iplf);
loLocked = iplf.make(oLocked,PInstance.LOCKED);
loSource = iplf.make(oSource,PInstance.OBJECT);
loName = iplf.make(objectName.getDocument(), PInstance.NAME);
loX = iplf.make(objectHorizontalPosition,PInstance.X);
loY = iplf.make(objectVerticalPosition,PInstance.Y);
loScaleX = iplf.make(objectScaleX,PInstance.SCALE_X);
loScaleY = iplf.make(objectScaleY,PInstance.SCALE_Y);
loRotation = iplf.make(objectRotation,PInstance.ROTATION);
loColour = iplf.make(objectColor,PInstance.COLOR);
loAlpha = iplf.make(objectAlpha,PInstance.ALPHA);
}

iplf.removeAllLinks();
if (selectedInstance == null) return;
iplf.setMap(selectedInstance.properties);

iplf.make(oLocked,PInstance.LOCKED);
iplf.make(oSource,PInstance.OBJECT);
iplf.make(objectName.getDocument(), PInstance.NAME);
iplf.make(objectHorizontalPosition,PInstance.X);
iplf.make(objectVerticalPosition,PInstance.Y);
iplf.make(objectScaleX,PInstance.SCALE_X);
iplf.make(objectScaleY,PInstance.SCALE_Y);
iplf.make(objectRotation,PInstance.ROTATION);
iplf.make(objectColor,PInstance.COLOR);
iplf.make(objectAlpha,PInstance.ALPHA);
}

@Override
Expand All @@ -2768,20 +2754,18 @@ public void fireTileUpdate()
Tile selectedTile = tList.getSelectedValue();
if (lastTile == selectedTile) return;
lastTile = selectedTile;
PropertyLink.removeAll(ltDepth,ltLocked,ltSource,ltsX,ltsY,ltX,ltY);

if (selectedTile != null)
{
PropertyLinkFactory<PTile> tplf = new PropertyLinkFactory<PTile>(selectedTile.properties,this);
this.addSecondaryPropertyLinkFactory(tplf);
ltDepth = tplf.make(teDepth,PTile.DEPTH);
ltLocked = tplf.make(tLocked,PTile.LOCKED);
ltSource = tplf.make(teSource,PTile.BACKGROUND);
ltsX = tplf.make(tsX,PTile.BG_X);
ltsY = tplf.make(tsY,PTile.BG_Y);
ltX = tplf.make(tileHorizontalPosition,PTile.ROOM_X);
ltY = tplf.make(tileVerticalPosition,PTile.ROOM_Y);
}
tplf.removeAllLinks();
if (selectedTile == null) return;
tplf.setMap(selectedTile.properties);

tplf.make(teDepth,PTile.DEPTH);
tplf.make(tLocked,PTile.LOCKED);
tplf.make(teSource,PTile.BACKGROUND);
tplf.make(tsX,PTile.BG_X);
tplf.make(tsY,PTile.BG_Y);
tplf.make(tileHorizontalPosition,PTile.ROOM_X);
tplf.make(tileVerticalPosition,PTile.ROOM_Y);
}

public void fireBackUpdate()
Expand All @@ -2794,22 +2778,26 @@ public void fireBackUpdate()
return;
}
lastValidBack = i;
PropertyLink.removeAll(lbVisible,lbForeground,lbSource,lbX,lbY,lbTileH,lbTileV,lbStretch,lbH,
lbV);
BackgroundDef b = res.backgroundDefs.get(i);
PropertyLinkFactory<PBackgroundDef> bdplf = new PropertyLinkFactory<PBackgroundDef>(
b.properties,this);

if (bdplf != null)
{
bdplf.setMap(b.properties);
return;
}

bdplf = new PropertyLinkFactory<PBackgroundDef>(b.properties,this);
this.addSecondaryPropertyLinkFactory(bdplf);
lbVisible = bdplf.make(bVisible,PBackgroundDef.VISIBLE);
lbForeground = bdplf.make(bForeground,PBackgroundDef.FOREGROUND);
lbSource = bdplf.make(bSource,PBackgroundDef.BACKGROUND);
lbX = bdplf.make(bX,PBackgroundDef.X);
lbY = bdplf.make(bY,PBackgroundDef.Y);
lbTileH = bdplf.make(bTileH,PBackgroundDef.TILE_HORIZ);
lbTileV = bdplf.make(bTileV,PBackgroundDef.TILE_VERT);
lbStretch = bdplf.make(bStretch,PBackgroundDef.STRETCH);
lbH = bdplf.make(bH,PBackgroundDef.H_SPEED);
lbV = bdplf.make(bV,PBackgroundDef.V_SPEED);
bdplf.make(bVisible,PBackgroundDef.VISIBLE);
bdplf.make(bForeground,PBackgroundDef.FOREGROUND);
bdplf.make(bSource,PBackgroundDef.BACKGROUND);
bdplf.make(bX,PBackgroundDef.X);
bdplf.make(bY,PBackgroundDef.Y);
bdplf.make(bTileH,PBackgroundDef.TILE_HORIZ);
bdplf.make(bTileV,PBackgroundDef.TILE_VERT);
bdplf.make(bStretch,PBackgroundDef.STRETCH);
bdplf.make(bH,PBackgroundDef.H_SPEED);
bdplf.make(bV,PBackgroundDef.V_SPEED);
}

public void fireViewUpdate()
Expand All @@ -2822,25 +2810,30 @@ public void fireViewUpdate()
return;
}
lastValidView = i;
PropertyLink.removeAll(lvVisible,lvRX,lvRY,lvRW,lvRH,lvPX,lvPY,lvPW,lvPH,lvObj,lvOHBor,lvOVBor,
lvOHSp,lvOVSp);
View view = res.views.get(i);
PropertyLinkFactory<PView> vplf = new PropertyLinkFactory<PView>(view.properties,this);

if (vplf != null)
{
vplf.setMap(view.properties);
return;
}

vplf = new PropertyLinkFactory<PView>(view.properties,this);
this.addSecondaryPropertyLinkFactory(vplf);
lvVisible = vplf.make(vVisible,PView.VISIBLE);
lvRX = vplf.make(vRX,PView.VIEW_X);
lvRY = vplf.make(vRY,PView.VIEW_Y);
lvRW = vplf.make(vRW,PView.VIEW_W);
lvRH = vplf.make(vRH,PView.VIEW_H);
lvPX = vplf.make(vPX,PView.PORT_X);
lvPY = vplf.make(vPY,PView.PORT_Y);
lvPW = vplf.make(vPW,PView.PORT_W);
lvPH = vplf.make(vPH,PView.PORT_H);
lvObj = vplf.make(vObj,PView.OBJECT);
lvOHBor = vplf.make(vOHBor,PView.BORDER_H);
lvOVBor = vplf.make(vOVBor,PView.BORDER_V);
lvOHSp = vplf.make(vOHSp,PView.SPEED_H);
lvOVSp = vplf.make(vOVSp,PView.SPEED_V);
vplf.make(vVisible,PView.VISIBLE);
vplf.make(vRX,PView.VIEW_X);
vplf.make(vRY,PView.VIEW_Y);
vplf.make(vRW,PView.VIEW_W);
vplf.make(vRH,PView.VIEW_H);
vplf.make(vPX,PView.PORT_X);
vplf.make(vPY,PView.PORT_Y);
vplf.make(vPW,PView.PORT_W);
vplf.make(vPH,PView.PORT_H);
vplf.make(vObj,PView.OBJECT);
vplf.make(vOHBor,PView.BORDER_H);
vplf.make(vOVBor,PView.BORDER_V);
vplf.make(vOHSp,PView.SPEED_H);
vplf.make(vOVSp,PView.SPEED_V);
}

// Display the selected tile with a border and centered in the editor window
Expand Down

0 comments on commit 4ef7256

Please sign in to comment.