View Javadoc

1   package org.catacomb.druid.build;
2   
3   
4   import org.catacomb.druid.market.HookupBoard;
5   import org.catacomb.interlish.content.ColorSet;
6   import org.catacomb.interlish.structure.Marketplace;
7   import org.catacomb.report.E;
8   
9   import java.awt.Color;
10  import java.util.ArrayList;
11  import java.util.HashMap;
12  
13  
14  
15  public class Context {
16  
17      ColorSet colorSet;
18  
19      HookupBoard hookupBoard;
20      GUIStore guiStore;
21  
22      static InfoAggregator infoAggregator;
23  
24      ArrayList<Object> cache;
25      HashMap<String, ContingencyGroup> contingencyGroups;
26  
27      String sourceLocation;
28  
29      Context parentContext;
30  
31  
32      public Context() {
33          this(null);
34      }
35  
36  
37      public Context(Context pc) {
38          parentContext = pc;
39  
40          if (parentContext != null) {
41              colorSet = parentContext.copyColorSet();
42  
43          } else {
44              colorSet = new ColorSet();
45              colorSet.setGray();
46          }
47  
48          guiStore = new GUIStore();
49          guiStore.setInfoReceiver(getInfoAggregator());
50  
51      }
52  
53  
54      // TODO any case for the aggregator not being static
55      public InfoAggregator getInfoAggregator() {
56  
57          if (infoAggregator == null) {
58              infoAggregator = new InfoAggregator();
59              getMarketplace().global().addProducer("Info", infoAggregator, "info");
60          }
61          return infoAggregator;
62      }
63  
64  
65  
66  
67      public ContingencyGroup getContingencyGroup(String gnm) {
68          if (contingencyGroups == null) {
69              contingencyGroups = new HashMap<String, ContingencyGroup>();
70          }
71  
72          ContingencyGroup ret = null;
73          if (contingencyGroups.containsKey(gnm)) {
74              ret = contingencyGroups.get(gnm);
75          } else {
76              ret = new ContingencyGroup(gnm);
77              contingencyGroups.put(gnm, ret);
78          }
79          return ret;
80      }
81  
82  
83  
84      public Marketplace getMarketplace() {
85          if (hookupBoard == null) {
86  
87              // dont use from parent context, either local or use the global one;
88  
89              hookupBoard = new HookupBoard();
90  
91              guiStore.setHookupBoard(hookupBoard);
92          }
93          return hookupBoard;
94      }
95  
96      public Marketplace getMarketplace(String scope) {
97          Marketplace hub = getMarketplace();
98          if (scope != null) {
99              if (scope.equals("global")) {
100                 hub = hub.global();
101             } else {
102                 E.warning("unrecognized scope value " + scope);
103             }
104         }
105         return hub;
106     }
107 
108     public ColorSet getColorSet() {
109         return colorSet;
110     }
111 
112     public ColorSet copyColorSet() {
113         return colorSet.copy();
114     }
115 
116     public Color getBg() {
117         return colorSet.getBackground();
118     }
119 
120 
121     public Color getFg() {
122         return colorSet.getForeground();
123     }
124 
125 
126     public void addToCache(Object obj) {
127         if (cache == null) {
128             cache = new ArrayList<Object>();
129         }
130         if (cache.contains(obj)) {
131             E.info("cache already got - not adding " + obj);
132             // OK;
133         } else {
134             cache.add(obj);
135         }
136     }
137 
138 
139     public void addComponent(Object obj, GUIPath gpath) {
140         guiStore.addComponent(obj, gpath);
141     }
142 
143 
144     public ArrayList<Object> getCache() {
145         return cache;
146     }
147 
148 
149     /*
150        public void setBackground(Color c) {
151           colorSet.setBackground(c);
152 
153           Color bgColor = colorSet.getBackground();
154           if (bgColor.getRed() == 240 && bgColor.getGreen() == 240) {
155              E.info("got the 240 color...");
156               // (new Exception()).printStackTrace();
157            }
158        }
159 
160 
161 
162        public void setForeground(Color c) {
163           colorSet.setForeground(c);
164        }
165 
166     */
167 
168     public void dumpIDs() {
169         E.info(guiStore.getTextDump());
170     }
171 
172 
173     public GUIStore getGUIStore() {
174         return guiStore;
175     }
176 
177 
178     public Context simpleCopy() {
179         Context ctx = new Context();
180         ctx.setColorSet(colorSet);
181         ctx.setInfoAgregator(getInfoAggregator());
182         return ctx;
183     }
184 
185 
186     public void setColorSet(ColorSet cs) {
187         colorSet = cs;
188 
189         Color bgColor = colorSet.getBackground();
190         if (bgColor.getRed() == 240 && bgColor.getGreen() == 240) {
191             E.info("*** set the 240 color...");
192             // (new Exception()).printStackTrace();
193         }
194     }
195 
196 
197     public void setInfoAgregator(InfoAggregator ia) {
198         infoAggregator = ia;
199     }
200 
201 
202     public void resetStore() {
203         guiStore.reset();
204     }
205 
206 
207     public HashMap<String, Object> getIdentifiedComponents() {
208         return guiStore.getIdentifiedComponentMap();
209     }
210 
211 
212 
213     public ArrayList<Object> getAnonymousComponents() {
214         return guiStore.getAnonymousComponents();
215     }
216 
217 
218     public void setBg(Color color) {
219         colorSet.setBg(color);
220     }
221 
222 
223     public void setSourceLocation(String spkg) {
224         sourceLocation = spkg;
225     }
226 
227 
228     public String getSourceLocation() {
229         return sourceLocation;
230     }
231 
232 
233 
234     /*
235      * public TargetStore getTargetStore() { return guiStore.getTargetStore(); }
236      *
237      * public ArrayList getComponents() { return guiStore.getComponents(); }
238      */
239 }