1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 
14 
15 
16 #include <ctype.h>
17 
18 #include "DXStrings.h"
19 #include "InteractorInstance.h"
20 #include "InteractorStyle.h"
21 #include "Dictionary.h"
22 #include "DictionaryIterator.h"
23 #include "Interactor.h"
24 #include "StepperInteractor.h"
25 #include "DialInteractor.h"
26 #include "SliderInteractor.h"
27 #include "ValueInteractor.h"
28 #include "ValueListInteractor.h"
29 #include "ScalarListInteractor.h"
30 #include "SelectorInteractor.h"
31 #include "FileSelectorInteractor.h"
32 #include "SelectorRadioInteractor.h"
33 //#include "SelectorPulldownInteractor.h"
34 #include "SelectorListInteractor.h"
35 #include "ToggleToggleInteractor.h"
36 #include "SelectorListToggleInteractor.h"
37 #include "ErrorDialogManager.h"
38 
39 
40 static Dictionary *theInteractorStyleDictionary =  NULL;
41 
42 
BuildtheInteractorStyleDictionary()43 void BuildtheInteractorStyleDictionary()
44 {
45    theInteractorStyleDictionary = new Dictionary;
46 
47    //
48    // Supported styles for Integer, Scalar and vector interactors.
49    //
50    InteractorStyle::AddSupportedStyle("Integer", StepperStyle,  "Stepper",
51 			       "StepperInteractor",
52 				StepperInteractor::AllocateInteractor);
53    InteractorStyle::AddSupportedStyle("Integer", DialStyle,  "Dial",
54                                 DialInteractor::AllocateInteractor);
55    InteractorStyle::AddSupportedStyle("Integer", SliderStyle,  "Slider",
56                                 SliderInteractor::AllocateInteractor);
57    InteractorStyle::AddSupportedStyle("Integer", TextStyle,  "Text", "ScalarInteractor",
58                                 ValueInteractor::AllocateInteractor);
59 
60    InteractorStyle::AddSupportedStyle("Scalar",  StepperStyle, "Stepper",
61 			       "StepperInteractor",
62 				StepperInteractor::AllocateInteractor);
63    InteractorStyle::AddSupportedStyle("Scalar", DialStyle,  "Dial",
64                                 DialInteractor::AllocateInteractor);
65    InteractorStyle::AddSupportedStyle("Scalar", SliderStyle,  "Slider",
66                                 SliderInteractor::AllocateInteractor);
67    InteractorStyle::AddSupportedStyle("Scalar", TextStyle,  "Text", "ScalarInteractor",
68                                 ValueInteractor::AllocateInteractor);
69 
70    InteractorStyle::AddSupportedStyle("Vector",  StepperStyle, "Stepper",
71 				"StepperInteractor",
72 				StepperInteractor::AllocateInteractor);
73    InteractorStyle::AddSupportedStyle("Vector",  TextStyle, "Text",  "Interactor",
74 				ValueInteractor::AllocateInteractor);
75 
76 
77    //
78    // Supported styles for list interactors.
79    //
80    InteractorStyle::AddSupportedStyle("ScalarList",
81 			ScalarListEditorStyle, "List Editor",
82 			ScalarListInteractor::AllocateInteractor);
83    InteractorStyle::AddSupportedStyle("ScalarList",
84 			TextStyle, "Text", "Interactor",
85 			ValueInteractor::AllocateInteractor);
86 
87    InteractorStyle::AddSupportedStyle("IntegerList",
88 			IntegerListEditorStyle, "List Editor",
89 			ScalarListInteractor::AllocateInteractor);
90    InteractorStyle::AddSupportedStyle("IntegerList",
91 			TextStyle, "Text", "Interactor",
92 			ValueInteractor::AllocateInteractor);
93 
94    InteractorStyle::AddSupportedStyle("VectorList",
95 			VectorListEditorStyle, "List Editor",
96 			ScalarListInteractor::AllocateInteractor);
97    InteractorStyle::AddSupportedStyle("VectorList",
98 			TextStyle, "Text", "Interactor",
99 			ValueInteractor::AllocateInteractor);
100 
101    InteractorStyle::AddSupportedStyle("Value",
102 			TextStyle,   "Text",    "Interactor",
103 			ValueInteractor::AllocateInteractor);
104    InteractorStyle::AddSupportedStyle("String",
105 			TextStyle,   "Text", "StringInteractor",
106 			ValueInteractor::AllocateInteractor);
107 
108    InteractorStyle::AddSupportedStyle("ValueList",
109 			TextListEditorStyle, "List Editor",
110 			ValueListInteractor::AllocateInteractor);
111    InteractorStyle::AddSupportedStyle("ValueList",
112 			TextStyle, "Text", "Interactor",
113 			ValueInteractor::AllocateInteractor);
114 
115    InteractorStyle::AddSupportedStyle("StringList",
116 			TextListEditorStyle, "List Editor",
117 			ValueListInteractor::AllocateInteractor);
118    InteractorStyle::AddSupportedStyle("StringList",
119 			TextStyle, "Text", "Interactor",
120 			ValueInteractor::AllocateInteractor);
121 
122 
123    //
124    // Supported styles for Selector interactors
125    //
126    InteractorStyle::AddSupportedStyle("Selector",
127 			SelectorOptionMenuStyle,  "Option Menu", "Selector",
128 			SelectorInteractor::AllocateInteractor);
129    InteractorStyle::AddSupportedStyle("Selector",
130 			SelectorRadioStyle,  "Radio Button", "RadioGroup",
131 			SelectorRadioInteractor::AllocateInteractor);
132 // This interactor solves a problem that users have with data-driven
133 // Option Menu selectors.  That is that the menu can become too big
134 // very easily.  Nonetheless, I'm not adding support for this new
135 // interactor because this problem can be solved by switching from
136 // Option Menu to Scrolled List. I'm just not happy with having so
137 // much overlap in functionality.
138 //   InteractorStyle::AddSupportedStyle("Selector",
139 //			SelectorPulldownStyle,  "Pulldown Menu",
140 //			SelectorPulldownInteractor::AllocateInteractor);
141    InteractorStyle::AddSupportedStyle("Selector",
142 			SelectorListStyle,  "Scrolled List", "ListSelector",
143 			SelectorListInteractor::AllocateInteractor);
144 
145    //
146    // Supported styles for other interactors
147    //
148    InteractorStyle::AddSupportedStyle("FileSelector",FileSelectorStyle,
149 			"FileSelector",
150 			FileSelectorInteractor::AllocateInteractor);
151    InteractorStyle::AddSupportedStyle("Toggle",ToggleToggleStyle,
152 			"Toggle", "Toggle",
153 			ToggleToggleInteractor::AllocateInteractor);
154    InteractorStyle::AddSupportedStyle("Reset",ToggleToggleStyle,
155 			"Toggle", "Toggle",
156 			ToggleToggleInteractor::AllocateInteractor);
157    InteractorStyle::AddSupportedStyle("SelectorList",SelectorListToggleStyle,
158 			"Button List", "ToggleGroup",
159 			SelectorListToggleInteractor::AllocateInteractor);
160    InteractorStyle::AddSupportedStyle("SelectorList",SelectorListStyle,
161 			"Scrolled List", "ListSelector",
162 			SelectorListInteractor::AllocateInteractor);
163 
164    //
165    // AT LAST, set the Default Style for each interactor.
166    //
167    InteractorStyle::SetDefaultStyle("Integer", StepperStyle);
168    InteractorStyle::SetDefaultStyle("Scalar", StepperStyle);
169    InteractorStyle::SetDefaultStyle("Vector", StepperStyle);
170    InteractorStyle::SetDefaultStyle("IntegerList", TextListEditorStyle);
171    InteractorStyle::SetDefaultStyle("ScalarList", TextListEditorStyle);
172    InteractorStyle::SetDefaultStyle("VectorList", TextListEditorStyle);
173    InteractorStyle::SetDefaultStyle("ValueList", TextListEditorStyle);
174    InteractorStyle::SetDefaultStyle("StringList", TextListEditorStyle);
175    InteractorStyle::SetDefaultStyle("Selector", SelectorOptionMenuStyle);
176    InteractorStyle::SetDefaultStyle("FileSelector", FileSelectorStyle);
177 
178 }
InteractorStyle(InteractorStyleEnum s,const char * n,const char * javaStyle,InteractorAllocator ia)179 InteractorStyle::InteractorStyle(InteractorStyleEnum s, const char *n,
180 		const char* javaStyle, InteractorAllocator ia)
181 {
182     this->style = s;
183     this->name = theSymbolManager->registerSymbol(n);
184     this->allocateInteractor = ia;
185     this->isDefault = FALSE;
186     this->interactorName = NULL;
187     if (javaStyle)
188 	this->javaStyle = DuplicateString(javaStyle);
189     else
190 	this->javaStyle = NUL(char*);
191 }
~InteractorStyle()192 InteractorStyle::~InteractorStyle()
193 {
194     if (this->interactorName)
195 	delete this->interactorName;
196     if (this->javaStyle)
197 	delete this->javaStyle;
198 }
199 
200 //
201 // Return the list of InteractorStyles for the give interactor (node name).
202 //
GetInteractorStyleDictionary(const char * interactor)203 Dictionary *InteractorStyle::GetInteractorStyleDictionary(
204 					const char* interactor)
205 {
206    ASSERT(theInteractorStyleDictionary != NUL(Dictionary*));
207    return (Dictionary*)theInteractorStyleDictionary->findDefinition(interactor);
208 }
209 
210 //
211 // Set the default style for the given interactor.
212 // If this function is never called, the default style will be the first one
213 // in the style dictionary.
214 //
SetDefaultStyle(const char * interactor,InteractorStyleEnum style)215 void InteractorStyle::SetDefaultStyle(const char* interactor,
216 			InteractorStyleEnum style)
217 {
218     Dictionary *styledict;
219     InteractorStyle *is;
220 
221 
222     styledict = InteractorStyle::GetInteractorStyleDictionary(interactor);
223     if (!styledict)
224 	return;
225 
226     DictionaryIterator iterator(*styledict);
227 
228     while ( (is = (InteractorStyle *) iterator.getNextDefinition()) )
229 	is->isDefault = is->style == style;
230 }
231 
232 //
233 // Get the InteractorStyle entry associated with the give interactor
234 // (node name) and the give style.
235 //
GetInteractorStyle(const char * interactor,InteractorStyleEnum style)236 InteractorStyle *InteractorStyle::GetInteractorStyle(const char* interactor,
237 			InteractorStyleEnum style)
238 {
239     Dictionary *styledict;
240     InteractorStyle *is, *firstIs = NULL;
241 
242 
243     styledict = InteractorStyle::GetInteractorStyleDictionary(interactor);
244     if (!styledict)
245 	return NUL(InteractorStyle*);
246 
247     DictionaryIterator iterator(*styledict);
248 
249     while ( (is = (InteractorStyle *) iterator.getNextDefinition()) ) {
250 	if (firstIs == NULL)
251 	    firstIs = is;
252 	if ((is->style == style)
253 	    OR (style == DefaultStyle AND is->isDefault))
254 	    return is;
255     }
256 
257     if(style == DefaultStyle)
258 	 return firstIs;
259 
260     return NULL;
261 }
262 //
263 // Get the InteractorStyle entry associated with the give interactor
264 // (node name) and the given style.
265 //
GetInteractorStyle(const char * interactor,const char * stylename)266 InteractorStyle *InteractorStyle::GetInteractorStyle(const char* interactor,
267 			const char *stylename)
268 {
269     Dictionary *styledict;
270 
271     styledict = InteractorStyle::GetInteractorStyleDictionary(interactor);
272     if (!styledict)
273 	return NUL(InteractorStyle*);
274 
275     return (InteractorStyle*)styledict->findDefinition(stylename);
276 
277 }
278 
279 //
280 // Added supported style/name/interactorbuild group to the list
281 // of supported styles for the given named interactor (node name).
282 //
AddSupportedStyle(const char * interactor,InteractorStyleEnum style,const char * stylename,InteractorAllocator ia)283 boolean	InteractorStyle::AddSupportedStyle(const char *interactor,
284 		InteractorStyleEnum style,
285 		const char *stylename,
286 		InteractorAllocator ia)
287 {
288     return InteractorStyle::AddSupportedStyle
289 	(interactor, style, stylename, NUL(char*), ia);
290 }
AddSupportedStyle(const char * interactor,InteractorStyleEnum style,const char * stylename,const char * javaStyle,InteractorAllocator ia)291 boolean	InteractorStyle::AddSupportedStyle(const char *interactor,
292 		InteractorStyleEnum style,
293 		const char *stylename,
294 		const char *javaStyle,
295 		InteractorAllocator ia)
296 {
297     Dictionary		*styledict;
298     InteractorStyle	*is;
299 
300     styledict = InteractorStyle::GetInteractorStyleDictionary(interactor);
301     if (!styledict) {
302 	styledict = new Dictionary;
303 	ASSERT(styledict);
304 	if (!theInteractorStyleDictionary->addDefinition(interactor,
305 							(void*)styledict))
306 	{
307 	    delete styledict;
308             ASSERT(0);
309 	}
310     }
311 
312     is = new InteractorStyle(style, stylename, javaStyle, ia);
313 
314     boolean ret = styledict->addDefinition(stylename,(const void*)is);
315     ASSERT(ret);
316     return ret;
317 }
318 
319 
createInteractor(InteractorInstance * ii)320 Interactor *InteractorStyle::createInteractor(InteractorInstance *ii)
321 {
322     ASSERT(this->allocateInteractor);
323 
324     if (!this->interactorName) {
325 	//
326 	// Generate a unique widget name based on the Node name and style.
327 	//
328 	char *styleName = (char*)theSymbolManager->getSymbolString(this->name);
329 	styleName = StripWhiteSpace(styleName);
330 	if (isupper(styleName[0]))
331 	    styleName[0] = tolower(styleName[0]);
332 
333 	int len = STRLEN(styleName) + STRLEN("Interactor") + 15;
334 	this->interactorName = new char[len];
335 	sprintf(this->interactorName,"%sInteractor",styleName);
336 	delete styleName;
337     }
338 
339     Interactor *interactor = this->allocateInteractor(this->interactorName,ii);
340     interactor->initialize();
341     interactor->createInteractor();
342     return interactor;
343 }
344 
345