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 #include "FileSelectorInstance.h"
14 #include "FileSelectorNode.h"
15 #include "ControlPanel.h"
16 
FileSelectorInstance(FileSelectorNode * n)17 FileSelectorInstance::FileSelectorInstance(FileSelectorNode *n) :
18 				ValueInstance(n)
19 {
20     this->fileFilter = NULL;
21 }
22 
~FileSelectorInstance()23 FileSelectorInstance::~FileSelectorInstance()
24 {
25     if (this->fileFilter)
26 	delete this->fileFilter;
27 }
setFileFilter(const char * filter)28 void FileSelectorInstance::setFileFilter(const char *filter)
29 {
30     if (this->fileFilter)
31 	delete this->fileFilter;
32 
33 #ifdef DXD_WIN
34     char *cf;
35     int i;
36     cf = (char *) malloc ((strlen(filter) +1)*sizeof(char));
37     strcpy(cf, filter);
38     for(i=0; i<strlen(cf); i++)
39 	if(cf[i] == '/') cf[i] = '\\';
40     this->fileFilter = DuplicateString(cf);
41     free(cf);
42 #else
43     this->fileFilter = DuplicateString(filter);
44 #endif
45 }
46 
printAsJava(FILE * jf)47 boolean FileSelectorInstance::printAsJava (FILE* jf)
48 {
49     int x,y,w,h;
50     this->getXYPosition (&x, &y);
51     this->getXYSize (&w,&h);
52     ControlPanel* cpan = this->getControlPanel();
53     boolean devstyle = cpan->isDeveloperStyle();
54 
55     InteractorNode* ino = (InteractorNode*)this->node;
56     const char* node_var_name = ino->getJavaVariable();
57 
58     //
59     // Count up the lines in the label and split it up since java doesn't
60     // know how to do this for us.
61     //
62     const char* ilab = this->getInteractorLabel();
63     int line_count = CountLines(ilab);
64 
65     const char* java_style = "Interactor";
66     if (this->style->hasJavaStyle())
67 	java_style = this->style->getJavaStyle();
68     const char* var_name = this->getJavaVariable();
69     fprintf (jf, "        %s %s = new %s();\n", java_style, var_name, java_style);
70     fprintf (jf, "        %s.addInteractor(%s);\n", node_var_name, var_name);
71 	fprintf (jf, "        %s.setUseQuotes(true);\n", var_name);
72     fprintf (jf, "        %s.setStyle(%d);\n", var_name, devstyle?1:0);
73 
74     fprintf (jf, "        %s.setLabelLines(%d);\n", var_name, line_count);
75     int i;
76     for (i=1; i<=line_count; i++) {
77 	const char* cp = InteractorInstance::FetchLine (ilab, i);
78 	fprintf (jf, "        %s.setLabel(\"%s\");\n", var_name, cp);
79     }
80 
81     if (this->isVerticalLayout())
82 	fprintf (jf, "        %s.setVertical();\n", var_name);
83     else
84 	fprintf (jf, "        %s.setHorizontal();\n", var_name);
85 
86     if (this->style->hasJavaStyle())
87 	fprintf (jf, "        %s.setBounds (%s, %d,%d,%d,%d);\n",
88 	    node_var_name, var_name, x,y,w,h);
89     else
90 	fprintf (jf, "        %s.setBounds (%s, %d,%d,%d,%d);\n",
91 	    node_var_name, var_name,x,y,w,65);
92 
93     fprintf (jf, "        %s.addInteractor(%s);\n", cpan->getJavaVariableName(), var_name);
94 
95     return TRUE;
96 }
97 
98