1 package org.catacomb.druid.gui.base;
2
3
4 import org.catacomb.druid.build.Context;
5 import org.catacomb.druid.build.FlatGUIPath;
6 import org.catacomb.druid.build.PanelFactory;
7 import org.catacomb.druid.build.Realizer;
8 import org.catacomb.interlish.structure.IDd;
9 import org.catacomb.report.E;
10
11
12 import java.util.HashMap;
13
14
15 public class DruKitPanel extends DruPanel implements PanelFactory {
16 private static final long serialVersionUID = 1L;
17
18
19 HashMap<String, Realizer> realizers;
20
21 Context context;
22
23 HashMap<String, PanelPack> singletons;
24
25 public DruKitPanel() {
26 realizers = new HashMap<String, Realizer>();
27 singletons = new HashMap<String, PanelPack>();
28 }
29
30
31 public void addRealizer(Realizer rlz) {
32 if (rlz instanceof IDd) {
33 String sid = ((IDd)rlz).getID();
34 if (sid == null) {
35 E.error("each top level item in a kit panel must have an id");
36 } else {
37 realizers.put(sid, rlz);
38 }
39 } else {
40 E.error("kit panel can only add idd cpts - not " + rlz);
41 }
42 }
43
44
45 public void setRealizationContext(Context ctx) {
46 context = ctx;
47
48 if (getInfoReceiver() == null) {
49
50 } else {
51 E.warning("resetting ir " + getInfoReceiver() + " " + ctx.getInfoAggregator());
52 }
53
54 setInfoReceiver(ctx.getInfoAggregator());
55 }
56
57
58
59 public boolean canMake(String sid) {
60 return (realizers.containsKey(sid));
61 }
62
63
64 public PanelPack newPanelPack(String sid) {
65 PanelPack ret = null;
66 if (realizers.containsKey(sid)) {
67
68 Realizer rlz = realizers.get(sid);
69 context.resetStore();
70 DruPanel drup = (DruPanel)(rlz.realize(context, new FlatGUIPath()));
71
72 ret = new PanelPack(drup,
73 context.getAnonymousComponents(),
74 context.getIdentifiedComponents());
75
76 } else {
77 E.error("no such item in kit " + sid);
78 for (String s : realizers.keySet()) {
79 E.info("known item: " + s);
80 }
81 }
82 return ret;
83 }
84
85 public PanelPack getSingletonPack(String sid) {
86 PanelPack ret = null;
87 if (singletons.containsKey(sid)) {
88 ret = singletons.get(sid);
89 } else {
90 ret = newPanelPack(sid);
91
92 singletons.put(sid, ret);
93 }
94 return ret;
95 }
96
97
98 public DruPanel showPanel(String sid, Object dest) {
99 removeAll();
100 PanelPack ppk = getSingletonPack(sid);
101 ppk.actionConnect(dest);
102 DruPanel dp = ppk.getMainPanel();
103 addPanel(dp);
104 return dp;
105 }
106
107
108 }