source: java/main/src/main/java/com/framsticks/gui/Browser.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: 5.0 KB
Line 
1package com.framsticks.gui;
2
3import com.framsticks.core.*;
4import com.framsticks.observers.Endpoint;
5import com.framsticks.observers.Observer;
6import com.framsticks.util.Logging;
7import com.framsticks.util.dispatching.Dispatcher;
8import com.framsticks.util.dispatching.Future;
9
10import org.apache.commons.configuration.Configuration;
11import org.apache.commons.lang.ArrayUtils;
12import org.apache.log4j.Logger;
13
14import javax.swing.*;
15
16import java.awt.Dimension;
17import java.util.ArrayList;
18import java.util.HashSet;
19import java.util.List;
20import java.util.Set;
21
22/**
23 * @author Piotr Sniegowski
24 */
25public class Browser extends Observer implements Dispatcher {
26
27        private static final Logger log = Logger.getLogger(Browser.class.getName());
28
29        protected final Set<Frame> frames = new HashSet<Frame>();
30        protected MainFrame mainFrame;
31        public List<PanelProvider> panelProviders = new ArrayList<PanelProvider>();
32        protected Dimension defaultFrameDimension;
33
34        public void addFrame(Frame frame) {
35                frames.add(frame);
36        }
37
38        public Browser() {
39                JPopupMenu.setDefaultLightWeightPopupEnabled(false);
40                addPanelProvider(new StandardPanelProvider());
41        }
42
43        @Override
44        public void configure(Configuration config) {
45                super.configure(config);
46
47                defaultFrameDimension = new Dimension(config.getInteger("size.width", 1000), config.getInteger("size.height", 500));
48
49                for (String name : config.getStringArray("panel_providers")) {
50                        try {
51                                Class<?> c = Class.forName(name);
52                                if (ArrayUtils.indexOf(c.getInterfaces(), PanelProvider.class) == -1) {
53                                        continue;
54                                }
55                                PanelProvider p = (PanelProvider)c.newInstance();
56                                addPanelProvider(p);
57                        } catch (Exception e) {
58                                log.error("failed to load PanelProvider " + name + ": " + e);
59                        }
60                }
61
62                // for (final String path : config.getStringArray("resolve_paths")) {
63                //      invokeLater()
64                //      autoResolvePath(path, new Future<Path>() {
65                //              @Override
66                //              public void result(Path p, Exception e) {
67                //                      Logging.log(log, "auto resolve path", path, e);
68                //              }
69                //      });
70                // }
71        }
72
73        public void addPanelProvider(PanelProvider panelProvider) {
74                log.debug("added panel provider of type: " + panelProvider.getClass().getCanonicalName());
75                panelProviders.add(panelProvider);
76        }
77
78        public void autoResolvePath(final String path, final Future<Path> future) {
79                final Instance i = endpoints.get("localhost").getInstance();
80                i.invokeLater(new Runnable() {
81                        @Override
82                        public void run() {
83                                i.resolveAndFetch(path, new Future<Path>() {
84                                        @Override
85                                        public void result(final Path p, Exception e) {
86                                                Logging.log(log, "auto resolve path", path, e);
87                                                if (future != null) {
88                                                        future.result(p, e);
89                                                }
90                                                if (e == null) {
91                                                        mainFrame.invokeLater(new Runnable() {
92                                                                @Override
93                                                                public void run() {
94                                                                        mainFrame.goTo(p);
95                                                                }
96                                                        });
97                                                }
98                                        }
99                                });
100                        }
101                });
102        }
103
104        public void clear() {
105                assert isActive();
106                for (Frame f : frames) {
107                        f.clear();
108                }
109        }
110
111        @Override
112        public void run() {
113                super.run();
114
115                assert isActive();
116
117                try {
118                        boolean found = false;
119                        // for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
120                        //      log.info("look and feel available: " + info.getName());
121                        //      if ("Nimbus".equals(info.getName())) {
122                        //              UIManager.setLookAndFeel(info.getClassName());
123                        //              found = true;
124                        //              break;
125                        //      }
126                        // }
127                        if (!found) {
128                                UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
129                        }
130                } catch (Exception ex) {
131                        log.warn("failed loading Look&Feel: ", ex);
132                }
133
134                javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);
135
136                mainFrame = new MainFrame(Browser.this);
137                addFrame(mainFrame);
138
139                for (Frame f : frames) {
140                        f.configure();
141                }
142
143                for (final Endpoint e : getEndpoints().values()) {
144                        e.invokeLater(new Runnable() {
145                                @Override
146                                public void run() {
147                                        final Path p = e.getInstance().getRootPath();
148                                        invokeLater(new Runnable() {
149                                                @Override
150                                                public void run() {
151                                                        mainFrame.addRootPath((BrowserEndpoint) e, p);
152                                                }
153                                        });
154                                }
155                        });
156                }
157
158                for (Frame f : frames) {
159                        f.setVisible(true);
160                }
161
162                // autoResolvePath("/simulator/genepools/groups/0", null);
163                // autoResolvePath("/", null);
164        }
165
166        public void createTreeNodeForChild(final Path path) {
167                assert !isActive();
168                //assert instance.isActive();
169
170
171/*
172                final TreeNode parentTreeNode = (TreeNode) child.getParent().getUserObject();
173                if (parentTreeNode == null) {
174                        Dispatching.invokeDispatch(this, manager, new Runnable() {
175                                @Override
176                                public void run() {
177                                        createTreeNodeForChild(child);
178                                }
179                        });
180                        return;
181                }
182                log.debug(child.getClass().getSimpleName() + " created: " + child);
183
184
185                invokeLater(new Runnable() {
186                        @Override
187                        public void run() {
188                                parentTreeNode.getOrCreateChildTreeNodeFor(child);
189                        }
190                });
191*/
192        }
193
194
195        @Override
196        protected Endpoint createEndpoint() {
197                return new BrowserEndpoint();
198        }
199
200        @Override
201        public Dispatcher createDefaultDispatcher() {
202                return SwingDispatcher.instance;
203        }
204
205        /**
206         * @return the mainFrame
207         */
208        public MainFrame getMainFrame() {
209                return mainFrame;
210        }
211
212}
Note: See TracBrowser for help on using the repository browser.