source: java/main/src/main/java/com/framsticks/gui/TreeAtFrame.java @ 101

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

HIGHLIGHTS:

  • improve tree side notes
  • improve GUI layout
  • add foldable list of occured events to EventControl?
  • improve automatic type conversion in proxy listeners
  • implement several Access functionalities as algorithms independent of Access type
  • introduce draft base classes for distributed experiments
  • automatically register dependant Java classes to FramsClass? registry
  • add testing prime experiment and configuration
  • simplify and improve task dispatching

CHANGELOG:
Improve task dispatching in RemoteTree?.

GUI no longer hangs on connection problems.

Make all dispatchers joinables.

Refactorize Thread dispatcher.

Remove Task and PeriodicTask?.

Use Java utilities in those situations.

Reworking tasks dispatching.

Fix bug in EventControl? listener dispatching.

Minor improvements.

Add testing configuration for ExternalProcess? in GUI.

More improvement to prime.

Support for USERREADONLY in GUI.

Add that flag to various params in Java classes.

Remove redundant register clauses from several FramsClassAnnotations?.

Automatically gather and register dependant classes.

Add configuration for prime.

Improve Simulator class.

Add prime.xml configuration.

Introduce draft Experiment and Simulator classes.

Add prime experiment tests.

Enclose typical map with listeners into SimpleUniqueList?.

Needfile works in GUI.

Improve needfile handling in Browser.

More improvement with NeedFile?.

Implementing needfile.

Update test.

Rename ChangeEvent? to TestChangeEvent?.

Automatic argument type search in RemoteTree? listeners.

MultiParamLoader? uses AccessProvider?. By default old implementation
enclosed in AccessStash? or Registry.

Minor changes.

Rename SourceInterface? to Source.

Also improve toString of File and ListSource?.

Remove unused SimpleSource? class.

Add clearing in HistoryControl?.

Show entries in table at EventControl?.

Improve EventControl?.

Add listeners registration to EventControl?.

Add foldable table to HistoryControl?.

Add control row to Procedure and Event controls.

Improve layout of controls.

Another minor change to gui layout.

Minor improvement in the SliderControl?.

Minor changes.

Move ReflectionAccess?.Backend to separate file.

It was to cluttered.

Cleanup in ReflectionAccess?.

Move setMin, setMax, setDef to AccessOperations?.

Extract loading operation into AccessOperations?.

Append Framsticks to name of UnsupportedOperationException?.

The java.lang.UnsupportedOperationException? was shadowing this class.

Rename params.Util to params.ParamsUtil?.

Several improvements.

Minor changes.

Implement revert functionality.

Improve local changes management.

Minor improvement.

Remove methods rendered superfluous after SideNoteKey? improvement.

Improve SideNoteKey?.

It is now generic type, so explicit type specification at
call site is no more needed.

Introduce SideNoteKey? interface.

Only Objects implementing that key may be used as side note keys.

Minor improvements.

Use strings instead of ValueControls? in several gui mappings.

File size: 3.1 KB
Line 
1package com.framsticks.gui;
2
3import org.apache.logging.log4j.Logger;
4import org.apache.logging.log4j.LogManager;
5
6import com.framsticks.core.SideNoteKey;
7import com.framsticks.core.Tree;
8import com.framsticks.core.Node;
9import com.framsticks.core.Path;
10import static com.framsticks.core.TreeOperations.*;
11import com.framsticks.gui.controls.ValueControl;
12import com.framsticks.params.CompositeParam;
13import com.framsticks.params.FramsClass;
14import com.framsticks.params.PrimitiveParam;
15
16import java.util.*;
17
18
19
20import com.framsticks.util.dispatching.FutureHandler;
21
22/**
23 * @author Piotr Sniegowski
24 */
25public class TreeAtFrame {
26
27        private static final Logger log = LogManager.getLogger(TreeAtFrame.class);
28
29        protected final Frame frame;
30        protected final Tree tree;
31        protected final Map<String, TreePanel> knownPanels = new HashMap<>();
32        protected Node rootNode;
33
34        protected final SideNoteKey<UserChanges> userChangesKey = SideNoteKey.make(UserChanges.class);
35
36        public TreeAtFrame(Tree tree, Frame frame) {
37                this.frame = frame;
38                this.tree = tree;
39        }
40
41        public Frame getFrame() {
42                return frame;
43        }
44
45        /**
46         * @return the tree
47         */
48        public Tree getTree() {
49                return tree;
50        }
51
52        /**
53         * @return the userChangesKey
54         */
55        public SideNoteKey<UserChanges> getUserChangesKey() {
56                return userChangesKey;
57        }
58
59        public final String getName() {
60                return tree.getName();
61        }
62
63        public TreePanel preparePanel(final CompositeParam param) {
64                assert frame.isActive();
65
66                TreePanel panel = knownPanels.get(param.getFramsTypeName());
67                if (panel != null) {
68                        return panel;
69                }
70
71                final FramsClass framsClass = tree.getInfoFromCache(param.getContainedTypeName());
72                final List<TreePanel> panels = new ArrayList<TreePanel>();
73
74                final TreePanel.Parameters parameters = new TreePanel.Parameters(this, param, framsClass);
75                for (PanelProvider pp : frame.browser.panelProviders) {
76                        TreePanel p = pp.providePanel(parameters);
77                        if (p != null) {
78                                panels.add(p);
79                        }
80                }
81
82                if (panels.isEmpty()) {
83                        panel = new EmptyTreePanel(parameters);
84                } else  if (panels.size() == 1) {
85                        panel = panels.get(0);
86                } else {
87                        panel = new MultiPanel(parameters, panels);
88                }
89
90                knownPanels.put(param.getFramsTypeName(), panel);
91
92                log.debug("prepared panel for {}", panel);
93                return panel;
94        }
95
96        public boolean changeValue(Object object, ValueControl component, Object newValue) {
97                log.debug("changing value of {} to '{}'", component, newValue);
98
99                getOrCreateSideNote(tree, object, userChangesKey).changes.put(component.getParam().getId(), newValue);
100
101                return true;
102        }
103
104
105        public void pushUserChangesToTree(final Path path) {
106                assert frame.isActive();
107                path.assureResolved();
108
109                final UserChanges userChanges = getSideNote(path, userChangesKey);
110                if (userChanges == null) {
111                        return;
112                }
113                removeSideNote(path, userChangesKey);
114
115                for (final Map.Entry<String, Object> e : userChanges.changes.entrySet()) {
116                        set(path, getParam(path, e.getKey(), PrimitiveParam.class), e.getValue(), new FutureHandler<Integer>(frame) {
117                                @Override
118                                protected void result(Integer flag) {
119                                        assert frame.isActive();
120                                        userChanges.changes.remove(e.getKey());
121                                }
122                        });
123                }
124        }
125
126}
Note: See TracBrowser for help on using the repository browser.