1 package org.catacomb.druid.gui.base;
2
3
4 import org.catacomb.interlish.content.StringValue;
5 import org.catacomb.interlish.structure.*;
6 import org.catacomb.report.E;
7
8
9 import java.util.ArrayList;
10 import java.util.HashMap;
11
12
13 public class PanelPack {
14
15 DruPanel mainPanel;
16
17 HashMap<String, Object> components;
18
19 ArrayList<Object> anonCpts;
20
21
22 public PanelPack(DruPanel dp, ArrayList<Object> anons, HashMap<String, Object> hm) {
23 mainPanel = dp;
24 anonCpts = anons;
25 components = hm;
26 }
27
28
29 public DruPanel getMainPanel() {
30 return mainPanel;
31 }
32
33
34 public boolean hasComponent(String sid) {
35 return components.containsKey(sid);
36 }
37
38
39 public Object getComponent(String sid) {
40 Object ret = null;
41 if (components.containsKey(sid)) {
42 ret = components.get(sid);
43 } else {
44 E.error("no such component in panel pack " + sid);
45 for (String s : components.keySet()) {
46 E.info("known cpt " + s);
47 }
48 }
49 return ret;
50 }
51
52
53 public void setText(String cpt, String txt) {
54 if (hasComponent(cpt)) {
55 Object obj = getComponent(cpt);
56 if (obj instanceof TextSettable) {
57 ((TextSettable)obj).setText(txt);
58 } else {
59 E.error("cant set text in " + obj);
60 }
61
62 } else {
63 E.error("no such cpt in panel pack " + cpt);
64 reportComponents();
65 }
66 }
67
68
69
70
71 public void actionConnect(Object tgt) {
72 DruActionRelay dar = new DruActionRelay(tgt);
73 for (Object obj : anonCpts) {
74 connectRelay(dar, obj);
75 }
76
77 for (Object obj : components.values()) {
78 connectRelay(dar, obj);
79 }
80
81 }
82
83
84 private void connectRelay(DruActionRelay dar, Object obj) {
85 if (obj instanceof ActionSource) {
86 ((ActionSource)obj).setActionRelay(dar);
87 }
88 }
89
90
91 public void reportComponents() {
92 int icpt = 0;
93 for (String s : components.keySet()) {
94 E.info("known cpt " + icpt + " " + s);
95 icpt += 1;
96 }
97 }
98
99
100 public void setStringValue(String cpt, StringValue sv) {
101 if (hasComponent(cpt)) {
102 Object obj = getComponent(cpt);
103 if (obj instanceof StringValueEditor) {
104 ((StringValueEditor)obj).setStringValue(sv);
105 } else {
106 E.error("cant set text in " + obj);
107 }
108
109 } else {
110 E.error("no such cpt in panel pack " + cpt);
111 reportComponents();
112 }
113
114 }
115
116 }