home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Chemistry / Elements_1.0 / Elements.app / sources / Boss.m < prev    next >
Text File  |  1992-08-07  |  5KB  |  213 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "Boss.h"
  5. #import <appkit/Text.h>
  6. #import <dpsclient/event.h>
  7. #import <appkit/Button.h>
  8.  
  9.  
  10. @implementation Boss:Object
  11.  
  12. - init
  13. {
  14. //    printf("\niniting\n");
  15. //    printf("appDirectory is %s\n",[NXApp appDirectory]);
  16.     sprintf(groupDir,"%s/%s",[NXApp appDirectory],"group");
  17.     sprintf(noGroupFile,"%s/%s",groupDir,"No Group.rtf");
  18.     sprintf(dataFile,"%s/byAtomNumber",[NXApp appDirectory]);
  19.     dataRead = 0;
  20.     return self;
  21. }
  22.  
  23. - keyEvent:(NXEvent *)event;
  24. {
  25. int theCell = [[tableMatrix selectedCell] tag];
  26. int nextCell;
  27. id theNextCell;
  28.     switch (event->data.key.keyCode){
  29.         case 22:    // printf("UP\n");
  30.           if (theCell == 26) nextCell = 76;
  31.           else if ((theCell <= 71) && (theCell >= 58)) nextCell = theCell + 32;
  32.           else if (theCell > 109) nextCell = 1;
  33.           else if (theCell >= 72) nextCell = theCell - 32;
  34.           else if (theCell >= 31) nextCell = theCell - 18;
  35.           else if (theCell >= 28) nextCell = theCell + 50;
  36.           else if (theCell >= 22) nextCell = theCell + 82;
  37.           else if (theCell == 21) nextCell = 89;
  38.           else if (theCell >= 10) nextCell = theCell - 8;
  39.           else if (theCell >= 5) nextCell = theCell + 76;
  40.           else if (theCell == 4) nextCell = 88;
  41.           else if (theCell == 3) nextCell = 1;
  42.           else if (theCell == 2) nextCell = 86;
  43.           else if (theCell == 1) nextCell = 87;
  44.           else nextCell = 1;
  45.           break;
  46.         case 15:    // printf("DOWN\n");
  47.           if (theCell == 76) nextCell = 26;
  48.           else if (theCell == 1) nextCell = 3;
  49.           else if (theCell <= 12) nextCell = theCell + 8;
  50.           else if (theCell <= 39) nextCell = theCell + 18;
  51.           else if (theCell <= 77) nextCell = theCell + 32;
  52.           else if (theCell <= 80) nextCell = theCell - 50;
  53.           else if (theCell <= 85) nextCell = theCell - 76;
  54.           else if (theCell == 86) nextCell = 2;
  55.           else if (theCell == 87) nextCell = 1;
  56.           else if (theCell == 88) nextCell = 4;
  57.           else if (theCell == 89) nextCell = 21;
  58.           else if (theCell <= 103) nextCell = theCell - 32;
  59.           else if (theCell <= 109) nextCell = theCell - 82;
  60.           else nextCell = 1;
  61.           break;
  62.         case 9:       // printf("LEFT\n");
  63.           switch(theCell){    
  64.             case 1:
  65.                 nextCell = 109;        break;
  66.             case 109:
  67.                 nextCell = 107;        break;
  68.             default:
  69.                nextCell = theCell - 1;}
  70.           break;
  71.         case 16:       // printf("RIGHT\n");
  72.           switch(theCell){
  73.             case 107:
  74.                 nextCell = 109;        break;
  75.             case 109:
  76.                 nextCell = 1;        break;
  77.             default:
  78.                nextCell = theCell + 1;}
  79.           break;
  80.         default:    //  not an arrow key
  81.           NXBeep();
  82.           return self;}
  83.     [tableMatrix selectCellWithTag:nextCell];
  84.     theNextCell = [tableMatrix selectedCell];
  85.     [theNextCell performClick:self];
  86.     //  [theNextCell highlight:TRUE];
  87.     //  [[tableMatrix findCellWithTag:nextCell] performClick:self];
  88.     return self;
  89. }
  90.  
  91. - readData
  92. {
  93. int j=-1;
  94. int i=0;
  95. char tokensep[] = "\t";
  96. char buf[500], *token;
  97.     if (( infile = fopen(dataFile,"r")) == NULL)
  98.     {
  99.           printf("%s didn't open\n",dataFile);    
  100.     }
  101.     else
  102.     {
  103. //          printf("%s successfully opened\n",dataFile);
  104.  
  105.           while (fgets(buf,500,infile)!=NULL)
  106.           {    // for every line in the file 
  107.              j++;
  108.              i = 0;
  109.              token = strtok(buf,tokensep);
  110.              while (token != NULL)
  111.              {    // for every item in the line
  112.                 i++;
  113.                 strncpy(theElements[j][i],token,NUMCHAR);
  114.              token = strtok(NULL, tokensep);
  115.              }
  116.           }
  117.     }
  118.     detCell[1]=name;
  119.     detCell[2]=symbol;
  120.     detCell[3]=atomicNumber;
  121.     for (i=4;i<=20;i++)
  122.         detCell[i]=[details findCellWithTag:i];
  123.     dataRead = 1;
  124.     return self;
  125. }
  126.  
  127.  
  128. - showElement:sender
  129. {
  130. int i;
  131. int AN = [[sender selectedCell] tag];
  132.     if (!dataRead) [self readData];
  133.     [elementWin disableFlushWindow];
  134.     for (i=1;i<=20;i++){
  135.         [detCell[i] setStringValue:theElements[AN][i]];
  136.         }
  137.     [[elementWin reenableFlushWindow] flushWindow];
  138.     [elementWin orderFront:self];
  139.     return self;
  140. }
  141.  
  142.  
  143. - (char *)getGroupName:(int)theTag
  144. {
  145. //    printf("%i is the tag\n",theTag);
  146.     switch(theTag){
  147.           case 10: return("IA");
  148.               break;
  149.         case 20: return("IIA");
  150.             break;
  151.         case 30: return("IIIA");
  152.             break;
  153.         case 40: return("IVA");
  154.             break;
  155.         case 50: return("VA");
  156.             break;
  157.         case 60: return("VIA");
  158.             break;
  159.         case 70: return("VIIA");
  160.             break;
  161.         case 80: return("VIIIA");
  162.             break;
  163.         case 11: return("IB");
  164.               break;
  165.         case 21: return("IIB");
  166.             break;
  167.         case 31: return("IIIB");
  168.             break;
  169.         case 41: return("IVB");
  170.             break;
  171.         case 51: return("VB");
  172.             break;
  173.         case 61: return("VIB");
  174.             break;
  175.         case 71: return("VIIB");
  176.             break;
  177.         case 81: return("VIIIB");
  178.             break;}
  179.     return("No Group.rtf");
  180.  
  181.  
  182. - showGroup:sender
  183. {
  184.     char groupName[MAXPATHLEN];
  185.     NXStream *stream;
  186.     static NXPoint origin = {0.0,0.0};
  187.  
  188. //    printf("\nGroupDir = %s\n",groupDir); 
  189. //    printf("GroupName = %s\n",groupName); 
  190.  
  191.     sprintf(groupName,"%s/%s",groupDir,[self getGroupName:[[sender selectedCell] tag]]);
  192. //    printf("Showing group file %s\n",groupName);
  193.     if ((stream = NXMapFile(groupName,NX_READONLY)) == NULL)
  194.         stream = NXMapFile(noGroupFile,NX_READONLY);
  195.     if (stream != NULL) {
  196.         [groupPanel disableFlushWindow];
  197.         [[groupText docView] readRichText:stream]; 
  198.     [[groupText docView] scrollPoint:&origin];
  199.     [[groupPanel reenableFlushWindow] flushWindow];
  200.         NXCloseMemory(stream,NX_FREEBUFFER);
  201.     }
  202.     [groupPanel orderFront:self];
  203.     return self;
  204. }
  205.  
  206. - (int)appPowerOffIn:(int)ms andSave:(int)aFlag
  207. {
  208.     [filezowner terminate];
  209. }
  210.  
  211. @end
  212.