%eden
/*
controlPanel.e

  This file creates the control panel and defines the actions to 
  perform when buttons on the GUI are pressed.
  
*/
%angel
comp1 = frame {
   side = "top"; 
   content = [comp1l,comp1r,comp1g,comp1b] };
comp1l = label {
   text = "Min" ;
   font = "helvetica 11 bold";
   foreground = "white";
   background = rgb2colour(comp1r_value,comp1g_value,comp1b_value);
   width = 3;
   side = "left" };
comp1r = scale {
   side = "left";
   from = 0;
   to = 255;
   showvalue = 0;
   length = 80;
   orient = "horizontal";
   background = rgb2colour(comp1r_value,0,0) };
comp1g = scale {
   side = "left";
   from = 0;
   to = 255;
   showvalue = 0;
   length = 80;
   orient = "horizontal";
   background = rgb2colour(0,comp1g_value,0) };
comp1b = scale {
   side = "left";
   from = 0;
   to = 255;
   showvalue = 0;
   length = 80;
   orient = "horizontal";
   background = rgb2colour(0,0,comp1b_value) };
comp2 = frame {
   side = "top"; 
   content = [comp2l,comp2r,comp2g,comp2b] };
comp2l = label {
   text = "Max" ;
   font = "helvetica 11 bold";
   foreground = "white";
   background = rgb2colour(comp2r_value,comp2g_value,comp2b_value);
   width = 3;
   side = "left" };
comp2r = scale {
   side = "left";
   from = 0;
   to = 255;
   showvalue = 0;
   length = 80;
   orient = "horizontal";
   background = rgb2colour(comp2r_value,0,0) };
comp2g = scale {
   side = "left";
   from = 0;
   to = 255;
   showvalue = 0;
   length = 80;
   orient = "horizontal";
   background = rgb2colour(0,comp2g_value,0) };
comp2b = scale {
   side = "left";
   from = 0;
   to = 255;
   showvalue = 0;
   length = 80;
   orient = "horizontal";
   background = rgb2colour(0,0,comp2b_value) };
%eden
schemenumber = 1;

grad0_bgcolour is rgb2colour(round((comp1r_value * (1 - 0)) + (comp2r_value * 0)),round((comp1g_value * (1 - 0)) + (comp2g_value * 0)),round((comp1b_value * (1 - 0)) + (comp2b_value * 0)));
grad1_bgcolour is rgb2colour(round((comp1r_value * (1 - 0.1)) + (comp2r_value * 0.1)),round((comp1g_value * (1 - 0.1)) + (comp2g_value * 0.1)),round((comp1b_value * (1 - 0.1)) + (comp2b_value * 0.1)));
grad2_bgcolour is rgb2colour(round((comp1r_value * (1 - 0.2)) + (comp2r_value * 0.2)),round((comp1g_value * (1 - 0.2)) + (comp2g_value * 0.2)),round((comp1b_value * (1 - 0.2)) + (comp2b_value * 0.2)));
grad3_bgcolour is rgb2colour(round((comp1r_value * (1 - 0.3)) + (comp2r_value * 0.3)),round((comp1g_value * (1 - 0.3)) + (comp2g_value * 0.3)),round((comp1b_value * (1 - 0.3)) + (comp2b_value * 0.3)));
grad4_bgcolour is rgb2colour(round((comp1r_value * (1 - 0.4)) + (comp2r_value * 0.4)),round((comp1g_value * (1 - 0.4)) + (comp2g_value * 0.4)),round((comp1b_value * (1 - 0.4)) + (comp2b_value * 0.4)));
grad5_bgcolour is rgb2colour(round((comp1r_value * (1 - 0.5)) + (comp2r_value * 0.5)),round((comp1g_value * (1 - 0.5)) + (comp2g_value * 0.5)),round((comp1b_value * (1 - 0.5)) + (comp2b_value * 0.5)));
grad6_bgcolour is rgb2colour(round((comp1r_value * (1 - 0.6)) + (comp2r_value * 0.6)),round((comp1g_value * (1 - 0.6)) + (comp2g_value * 0.6)),round((comp1b_value * (1 - 0.6)) + (comp2b_value * 0.6)));
grad7_bgcolour is rgb2colour(round((comp1r_value * (1 - 0.7)) + (comp2r_value * 0.7)),round((comp1g_value * (1 - 0.7)) + (comp2g_value * 0.7)),round((comp1b_value * (1 - 0.7)) + (comp2b_value * 0.7)));
grad8_bgcolour is rgb2colour(round((comp1r_value * (1 - 0.8)) + (comp2r_value * 0.8)),round((comp1g_value * (1 - 0.8)) + (comp2g_value * 0.8)),round((comp1b_value * (1 - 0.8)) + (comp2b_value * 0.8)));
grad9_bgcolour is rgb2colour(round((comp1r_value * (1 - 0.9)) + (comp2r_value * 0.9)),round((comp1g_value * (1 - 0.9)) + (comp2g_value * 0.9)),round((comp1b_value * (1 - 0.9)) + (comp2b_value * 0.9)));
grad10_bgcolour is rgb2colour(round((comp1r_value * (1 - 1)) + (comp2r_value * 1)),round((comp1g_value * (1 - 1)) + (comp2g_value * 1)),round((comp1b_value * (1 - 1)) + (comp2b_value * 1)));

