- Timestamp:
- 06/22/13 21:51:33 (11 years ago)
- Location:
- java/main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main
-
Property
svn:ignore
set to
target
-
Property
svn:ignore
set to
-
java/main/src/main/java/com/framsticks/gui/EndpointAtFrame.java
r77 r84 1 1 package com.framsticks.gui; 2 2 3 import java.util.HashMap; 4 import java.util.Map; 3 import org.apache.log4j.Logger; 4 5 import com.framsticks.core.Instance; 6 import com.framsticks.core.InstanceListener; 7 import com.framsticks.core.ListChange; 8 import com.framsticks.core.Node; 9 import com.framsticks.core.Path; 10 import com.framsticks.params.CompositeParam; 11 import com.framsticks.params.FramsClass; 12 13 import java.util.*; 14 15 import javax.swing.tree.TreePath; 5 16 6 17 /** 7 18 * @author Piotr Sniegowski 8 19 */ 9 public class EndpointAtFrame { 10 protected final BrowserEndpoint endpoint; 11 protected final Frame frame; 12 protected final Map<String, Panel> knownPanels = new HashMap<String, Panel>(); 20 public class EndpointAtFrame implements InstanceListener { 13 21 14 public EndpointAtFrame(BrowserEndpoint endpoint, Frame frame) { 15 this.endpoint = endpoint; 16 this.frame = frame; 17 } 22 private static final Logger log = Logger.getLogger(EndpointAtFrame.class); 18 23 24 protected final BrowserEndpoint endpoint; 25 protected final Frame frame; 26 protected final Instance instance; 27 protected final Map<String, Panel> knownPanels = new HashMap<String, Panel>(); 28 protected TreeNode rootTreeNode; 19 29 20 public BrowserEndpoint getEndpoint() { 21 return endpoint; 22 } 30 public EndpointAtFrame(BrowserEndpoint endpoint, Frame frame) { 31 this.endpoint = endpoint; 32 this.frame = frame; 33 this.instance = endpoint.getInstance(); 34 } 23 35 24 public Frame getFrame() {25 return frame;26 36 public BrowserEndpoint getEndpoint() { 37 return endpoint; 38 } 27 39 28 public void registerPanel(Panel panel) { 29 assert frame.isActive(); 30 knownPanels.put(panel.getClassName(), panel); 31 frame.cardPanel.add(panel, panel.getFullName()); 32 } 40 public Frame getFrame() { 41 return frame; 42 } 33 43 34 public Panel findPanel(String className) { 35 assert frame.isActive(); 36 return (knownPanels.containsKey(className) ? knownPanels.get(className) : null); 37 } 44 public void registerPanel(Panel panel) { 45 } 38 46 39 public final String getName() { 40 return endpoint.getName(); 41 } 47 public Panel findPanel(String accessId) { 48 assert frame.isActive(); 49 return (knownPanels.containsKey(accessId) ? knownPanels.get(accessId) : null); 50 } 51 52 public final String getName() { 53 return endpoint.getName(); 54 } 55 56 public Panel preparePanel(CompositeParam param, FramsClass framsClass) { 57 assert frame.isActive(); 58 Panel panel = preparePanelImpl(param, framsClass); 59 assert panel != null; 60 String accessId = param.computeAccessId(); 61 panel.uniqueName = accessId + "@" + endpoint.getName(); 62 knownPanels.put(accessId, panel); 63 frame.cardPanel.add(panel, panel.uniqueName); 64 log.debug("prepared panel for " + panel); 65 return panel; 66 } 67 68 protected Panel preparePanelImpl(CompositeParam param, FramsClass framsClass) { 69 assert frame.isActive(); 70 List<Panel> panels = new ArrayList<Panel>(); 71 72 Panel.Parameters parameters = new Panel.Parameters(this, param, 73 framsClass); 74 for (PanelProvider pp : frame.browser.panelProviders) { 75 Panel p = pp.providePanel(parameters); 76 if (p != null) { 77 panels.add(p); 78 } 79 } 80 81 if (panels.isEmpty()) { 82 return new EmptyPanel(parameters); 83 } 84 if (panels.size() == 1) { 85 return panels.get(0); 86 } 87 return new MultiPanel(parameters, panels); 88 89 } 90 91 @Override 92 public void onListChange(Path path, ListChange change) { 93 94 } 95 96 public TreePath getTreePath(Path path, boolean create) { 97 assert frame.isActive(); 98 TreeNode t = rootTreeNode; 99 TreePath result = new TreePath(frame.rootNode).pathByAddingChild(rootTreeNode); 100 List<Node> nodes = path.getNodes(); 101 Iterator<Node> i = nodes.iterator(); 102 i.next(); 103 // Node first = i.next(); 104 105 // if (!t.path.isResolved()) { 106 // t.path = new Path(path.getInstance(), nodes, first); 107 // } 108 while (i.hasNext()) { 109 Node n = i.next(); 110 TreeNode r = null; 111 for (TreeNode c : t.childrenIterable()) { 112 if (c.paramId.equals(n.getParam().getId())) { 113 r = c; 114 break; 115 } 116 } 117 if (r == null) { 118 log.debug("missing " + n.getParam().getId() + " in " + t); 119 if (!create) { 120 return result; 121 } 122 Path p = new Path(path.getInstance(), nodes, n); 123 log.debug("forced resolution: creating treenode for " + p); 124 TreeNode childNode = new TreeNode(EndpointAtFrame.this, p); 125 126 frame.addNode(childNode, t); 127 // frame.treeModel.reload(); 128 // t.add(childNode); 129 // frame.treeModel.nodeStructureChanged(t); 130 131 r = childNode; 132 } else { 133 // if (!r.path.isResolved()) { 134 // r.path = new Path(path.getInstance(), nodes, n); 135 // } 136 } 137 result = result.pathByAddingChild(r); 138 t = r; 139 } 140 return result; 141 } 142 143 @Override 144 public void onFetch(final Path path) { 145 assert instance.isActive(); 146 log.trace("fetched " + path); 147 148 frame.invokeLater(new Runnable() { 149 @Override 150 public void run() { 151 152 TreePath treePath = getTreePath(path, true); 153 assert treePath.getPathCount() == path.size() + 1; 154 155 final TreeNode result = (TreeNode) treePath.getLastPathComponent(); 156 // log.trace("found " + result + " == " + path); 157 instance.invokeLater(new Runnable() { 158 @Override 159 public void run() { 160 result.reactForFetchResult(path, null); 161 } 162 }); 163 } 164 }); 165 } 166 167 @Override 168 public void onRun(Exception e) { 169 170 } 171 172 @Override 173 public void onStop(Exception e) { 174 175 } 42 176 }
Note: See TracChangeset
for help on using the changeset viewer.