diff --git a/src/com/gpl/rpg/atcontentstudio/ui/CustomListModel.java b/src/com/gpl/rpg/atcontentstudio/ui/CustomListModel.java index 90dff18..3754fa3 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/CustomListModel.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/CustomListModel.java @@ -29,6 +29,7 @@ public abstract class CustomListModel implements ListModel { return getItems().get(index); } + public void addObject(E item) {addItem(item);} public void addItem(E item) { if (getItems() == null) { setItems(new ArrayList()); @@ -40,6 +41,7 @@ public abstract class CustomListModel implements ListModel { } } + public void removeObject(E item) {removeItem(item);} public void removeItem(E item) { int index = getItems().indexOf(item); getItems().remove(item); @@ -69,6 +71,7 @@ public abstract class CustomListModel implements ListModel { } } + public void objectChanged(E item) {itemChanged(item);} public void itemChanged(E item) { int index = getItems().indexOf(item); for (ListDataListener l : listeners) { diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java index e84ca30..6beab6d 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java @@ -31,16 +31,9 @@ import com.gpl.rpg.atcontentstudio.ATContentStudio; import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.Project; import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode; -import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition; -import com.gpl.rpg.atcontentstudio.model.gamedata.Common; -import com.gpl.rpg.atcontentstudio.model.gamedata.Item; -import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory; +import com.gpl.rpg.atcontentstudio.model.gamedata.*; import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet; -import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel; -import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; -import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener; -import com.gpl.rpg.atcontentstudio.ui.IntegerBasedCheckBox; -import com.gpl.rpg.atcontentstudio.ui.OverlayIcon; +import com.gpl.rpg.atcontentstudio.ui.*; import com.jidesoft.swing.JideBoxLayout; public class ItemEditor extends JSONElementEditor { @@ -1185,127 +1178,34 @@ public class ItemEditor extends JSONElementEditor { } - public static class SourceTimedConditionsListModel implements ListModel { - - Common.DeathEffect source; - + public static class SourceTimedConditionsListModel extends CustomListModel { public SourceTimedConditionsListModel(Common.DeathEffect effect) { - this.source = effect;; + super(effect);; + } + @Override + protected List getItems() { + return source.conditions_source; } @Override - public int getSize() { - if (source.conditions_source == null) return 0; - return source.conditions_source.size(); - } - - @Override - public Common.TimedConditionEffect getElementAt(int index) { - if (source.conditions_source == null) return null; - return source.conditions_source.get(index); - } - - public void addItem(Common.TimedConditionEffect item) { - if (source.conditions_source == null) { - source.conditions_source = new ArrayList(); - } - source.conditions_source.add(item); - int index = source.conditions_source.indexOf(item); - for (ListDataListener l : listeners) { - l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index)); - } - } - - public void removeItem(Common.TimedConditionEffect item) { - int index = source.conditions_source.indexOf(item); - source.conditions_source.remove(item); - if (source.conditions_source.isEmpty()) { - source.conditions_source = null; - } - for (ListDataListener l : listeners) { - l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index)); - } - } - - public void itemChanged(Common.TimedConditionEffect item) { - int index = source.conditions_source.indexOf(item); - for (ListDataListener l : listeners) { - l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index)); - } - } - - List listeners = new CopyOnWriteArrayList(); - - @Override - public void addListDataListener(ListDataListener l) { - listeners.add(l); - } - - @Override - public void removeListDataListener(ListDataListener l) { - listeners.remove(l); + protected void setItems(List items) { + source.conditions_source = items; } } - public static class TargetTimedConditionsListModel implements ListModel { - - Common.HitEffect source; - + public static class TargetTimedConditionsListModel extends CustomListModel { public TargetTimedConditionsListModel(Common.HitEffect effect) { - this.source = effect;; + super(effect); } @Override - public int getSize() { - if (source.conditions_target == null) return 0; - return source.conditions_target.size(); - } - - @Override - public Common.TimedConditionEffect getElementAt(int index) { - if (source.conditions_target == null) return null; - return source.conditions_target.get(index); - } - - public void addItem(Common.TimedConditionEffect item) { - if (source.conditions_target == null) { - source.conditions_target = new ArrayList(); - } - source.conditions_target.add(item); - int index = source.conditions_target.indexOf(item); - for (ListDataListener l : listeners) { - l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index)); - } - } - - public void removeItem(Common.TimedConditionEffect item) { - int index = source.conditions_target.indexOf(item); - source.conditions_target.remove(item); - if (source.conditions_target.isEmpty()) { - source.conditions_target = null; - } - for (ListDataListener l : listeners) { - l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index)); - } + protected List getItems() { + return source.conditions_target; } - public void itemChanged(Common.TimedConditionEffect item) { - int index = source.conditions_target.indexOf(item); - for (ListDataListener l : listeners) { - l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index)); - } - } - - List listeners = new CopyOnWriteArrayList(); - @Override - public void addListDataListener(ListDataListener l) { - listeners.add(l); - } - - @Override - public void removeListDataListener(ListDataListener l) { - listeners.remove(l); + protected void setItems(List items) { + source.conditions_target = items; } } @@ -1343,65 +1243,19 @@ public class ItemEditor extends JSONElementEditor { } } - public static class ConditionsListModel implements ListModel { - - Item.EquipEffect source; - + public static class ConditionsListModel extends CustomListModel { public ConditionsListModel(Item.EquipEffect equipEffect) { - this.source = equipEffect; + super(equipEffect); } @Override - public int getSize() { - if (source.conditions == null) return 0; - return source.conditions.size(); - } - - @Override - public Common.ConditionEffect getElementAt(int index) { - if (source.conditions == null) return null; - return source.conditions.get(index); - } - - public void addItem(Common.ConditionEffect item) { - if (source.conditions == null) { - source.conditions = new ArrayList(); - } - source.conditions.add(item); - int index = source.conditions.indexOf(item); - for (ListDataListener l : listeners) { - l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index)); - } - } - - public void removeItem(Common.ConditionEffect item) { - int index = source.conditions.indexOf(item); - source.conditions.remove(item); - if (source.conditions.isEmpty()) { - source.conditions = null; - } - for (ListDataListener l : listeners) { - l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index)); - } + protected List getItems() { + return source.conditions; } - public void itemChanged(Common.ConditionEffect item) { - int index = source.conditions.indexOf(item); - for (ListDataListener l : listeners) { - l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index)); - } - } - - List listeners = new CopyOnWriteArrayList(); - @Override - public void addListDataListener(ListDataListener l) { - listeners.add(l); - } - - @Override - public void removeListDataListener(ListDataListener l) { - listeners.remove(l); + protected void setItems(List conditions) { + source.conditions = conditions; } } diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java index fba51e1..5fe32f3 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java @@ -34,11 +34,7 @@ import com.gpl.rpg.atcontentstudio.model.Project; import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode; import com.gpl.rpg.atcontentstudio.model.gamedata.*; import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet; -import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel; -import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; -import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener; -import com.gpl.rpg.atcontentstudio.ui.IntegerBasedCheckBox; -import com.gpl.rpg.atcontentstudio.ui.OverlayIcon; +import com.gpl.rpg.atcontentstudio.ui.*; import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.dialoguetree.DialogueGraphView; import com.jidesoft.swing.JideBoxLayout; @@ -1025,127 +1021,35 @@ public class NPCEditor extends JSONElementEditor { deathSourceConditionForever.setEnabled(!clear); } - public static class TargetTimedConditionsListModel implements ListModel { - - Common.HitEffect source; - + public static class TargetTimedConditionsListModel extends CustomListModel { public TargetTimedConditionsListModel(Common.HitEffect effect) { - this.source = effect; + super(effect); } @Override - public int getSize() { - if (source.conditions_target == null) return 0; - return source.conditions_target.size(); - } - - @Override - public Common.TimedConditionEffect getElementAt(int index) { - if (source.conditions_target == null) return null; - return source.conditions_target.get(index); + protected List getItems() { + return source.conditions_target; } - public void addItem(Common.TimedConditionEffect item) { - if (source.conditions_target == null) { - source.conditions_target = new ArrayList(); - } - source.conditions_target.add(item); - int index = source.conditions_target.indexOf(item); - for (ListDataListener l : listeners) { - l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index)); - } - } - - public void removeItem(Common.TimedConditionEffect item) { - int index = source.conditions_target.indexOf(item); - source.conditions_target.remove(item); - if (source.conditions_target.isEmpty()) { - source.conditions_target = null; - } - for (ListDataListener l : listeners) { - l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index)); - } - } - - public void itemChanged(Common.TimedConditionEffect item) { - int index = source.conditions_target.indexOf(item); - for (ListDataListener l : listeners) { - l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index)); - } - } - - List listeners = new CopyOnWriteArrayList(); - @Override - public void addListDataListener(ListDataListener l) { - listeners.add(l); - } - - @Override - public void removeListDataListener(ListDataListener l) { - listeners.remove(l); + protected void setItems(List items) { + source.conditions_target = items; } } - public static class SourceTimedConditionsListModel implements ListModel { - - Common.DeathEffect source; - + public static class SourceTimedConditionsListModel extends CustomListModel { public SourceTimedConditionsListModel(Common.DeathEffect effect) { - this.source = effect; + super(effect); } @Override - public int getSize() { - if (source.conditions_source == null) return 0; - return source.conditions_source.size(); - } - - @Override - public Common.TimedConditionEffect getElementAt(int index) { - if (source.conditions_source == null) return null; - return source.conditions_source.get(index); - } - - public void addItem(Common.TimedConditionEffect item) { - if (source.conditions_source == null) { - source.conditions_source = new ArrayList(); - } - source.conditions_source.add(item); - int index = source.conditions_source.indexOf(item); - for (ListDataListener l : listeners) { - l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index)); - } - } - - public void removeItem(Common.TimedConditionEffect item) { - int index = source.conditions_source.indexOf(item); - source.conditions_source.remove(item); - if (source.conditions_source.isEmpty()) { - source.conditions_source = null; - } - for (ListDataListener l : listeners) { - l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index)); - } + protected List getItems() { + return source.conditions_source; } - public void itemChanged(Common.TimedConditionEffect item) { - int index = source.conditions_source.indexOf(item); - for (ListDataListener l : listeners) { - l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index)); - } - } - - List listeners = new CopyOnWriteArrayList(); - @Override - public void addListDataListener(ListDataListener l) { - listeners.add(l); - } - - @Override - public void removeListDataListener(ListDataListener l) { - listeners.remove(l); + protected void setItems(List items) { + source.conditions_source = items; } } diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/QuestEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/QuestEditor.java index 39a0b73..1b62bea 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/QuestEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/QuestEditor.java @@ -28,12 +28,10 @@ import javax.swing.event.ListSelectionListener; import com.gpl.rpg.atcontentstudio.ATContentStudio; import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode; +import com.gpl.rpg.atcontentstudio.model.gamedata.Common; import com.gpl.rpg.atcontentstudio.model.gamedata.Quest; import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage; -import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel; -import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; -import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener; -import com.gpl.rpg.atcontentstudio.ui.IntegerBasedCheckBox; +import com.gpl.rpg.atcontentstudio.ui.*; import com.jidesoft.swing.JideBoxLayout; public class QuestEditor extends JSONElementEditor { @@ -183,88 +181,21 @@ public class QuestEditor extends JSONElementEditor { pane.revalidate(); pane.repaint(); } - - public static class StagesListModel implements ListModel { - Quest source; + public static class StagesListModel extends CustomListModel { public StagesListModel(Quest quest) { - this.source = quest; - } - - - @Override - public int getSize() { - if (source.stages == null) return 0; - return source.stages.size(); + super(quest); } @Override - public QuestStage getElementAt(int index) { - if (source.stages == null) return null; - return source.stages.get(index); - } - - public void addItem(QuestStage item) { - if (source.stages == null) { - source.stages = new ArrayList(); - } - source.stages.add(item); - int index = source.stages.indexOf(item); - for (ListDataListener l : listeners) { - l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index)); - } - } - - public void removeItem(QuestStage item) { - int index = source.stages.indexOf(item); - source.stages.remove(item); - if (source.stages.isEmpty()) { - source.stages = null; - } - for (ListDataListener l : listeners) { - l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index)); - } - } - - public void itemChanged(QuestStage item) { - int index = source.stages.indexOf(item); - for (ListDataListener l : listeners) { - l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index)); - } - } - - public void moveUp(QuestStage item) { - int index = source.stages.indexOf(item); - QuestStage exchanged = source.stages.get(index - 1); - source.stages.set(index, exchanged); - source.stages.set(index - 1, item); - for (ListDataListener l : listeners) { - l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index - 1, index)); - } - } - - public void moveDown(QuestStage item) { - int index = source.stages.indexOf(item); - QuestStage exchanged = source.stages.get(index + 1); - source.stages.set(index, exchanged); - source.stages.set(index + 1, item); - for (ListDataListener l : listeners) { - l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index + 1)); - } - } - - - List listeners = new CopyOnWriteArrayList(); - - @Override - public void addListDataListener(ListDataListener l) { - listeners.add(l); + protected List getItems() { + return source.stages; } @Override - public void removeListDataListener(ListDataListener l) { - listeners.remove(l); + protected void setItems(List items) { + source.stages = items; } } diff --git a/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java index aeae742..47e03d8 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java @@ -62,6 +62,7 @@ import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; +import com.gpl.rpg.atcontentstudio.ui.*; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rsyntaxtextarea.SyntaxConstants; @@ -95,13 +96,6 @@ import com.gpl.rpg.atcontentstudio.model.maps.SignArea; import com.gpl.rpg.atcontentstudio.model.maps.SpawnArea; import com.gpl.rpg.atcontentstudio.model.maps.TMXMap; import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet; -import com.gpl.rpg.atcontentstudio.ui.BooleanBasedCheckBox; -import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel; -import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; -import com.gpl.rpg.atcontentstudio.ui.Editor; -import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener; -import com.gpl.rpg.atcontentstudio.ui.IntegerBasedCheckBox; -import com.gpl.rpg.atcontentstudio.ui.ScrollablePanel; import com.gpl.rpg.atcontentstudio.utils.DesktopIntegration; import com.gpl.rpg.atcontentstudio.utils.FileUtils; import com.jidesoft.swing.JideBoxLayout; @@ -1286,58 +1280,20 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe } } - public class MapObjectsListModel implements ListModel { - - public MapObjectGroup group; - + public class MapObjectsListModel extends CustomListModel { public MapObjectsListModel(MapObjectGroup group) { - this.group = group; - } - - @Override - public int getSize() { - return group.mapObjects.size(); + super(group); } @Override - public MapObject getElementAt(int index) { - return group.mapObjects.get(index); - } - - public void objectChanged(MapObject area) { - for (ListDataListener l : listeners) { - l.contentsChanged(new ListDataEvent(groupObjectsList, ListDataEvent.CONTENTS_CHANGED, group.mapObjects.indexOf(area), group.mapObjects.indexOf(area))); - } - } - - public void addObject(MapObject area) { - group.mapObjects.add(area); - int index = group.mapObjects.indexOf(area); - for (ListDataListener l : listeners) { - l.intervalAdded(new ListDataEvent(groupObjectsList, ListDataEvent.INTERVAL_ADDED, index, index)); - } - } - - public void removeObject(MapObject area) { - int index = group.mapObjects.indexOf(area); - group.mapObjects.remove(area); - for (ListDataListener l : listeners) { - l.intervalRemoved(new ListDataEvent(groupObjectsList, ListDataEvent.INTERVAL_REMOVED, index, index)); - } - } - - List listeners = new CopyOnWriteArrayList(); - - @Override - public void addListDataListener(ListDataListener l) { - listeners.add(l); + protected List getItems() { + return source.mapObjects; } @Override - public void removeListDataListener(ListDataListener l) { - listeners.remove(l); + protected void setItems(List items) { + source.mapObjects = items; } - } public class GroupObjectsRenderer extends DefaultListCellRenderer {