source: java/main/src/main/java/com/framsticks/gui/InstanceAtFrame.java @ 90

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

HIGHLIGHTS:

CHANGELOG:
Make ProcedureParam? hold only ValueParams?.

Use id instead of names when naming gui components internally.

Basic procedure calling in GUI.

The actual procedure call is currently only backed
by the ObjectInstance?.

Add UnimplementedException?.

Improve naming of various gui elements.

Allow easy navigating in FEST Swing testing.

Add optional explicit order attribute to FramsClassAnnotation?.

That's because java reflection does return declared members
in any specific order. That ordering is needed only for
classes that have no representation in framsticks and need
a deterministic ordering of params.

Add ControlOwner? interface.

Add test for procedure calling in Browser.

First version of ParamAnnotation? for procedures.

Development of ProcedureParam?.

Add draft version of ProcedureParam? implementation in ReflectionAccess?.

Allow viewing FramsClasses? in gui Browser.

Extract ResourceBuilder? from ModelBuilder?.

Remove internalId from Param.

It was currently completely not utilised. Whether it is still needed
after introduction of ParamAnnotation? is arguable.

Add remaining param attributes to ParamAnnotation?.

Change AutoBuilder? semantics.

AutoBuilder? returns list of objects that are to be appended
with methods @AutoAppendAnnotation?.

This allows to omit explicit addition of ModelPackage? to instance
if the instance uses ModelBuilder? (registration of ModelPackage? comes
from schema).

Fix params ordering problem in auto created FramsClasses?.

Improve ObjectInstance?.

Several fixes to ModelBuilder?.

Improve test for ObjectInstance? in Browser.

Make initialization of robot static.

With robot recreated for second browser test, the test hanged
deep in AWT.

Add base convenience base test for Browser tests.

More tests to ObjectInstance?.

Rename Dispatcher.invokeLater() to dispatch().

Add assertDispatch.

It allows assertions in other threads, than TestNGInvoker.
Assertions are gathered after each method invocation and rethrown.

Use timeOut annotation attribute for tests involving some waiting.

Remove firstTask method (merge with joinableStart).

Clean up leftovers.

Remove unused FavouritesXMLFactory (the reading part is already
completely done with generic XmlLoader?, and writing part will be done
based on the same approach if needed).
Move UserFavourite? to the com.framsticks.gui.configuration package.

Remove GenotypeBrowser? as to specific.

This functionality will be available in ObjectInstance?.

Add interface ParamsPackage?.

Package containing registration of Java classes meant to use with
ReflectionAccess? may be in Instance using configuration.

Minor changes.

Make Group immutable.

Add AutoBuilder? interface extending Builder - only those would
be used to automatically build from XML.

Fix groups in FramsClass?.

Minor naming cleanup in Registry.

Add ModelComponent? interface.

All class creating the Model are implementing that interface.

Extract Model.build into ModelBuilder?.

ModelBuilder? will be compatible with other builders
and allow using it from configuration.

Fix NeuroConnection?.

Add synchronous get operation for dispatchers.

Rename JoinableMonitor? to Monitor.

Add ObjectInstance?.

This class is mainly for demonstration
and testing purposes.

Improve FramsServer? runner.

  • improve ExternalProcess? runner,
  • runner can kill the server but also react properly, when the server exists on it's own,
  • set default path to search for framsticks server installation,
  • add LoggingOutputListener?.
