View Javadoc

1   package org.catacomb.druid.build;
2   
3   import org.catacomb.druid.market.HookupBoard;
4   import org.catacomb.interlish.structure.InfoReceiver;
5   import org.catacomb.interlish.structure.Marketplace;
6   import org.catacomb.interlish.structure.TargetStore;
7   
8   
9   import java.util.ArrayList;
10  import java.util.HashMap;
11  import java.util.Map;
12  
13  
14  public class GUIStore {
15  
16      DruidTargetStore targetStore;
17      HashMap<String, ArrayList<Object>> withoutIDs;
18      ArrayList<Object> allComponents;
19  
20      InfoReceiver infoReceiver;
21  
22  
23      public GUIStore() {
24          reset();
25      }
26  
27  
28      public void reset() {
29          targetStore = new DruidTargetStore();
30          withoutIDs = new HashMap<String, ArrayList<Object>>();
31          allComponents = new ArrayList<Object>();
32          //   E.info("reset store ");
33      }
34  
35  
36  
37  
38  
39  
40      public void addComponent(Object obj, GUIPath gpath) {
41          if (gpath.isUnique()) {
42              addIDdComponent(obj, gpath.getPath());
43  
44          } else {
45              addAnonymousComponent(obj, gpath.getPath());
46          }
47  
48          allComponents.add(obj);
49      }
50  
51  
52      public HashMap<String, ArrayList<Object>> getAnonymousComponentMap() {
53          return withoutIDs;
54      }
55  
56  
57      public HashMap<String, Object> getIdentifiedComponentMap() {
58          return targetStore.getIdentifiedComponentMap();
59      }
60  
61  
62      public void addIDdComponent(Object obj, String id) {
63  
64          targetStore.addComponent(id, obj);
65      }
66  
67  
68  
69      public void addAnonymousComponent(Object obj, String path) {
70          if (withoutIDs.containsKey(path)) {
71              (withoutIDs.get(path)).add(obj);
72  
73          } else {
74              ArrayList<Object> arl = new ArrayList<Object>();
75              arl.add(obj);
76              withoutIDs.put(path, arl);
77          }
78  
79          /*
80           * E.info("GEN stored " + path); E.info(" " + obj);
81           */
82      }
83  
84  
85  
86      public String getTextDump() {
87          StringBuffer sb = new StringBuffer();
88  
89          sb.append("\n uniquely identified components\n");
90          appendHM(sb, targetStore.getHashMap());
91  
92          sb.append("\n\n");
93          sb.append("generic container components\n");
94          appendHM(sb, withoutIDs);
95          sb.append("\n\n");
96          return sb.toString();
97      }
98  
99  
100     private void appendHM(StringBuffer sb, HashMap<String, ? extends Object> hm) {
101         for (String s : hm.keySet()) {
102             sb.append("   ");
103             sb.append(s);
104             sb.append("\n");
105         }
106     }
107 
108 
109 
110     public TargetStore getTargetStore() {
111         return targetStore;
112     }
113 
114 
115     public ArrayList getComponents() {
116         return allComponents;
117     }
118 
119 
120     public void setHookupBoard(HookupBoard hb) {
121         targetStore.setHookupBoard(hb);
122     }
123 
124 
125     public HookupBoard getHookupBoard() {
126         return targetStore.getHoookupBoard();
127     }
128 
129 
130     public void setInfoReceiver(InfoReceiver ir) {
131         infoReceiver = ir;
132         targetStore.setInfoReceiver(ir);
133 
134     }
135 
136     public InfoReceiver getInfoReceiver() {
137         return infoReceiver;
138     }
139 
140 
141     public void clear() {
142         targetStore.clear();
143     }
144 
145     public HashMap<String, Object> getIdentifiedComponents() {
146         return targetStore.getHashMap();
147     }
148 
149 
150     public ArrayList<Object> getAnonymousComponents() {
151         ArrayList<Object> ret = new ArrayList<Object>();
152 
153         for (Map.Entry<String, ArrayList<Object>> entry : withoutIDs.entrySet()) {
154             ret.addAll(entry.getValue());
155         }
156         return ret;
157     }
158 
159 
160     public Marketplace getMarketplace() {
161         return getHookupBoard();
162     }
163 
164 
165 }