source: java/main/src/main/java/com/framsticks/test/TestClass.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1package com.framsticks.test;
2
3import java.util.Map;
4
5import org.apache.logging.log4j.Logger;
6import org.apache.logging.log4j.LogManager;
7
8import com.framsticks.params.EventListener;
9import com.framsticks.params.SimplePrimitive;
10import com.framsticks.params.SimpleUniqueList;
11import com.framsticks.params.annotations.AutoAppendAnnotation;
12import com.framsticks.params.annotations.FramsClassAnnotation;
13import com.framsticks.params.annotations.ParamAnnotation;
14import com.framsticks.params.types.ProcedureParam;
15import com.framsticks.structure.messages.ListChange;
16import com.framsticks.structure.messages.ValueChange;
17
18@FramsClassAnnotation(
19        order = {
20                "name",
21                "history",
22                "history_changed",
23                "appendHistory",
24                "resetHistory",
25                "children",
26                "createChild",
27                "children_changed"
28        }
29)
30public class TestClass {
31        private static final Logger log = LogManager.getLogger(TestClass.class);
32
33
34        protected String name = "test";
35        protected final SimplePrimitive<String> history = new SimplePrimitive<>("initial|");
36
37        protected final SimpleUniqueList<TestChild> children = new SimpleUniqueList<>(TestChild.class, 'c');
38
39        /**
40         *
41         */
42        public TestClass() {
43        }
44
45        /**
46         * @return the name
47         */
48        @ParamAnnotation
49        public String getName() {
50                return name;
51        }
52
53        /**
54         * @param name the name to set
55         */
56        @ParamAnnotation
57        public void setName(String name) {
58                this.name = name;
59        }
60
61        /**
62         * @return the history
63         */
64        @ParamAnnotation
65        public String getHistory() {
66                return history.get();
67        }
68
69        /**
70         * @param history the history to set
71         */
72        @ParamAnnotation
73        public void setHistory(String history) {
74                this.history.set(history);
75        }
76
77        /**
78         * @return the children
79         */
80        @ParamAnnotation
81        public Map<String, TestChild> getChildren() {
82                return children.getMap();
83        }
84
85        @ParamAnnotation(paramType = ProcedureParam.class)
86        public int appendHistory(String line) {
87                log.debug("appending '{}'", line);
88                history.set(history.get() + line + "|");
89                // fireHistoryChange();
90                return history.get().length();
91        }
92
93        @ParamAnnotation(paramType = ProcedureParam.class)
94        public void resetHistory() {
95                log.debug("reseting");
96                history.set("");
97        }
98
99        @ParamAnnotation(paramType = ProcedureParam.class)
100        public void createChild(String name) {
101                TestChild child = new TestChild();
102                child.name = name;
103                addChild(child);
104        }
105
106        @AutoAppendAnnotation
107        public void addChild(TestChild child) {
108                child.parent = this;
109                children.add(child);
110        }
111
112        @ParamAnnotation(id = "history_changed")
113        public void addHistoryListener(EventListener<ValueChange> listener) {
114                history.addListener(listener);
115        }
116
117        @ParamAnnotation(id = "history_changed")
118        public void removeHistoryListener(EventListener<ValueChange> listener) {
119                history.removeListener(listener);
120        }
121
122        @ParamAnnotation(id = "children_changed")
123        public void addChildrenListener(EventListener<ListChange> listener) {
124                children.addListener(listener);
125        }
126
127        @ParamAnnotation(id = "children_changed")
128        public void removeChildrenListener(EventListener<ListChange> listener) {
129                children.removeListener(listener);
130        }
131
132        @Override
133        public String toString() {
134                return "test class " + history;
135        }
136
137
138}
Note: See TracBrowser for help on using the repository browser.