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