grad_width = 3;
grad_height = 3;

%angel
compx = frame {
   side = "top"; 
   content = [grad0,grad1,grad2,grad3,grad4,grad5,grad6,grad7,grad8,grad9,grad10] };
grad0 = label {
   text = "Min" ;
   font = "helvetica 10 bold";
   foreground = "white";
   background = grad0_bgcolour;
   height = grad_height;
   side = "left" };
grad1 = label {
   text = "" ;
   background = grad1_bgcolour;
   width = grad_width;
   height = grad_height;
   side = "left" };
grad2 = label {
   text = "" ;
   background = grad2_bgcolour;
   width = grad_width;
   height = grad_height;
   side = "left" };
grad3 = label {
   text = "" ;
   background = grad3_bgcolour;
   width = grad_width;
   height = grad_height;
   side = "left" };
grad4 = label {
   text = "" ;
   background = grad4_bgcolour;
   width = grad_width;
   height = grad_height;
   side = "left" };
grad5 = label {
   text = "" ;
   background = grad5_bgcolour;
   width = grad_width;
   height = grad_height;
   side = "left" };
grad6 = label {
   text = "" ;
   background = grad6_bgcolour;
   width = grad_width;
   height = grad_height;
   side = "left" };
grad7 = label {
   text = "" ;
   background = grad7_bgcolour;
   width = grad_width;
   height = grad_height;
   side = "left" };
grad8 = label {
   text = "" ;
   background = grad8_bgcolour;
   width = grad_width;
   height = grad_height;
   side = "left" };
grad9 = label {
   text = "" ;
   background = grad9_bgcolour;
   width = grad_width;
   height = grad_height;
   side = "left" };
grad10 = label {
   text = "Max" ;
   font = "helvetica 10 bold";
   foreground = "white";
   background = grad10_bgcolour;
   height = grad_height;
   side = "left" }; 
   

colourschemeselect = frame {
   side = "top"; 
   content = [choose,radio1,radio2,radio3] };
radio1 = radiobutton {
   text = "Green/Red";
   font = "helvetica 10 normal";
   variable = "schemenumber";
   value = 1 };
radio2 = radiobutton {
   text = "Blue/Purple/Red";
   font = "helvetica 10 normal";
   variable = "schemenumber";
   value = 2 };
radio3 = radiobutton {
   text = "Yellow/Red";
   font = "helvetica 10 normal";
   variable = "schemenumber";
   value = 3 };
choose = label { 
  text="Choose Preset Colour Scheme:";
  font = "helvetica 10 bold" };
  
colourmodelselect = frame {
   side = "top"; 
   content = [choose2,radio1b,radio2b,radio3b] };
radio1b = radiobutton {
   text = "Local by ranking";
   font = "helvetica 10 normal";
   variable = "colourmodeltype";
   value = 1 };
radio2b = radiobutton {
   text = "Local by magnitude";
   font = "helvetica 10 normal";
   variable = "colourmodeltype";
   value = 2 };
radio3b = radiobutton {
   text = "Global by magnitude";
   font = "helvetica 10 normal";
   variable = "colourmodeltype";
   value = 3 };
choose2 = label { 
  text="Apply colour model:";
  font = "helvetica 10 bold" };
  
distmeasureselect = frame {
   side = "top"; 
   content = [choose3,radio1c,radio2c] };
radio1c = radiobutton {
   text = "Degree of Disorder";
   font = "helvetica 10 normal";
   variable = "distancemeasure";
   value = 1 };
radio2c = radiobutton {
   text = "Euclidean Distance";
   font = "helvetica 10 normal";
   variable = "distancemeasure";
   value = 2 };
choose3 = label { 
  text="Select Distance Measure:";
  font = "helvetica 10 bold" };
  


customlabel = label {
  text="Set Custom Colour Scheme:";
  font = "helvetica 10 bold" };
customlabel2 = label {
  text="Colour Scheme:";
  font = "helvetica 10 bold" };
customlabel3 = label {
  text="Manage User Models:";
  font = "helvetica 10 bold" };
customlabel4 = label {
  text="Instructions:";
  font = "helvetica 10 bold" };
ins1a = label {
  text="1. Type the 5 sentences. You will be able to see your";
  font = "helvetica 10 normal" };
ins1b = label {
  text="user model growing as you type. ";
  font = "helvetica 10 normal" };  
ins2a = label {
  text="2. Click 'Save User Model'. Your data will be copied into";
  font = "helvetica 10 normal" };
