source: java/main/src/main/java/com/framsticks/core/Path.java @ 84

Last change on this file since 84 was 84, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • simplification of entities management model
  • cleanup around params (improve hierarchy)
  • migrate from JUnit to TestNG
  • introduce FEST to automatically test GUI
  • improve slider control
  • loosen synchronization between gui tree and backend representation
  • and many other bug fixes

NOTICE:

  • a great many of lines is changed only because of substituting spaces with tabs

CHANGELOG (oldest changes at the bottom):

Some cleaning after fix found.

Fix bug with tree.

More changes with TreeNodes?.

Finally fix issue with tree.

Improve gui tree management.

Decouple update of values from fetch request in gui.

Minor changes.

Minor changes.

Minor change.

Change Path construction wording.

More fixes to SliderControl?.

Fix SliderControl?.

Fix SliderControl?.

Minor improvement.

Several changes.

Make NumberParam? a generic class.

Add robot to the gui test.

Setup common testing logging configuration.

Remove Parameters class.

Remove entityOwner from Parameters.

Move name out from Parameters class.

Move configuration to after the construction.

Simplify observers and endpoints.

Remove superfluous configureEntity overrides.

Add dependency on fest-swing-testng.

Use FEST for final print test.

Use FEST for more concise and readable assertions.

Divide test of F0Parser into multiple methods.

Migrate to TestNG

Minor change.

Change convention from LOGGER to log.

Fix reporting of errors during controls filling.

Bound maximal height of SliderControl?.

Minor improvements.

Improve tooltips for controls.

Also use Delimeted in more places.

Move static control utilities to Gui.

Rename package gui.components to controls.

Some cleaning in controls.

Improve Param classes placing.

Move ValueParam?, PrimitiveParam? and CompositeParam? one package up.

Improve ParamBuilder?.

Move getDef to ValueParam? and PrimitiveParam?.

Move getMax and getDef to ValueParam?.

Move getMin to ValueParam?.

Upgrade to laters apache commons versions.

Use filterInstanceof extensively.

Add instanceof filters.

Make ValueParam? in many places of Param.

Place assertions about ValueParam?.

Add ValueParam?

Rename ValueParam? to PrimitiveParam?

Minor changes.

Several improvements to params types.

Add NumberParam?.

Add TextControl? component.

Add .swp files to .gitignore

Greatly improved slider component.

Some improvements.

Make Param.reassign return also a state.

Add IterableIterator?.

Several changes.

  • Move util classes to better packages.
  • Remove warnings from eclim.

Several improvements.

Fix bug with BooleanParam?.

Some experiments with visualization.

Another fix to panel management.

Improve panel management.

Some refactorization around panels.

Add root class for panel.

