source: java/main/src/main/java/com/framsticks/parsers/F0Writer.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: 2.2 KB
Line 
1package com.framsticks.parsers;
2
3import com.framsticks.model.Model;
4import com.framsticks.params.*;
5import com.framsticks.util.Misc;
6import com.framsticks.util.lang.Containers;
7import static com.framsticks.util.lang.Containers.filterInstanceof;
8
9/**
10 * Author: Piotr Śniegowski
11 */
12public class F0Writer {
13
14        protected final Schema schema;
15        protected final SinkInterface sink;
16        protected final Model model;
17        protected boolean omit = true;
18
19        public F0Writer(Schema schema, Model model, SinkInterface sink) {
20                this.schema = schema;
21                this.model = model;
22                this.sink = sink;
23        }
24
25        F0Writer omitDefaultValues(boolean omit) {
26                this.omit = omit;
27                return this;
28        }
29
30        protected void write(AccessInterface access) {
31                if (access instanceof ListAccess) {
32                        // TODO
33                        for (ValueParam p : Containers.filterInstanceof(access.getParams(), ValueParam.class)) {
34                                write(schema.getRegistry().prepareAccess((CompositeParam) p).select(access.get(p, Object.class)));
35                        }
36                        return;
37                }
38                StringBuilder line = new StringBuilder();
39                line.append(access.getId()).append(":");
40                boolean placeComma = false;
41                boolean contiguous = true;
42
43                for (ValueParam param : filterInstanceof(access.getParams(), ValueParam.class)) {
44                        if (param instanceof CompositeParam) {
45                                AccessInterface a = schema.getRegistry().prepareAccess((CompositeParam)param);
46                                a.select(access.get((ValueParam) param, Object.class));
47                                write(a);
48                                continue;
49                        }
50                        Object value = access.get(param, Object.class);
51                        if ((param instanceof PrimitiveParam) && Misc.equals(value, ((PrimitiveParam) param).getDef(Object.class))) {
52                                contiguous = false;
53                                continue;
54                        }
55                        if (value == null) {
56                                contiguous = false;
57                                continue;
58                        }
59
60                        if (placeComma) {
61                                line.append(",");
62                        } else {
63                                placeComma = true;
64                        }
65
66                        if ((!contiguous) || ((param.getFlags() & Flags.CANOMITNAME) == 0)) {
67                                line.append(param.getId()).append("=");
68                                contiguous = true;
69                        }
70                        String printed = value.toString().replace("\"", "\\\"");
71                        if (printed.contains(",")) {
72                                line.append("\"").append(printed).append("\"");
73                        } else {
74                                line.append(value);
75                        }
76                }
77                sink.print(line).breakLine();
78        }
79        public void write() {
80                AccessInterface access = schema.getRegistry().createAccess("m");
81                access.select(model);
82                write(access);
83        }
84
85
86}
Note: See TracBrowser for help on using the repository browser.