Changeset 97 for java/main/src/main/java/com/framsticks/gui/Browser.java
- Timestamp:
- 07/06/13 03:51:11 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/gui/Browser.java
r96 r97 2 2 3 3 import com.framsticks.core.*; 4 import com.framsticks.gui.console.Console; 5 import com.framsticks.gui.console.TrackConsole; 4 6 import com.framsticks.params.annotations.AutoAppendAnnotation; 5 7 import com.framsticks.params.annotations.FramsClassAnnotation; 6 8 import com.framsticks.params.annotations.ParamAnnotation; 9 import com.framsticks.remote.RemoteTree; 10 import com.framsticks.util.FramsticksException; 7 11 import com.framsticks.util.dispatching.AbstractJoinable; 8 12 import com.framsticks.util.dispatching.Dispatcher; 9 13 import com.framsticks.util.dispatching.Dispatching; 14 import com.framsticks.util.dispatching.ExceptionResultHandler; 10 15 import com.framsticks.util.dispatching.Future; 16 import com.framsticks.util.dispatching.FutureHandler; 11 17 import com.framsticks.util.dispatching.Joinable; 12 18 import com.framsticks.util.dispatching.JoinableCollection; … … 19 25 20 26 import java.awt.Dimension; 27 import java.awt.Toolkit; 28 import java.awt.datatransfer.StringSelection; 29 import java.awt.event.ActionEvent; 21 30 import java.util.ArrayList; 31 import java.util.LinkedList; 22 32 import java.util.List; 23 33 import com.framsticks.util.dispatching.RunAt; … … 27 37 */ 28 38 @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>(); 39 public class Browser extends AbstractJoinable implements Dispatcher<Browser>, JoinableParent, ExceptionResultHandler { 40 41 private static final Logger log = Logger.getLogger(Browser.class); 42 43 protected final JoinableCollection<Frame> frames = new JoinableCollection<Frame>().setObservableName("frames"); 44 protected final JoinableCollection<Tree> trees = new JoinableCollection<Tree>().setObservableName("trees"); 45 protected final JoinableCollection<Console> consoles = new JoinableCollection<Console>().setObservableName("consoles"); 46 47 protected final List<PopupMenuEntryProvider> popupMenuEntryProviders = new LinkedList<>(); 48 49 protected final MainFrame mainFrame; 50 protected final List<PanelProvider> panelProviders = new ArrayList<PanelProvider>(); 38 51 protected Dimension defaultFrameDimension; 39 52 … … 51 64 mainFrame = new MainFrame(Browser.this); 52 65 addFrame(mainFrame); 66 67 addPopupMenuEntryProvider(new PopupMenuEntryProvider() { 68 @Override 69 public void provide(JPopupMenu menu, Path path) { 70 menu.add(new JMenuItem(path.getFullTextual())); 71 menu.addSeparator(); 72 } 73 }); 74 75 addPopupMenuEntryProvider(new PopupMenuEntryProvider() { 76 @SuppressWarnings("serial") 77 @Override 78 public void provide(JPopupMenu menu, final Path path) { 79 menu.add(new AbstractAction("Copy path to clipboard") { 80 @Override 81 public void actionPerformed(ActionEvent e) { 82 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(path.getFullTextual()), null); 83 } 84 }); 85 } 86 }); 87 88 addPopupMenuEntryProvider(new PopupMenuEntryProvider() { 89 @SuppressWarnings("serial") 90 @Override 91 public void provide(JPopupMenu menu, final Path path) { 92 if (!(path.getTree() instanceof RemoteTree)) { 93 return; 94 } 95 final RemoteTree remoteTree = (RemoteTree) path.getTree(); 96 menu.add(new AbstractAction("Open tracking console") { 97 @Override 98 public void actionPerformed(ActionEvent e) { 99 consoles.add(new TrackConsole().setConnection(remoteTree.getConnection())); 100 } 101 }); 102 } 103 }); 104 // addNodeActionToTreePopupMenu("", new NodeAction() ) 105 53 106 } 54 107 … … 60 113 61 114 @AutoAppendAnnotation 62 public void addInstance(Instance instance) { 63 log.info("adding instance: " + instance); 64 instances.add(instance); 115 public void addPopupMenuEntryProvider(PopupMenuEntryProvider popupMenuEntryProvider) { 116 popupMenuEntryProviders.add(popupMenuEntryProvider); 117 } 118 119 @AutoAppendAnnotation 120 public void addTree(Tree tree) { 121 log.info("adding tree: " + tree); 122 trees.add(tree); 65 123 } 66 124 67 125 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 p ublic void run() {72 InstanceUtils.resolveAndFetch(i, path, new Future<Path>(future) {126 final Tree i = trees.get("localhost"); 127 i.dispatch(new RunAt<Tree>(future) { 128 @Override 129 protected void runAt() { 130 TreeOperations.resolveAndGet(i, path, new FutureHandler<Path>(future) { 73 131 @Override 74 132 protected void result(final Path p) { 75 133 future.pass(p); 76 mainFrame.dispatch(new RunAt<Frame>( ) {134 mainFrame.dispatch(new RunAt<Frame>(future) { 77 135 @Override 78 p ublic void run() {136 protected void runAt() { 79 137 mainFrame.goTo(p); 80 138 } … … 93 151 } 94 152 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 @Override126 public void run() {127 final Path p = Path.to(i, "/");128 dispatch(new RunAt<Browser>() {129 @Override130 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 153 public void createTreeNodeForChild(final Path path) { 147 154 assert !isActive(); 148 //assert instance.isActive();155 //assert tree.isActive(); 149 156 150 157 /* … … 174 181 protected void joinableStart() { 175 182 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; 183 Dispatching.use(trees, this); 184 Dispatching.use(consoles, this); 185 186 dispatch(new RunAt<Browser>(this) { 187 @Override 188 protected void runAt() { 189 190 for (final Tree i : trees) { 191 i.dispatch(new RunAt<Tree>(this) { 192 @Override 193 protected void runAt() { 194 final Path p = Path.to(i, "/"); 195 dispatch(new RunAt<Browser>(this) { 196 @Override 197 protected void runAt() { 198 mainFrame.addRootPath(p); 199 } 200 }); 201 } 202 }); 203 } 204 } 205 }); 206 } 207 208 /** 209 * @return the tree 210 */ 211 public JoinableCollection<Tree> getTrees() { 212 return trees; 191 213 } 192 214 … … 227 249 protected void joinableJoin() throws InterruptedException { 228 250 Dispatching.join(frames); 229 Dispatching.join(instances); 251 Dispatching.join(trees); 252 Dispatching.join(consoles); 230 253 // super.join(); 231 254 } … … 233 256 @Override 234 257 protected void joinableInterrupt() { 258 Dispatching.drop(consoles, this); 235 259 Dispatching.drop(frames, this); 236 Dispatching.drop( instances, this);260 Dispatching.drop(trees, this); 237 261 } 238 262 … … 255 279 } 256 280 281 @Override 282 public void handle(FramsticksException exception) { 283 mainFrame.handle(exception); 284 } 257 285 258 286 // @Override 259 287 // public boolean isDone() { 260 // return frames.isDone() && instances.isDone();288 // return frames.isDone() && trees.isDone(); 261 289 // } 262 290 }
Note: See TracChangeset
for help on using the changeset viewer.