File size: 4.8 KB
Line 
1package com.framsticks.core;
2
3import com.framsticks.params.AccessInterface;
4import com.framsticks.params.CompositeParam;
5import com.framsticks.params.Param;
6import com.framsticks.util.dispatching.Dispatching;
7import java.util.Iterator;
8import java.util.LinkedList;
9import java.util.List;
10
11import org.apache.commons.collections.ListUtils;
12
13/**
14 * @author Piotr Sniegowski
15 */
16public class Path {
17        // private final static Logger log = Logger.getLogger(Path.class.getName());
18
19        final LinkedList<Node> nodes = new LinkedList<Node>();
20        String textual;
21        Instance instance;
22
23        protected Object getKnownChild(AccessInterface access, CompositeParam param) {
24                Object child = access.get(param, Object.class);
25                if (child == null) {
26                        return null;
27                }
28                return (instance.registry.prepareAccess(param) != null) ? child : null;
29        }
30
31        // public Path constructPath(Instance instance, String textual) {
32        //      assert instance.isActive();
33
34        // }
35
36        Path(Instance instance, String textual) {
37                assert instance.isActive();
38                this.instance = instance;
39
40                nodes.add(instance.root);
41                Node current = instance.root;
42
43                StringBuilder b = new StringBuilder();
44                Iterator<String> i = Instance.splitPath(textual);
45                while (i.hasNext() && current.getObject() != null) {
46                        AccessInterface access = instance.registry.prepareAccess(current.getParam());
47                        if (access == null) {
48                                break;
49                        }
50                        String e = i.next();
51                        Param p = access.getParam(e);
52                        if (!(p instanceof CompositeParam)) {
53                                //entries.add(new Entry());
54                                break;
55                        }
56                        CompositeParam c = (CompositeParam)p;
57                        b.append("/").append(e);
58                        access.select(current.getObject());
59                        current = new Node(c, getKnownChild(access, c));
60                        nodes.add(current);
61                }
62                this.textual = (size() == 1) ? "/" : b.toString();
63        }
64
65        public Path(Instance instance, List<Node> nodes, Node node) {
66                this.instance = instance;
67                StringBuilder b = new StringBuilder();
68                boolean add = false;
69                for (Node n : nodes) {
70                        this.nodes.add(n);
71                        if (add) {
72                                b.append("/").append(n.getParam().getId());
73                        }
74                        add = true;
75                        if (n == node) {
76                                break;
77                        }
78                }
79                this.textual = (size() == 1) ? "/" : b.toString();
80        }
81
82        protected Path() {
83
84        }
85
86        public Path appendNode(Node node) {
87                assert isResolved();
88                Path result = new Path();
89                result.textual = textual + ((size() == 1) ? "" : "/") + node.getParam().getId();
90                result.instance = instance;
91                result.nodes.addAll(nodes);
92                result.nodes.add(node);
93                return result;
94        }
95
96        public Path appendParam(CompositeParam param) {
97                assert isResolved();
98                return appendNode(new Node(param, null));
99        }
100
101        public Path appendResolution(Object object) {
102                assert !isResolved();
103                Path result = new Path();
104                result.textual = textual;
105                result.instance = instance;
106                result.nodes.addAll(nodes);
107                result.nodes.add(new Node(result.nodes.pollLast().getParam(), object));
108                return result;
109        }
110
111        public final Object getTopObject() {
112                return getTop().getObject();
113        }
114
115        public final Node getTop() {
116                return nodes.getLast();
117        }
118
119        public final Node getUnder() {
120                assert nodes.size() >= 2;
121                return nodes.get(nodes.size() - 2);
122        }
123
124        public final String getTextual() {
125                return textual;
126        }
127
128        public String toString() {
129                return instance + textual + (!isResolved() ? "!" : "");
130        }
131
132        public final int size() {
133                assert Dispatching.isThreadSafe();
134                return nodes.size();
135        }
136
137        public final boolean isResolved() {
138                assert Dispatching.isThreadSafe();
139                return getTop().getObject() != null;
140        }
141
142        public final boolean isResolved(String textual) {
143                assert Dispatching.isThreadSafe();
144                return isTheSame(textual) && isResolved();
145        }
146
147        public final boolean isTheSame(String textual) {
148                assert Dispatching.isThreadSafe();
149                return this.textual.equals(textual);
150        }
151
152        public final Instance getInstance() {
153                assert Dispatching.isThreadSafe();
154                return instance;
155        }
156
157
158        /** Attach resolution at end, if available.
159         *
160         * @return Modified path, if resolution was available, this otherwise.
161         */
162        public Path tryFindResolution() {
163                assert instance.isActive();
164                assert !isResolved();
165                if (size() == 1) {
166                        return new Path(instance, "/");//appendResolution(instance.root.object);
167                }
168                Object child = getKnownChild(instance.bindAccess(getUnder()), getTop().getParam());
169                if (child == null) {
170                        return this;
171                }
172                return appendResolution(child);
173        }
174
175        public boolean matches(Path p) {
176                assert Dispatching.isThreadSafe();
177                assert instance == p.instance;
178                Iterator<Node> a = nodes.iterator();
179                Iterator<Node> b = p.nodes.iterator();
180                while (a.hasNext() && b.hasNext()) {
181                        Node an = a.next();
182                        Node bn = b.next();
183                        if (an.object != bn.object) {
184                                return false;
185                        }
186                }
187                return a.hasNext() == b.hasNext();
188        }
189
190        public String getLastElement() {
191                return getTop().getParam().getId();
192        }
193
194        public final boolean isOwner(Instance instance) {
195                return this.instance == instance;
196        }
197
198        @SuppressWarnings("unchecked")
199        public
200        List<Node> getNodes() {
201                return ListUtils.unmodifiableList(nodes);
202        }
203}
204
Note: See TracBrowser for help on using the repository browser.