source: java/main/src/main/java/com/framsticks/gui/Browser.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: 6.1 KB
Line 
1package com.framsticks.gui;
2
3import com.framsticks.core.*;
4import com.framsticks.params.annotations.AutoAppendAnnotation;
5import com.framsticks.params.annotations.FramsClassAnnotation;
6import com.framsticks.params.annotations.ParamAnnotation;
7import com.framsticks.util.Logging;
8import com.framsticks.util.dispatching.AbstractJoinable;
9import com.framsticks.util.dispatching.Dispatcher;
10import com.framsticks.util.dispatching.Dispatching;
11import com.framsticks.util.dispatching.Future;
12import com.framsticks.util.dispatching.Joinable;
13import com.framsticks.util.dispatching.JoinableCollection;
14import com.framsticks.util.dispatching.JoinableParent;
15import com.framsticks.util.dispatching.JoinableState;
16
17import javax.swing.*;
18
19import org.apache.log4j.Logger;
20
21import java.awt.Dimension;
22import java.util.ArrayList;
23import java.util.List;
24import java.util.Map;
25import com.framsticks.util.dispatching.RunAt;
26
27/**
28 * @author Piotr Sniegowski
29 */
30@FramsClassAnnotation
31public class Browser extends AbstractJoinable implements Dispatcher<Browser>, Entity, JoinableParent {
32
33        private static final Logger log = Logger.getLogger(Browser.class.getName());
34
35        protected JoinableCollection<Frame> frames = new JoinableCollection<Frame>().setObservableName("frames");
36        protected JoinableCollection<Instance> instances = new JoinableCollection<Instance>().setObservableName("instances");
37
38        protected MainFrame mainFrame;
39        public List<PanelProvider> panelProviders = new ArrayList<PanelProvider>();
40        protected Dimension defaultFrameDimension;
41
42        String name;
43
44        public void addFrame(Frame frame) {
45                frames.add(frame);
46        }
47
48        public Browser() {
49                setName("browser");
50                JPopupMenu.setDefaultLightWeightPopupEnabled(false);
51                addPanelProvider(new StandardPanelProvider());
52
53                mainFrame = new MainFrame(Browser.this);
54                addFrame(mainFrame);
55        }
56
57        @AutoAppendAnnotation
58        public void addPanelProvider(PanelProvider panelProvider) {
59                log.debug("added panel provider of type: " + panelProvider.getClass().getCanonicalName());
60                panelProviders.add(panelProvider);
61        }
62
63        @AutoAppendAnnotation
64        public void addInstance(Instance instance) {
65                log.info("adding instance: " + instance);
66                instances.add(instance);
67        }
68
69        public void autoResolvePath(final String path, final Future<Path> future) {
70                final Instance i = instances.get("localhost");
71                i.dispatch(new RunAt<Instance>() {
72                        @Override
73                        public void run() {
74                                i.resolveAndFetch(path, new Future<Path>() {
75                                        @Override
76                                        public void result(final Path p, Exception e) {
77                                                Logging.log(log, "auto resolve path", path, e);
78                                                if (future != null) {
79                                                        future.result(p, e);
80                                                }
81                                                if (e == null) {
82                                                        mainFrame.dispatch(new RunAt<Frame>() {
83                                                                @Override
84                                                                public void run() {
85                                                                        mainFrame.goTo(p);
86                                                                }
87                                                        });
88                                                }
89                                        }
90                                });
91                        }
92                });
93        }
94
95        public void clear() {
96                assert isActive();
97                for (Frame f : frames) {
98                        f.clear();
99                }
100        }
101
102        protected void initializeGUI() {
103                assert isActive();
104                log.debug("executing first task");
105
106                try {
107                        boolean found = false;
108                        // for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
109                        //      log.info("look and feel available: " + info.getName());
110                        //      if ("Nimbus".equals(info.getName())) {
111                        //              UIManager.setLookAndFeel(info.getClassName());
112                        //              found = true;
113                        //              break;
114                        //      }
115                        // }
116                        if (!found) {
117                                UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
118                        }
119                } catch (Exception ex) {
120                        log.warn("failed loading Look&Feel: ", ex);
121                }
122
123                javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);
124
125
126                for (Frame f : frames) {
127                        f.configure();
128                }
129
130                for (final Instance i : instances) {
131                        i.dispatch(new RunAt<Instance>() {
132                                @Override
133                                public void run() {
134                                        final Path p = i.getRootPath();
135                                        dispatch(new RunAt<Browser>() {
136                                                @Override
137                                                public void run() {
138                                                        mainFrame.addRootPath(p);
139                                                }
140                                        });
141                                }
142                        });
143                }
144
145                for (Frame f : frames) {
146                        f.getSwing().setVisible(true);
147                }
148
149                // autoResolvePath("/simulator/genepools/groups/0", null);
150                // autoResolvePath("/", null);
151        }
152
153        public void createTreeNodeForChild(final Path path) {
154                assert !isActive();
155                //assert instance.isActive();
156
157                /*
158                 final TreeNode parentTreeNode = (TreeNode) child.getParent().getUserObject();
159                 if (parentTreeNode == null) {
160                 Dispatching.invokeDispatch(this, manager, new Runnable() {
161                 @Override
162                 public void run() {
163                 createTreeNodeForChild(child);
164                 }
165                 });
166                 return;
167                 }
168                 log.debug(child.getClass().getSimpleName() + " created: " + child);
169
170
171                 invokeLater(new Runnable() {
172                 @Override
173                 public void run() {
174                 parentTreeNode.getOrCreateChildTreeNodeFor(child);
175                 }
176                 });
177                 */
178        }
179
180        @Override
181        protected void joinableStart() {
182                Dispatching.use(frames, this);
183                Dispatching.use(instances, this);
184
185                dispatch(new RunAt<Browser>() {
186                        @Override
187                        public void run() {
188                                initializeGUI();
189                        }
190                });
191        }
192
193        /**
194         * @return the instances
195         */
196        public Map<String, Instance> getInstances() {
197                return instances.getObservables();
198        }
199
200        /**
201         * @return the mainFrame
202         */
203        public MainFrame getMainFrame() {
204                return mainFrame;
205        }
206
207        /**
208         * @return the name
209         */
210        @ParamAnnotation
211        public String getName() {
212                return name;
213        }
214
215        /**
216         * @param name the name to set
217         */
218        @ParamAnnotation
219        public void setName(String name) {
220                this.name = name;
221        }
222
223        @Override
224        public boolean isActive() {
225                return SwingDispatcher.getInstance().isActive();
226        }
227
228        @Override
229        public void dispatch(RunAt<? extends Browser> runnable) {
230                SwingDispatcher.getInstance().dispatch(runnable);
231        }
232
233        @Override
234        protected void joinableJoin() throws InterruptedException {
235                Dispatching.join(frames);
236                Dispatching.join(instances);
237                // super.join();
238        }
239
240        @Override
241        protected void joinableInterrupt() {
242                Dispatching.drop(frames, this);
243                Dispatching.drop(instances, this);
244        }
245
246        @Override
247        public void childChangedState(Joinable joinable, JoinableState state) {
248                if (joinable == frames) {
249                        proceedToState(state);
250                }
251
252        }
253
254        @Override
255        protected void joinableFinish() {
256                // TODO Auto-generated method stub
257
258        }
259
260        @Override
261        public String toString() {
262                return getName();
263        }
264
265
266        // @Override
267        // public boolean isDone() {
268        //      return frames.isDone() && instances.isDone();
269        // }
270}
Note: See TracBrowser for help on using the repository browser.