source: java/main/src/main/java/com/framsticks/model/ModelBuilder.java @ 100

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

HIGHLIGHTS:

  • add <include/> to configuration
  • add side notes to tree
    • used to store arbitrary information alongside the tree structure
  • migrate to log4j2
    • supports lazy string evaluation of passed arguments
  • improve GUI tree
    • it stays in synchronization with actual state (even in high load test scenario)
  • improve panel management in GUI
  • make loading objects in GUI more lazy
  • offload parsing to connection receiver thread
    • info parsing
    • first step of objects parsing
  • fix connection parsing bug (eof in long values)
  • support zero-arguments procedure in table view

CHANGELOG:
Implement procedure calls from table view.

Refactorization around procedures in tables.

Add table editor for buttons.

Render buttons in the the list view.

Further improve Columns.

Add Column class for TableModel?.

Accept also non-arguments ProcedureParams? in tableView.

Increase maximal TextAreaControl? size.

Add tooltip to ProcedureControl?.

Fix bug of interpreting eofs in long values by connection reader.

Further rework connection parsing.

Simplify client connection processing.

Test ListChange? modification.

Test ListChange? events with java server.

Add TestChild?.

Fix bug with fast deregistering when connecting to running server.

Another minor refactorization in TreeOperations?.

Fix bug in SimpleAbstractAccess? loading routine.

Another minor improvement.

Minor change.

Make reading of List objects two-phase.

Another minor change.

Dispatch parsing into receiver thread.

Another step.

Enclose passing value in ObjectParam? case in closure.

Minor step.

Minor change on way to offload parsing.

Temporarily comment out single ValueParam? get.

It will be generalized to multi ValueParam?.

Process info in receiver thread.

Add DispatchingExceptionHandler?.

Make waits in browser test longer.

Use FETCHED_MARK.

It is honored in GUI, where it used to decide whether to get values

after user action.

It is set in standard algorithm for processing fetched values.

Add remove operation to side notes.

Make loading more lazy.

Improve loading policy.

On node choose load itself, on node expansion, load children.

Minor improvement.

Fix bug with panel interleaving.

Minor improvements.

Improve panel management.

More cleaning around panels.

Reorganize panels.

Further improve tree.

Fix bug in TreeModel?.

Remove children from TreeNode?.

Implement TreeNode? hashCode and equals.

Make TreeNode? delegate equals and hashcode to internal reference.

Move listeners from TreeNode? to side notes.

Store path.textual as a side note.

Side note params instead of accesses for objects.

More refactorizations.

In TreeNode? bindAccess based on side notes.

Minor step.

Hide createAccess.

Rename AccessInterface? to Access.

Minor changes.

Several improvements in high load scenarios.

Change semantics of ArrayListAccess?.set(index, null);

It now removes the element, making list shorter
(it was set to null before).

Add path remove handler.

Handle exceptions in Connection.

Update .gitignore

Configure logging to file.

Move registration to TreeModel?.

Further refactorization.

Minor refactorization.

Minor improvements.

Use specialized event also for Modify action of ListChange?.

Use remove events.

Use the insertion events for tree.

Further improve tree refreshing.

Further improve reacting on events in GUI.

Fix problem with not adding objects on addition list change.

Migrate to log4j lazy String construction interface.

Migrate imports to log4j2.

Drop dependency on adapter to version 1.2.

Switch log4j implementation to log4j2.

Add dirty mark to the NodeAtFrame?.

Make selecting in AccessInterfaces? type safe.

Ignore containers size settings in Model and Genotype.

Use tree side notes to remember local changes and panels.

Add sideNotes to tree.

They will be used to store various accompanying information
right in the tree.

Use ReferenceIdentityMap? from apache in TreeNode?.

It suits the need perfectly (weak semantics on both key and value).

Make ArrayListParam? do not react size changes.

Guard in TableModel? before not yet loaded objects.

Add <include/> clause and AutoInjector?.

Extract common columns configuration to separate xml,
that can be included by other configurations.

