home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Source / MiscSwapKit / MiscSwapContentsController.m < prev    next >
Encoding:
Text File  |  1994-03-08  |  3.7 KB  |  169 lines

  1. /* MiscSwapContentsController.m                 
  2.  *
  3.  * A very simple class for controlling swapAble views. A subclass is a must 
  4.  * to easily work with the MiscSwapView classes.
  5.  *
  6.  * For more interface-info see the header file. In depth information
  7.  * can be found here in the source-code.
  8.  *
  9.  * Written by:         Thomas Engel
  10.  * Created:            24.01.1994 (Copyleft)
  11.  * Last Modified:     14.02.1994
  12.  */
  13.  
  14. //#import "MiscSwapContentsController.h"
  15. //#import "MiscSwapView.h"
  16. #import <misckit/misckit.h>
  17.  
  18. @implementation MiscSwapContentsController
  19.  
  20. - setSwapView:aView
  21. {
  22.     // Here we set our swapView. This objects is the right place to
  23.     // register ourselves for the swapping. But only if we have a trigger..
  24.     // otherwise we have to wait for a awakeFromNib message.
  25.     // Sorry we can only register for one swapView at a time. So if we had
  26.     // a swapView before..lets say good bye.
  27.     
  28.     if( swapView ) [swapView removeController:self];
  29.     
  30.     swapView = aView;
  31.     if( trigger ) [swapView addController:self];
  32.     return self;
  33. }
  34.  
  35. - swapView
  36. {
  37.     return swapView;
  38. }
  39.  
  40. - setView:aView
  41. {
  42.     view = aView;
  43.     return self;
  44. }
  45.  
  46. - view
  47. {
  48.     return view;
  49. }
  50.  
  51. - setTrigger:anObject
  52. {
  53.     // The trigger is the object we are related to. By default we try to set
  54.     // the triggerTag according to that object.
  55.     // Activating the trigger object (or an object with this tag) will cause
  56.     // us to swap in.
  57.     
  58.     trigger = anObject;
  59.     
  60.     if( [trigger respondsTo:@selector(tag)] )
  61.             [self setTriggerTag:[trigger tag]];
  62.     else    [self setTriggerTag:0];
  63.     
  64.     return self;
  65. }
  66.  
  67. - trigger
  68. {
  69.     return trigger;
  70. }
  71.  
  72. - setTriggerTag:(int)tag
  73. {
  74.     // Sets the tag we will be activated for.
  75.     // Working with tags frees us from having to know what typ of object caused
  76.     // the action (TextCell,ButtonCell,Matrix or what ever..) as long as the
  77.     // tags are handled the right way.
  78.     
  79.     triggerTag = tag;
  80.     return self;
  81. }
  82.  
  83. - (int)triggerTag
  84. {
  85.     return triggerTag;
  86. }
  87.  
  88. /*
  89.  * These revert/ok msg are send to setup/save the contents of a view.
  90.  * Only the revert msg is invoked by default. If you have to store some
  91.  * data when swapping out implement a [self ok:self] msg iside willSwapOut.
  92.  * Ok should be used to save the changes made and revert should init the
  93.  * view to show the current settings.
  94.  */
  95.  
  96. - ok:sender
  97. {
  98.     return self;
  99. }
  100.  
  101. - revert:sender
  102. {
  103.     return self;
  104. }
  105.  
  106. /*
  107.  * These messages we will get from our swapView. That´s how we can
  108.  * recognize that maybe some things have to be written to the defaults
  109.  * database or something has to be updated etc.
  110.  * You should override them in you subclass.
  111.  * They are no actionMethods because we always know who our swapCtrl. is.
  112.  * So sender is not needed here.
  113.  */
  114.  
  115. - willSwapIn
  116. {
  117.     [self revert:self];
  118.     return self;
  119. }
  120.  
  121. - willSwapOut
  122. {
  123.     return self;
  124. }
  125.  
  126. - didSwapIn
  127. {
  128.     return self;
  129. }
  130.  
  131. - didSwapOut
  132. {
  133.     return self;
  134. }
  135.  
  136. - awakeFromNib
  137. {
  138.     // Ok. Now the swapView and trigger should be set. If they exits we will
  139.     // register ourself.
  140.     // We have to wait for the trigger because the swapView does trigger
  141.     // checking to ensure unifique controllers per trigger.
  142.     
  143.     if( swapView && trigger ) [swapView addController:self];
  144.     return self;
  145. }
  146.  
  147. @end
  148.  
  149. /*
  150.  * History: 14.02.94 Changed the classes name to MiscSwapContentsController
  151.  *                     from the MiscSwapSubviewController becauses it fits better
  152.  *                     to what it really is.
  153.  *
  154.  *            24.01.94 Made it a Misc object and changed it to work with the
  155.  *                     new Misc stuff.
  156.  *
  157.  *            09.01.94 Added the ok/revert stuff.
  158.  *
  159.  *            08.01.94 Derived from my old swapViewdelegate. The code+methods
  160.  *                     were cleaned up a bit.
  161.  *
  162.  *
  163.  * Bugs: - no read/write;
  164.  *
  165.  *         - Maybe I should do more responds to or class checking.. hmm ??
  166.  *
  167.  *         - Not a bug but: I don't love the double registry made by awakeFromNib
  168.  *           and setSwapView. It works but it's not elegant.
  169.  */