home *** CD-ROM | disk | FTP | other *** search
/ NeXT 3rd Party Products 1993 / NEXT_3rd_party_products_93.iso / Xanthus / Graphity_Demo / API / Demo4 / GraphityAPIDemo4.m < prev    next >
Text File  |  1993-05-07  |  3KB  |  173 lines

  1.  
  2. #import "app.h"
  3.  
  4. #define GRAPH_NAME    "MyGraph4"
  5.  
  6. @implementation GraphityAPIDemo4
  7.  
  8. - reportError: (const char *)message;
  9. {
  10.     NXRunAlertPanel("Problem!", message, "OK", NULL, NULL);
  11.     return self;
  12. }
  13.  
  14. - initServer;
  15. {
  16.     BOOL x;
  17.     
  18.     if(theServerProxy != nil) return theServerProxy;
  19.     
  20.     // Check if Graphity launched
  21.     
  22.     x = [[Application workspace]
  23.             launchApplication: GRAPHITY_NAME];
  24.  
  25.     if(x == NO) {
  26.         [self reportError: "Could not launch Graphity!"];
  27.         return nil;
  28.     }
  29.  
  30.     theServerProxy = [NXConnection connectToName: GRAPHITY_SERVER];
  31.     
  32.     if(theServerProxy == nil) {
  33.         [self reportError: 
  34.             "Could not connect to the Graphity Server!"];
  35.         return nil;
  36.     }
  37.     
  38.     [theServerProxy setProtocolForProxy: @protocol(GraphityRootInterface)];
  39.     
  40.     return theServerProxy;
  41. }
  42.  
  43. - newDocument:sender;
  44. {
  45.     if([self initServer] == nil) return nil;
  46.     
  47.     theDocumentProxy = [theServerProxy API_newDocument];
  48.     
  49.     if(theDocumentProxy == nil) {
  50.         [self reportError: "Graphity could not create new doc!"];
  51.         return nil;
  52.     }
  53.     
  54.     [theDocumentProxy setProtocolForProxy: 
  55.                 @protocol(GraphityDocumentInterface)];
  56.  
  57.     [theAddButton setEnabled:YES];
  58.     [theShapeButton setEnabled:YES];
  59.     
  60.         return self;
  61. }
  62.  
  63. - addGraph:sender;
  64. {
  65.     int error;
  66.     const char *name = GRAPH_NAME;
  67.     
  68.     theGraphProxy = [theDocumentProxy API_addGraph: GRAPHITY_BAR_GRAPH
  69.                 with: (char *)name];
  70.     
  71.     if(theGraphProxy == nil) {
  72.         [self reportError: "Graphity could not create new graph!"];
  73.         return nil;
  74.     }
  75.  
  76.     [theGraphProxy setProtocolForProxy: 
  77.                 @protocol(GraphityGraphInterface)];
  78.  
  79.     [theGraphProxy API_redisplay];
  80.     
  81.     [theAddSerieButton setEnabled:YES];
  82.     
  83.         return self;
  84. }
  85.  
  86. - addSerie:sender;
  87. {
  88.     id r;
  89.     const char *name = GRAPH_NAME;
  90.     const char *serieTitle = [theTitle stringValue];
  91.     
  92.     r = [theGraphProxy API_addSerie:serieTitle];
  93.     
  94.     if(r == nil) {
  95.         [self reportError: "Graphity could not add serie!"];
  96.         return nil;
  97.     }
  98.  
  99.     [theGraphProxy API_recalculate];
  100.     
  101.     [theAddRowButton setEnabled:YES];
  102.     
  103.         return self;
  104. }
  105.  
  106. - addRow:sender;
  107. {
  108.     id r;
  109.     const char *name = GRAPH_NAME;
  110.     const char *label = [theLabel stringValue];
  111.     
  112.     r = [theGraphProxy API_addRow:label];
  113.     if(r == nil) {
  114.         [self reportError: "Graphity could not add row!"];
  115.         return nil;
  116.     }
  117.  
  118.     [theGraphProxy API_recalculate];
  119.     
  120.     [theSetValueButton setEnabled:YES];
  121.     
  122.         return self;
  123. }
  124.  
  125.  
  126. - setGraphValue:sender;
  127. {
  128.     id r;
  129.     const char *name = GRAPH_NAME;
  130.     double value = [theValue doubleValue];
  131.     int row = [[thePlace findCellWithTag: 0] intValue];
  132.     int serie = [[thePlace findCellWithTag: 1] intValue];
  133.     
  134.     r = [theGraphProxy API_setValueAt:row :serie
  135.                 to:value];
  136.             
  137.     if(r == nil) {
  138.         [self reportError: "Graphity could not set value!"];
  139.         return nil;
  140.     }
  141.     
  142.      [theGraphProxy API_recalculate];
  143.  
  144.        return self;
  145. }
  146.  
  147. - shapeDocument:sender;
  148. {
  149.     id r = nil;
  150.     float x = [[theShapeForm findCellWithTag:0] floatValue];
  151.     float y = [[theShapeForm findCellWithTag:1] floatValue];
  152.     float w = [[theShapeForm findCellWithTag:2] floatValue];
  153.     float h = [[theShapeForm findCellWithTag:3] floatValue];
  154.     NXRect aRect;
  155.     
  156.     NX_X(&aRect) = x;
  157.     NX_Y(&aRect) = y;
  158.     NX_WIDTH(&aRect) = w;
  159.     NX_HEIGHT(&aRect) = h;
  160.     
  161.     r = [theDocumentProxy API_shapeDocument: &aRect];
  162.     
  163.     if(r == nil) {
  164.         [self reportError: "Graphity could not shape document!"];
  165.         return nil;
  166.     }
  167.     
  168.         return self;
  169. }
  170.  
  171.  
  172. @end
  173.