source: java/main/src/main/java/com/framsticks/gui/Browser.java @ 98

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

HIGHLIGHTS:

CHANGELOG:
Get data also on tree expansion.

Use nice framstick icon for empty nodes.

Update panel after reload if it is current.

Add shallow reload procedure.

Cut Gui prefix from several tree classes.

Bring back counter of GuiTreeNode?.

Use IdentityHashMap? were it is more appriopriate.

Remove TreeListener?.

Do not use TreeListener? in GUI.

Minor change.

Done migration to GuiTreeModel?.

BrowserTest? in that version always crashes frams.linux.

Move rendering implementation into GuiAbstractNode?.

Use hand-crafted list in GuiTreeNode?.

Generally, it would be a great place for WeakIdentityHashMap?
(but there is none in Java Collection Framework).

Remove superfluous logging.

Fix bug in GuiTreeNode?.

Use IdentityHashMap? instead of HashMap?.

Improve structure update.

Filter out invalid uids in UniqueListAccess?.

Improve TreeCellRenderer?.

Add filtering in TrackConsole?.

Improve TreeModel?.

More changes.

More improvements.

More changes.

Remove TreeNode?.

Support MetaNode? in the GuiTreeModel?.

Implement more in GuiTreeModel?.

Add CompositeParam? interface to FramsClass? and AccessInterface?.

Allow access by number to UniqueList?.

Add UidComparator?.

Use TreeMap? as a default accessee in unique list.

It keeps order of keys.

Introduce classes to use with new TreeModel?.

Another step.

Migrate from TreeNode? to Node in many places.

Remove some uses of TreeNode? as DefaultMutableTreeNode?.

Remove Path from TreeNode? interface.

Remove Path from TreeNode?.

Add Path recration from node feature.

Reworking TreeCellRenderer?.

Minor change of TreeOperations? interface.

Remove last methods from TreeNode?.

Another minor step.

Do not store reference to TreeAtFrame? in TreeNode?.

Add proxy exceptionHandler to StatusBar?.

Move panels management to TreeAtFrame?.

Store localChanges in the NodeAtFrame?.

More cleanup.

Move name computing to TreeCellRenderer?.

Move tooltip and icon computations to TreeCellRenderer?.

More dispatches removed.

Remove most dispatching from TreeNode?.

TreeNode? does not actually redispatch tasks.

Make Tree embedded in Browser use SwingDispatcher?.

Make lazy binding of Tree with Dispatcher.

Minor changes.

Organizational change in AbstractTree?.

Make AbstractTree? compose from Thread instead of inherit from it.

Make SwingDispatcher? and AtOnceDispatcher? Joinable compatible.

Add ListPanelProvider?.

Improve Controls readonly and enabled handling.

Properly pass ExceptionHandlers? in more places.

Make Tree.get accept ValueParam?.

  • This is to allow access number of list elements.

Remove not needed get redirection in ClientAtServer?.

Rename tryResolve to tryGet.

Unify tryResolveAndGet into tryResolve.

Remove resolveTop from Tree interface.

Make Tree.get accept Future<Path>.

Use get to implement resolveTop also in ObjectTree?.

Unify resolveTop and get in RemoteTree?.

Another minor step.

More minor changes in tree operations.

Minor organizational changes.

In RemoteTree? first fetch info for root.

Reworking resolving.

Minor changes.

Make ListAccess? return proxy iterators (instead of creating temporary collection).

Let AccessInterface? return Iterable<Param>.

Improve resolving.

More improvements.

First working completion in ManagedConsole?.

Rename resolve to resolveTop.

This reflects the actuall functionality.

Change semantic of tryResolve and tryResolveAndGet.