File size: 4.3 KB
Line 
1package com.framsticks.gui;
2
3import org.apache.log4j.Logger;
4
5import com.framsticks.core.Instance;
6import com.framsticks.core.InstanceListener;
7import com.framsticks.core.ListChange;
8import com.framsticks.core.Node;
9import com.framsticks.core.Path;
10import com.framsticks.params.CompositeParam;
11import com.framsticks.params.FramsClass;
12
13import java.util.*;
14
15import javax.swing.tree.TreePath;
16import com.framsticks.util.dispatching.RunAt;
17
18/**
19 * @author Piotr Sniegowski
20 */
21public class InstanceAtFrame implements InstanceListener {
22
23        private static final Logger log = Logger.getLogger(InstanceAtFrame.class);
24
25        protected final Frame frame;
26        protected final Instance instance;
27        protected final Map<String, Panel> knownPanels = new HashMap<String, Panel>();
28        protected TreeNode rootTreeNode;
29
30        public InstanceAtFrame(Instance instance, Frame frame) {
31                this.frame = frame;
32                this.instance = instance;
33        }
34
35        public Frame getFrame() {
36                return frame;
37        }
38
39        /**
40         * @return the instance
41         */
42        public Instance getInstance() {
43                return instance;
44        }
45
46        public void registerPanel(Panel panel) {
47        }
48
49        public Panel findPanel(String accessId) {
50                assert frame.isActive();
51                return (knownPanels.containsKey(accessId) ? knownPanels.get(accessId) : null);
52        }
53
54        public final String getName() {
55                return instance.getName();
56        }
57
58        public Panel preparePanel(CompositeParam param, FramsClass framsClass) {
59                assert frame.isActive();
60                Panel panel = preparePanelImpl(param, framsClass);
61                assert panel != null;
62                String accessId = param.computeAccessId();
63                panel.uniqueName = accessId + "@" + instance.getName();
64                knownPanels.put(accessId, panel);
65                frame.cardPanel.add(panel, panel.uniqueName);
66                log.debug("prepared panel for " + panel);
67                return panel;
68        }
69
70        protected Panel preparePanelImpl(CompositeParam param, FramsClass framsClass) {
71                assert frame.isActive();
72                List<Panel> panels = new ArrayList<Panel>();
73
74                Panel.Parameters parameters = new Panel.Parameters(this, param, framsClass);
75                for (PanelProvider pp : frame.browser.panelProviders) {
76                        Panel p = pp.providePanel(parameters);
77                        if (p != null) {
78                                panels.add(p);
79                        }
80                }
81
82                if (panels.isEmpty()) {
83                        return new EmptyPanel(parameters);
84                }
85                if (panels.size() == 1) {
86                        return panels.get(0);
87                }
88                return new MultiPanel(parameters, panels);
89
90        }
91
92        @Override
93        public void onListChange(Path path, ListChange change) {
94
95        }
96
97        public TreePath getTreePath(Path path, boolean create) {
98                assert frame.isActive();
99                TreeNode t = rootTreeNode;
100                TreePath result = new TreePath(frame.rootNode).pathByAddingChild(rootTreeNode);
101                List<Node> nodes = path.getNodes();
102                Iterator<Node> i = nodes.iterator();
103                i.next();
104                // Node first = i.next();
105
106                // if (!t.path.isResolved()) {
107                //      t.path = new Path(path.getInstance(), nodes, first);
108                // }
109                while (i.hasNext()) {
110                        Node n = i.next();
111                        TreeNode r = null;
112                        for (TreeNode c : t.childrenIterable()) {
113                                if (c.paramId.equals(n.getParam().getId())) {
114                                        r = c;
115                                        break;
116                                }
117                        }
118                        if (r == null) {
119                                log.debug("missing " + n.getParam().getId() + " in " + t);
120                                if (!create) {
121                                        return result;
122                                }
123                                Path p = Path.build().instance(path.getInstance()).buildUpTo(nodes, n).finish();
124
125
126                                log.debug("forced resolution: creating treenode for " + p);
127                                TreeNode childNode = new TreeNode(InstanceAtFrame.this, p);
128
129                                frame.addNode(childNode, t);
130                                // frame.treeModel.reload();
131                                // t.add(childNode);
132                                // frame.treeModel.nodeStructureChanged(t);
133
134                                r = childNode;
135                        } else {
136                                // if (!r.path.isResolved()) {
137                                //      r.path = new Path(path.getInstance(), nodes, n);
138                                // }
139                        }
140                        result = result.pathByAddingChild(r);
141                        t = r;
142                }
143                return result;
144        }
145
146        @Override
147        public void onFetch(final Path path) {
148                assert instance.isActive();
149                log.trace("fetched " + path);
150
151                frame.dispatch(new RunAt<Frame>() {
152                        @Override
153                        public void run() {
154
155                                TreePath treePath = getTreePath(path, true);
156                                assert treePath.getPathCount() == path.size() + 1;
157
158                                final TreeNode result = (TreeNode) treePath.getLastPathComponent();
159                                // log.trace("found " + result + " == " + path);
160                                instance.dispatch(new RunAt<Instance>() {
161                                        @Override
162                                        public void run() {
163                                                result.reactForFetchResult(path, null);
164                                        }
165                                });
166                        }
167                });
168        }
169
170        @Override
171        public void onRun(Exception e) {
172
173        }
174
175        @Override
176        public void onStop(Exception e) {
177
178        }
179}
Note: See TracBrowser for help on using the repository browser.