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