File size: 7.9 KB
Line 
1package com.framsticks.gui;
2
3import com.framsticks.core.*;
4import com.framsticks.gui.console.Console;
5import com.framsticks.gui.console.TrackConsole;
6import com.framsticks.params.annotations.AutoAppendAnnotation;
7import com.framsticks.params.annotations.FramsClassAnnotation;
8import com.framsticks.params.annotations.ParamAnnotation;
9import com.framsticks.remote.RemoteTree;
10import com.framsticks.util.FramsticksException;
11import com.framsticks.util.dispatching.AbstractJoinable;
12import com.framsticks.util.dispatching.Dispatcher;
13import com.framsticks.util.dispatching.Dispatching;
14import com.framsticks.util.dispatching.ExceptionResultHandler;
15import com.framsticks.util.dispatching.Future;
16import com.framsticks.util.dispatching.Joinable;
17import com.framsticks.util.dispatching.JoinableCollection;
18import com.framsticks.util.dispatching.JoinableParent;
19import com.framsticks.util.dispatching.JoinableState;
20
21import javax.swing.*;
22
23import org.apache.log4j.Logger;
24
25import java.awt.Dimension;
26import java.awt.Toolkit;
27import java.awt.datatransfer.StringSelection;
28import java.awt.event.ActionEvent;
29import java.util.ArrayList;
30import java.util.LinkedList;
31import java.util.List;
32import com.framsticks.util.dispatching.RunAt;
33
34/**
35 * @author Piotr Sniegowski
36 */
37@FramsClassAnnotation
38public class Browser extends AbstractJoinable implements Dispatcher<Browser>, JoinableParent, ExceptionResultHandler {
39
40        private static final Logger log = Logger.getLogger(Browser.class);
41
42        protected final JoinableCollection<Frame> frames = new JoinableCollection<Frame>().setObservableName("frames");
43        protected final JoinableCollection<Tree> trees = new JoinableCollection<Tree>().setObservableName("trees");
44        protected final JoinableCollection<Console> consoles = new JoinableCollection<Console>().setObservableName("consoles");
45
46        protected final List<PopupMenuEntryProvider> popupMenuEntryProviders = new LinkedList<>();
47        // protected final SwingDispatcher
48
49        protected final MainFrame mainFrame;
50        protected final List<PanelProvider> panelProviders = new ArrayList<PanelProvider>();
51        protected Dimension defaultFrameDimension;
52
53        String name;
54
55        public void addFrame(Frame frame) {
56                frames.add(frame);
57        }
58
59        public Browser() {
60                setName("browser");
61                JPopupMenu.setDefaultLightWeightPopupEnabled(false);
62                addPanelProvider(new StandardPanelProvider());
63
64                mainFrame = new MainFrame(Browser.this);
65
66                // mainFrame.getStatusBar().setExceptionHandler(ThrowExceptionHandler.getInstance());
67
68                addFrame(mainFrame);
69
70                addPopupMenuEntryProvider(new PopupMenuEntryProvider() {
71                        @Override
72                        public void provide(JPopupMenu menu, Path path) {
73                                menu.add(new JMenuItem(path.getFullTextual()));
74                                menu.addSeparator();
75                        }
76                });
77
78                addPopupMenuEntryProvider(new PopupMenuEntryProvider() {
79                        @SuppressWarnings("serial")
80                        @Override
81                        public void provide(JPopupMenu menu, final Path path) {
82                                menu.add(new AbstractAction("Copy path to clipboard") {
83                                        @Override
84                                        public void actionPerformed(ActionEvent e) {
85                                                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(path.getFullTextual()), null);
86                                        }
87                                });
88                        }
89                });
90
91                addPopupMenuEntryProvider(new PopupMenuEntryProvider() {
92                        @SuppressWarnings("serial")
93                        @Override
94                        public void provide(JPopupMenu menu, final Path path) {
95                                if (!(path.getTree() instanceof RemoteTree)) {
96                                        return;
97                                }
98                                final RemoteTree remoteTree = (RemoteTree) path.getTree();
99                                menu.add(new AbstractAction("Open tracking console") {
100                                        @Override
101                                        public void actionPerformed(ActionEvent e) {
102                                                consoles.add(new TrackConsole().setConnection(remoteTree.getConnection()));
103                                        }
104                                });
105                        }
106                });
107                // addNodeActionToTreePopupMenu("", new NodeAction() )
108
109        }
110
111        @AutoAppendAnnotation
112        public void addPanelProvider(PanelProvider panelProvider) {
113                log.debug("added panel provider of type: " + panelProvider.getClass().getCanonicalName());
114                panelProviders.add(panelProvider);
115        }
116
117        @AutoAppendAnnotation
118        public void addPopupMenuEntryProvider(PopupMenuEntryProvider popupMenuEntryProvider) {
119                popupMenuEntryProviders.add(popupMenuEntryProvider);
120        }
121
122        @AutoAppendAnnotation
123        public void addTree(Tree tree) {
124                log.info("adding tree: " + tree);
125                tree.setDispatcher(new SwingDispatcher<Tree>());
126                trees.add(tree);
127        }
128
129        public void autoResolvePath(final String path, final Future<Path> future) {
130                // final Tree i = trees.get("localhost");
131                // i.dispatch(new RunAt<Tree>(future) {
132                //      @Override
133                //      protected void runAt() {
134                //              TreeOperations.tryGet(i, path, new FutureHandler<Path>(future) {
135                //                      @Override
136                //                      protected void result(final Path p) {
137                //                              future.pass(p);
138                //                              mainFrame.dispatch(new RunAt<Frame>(future) {
139                //                                      @Override
140                //                                      protected void runAt() {
141                //                                              mainFrame.goTo(p);
142                //                                      }
143                //                              });
144                //                      }
145                //              });
146                //      }
147                // });
148        }
149
150        public void clear() {
151                assert isActive();
152                for (Frame f : frames) {
153                        f.clear();
154                }
155        }
156
157        public void createTreeNodeForChild(final Path path) {
158                assert !isActive();
159                //assert tree.isActive();
160
161                /*
162                 final TreeNode parentTreeNode = (TreeNode) child.getParent().getUserObject();
163                 if (parentTreeNode == null) {
164                 Dispatching.invokeDispatch(this, manager, new Runnable() {
165                 @Override
166                 public void run() {
167                 createTreeNodeForChild(child);
168                 }
169                 });
170                 return;
171                 }
172                 log.debug(child.getClass().getSimpleName() + " created: " + child);
173
174
175                 invokeLater(new Runnable() {
176                 @Override
177                 public void run() {
178                 parentTreeNode.getOrCreateChildTreeNodeFor(child);
179                 }
180                 });
181                 */
182        }
183
184        @Override
185        protected void joinableStart() {
186                Dispatching.use(frames, this);
187                Dispatching.use(trees, this);
188                Dispatching.use(consoles, this);
189
190                dispatch(new RunAt<Browser>(this) {
191                        @Override
192                        protected void runAt() {
193
194                                for (final Tree i : trees) {
195                                        i.dispatch(new RunAt<Tree>(this) {
196                                                @Override
197                                                protected void runAt() {
198                                                        final Path p = Path.to(i, "/");
199                                                        dispatch(new RunAt<Browser>(this) {
200                                                                @Override
201                                                                protected void runAt() {
202                                                                        mainFrame.addRootPath(p);
203                                                                }
204                                                        });
205                                                }
206                                        });
207                                }
208                        }
209                });
210        }
211
212        /**
213         * @return the tree
214         */
215        public JoinableCollection<Tree> getTrees() {
216                return trees;
217        }
218
219        /**
220         * @return the mainFrame
221         */
222        public MainFrame getMainFrame() {
223                return mainFrame;
224        }
225
226        /**
227         * @return the name
228         */
229        @ParamAnnotation
230        public String getName() {
231                return name;
232        }
233
234        /**
235         * @param name the name to set
236         */
237        @ParamAnnotation
238        public void setName(String name) {
239                this.name = name;
240        }
241
242        @Override
243        public boolean isActive() {
244                return SwingDispatcher.getInstance().isActive();
245        }
246
247        @Override
248        public void dispatch(RunAt<? extends Browser> runnable) {
249                SwingDispatcher.getInstance().dispatch(runnable);
250        }
251
252        @Override
253        protected void joinableJoin() throws InterruptedException {
254                Dispatching.join(frames);
255                Dispatching.join(trees);
256                Dispatching.join(consoles);
257                // super.join();
258        }
259
260        @Override
261        protected void joinableInterrupt() {
262                Dispatching.drop(consoles, this);
263                Dispatching.drop(frames, this);
264                Dispatching.drop(trees, this);
265        }
266
267        @Override
268        public void childChangedState(Joinable joinable, JoinableState state) {
269                if (joinable == frames) {
270                        proceedToState(state);
271                }
272
273        }
274
275        @Override
276        protected void joinableFinish() {
277
278        }
279
280        @Override
281        public String toString() {
282                return getName();
283        }
284
285        @Override
286        public void handle(FramsticksException exception) {
287                mainFrame.handle(exception);
288        }
289
290        // final protected Map<EventParam, Subscription<?>> userSubscriptions = new HashMap<>();
291        // public boolean hasSubscribed(EventParam param) {
292        //      assert frame.isActive();
293        //      return userSubscriptions.containsKey(param);
294        // }
295
296        // public void unsubscribe(EventParam eventParam) {
297        //      assert frame.isActive();
298        //      if (!hasSubscribed(eventParam)) {
299        //              log.error("could not unsubscribe from " + eventParam);
300        //              return;
301        //      }
302        //      userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback(log, "unsubscribed " + eventParam));
303        //      userSubscriptions.remove(eventParam);
304        // }
305
306
307
308
309}
Note: See TracBrowser for help on using the repository browser.