Changeset 101 for java/main/src/main/java/com/framsticks/test
- Timestamp:
- 07/14/13 23:20:04 (11 years ago)
- Location:
- java/main/src/main/java/com/framsticks/test
- Files:
-
- 2 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/test/TestChild.java
r100 r101 1 1 package com.framsticks.test; 2 2 3 import com.framsticks. core.ListChange;3 import com.framsticks.params.AbstractUniqueObject; 4 4 import com.framsticks.params.annotations.FramsClassAnnotation; 5 5 import com.framsticks.params.annotations.ParamAnnotation; 6 6 7 7 @FramsClassAnnotation 8 public class TestChild {8 public class TestChild extends AbstractUniqueObject { 9 9 10 10 protected String name = "child"; 11 11 12 protected String uid;13 12 protected final TestClass parent; 14 13 /** … … 17 16 public TestChild(TestClass parent) { 18 17 this.parent = parent; 19 this.uid = "c" + (parent.counter++);20 18 } 21 19 … … 34 32 public void setName(String name) { 35 33 this.name = name; 36 parent.fireChildrenChange(this, ListChange.Action.Modify); 37 } 38 39 /** 40 * @return the uid 41 */ 42 @ParamAnnotation 43 public String getUid() { 44 return uid; 34 parent.children.modify(this); 45 35 } 46 36 -
java/main/src/main/java/com/framsticks/test/TestClass.java
r100 r101 1 1 package com.framsticks.test; 2 2 3 import java.util.Collections;4 import java.util.LinkedList;5 import java.util.List;6 3 import java.util.Map; 7 4 … … 11 8 import com.framsticks.core.ListChange; 12 9 import com.framsticks.params.EventListener; 13 import com.framsticks.params.UniqueListAccess; 10 import com.framsticks.params.EventListeners; 11 import com.framsticks.params.SimpleUniqueList; 14 12 import com.framsticks.params.annotations.FramsClassAnnotation; 15 13 import com.framsticks.params.annotations.ParamAnnotation; … … 26 24 "createChild", 27 25 "children_changed" 28 },29 register = {30 ChangeEvent.class,31 TestChild.class,32 ListChange.class33 26 } 34 27 ) … … 40 33 protected String name = "test"; 41 34 protected String history = "initial|"; 42 protected final List<EventListener<ChangeEvent>> historyListeners = new LinkedList<>(); 43 protected final List<EventListener<ListChange>> childrenListeners = new LinkedList<>(); 35 protected final EventListeners<TestChangeEvent> historyListeners = new EventListeners<>(); 44 36 45 protected final Map<String, TestChild> children = UniqueListAccess.createMap(TestChild.class, this); 46 protected int counter = 0; 37 protected final SimpleUniqueList<TestChild> children = new SimpleUniqueList<>(TestChild.class, 'c'); 47 38 48 39 /** … … 89 80 @ParamAnnotation 90 81 public Map<String, TestChild> getChildren() { 91 return Collections.unmodifiableMap(children);82 return children.getView(); 92 83 } 93 84 … … 111 102 TestChild child = new TestChild(this); 112 103 child.name = name; 113 children.put(child.getUid(), child); 114 fireChildrenChange(child, ListChange.Action.Add); 104 children.add(child); 115 105 } 116 106 117 107 protected void fireHistoryChange() { 118 for (EventListener<ChangeEvent> l : historyListeners) { 119 ChangeEvent event = new ChangeEvent(); 120 event.history = history; 121 l.action(event); 122 } 108 TestChangeEvent event = new TestChangeEvent(); 109 event.history = history; 110 historyListeners.actionForAll(event); 123 111 } 124 112 125 protected void fireChildrenChange(TestChild child, ListChange.Action action) {126 ListChange change = new ListChange(action, UniqueListAccess.getNumberInMap(children, child), child.getUid());127 for (EventListener<ListChange> l : childrenListeners) {128 l.action(change);129 }130 }131 113 132 114 @ParamAnnotation(id = "history_changed") 133 public void addHistoryListener(EventListener< ChangeEvent> listener) {115 public void addHistoryListener(EventListener<TestChangeEvent> listener) { 134 116 historyListeners.add(listener); 135 117 } 136 118 137 119 @ParamAnnotation(id = "history_changed") 138 public void removeHistoryListener(EventListener< ChangeEvent> listener) {120 public void removeHistoryListener(EventListener<TestChangeEvent> listener) { 139 121 historyListeners.remove(listener); 140 122 } … … 142 124 @ParamAnnotation(id = "children_changed") 143 125 public void addChildrenListener(EventListener<ListChange> listener) { 144 children Listeners.add(listener);126 children.addListener(listener); 145 127 } 146 128 147 129 @ParamAnnotation(id = "children_changed") 148 130 public void removeChildrenListener(EventListener<ListChange> listener) { 149 children Listeners.remove(listener);131 children.removeListener(listener); 150 132 } 151 133
Note: See TracChangeset
for help on using the changeset viewer.