[77] | 1 | package com.framsticks.gui; |
---|
| 2 | |
---|
| 3 | import com.framsticks.core.*; |
---|
| 4 | import com.framsticks.observers.Endpoint; |
---|
| 5 | import com.framsticks.observers.Observer; |
---|
| 6 | import com.framsticks.util.Dispatcher; |
---|
| 7 | import org.apache.log4j.Logger; |
---|
| 8 | |
---|
| 9 | import javax.swing.*; |
---|
| 10 | import java.util.HashSet; |
---|
| 11 | import java.util.Set; |
---|
| 12 | |
---|
| 13 | /** |
---|
| 14 | * @author Piotr Sniegowski |
---|
| 15 | */ |
---|
| 16 | public class Browser extends Observer implements Dispatcher { |
---|
| 17 | |
---|
| 18 | private static final Logger LOGGER = Logger.getLogger(Browser.class.getName()); |
---|
| 19 | |
---|
| 20 | protected final Set<Frame> frames = new HashSet<Frame>(); |
---|
| 21 | protected MainFrame mainFrame; |
---|
| 22 | |
---|
| 23 | public void addFrame(Frame frame) { |
---|
| 24 | frames.add(frame); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | public Browser(Parameters parameters) { |
---|
| 28 | super(parameters); |
---|
| 29 | dispatcher = SwingDispatcher.instance; |
---|
| 30 | invokeLater(new Runnable() { |
---|
| 31 | @Override |
---|
| 32 | public void run() { |
---|
| 33 | assert isActive(); |
---|
| 34 | |
---|
| 35 | } |
---|
| 36 | }); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | public void clear() { |
---|
| 40 | assert isActive(); |
---|
| 41 | for (Frame f : frames) { |
---|
| 42 | f.clear(); |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | @Override |
---|
[78] | 47 | protected void configure() throws Exception { |
---|
[77] | 48 | super.configure(); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | @Override |
---|
| 53 | public void run() { |
---|
| 54 | super.run(); |
---|
| 55 | |
---|
| 56 | try { |
---|
| 57 | UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); |
---|
| 58 | } catch (Exception ex) { |
---|
| 59 | LOGGER.warn("failed loading Look&Feel: ", ex); |
---|
| 60 | } |
---|
| 61 | javax.swing.JFrame.setDefaultLookAndFeelDecorated(true); |
---|
| 62 | |
---|
| 63 | mainFrame = new MainFrame(Browser.this); |
---|
| 64 | addFrame(mainFrame); |
---|
| 65 | |
---|
| 66 | for (Frame f : frames) { |
---|
| 67 | f.configure(); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | for (final Endpoint e : getEndpoints().values()) { |
---|
| 71 | e.invokeLater(new Runnable() { |
---|
| 72 | @Override |
---|
| 73 | public void run() { |
---|
| 74 | final Path p = new Path(e.getInstance(), "/"); |
---|
| 75 | invokeLater(new Runnable() { |
---|
| 76 | @Override |
---|
| 77 | public void run() { |
---|
| 78 | mainFrame.addRootPath((BrowserEndpoint) e, p); |
---|
| 79 | } |
---|
| 80 | }); |
---|
| 81 | } |
---|
| 82 | }); |
---|
| 83 | |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | for (Frame f : frames) { |
---|
| 87 | f.setVisible(true); |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | public void createTreeNodeForChild(final Path path) { |
---|
| 92 | assert !isActive(); |
---|
| 93 | //assert instance.isActive(); |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | /* |
---|
| 97 | final TreeNode parentTreeNode = (TreeNode) child.getParent().getUserObject(); |
---|
| 98 | if (parentTreeNode == null) { |
---|
| 99 | Dispatching.invokeDispatch(this, manager, new Runnable() { |
---|
| 100 | @Override |
---|
| 101 | public void run() { |
---|
| 102 | createTreeNodeForChild(child); |
---|
| 103 | } |
---|
| 104 | }); |
---|
| 105 | return; |
---|
| 106 | } |
---|
| 107 | LOGGER.debug(child.getClass().getSimpleName() + " created: " + child); |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | invokeLater(new Runnable() { |
---|
| 111 | @Override |
---|
| 112 | public void run() { |
---|
| 113 | parentTreeNode.getOrCreateChildTreeNodeFor(child); |
---|
| 114 | } |
---|
| 115 | }); |
---|
| 116 | */ |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | @Override |
---|
| 121 | protected Endpoint createEndpoint() { |
---|
| 122 | return new BrowserEndpoint(); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | } |
---|