ins2b = label {
  text="the row for User 10 (unless you specify a different row)";
  font = "helvetica 10 normal" };
ins3 = label {
  text="3. Click 'Reset User Model'.";
  font = "helvetica 10 normal" };
ins4a = label {
  text="4. Re-type the sentences. You should observe the similarities";
  font = "helvetica 10 normal" };
ins4b = label {
  text="between this new model and the model you just saved.";
  font = "helvetica 10 normal" };
saveframe = frame {
   side = "top"; 
   content = [savelabel,savebuttonprev,savebuttonnext,savelabel2,savebutton] };
savelabel = label {
   text = "" ;
   side = "left" };
savebuttonprev = button {
   text = "<";
   font = "helvetica 11 normal";
   side = "left" };
savebuttonnext = button {
   text = ">";
   font = "helvetica 11 normal";
   side = "left" };
savelabel = label {
   text = strcat("Row ", str(savemodelnumber)) ;
   font = "helvetica 11 normal";
   side = "left" };
savebutton = button {
   text = "Save User Model";
   font = "helvetica 11 normal";
   side = "left" };
   
   
resetbutton = button {
   text = "Reset User Model";
   font = "helvetica 11 normal";
   side = "top" };

controlwindow = window {
   title = "Control Panel";
   content = [comps] };  
comps = frame {
   side = "left";
   content = [customlabel4,ins1a,ins1b,ins2a,ins2b,ins3,ins4a,ins4b,customlabel,comp1,comp2,customlabel2,compx,colourschemeselect,colourmodelselect,distmeasureselect,customlabel4,saveframe,resetbutton] };

%eden
  colourmodeltype = 0;
  distancemeasure = 1;
  
  comp1r_value = 0;
  comp1g_value = 255;
  comp1b_value = 0;
  comp2r_value = 255;
  comp2g_value = 0;
  comp2b_value = 0;

colourvalues is [
  [comp1r_value,comp1g_value,comp1b_value],
  [comp2r_value,comp2g_value,comp2b_value] ];
  
  mincolour is [comp1r_value,comp1g_value,comp1b_value];
  maxcolour is [comp2r_value,comp2g_value,comp2b_value];
  
proc changecolourscheme : schemenumber {
 if (schemenumber == 1) {
  comp1r_value = 0;
  comp1g_value = 255;
  comp1b_value = 0;
  comp2r_value = 255;
  comp2g_value = 0;
  comp2b_value = 0;
 }
 if (schemenumber == 2) {
  comp1r_value = 0;
  comp1g_value = 125;
  comp1b_value = 255;
  comp2r_value = 255;
  comp2g_value = 0;
  comp2b_value = 0;
 }
 if (schemenumber == 3) {
  comp1r_value = 255;
  comp1g_value = 255;
  comp1b_value = 0;
  comp2r_value = 255;
  comp2g_value = 0;
  comp2b_value = 0;
 }
}

proc savebutton_mouseclick_trigger : savebutton_mouseclick {
   if (savebutton_mouseclick == 0) {
      for (i = 1; i <= 26; i++) {
	   datagrid[savemodelnumber][i+1] = userave[i];
	  }
	  writeToOutputConsole(strcat("model data saved to row ",str(savemodelnumber)));
   }
}

proc savebuttonprev_mouseclick_trigger : savebuttonprev_mouseclick {
   if (savebuttonprev_mouseclick == 0 && savemodelnumber > 1) {
      savemodelnumber--;
   }
}

proc savebuttonnext_mouseclick_trigger : savebuttonnext_mouseclick {
   if (savebuttonnext_mouseclick == 0 && savemodelnumber < 10) {
      savemodelnumber++;
   }
}

proc resetbutton_mouseclick_trigger : resetbutton_mouseclick {
   if (resetbutton_mouseclick == 0) {
      totalkeystrokes = 0;
	  datalist = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]];
	  writeToOutputConsole("User Model reset.");
   }
}

proc saveData {
	fp=fopen("keystrokedata.txt", "w");
	fprintf(fp,"keystrokedata (userid INT, a REAL, b REAL, c REAL, d REAL, e REAL, f REAL, g REAL, h REAL, i REAL, j REAL, k REAL, l REAL, m REAL, n REAL, o REAL, p REAL, q REAL, r REAL, s REAL, t REAL, u REAL, v REAL, w REAL, x REAL, y REAL, z REAL);\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[1]));
	fprintf(fp,";\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[2]));
	fprintf(fp,";\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[3]));
	fprintf(fp,";\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[4]));
	fprintf(fp,";\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[5]));
	fprintf(fp,";\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[6]));
	fprintf(fp,";\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[7]));
	fprintf(fp,";\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[8]));
	fprintf(fp,";\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[9]));
	fprintf(fp,";\n");
	fprintf(fp,"keystrokedata << ");
	fprintf(fp,str(datagrid[10]));
	fprintf(fp,";\n");
	fclose(fp);
}


