Пример #1
0
JNIEXPORT jobjectArray JNICALL Java_ConfigManager_getListValue(JNIEnv * env, jobject obj, jstring parameterName)
{
    const jbyte* str;
    char* name;
    char* value;
    int i;
    ParameterList* list;
    jobjectArray result = NULL;
    str = (*env)->GetStringUTFChars(env, parameterName, NULL);
    if (str != NULL)
    {
        name = StringNew((char*) str);
        list = PM_getValue(GetJavaPMPointer(env, obj), name).list_val;
        result = (jobjectArray) (*env)->NewObjectArray(env, PL_getLength(list), (*env)->FindClass(env, "java/lang/String"), NULL);
        i = 0;
        while((value = PL_next(list)) != NULL)
        {
            (*env)->SetObjectArrayElement(env, result, i, (*env)->NewStringUTF(env, value));
            i++;
        }
        (*env)->ReleaseStringUTFChars(env, parameterName, str);
        StringFree(name);
    }
    return result;
}
Пример #2
0
//After parsing, look at all the fields and manage, add all values
JNIEXPORT void JNICALL Java_Dialogc_DialogcManage (JNIEnv * env, jobject job){
	char * value;
	ParameterManager *PM=params;
	fields = PM_getValue(params,"fields").list_val;
	buttons = PM_getValue(params,"buttons").list_val;
	while(value = PL_next(fields))
	{

		PM_manage(params,value,NO_TYPE,1);

	}
	while(value = PL_next(buttons))
	{
		PM_manage(params,value,NO_TYPE,1);
	}
}
Пример #3
0
//Compile and run after the file is written
JNIEXPORT void JNICALL Java_Dialogc_DialogcCRun(JNIEnv *env, jobject obj, jstring filePath, jstring dir)
{
	char * title=PM_getValue(params,"title").str_val;
	const char *wDir = (*env)->GetStringUTFChars(env,dir,NULL);
	char *path=(char *)malloc(sizeof(char)*100);
	// char *str;
	strcpy(path,wDir);
	strcat(path,"/");
	for(int i=0;i<strlen(title);i++)
	{
		if(title[i]==' ')
		title[i]='_';
	}
	strcat(path,title);
	strcat(path,".java");


	char command[50];
	strcpy( command, "javac " );
	strcat( command, title );
	strcat(command,".java");
	system(command);

	strcpy( command, "java " );
	strcat( command, title);
	system(command);
}
Пример #4
0
JNIEXPORT jboolean JNICALL Java_ConfigManager_getBooleanValue(JNIEnv * env, jobject obj, jstring parameterName)
{
    const jbyte* str;
    char* name;
    jboolean result = false;
    str = (*env)->GetStringUTFChars(env, parameterName, NULL);
    if (str != NULL)
    {
        name = StringNew((char*) str);
        result = PM_getValue(GetJavaPMPointer(env, obj), name).bool_val;
        (*env)->ReleaseStringUTFChars(env, parameterName, str);
        StringFree(name);
    }
    return result;
}
Пример #5
0
JNIEXPORT jstring JNICALL Java_ConfigManager_getStringValue(JNIEnv * env, jobject obj, jstring parameterName)
{
    const jbyte* str;
    char* name;
    char* result = NULL;
    str = (*env)->GetStringUTFChars(env, parameterName, NULL);
    if (str != NULL)
    {
        name = StringNew((char*) str);
        result = PM_getValue(GetJavaPMPointer(env, obj), name).str_val;
        (*env)->ReleaseStringUTFChars(env, parameterName, str);
        StringFree(name);
    }
    return (*env)->NewStringUTF(env, result);
}
Пример #6
0
/* emitJava 
 * Emits java code to a file
 * Parameters:	tfb - title, fields, and buttons
 *				types - data types and action listeners
 *				fieldCount - number of fields
 *				buttonCount - number of buttons
 *				Cpn - projectName
 * Returns: nothing
*/
void emitJava( ParameterManager * tfb, ParameterManager * types, int fieldCount, int buttonCount, const char * Cpn ) {
	FILE * fp; //new or not new java file we are printing to; we dunno and it doesn't matter
	char * filename = malloc(sizeof(char)*100);
	char * curName = malloc(sizeof(char)*100);
	ParameterList * fields, * buttons;
	int i = 0;
	fields = PM_getValue( tfb, "fields").list_val;
	buttons = PM_getValue( tfb, "buttons").list_val;
	mkdir( Cpn, S_IRWXU ); //make the directory we need, it may fail, but only if directory already exists, in which case we dont care, we just need to to be there

	sprintf(filename, "%s/%s.java", Cpn, Cpn); //file we'll be opening, with its directory path
	fp = fopen(filename, "w");
	//TIME FOR THE FUN STUFF

	fprintf(fp, "package %s;\n\n", Cpn );
	fputs("import java.awt.*;\nimport javax.swing.*;\nimport java.awt.event.ActionListener;\nimport java.awt.event.ActionEvent;\nimport java.lang.NumberFormatException;\n", fp);
	fputs("import java.lang.Integer;\nimport java.lang.Float;\nimport java.lang.Boolean;\n\n", fp);
	fprintf(fp, "public class %s extends JFrame implements ActionListener {\n\n", Cpn);

	for( i = 0; i < fieldCount; i++ ) {
		fprintf(fp, "\tprivate JTextArea %s;\n", PL_next(fields)  );
	}
	PL_reset(fields);

	for( i = 0; i < buttonCount; i++ ) {
		fprintf(fp, "\tprivate JButton %s;\n", PL_next(buttons) );
	}
	PL_reset(buttons);

	fputs("\tprivate JTextArea textArea;\n\n", fp);
	fprintf(fp, "\tprivate static final int NUM_FIELDS = %d;\n\tprivate static final int WIDTH = 450;\n\tprivate static final int HEIGHT = 250+(NUM_FIELDS*75);\n\n", fieldCount );
	fprintf(fp, "\tpublic %s() {\n\n", Cpn);

	fprintf(fp, "\t\tsuper(\"%s\");\n\t\tsetLayout(new GridLayout( 2, 1 ));\n\t\tsetSize(WIDTH,HEIGHT);\n\n", PM_getValue(tfb, "title").str_val );
	fputs("\t\t//field and button panel\n\t\tJPanel fieldAndButtonPanel =  new JPanel();\n\t\tfieldAndButtonPanel.setLayout( new GridLayout(NUM_FIELDS+1, 1));\n\n", fp);

	for( i = 0; i < fieldCount; i++ ) { //field building
		curName = PL_next(fields);
		fprintf(fp, "\t\t//%s\n", curName );
		fprintf(fp, "\t\tJPanel %sPanel = new JPanel();\n", curName);
		fprintf(fp, "\t\t%sPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));\n", curName);
		fprintf(fp, "\t\t%s = new JTextArea( 1, 25 );\n", curName);
		fprintf(fp, "\t\tJLabel %sLabel = new JLabel(\"%s\");\n", curName, curName);
		fprintf(fp, "\t\t%sPanel.add(%sLabel);\n", curName, curName);
		fprintf(fp, "\t\t%sPanel.add(%s);\n", curName, curName);
		fprintf(fp, "\t\t//end %s\n\n", curName);
	}
	PL_reset(fields);

	fputs("\t\t//button panel\n\t\tJPanel buttonPanel = new JPanel();\n\t\tbuttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));\n\n", fp);

	for( i = 0; i < buttonCount; i++ ) { //button building
		curName = PL_next(buttons);
		fprintf(fp, "\t\t//%s\n", curName);
		fprintf(fp, "\t\t%s = new JButton(\"%s\");\n", curName,curName);
		fprintf(fp, "\t\t%s.setPreferredSize(new Dimension(85 ,30));\n", curName);
		fprintf(fp, "\t\t%s.addActionListener(this);\n", curName );
		fprintf(fp, "\t\t//end %s\n\n", curName);
	}
	PL_reset(buttons);

	for( i = 0; i < buttonCount; i++ ) { //adding buttons to panel
		curName = PL_next(buttons);
		fprintf(fp, "\t\tbuttonPanel.add(%s);\n", curName );
	}
	PL_reset(buttons);
	fputs("\t\t//end button panel\n\n", fp);

	for( i = 0; i < fieldCount; i++ ) { //adding fields to main panel
		curName = PL_next(fields);
		fprintf(fp, "\t\tfieldAndButtonPanel.add(%sPanel);\n", curName);
	}
	PL_reset(fields);
	fputs("\t\tfieldAndButtonPanel.add(buttonPanel);\n\t\t//end field and button panel\n\n", fp );

	//status area
	fputs("\t\t//text area\n", fp);
	fputs("\t\ttextArea = new JTextArea(20, 50);\n", fp);
	fputs("\t\ttextArea.setEditable(false);\n", fp);
	fputs("\t\tJScrollPane textPane = new JScrollPane( textArea );\n", fp);
	fputs("\t\tJPanel textPanel = new JPanel();\n", fp);
	fputs("\t\ttextPanel.setLayout( new BorderLayout() );\n\n", fp);
	fputs("\t\tJLabel textLabel = new JLabel(\"STATUS\");\n", fp);
	fputs("\t\ttextPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);\n", fp);
	fputs("\t\ttextPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);\n", fp);
	fputs("\t\ttextPanel.add(textLabel, BorderLayout.NORTH);\n", fp);
	fputs("\t\ttextPanel.add(textPane, BorderLayout.CENTER);\n\n", fp);
	fputs("\t\ttextPanel.add(textLabel);\n", fp);
	fputs("\t\ttextPanel.add(textPane);\n", fp);
	fputs("\t\t//end text area\n\n", fp);
	fputs("\t\tadd(fieldAndButtonPanel);\n", fp);
	fputs("\t\tadd(textPanel);\n\t}\n\n", fp);

	//accessors and mutators
	fputs("\t//accessors and mutators\n", fp);
	for( i = 0; i < fieldCount; i++ ) {
		curName = PL_next(fields);
		fprintf(fp, "\tpublic void setDC%s( String instring ) {\n\t\t%s.setText(instring);\n\t}\n\n", curName, curName);		
		if ( strcmp( "string", PM_getValue(types, curName).str_val) == 0 ) {
			fprintf(fp, "\tpublic String getDC%s() {\n\t\treturn new String(%s.getText());\n\t}\n\n", curName, curName );
		} else if ( strcmp( "integer", PM_getValue(types, curName).str_val) == 0 ) {
			fprintf(fp, "\tpublic int getDC%s() throws IllegalFieldValueException {\n\t\tint i;\n", curName );
			fprintf(fp, "\t\ttry {\n\t\t\ti = Integer.parseInt(%s.getText());\n\t\t} catch ( NumberFormatException e ) {\n", curName);
			fprintf(fp, "\t\t\tthrow new IllegalFieldValueException(%s.getText());\n\t\t}\n\t\treturn i;\n\t}\n\n", curName);
		} else if ( strcmp( "float", PM_getValue(types, curName).str_val) == 0 ) {
			fprintf(fp, "\tpublic float getDC%s() throws IllegalFieldValueException {\n\t\tfloat f;\n", curName );
			fprintf(fp, "\t\ttry {\n\t\t\tf = Float.parseFloat(%s.getText());\n\t\t} catch ( NumberFormatException e ) {\n", curName);
			fprintf(fp, "\t\t\tthrow new IllegalFieldValueException(%s.getText());\n\t\t}\n\t\treturn f;\n\t}\n\n", curName);
		} else if ( strcmp( "boolean", PM_getValue(types, curName).str_val) == 0 ) {
			fprintf(fp, "\tpublic Boolean getDC%s() throws IllegalFieldValueException {\n\t\tBoolean b;\n", curName );
			fprintf(fp, "\t\ttry {\n\t\t\tb = Boolean.parseBoolean(%s.getText());\n\t\t} catch ( NumberFormatException e ) {\n", curName);
			fprintf(fp, "\t\t\tthrow new IllegalFieldValueException(%s.getText());\n\t\t}\n\t\treturn b;\n\t}\n\n", curName);
		}
	}

	//appendToStatusArea
	fputs("\tpublic void appendToStatusArea( String instring ) {\n\t\tString curContent = textArea.getText();\n\t\tcurContent += (instring + \"\\n\");\n\t\ttextArea.setText(curContent);\t\n}\n\n", fp);

	//actionPerformed
	fputs("\tpublic void actionPerformed( ActionEvent e ) {\n\t\tappendToStatusArea(e.getActionCommand() + \" button pressed\");\n\t}\n\n", fp);

	//main
	fprintf(fp, "\tpublic static void main( String[] args ) {\n\t\t%s runWindow = new %s();\n\t\trunWindow.setVisible(true);\n\t}\n}", Cpn, Cpn);
	
	//execption
	memset(filename, 0, strlen(filename));
	sprintf(filename, "%s/IllegalFieldValueException.java", Cpn);
	freopen(filename, "w", fp);

	fprintf(fp, "package %s;\n\n", Cpn);
	fputs("import java.lang.Exception;\n\n", fp);
	fputs("public class IllegalFieldValueException extends Exception {\n\tpublic IllegalFieldValueException(String message) {\n\t\tsuper(\"Values not of defined type: \" + message );\n\t}\n}", fp);

	//and thats it folks
	fclose(fp);
	free(filename);
}
Пример #7
0
//Set the values of the title and buttons into the array
JNIEXPORT void JNICALL Java_Dialogc_DialogcPeek(JNIEnv *env, jobject job)
{
	ParameterManager *PM=params;
	char *title;
	char * value;
	int i=0;
	fields = PM_getValue(params,"fields").list_val;
	buttons = PM_getValue(params,"buttons").list_val;
	for(int i=0;i<100;i++)
	{
		guiFields[i][0]=NULL;
		guiButts[i][0]=NULL;
		ftypes[i][i]=NULL;
		btypes[i][i]=NULL;
	}
	while(value = PL_next(fields))
	{
		PM=params;
		while(PM!=NULL)
		{ //Check the name, then set the value
			if((strcmp(value,PM->pName) == 0))
			{
				if(PM->type==1)
				{
					ftypes[i][0]="int";
				}
				if(PM->type==2)
				{
					ftypes[i][0]="double";
				}
				if(PM->type==5)
				{
					ftypes[i][0]="String";
				}
			}
			PM = PM->next;
		}
		guiFields[i][0]=value;
		i++;
	}

	for(int q=0;q<i;q++)
	{

		title = PM_getValue(params,guiFields[q][0]).str_val;
	}
	i=0;

	while(value = PL_next(buttons))
	{
		PM=params;
		while(PM!=NULL)
		{ //Check the name, then set the value
			if((strcmp(value,PM->pName) == 0))
			{
				btypes[i][0]="QueryListener";
			}
			PM = PM->next;
		}

		guiButts[i][0]=value;
		i++;
	}
	for(int q=0;q<i;q++)
	{
		title = PM_getValue(params,guiButts[q][0]).str_val;
	}
}
Пример #8
0
//Write the custom GUI based on for loops
JNIEXPORT void JNICALL Java_Dialogc_DialogcWrite(JNIEnv * env, jobject obj, jstring filePath, jstring dir)
{
	int lastField=0;
	char * title=PM_getValue(params,"title").str_val;
	const char *wDir = (*env)->GetStringUTFChars(env,dir,NULL);
	char *path=(char *)malloc(sizeof(char)*100);
	strcpy(path,wDir);
	strcat(path,"/");

	//Changes the space so the compiler doesnt cry
	for(int i=0;i<strlen(title);i++)
	{
		if(title[i]==' ')
		title[i]='_';
	}
	//strcat(path,"FieldEdit");
	strcat(path,title);
	strcat(path,".java");
	FILE *fp=fopen(path,"w");


	fprintf(fp,"import java.awt.*;\n");
	fprintf(fp,"import java.io.*;\n");
	fprintf(fp,"import java.nio.*;\n");
	fprintf(fp,"import java.util.*;\n");
	fprintf(fp,"import javax.swing.*;\n");
	fprintf(fp,"import java.awt.event.ActionEvent;\n");
	fprintf(fp,"import java.awt.event.ActionListener;\n");


	fprintf(fp,"public class %s extends JFrame implements ActionListener\n",title);
	fprintf(fp,"{\npublic %s()\n{\n\tguiUI();\n}\n",title);
	fprintf(fp,"\tJTextArea editArea = new JTextArea(6, 20);\n");
	for(int i=0;i<100;i++)
	{
		if(guiFields[i][0]!=NULL)
		{

			fprintf(fp,"\tJLabel %sLbl= new JLabel(\"%s\");\n",guiFields[i][0],guiFields[i][0]);
			fprintf(fp,"\tJTextField %stField= new JTextField();\n",guiFields[i][0]);
		}
	}

	fprintf(fp,"private void guiUI()\n{\n");

	//Add Labels and text fields
	for(int i=0;i<100;i++)
	{
		if(guiFields[i][0]!=NULL)
		{

			fprintf(fp,"\t%sLbl.setBounds(30, %d, 150, 80);\n",guiFields[i][0],40+(i*30));
			fprintf(fp,"\t%stField.setBounds(180, %d, 300, 20);\n",guiFields[i][0],75+(i*30));
			lastField=75+(i*30)+50;
		}
	}
	//Add buttons and listeners
	for(int i=0;i<100;i++)
	{
		if(guiButts[i][0]!=NULL)
		{
			fprintf(fp,"\tJButton %sButton= new JButton(\"%s\");\n",guiButts[i][0],guiButts[i][0]);
			fprintf(fp,"\t%sButton.setBounds(%d,%d,90,40);\n",guiButts[i][0],60+(i*100),lastField);
			fprintf(fp,"\t%sButton.addActionListener(this);\n",guiButts[i][0]);
		}
	}
	for(int i=0;i<strlen(title);i++)
	{
		if(title[i]=='_')
		title[i]=' ';
	}
	fprintf(fp,"\tJFrame frame= new JFrame(\"%s\");\n\n",title);
	for(int i=0;i<strlen(title);i++)
	{
		if(title[i]==' ')
		title[i]='_';
	}
	fprintf(fp,"JScrollPane scrollingArea = new JScrollPane(editArea);\n");
	fprintf(fp,"JPanel editorWindow = new JPanel();\n");
	fprintf(fp,"editorWindow.setBounds(0,300,600,250);\n");
	fprintf(fp,"editorWindow.setLayout(new BorderLayout());\n");
	fprintf(fp,"editorWindow.add(scrollingArea, BorderLayout.SOUTH);\n");
	fprintf(fp,"frame.setLayout(null);\n\n");

	//Add labels and fields to the frame
	for(int i=0;i<100;i++)
	{
		if(guiFields[i][0]!=NULL)
		{
			fprintf(fp,"\tframe.add(%sLbl);\n",guiFields[i][0]);
			fprintf(fp,"\tframe.add(%stField);\n",guiFields[i][0]);
		}
	}
	//Add the buttons to the frame
	for(int i=0;i<100;i++)
	{
		if(guiButts[i][0]!=NULL)
		{
			fprintf(fp,"\tframe.add(%sButton);\n",guiButts[i][0]);

		}
	}
	//Write basic GUI values
	fprintf(fp,"\nframe.setSize(600,600);\n");
	fprintf(fp,"frame.setVisible(true);\n");
	fprintf(fp,"frame.setResizable(false);\n");
	fprintf(fp,"frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );\n");
	fprintf(fp,"editArea.setText(\"\");\n");
	fprintf(fp,"frame.add(editorWindow);\n");
	fprintf(fp,"}\n");

	//Set actions
	fprintf(fp,"public void actionPerformed(ActionEvent E) {\n");

	for(int i=0;i<100;i++)
	{
		if(guiButts[i][0]!=NULL)
		{
			fprintf(fp,"\tif (E.getActionCommand() ==\"%s\") {\n",guiButts[i][0]);
			//fprintf(fp,"\t\teditArea.append(\"%s button pressed\"+\"\\n\");\n",guiButts[i][0]);
			for(int j=0;j<100;j++)
			{
				if(guiFields[j][0]!=NULL)
				{
					fprintf(fp,"\tgetDC%s ();\n",guiFields[j][0]);
				}

			}
			fprintf(fp,"\teditArea.append(\" \\n\");\n");
			fprintf(fp,"\t\t}\n");

		}
	}
	fprintf(fp,"}\n");
	for(int i=0;i<100;i++)
	{
		if(guiFields[i][0]!=NULL)
		{
			if((strcmp(ftypes[i][0],"int")==0))
			{
				fprintf(fp,"public %s getDC%s () {\n",ftypes[i][0],guiFields[i][0]);
				fprintf(fp,"\t\tString %sTest = %stField.getText();\n",guiFields[i][0],guiFields[i][0]);
				fprintf(fp,"\t\tint valid=1;\n");
				fprintf(fp,"\t\ttry {\n");
				fprintf(fp,"\t\t\tvalid=Integer.parseInt(%sTest);\n",guiFields[i][0]);
				fprintf(fp,"\t\t\t} catch (NumberFormatException e) {\n");
				fprintf(fp,"\t\t\tvalid=-999;\n");
				fprintf(fp,"\t\t\t\teditArea.append(\"%s: Invalid Type\\n\");\n",guiFields[i][0]);
				fprintf(fp,"\t\t\t}\n");
				fprintf(fp,"\t\tif(valid!=-999)\n");
				fprintf(fp,"\t\t\t\teditArea.append(\"%s: \"+valid+\"\\n\");\n",guiFields[i][0]);
				fprintf(fp,"\t\treturn valid;\n");
				fprintf(fp,"\t}\n");
			}
			if((strcmp(ftypes[i][0],"double")==0))
			{
				fprintf(fp,"public %s getDC%s () {\n",ftypes[i][0],guiFields[i][0]);
				fprintf(fp,"\t\tString %sTest = %stField.getText();\n",guiFields[i][0],guiFields[i][0]);
				fprintf(fp,"\t\tdouble valid=1;\n");
				fprintf(fp,"\t\ttry {\n");
				fprintf(fp,"\t\t\tvalid=Double.parseDouble(%sTest);\n",guiFields[i][0]);
				fprintf(fp,"\t\t\t} catch (NumberFormatException e) {\n");
				fprintf(fp,"\t\t\tvalid=-999;\n");
				fprintf(fp,"\t\t\t\teditArea.append(\"%s: Invalid Type\\n\");\n",guiFields[i][0]);
				fprintf(fp,"\t\t\t}\n");
				fprintf(fp,"\t\tif(valid!=-999)\n");
				fprintf(fp,"\t\t\t\teditArea.append(\"%s: \"+valid+\"\\n\");\n",guiFields[i][0]);
				fprintf(fp,"\t\treturn valid;\n");
				fprintf(fp,"\t}\n");
			}
			if((strcmp(ftypes[i][0],"String")==0))
			{
				fprintf(fp,"public %s getDC%s () {\n",ftypes[i][0],guiFields[i][0]);
				fprintf(fp,"\t\tString %sString = %stField.getText();\n",guiFields[i][0],guiFields[i][0]);
				fprintf(fp,"\tif(%stField.getText().equals(\"\"))\n",guiFields[i][0]);
				fprintf(fp,"\t\t\t\t{editArea.append(\"%s: Empty String\\n\");}\n",guiFields[i][0]);
				fprintf(fp,"\telse\n{\n");
				fprintf(fp,"\t\t\teditArea.append(\"%s: \"+%sString+\"\\n\");\n}\n",guiFields[i][0],guiFields[i][0]);
				fprintf(fp,"\t\treturn %sString;\n",guiFields[i][0]);
				fprintf(fp,"\t}\n");
			}

		}
	}
	fprintf(fp,"\tpublic void appendToStatusArea (String message){\n\n\t}\n");
	//Run itself
	fprintf(fp,"\tpublic  static void main ( String[] args ){");
	fprintf(fp,"\t\n\t\t%s ex = new %s();\n\t}\n",title,title);
	fprintf(fp,"}\n");
	fclose(fp);
}