File size: 3.4 KB
Line 
1package com.framsticks.model;
2
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.Iterator;
6import java.util.List;
7
8import com.framsticks.model.f0.Schema;
9import com.framsticks.params.Util;
10import com.framsticks.params.annotations.AutoAppendAnnotation;
11import com.framsticks.params.annotations.FramsClassAnnotation;
12// import com.framsticks.params.annotations.ParamAnnotation;
13import com.framsticks.parsers.F0Parser;
14import com.framsticks.util.AutoBuilder;
15import com.framsticks.util.FramsticksException;
16import com.framsticks.util.ResourceBuilder;
17import com.framsticks.util.lang.Casting;
18import com.framsticks.util.lang.IterableIterator;
19import com.framsticks.util.math.Orientation;
20
21@FramsClassAnnotation
22public class ModelBuilder extends ResourceBuilder<Model> implements AutoBuilder {
23
24        Schema schema;
25        final List<ModelComponent> components = new ArrayList<>();
26
27        @Override
28        public Model finish() {
29                if (stream == null && components.isEmpty()) {
30                        throw new FramsticksException().msg("model builder instance not ready");
31                }
32                if (stream != null) {
33                        if (schema == null) {
34                                schema = Schema.getDefaultSchema();
35                        }
36                        F0Parser parser = new F0Parser(schema, stream);
37                        components.addAll(Util.stripAccess(parser.parse(), ModelComponent.class));
38                }
39                return build();
40        }
41
42        /**
43         * @return the schema
44         */
45        public Schema getSchema() {
46                return schema;
47        }
48
49        /**
50         * @param schema the schema to set
51         */
52        @AutoAppendAnnotation
53        public ModelBuilder schema(Schema schema) {
54                this.schema = schema;
55                return this;
56        }
57
58        @AutoAppendAnnotation
59        public ModelBuilder addComponent(ModelComponent component) {
60                components.add(component);
61                return this;
62        }
63
64        @AutoAppendAnnotation
65        public ModelBuilder addComponents(List<ModelComponent> component) {
66                this.components.addAll(component);
67                return this;
68        }
69
70        public Model build() {
71                Iterator<ModelComponent> i = components.iterator();
72                if (!i.hasNext()) {
73                        throw new FramsticksException().msg("empty components list");
74                }
75                Model f0Genotype = Casting.tryCast(Model.class, i.next());
76                if (f0Genotype == null) {
77                        throw new FramsticksException().msg("first component is not a Model");
78                }
79                for (ModelComponent component : new IterableIterator<ModelComponent>(i)) {
80                        if (component instanceof Joint) {
81                                f0Genotype.joints.add((Joint)component);
82                                continue;
83                        }
84                        if (component instanceof Part) {
85                                f0Genotype.parts.add((Part)component);
86                                continue;
87                        }
88                        if (component instanceof NeuroDefinition) {
89                                f0Genotype.neuroDefinitions.add((NeuroDefinition) component);
90                                continue;
91                        }
92                        if (component instanceof NeuroConnection) {
93                                f0Genotype.neuroConnections.add((NeuroConnection) component);
94                                continue;
95                        }
96                        throw new FramsticksException().msg("invalid class").arg("class", component.getClass().getCanonicalName());
97                }
98
99                for (Part p : f0Genotype.getParts()) {
100                        p.setOrientation(new Orientation().rotate(p.getRotation()));
101                }
102                for (Joint j : f0Genotype.getJoints()) {
103                        /** based on c++ Joint::attachToParts*/
104                        Part p1 = f0Genotype.parts.get(j.part1);
105                        Part p2 = f0Genotype.parts.get(j.part2);
106                        assert p1 != null && p2 != null;
107                        Orientation o = new Orientation().rotate(j.getRotation());
108                        p2.setOrientation(p1.getOrientation().transform(o));
109                        p2.setPosition(p2.getOrientation().transform(j.getDelta()).add(p1.getPosition()));
110                }
111                return f0Genotype;
112        }
113
114        @Override
115        public List<Object> autoFinish() {
116                Model model = finish();
117                assert schema != null;
118                return Arrays.asList(schema.getRegistry(), model);
119        }
120
121}
Note: See TracBrowser for help on using the repository browser.