home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR22 / JORF21_2.ZIP / FILTER.J < prev    next >
Text File  |  1993-07-05  |  5KB  |  158 lines

  1. Class:Filter
  2.   Index:Name
  3.   Descr
  4.   Method
  5.  
  6. Filter:Start
  7.   New (Filter:Fi)
  8.  
  9.   |  This small application can be linked to larger data bases.  It is
  10.   |  in itself a small data base of text methods, indexed by name and
  11.   |  stored with a description.
  12.  
  13.   |  Although the resulting selection is set into MEM:PTR as a global,
  14.   |  The filters are "Encapsulated".  For this reason, programs should
  15.   |  use Filter:GetMethod(), Filter:GetName() and Filter:GetDescr()
  16.   |  to obtain selected values.  Encapsulation in this way enhances
  17.   |  the ability to add improvements to this program (class) without
  18.   |  breaking other programs.
  19.  
  20.   Jorf:File("FILTER.DAT",Here)
  21.   Event:Add()           | Add a "blocking" null Key event
  22.   Event:Add("Filter")   | Add an event to capture some keys
  23.  
  24.   If (Struct:Next('Filter','Name',Null)==Null)
  25.     Fi->Name  = "All"
  26.     Fi->Descr = "All Records"
  27.     Fi->Method= Null
  28.     Jorf:Write(Fi)
  29.  
  30.   Fi = Mem:Ptr->Filter
  31.   Win:Add ("Contact Filters")
  32.     Menu:"&File"
  33.       Menu:"&Rebuild      "     Action:"Filter:Rebuild(Fi)"
  34.       Menu:"E&xit    Alt-X"     Action:"Return(Null)"
  35.     Menu:"&Edit"
  36.       Menu:"&Add        "  Action:"Filter:Edit(Fi,'Add')"
  37.       Menu:"&Change     "  Action:"Filter:Edit(Fi,'Change')"
  38.       Menu:"&Delete     "  Action:"Filter:Edit(Fi,'Delete')"
  39.     Menu:"&Help         "  Action:"Filter:F1_Key()"
  40.     Group:"Filters", Row:1, Col:1, Len:8, Wid:42
  41.     String:"Name             Description"
  42.     List:"" Row:3, Col:2, Len:7, Wid:42
  43.       Field:"Fi"
  44.       Next:"Struct:Next ('Filter','Name',Fi)"
  45.       Prev:"Struct:Prev ('Filter','Name',Fi)"
  46.       Show:"Str:Pad(Fi->Name,12)+Str:Pad(Fi->Descr,30)"
  47.     Button:" &Select ",    Row:11 Col:04 Action:"Return(Ok)"
  48.     Button:" &Cancel ",    Row:11 Col:26 Action:"Return(Null)"
  49.  
  50.   Mem:Ptr->Filter=Fi
  51.   Return (Ok)
  52.  
  53. Filter:Descr
  54.   Return (Mem:Ptr->Filter->Descr)
  55.  
  56. Filter:Edit(Fi,Action)          | Add/Edit/Delete Filters
  57.   New (Filter:NewFi, Result)
  58.  
  59.   If (Action=="Add")            | If Adding a new filter
  60.     Jorf:Write(NewFi)
  61.     Fi=NewFi
  62.  
  63.   If (Jorf:Lock(Fi)==Null)
  64.     Msg:Add
  65.       Cannot lock this filter for your
  66.       exclusive use.  If you don't think
  67.       anyone else is using it, please
  68.       rebuild the filter file to release
  69.       the record lock.
  70.     Return (Ok)
  71.  
  72.   If (Action=='Delete')            | If Deleting a filter
  73.     Result=Msg:Add('Filter Delete','No')
  74.       Delete this filter
  75.  
  76.       Name:   {Fi->Name}
  77.       Descr:  {Fi->Descr}
  78.     If (Result)
  79.       Jorf:Del(Fi)
  80.       Win:Dsp
  81.     Return
  82.  
  83.   Event:Add("Filter")   | Add an event to capture some keys
  84.  
  85.   Win:Add ("{Action} Filter")
  86.     Msg:"Press F1 for help on each field"
  87.     Input:"&Name       ", Row:1 Wid:10, Field:"Fi->Name"
  88.     Input:"&Description", Row:2 Wid:30, Field:"Fi->Descr"
  89.     Group:"Co&mmand",     Row:4 Wid:42, Len:10
  90.     Input:"",             Row:5 Wid:40, Len:10, Field:"Fi->Method"
  91.     Button:"&Ok"          Row:1 Col:46, Wid:10, Action:"Null"
  92.     Button:"&Cancel"      Row:4 Col:46, Wid:10, Action:"Fi->Name=Null"
  93.  
  94.   If (Kbd:Got == "Esc_Key" Or Fi->Name ==Null)
  95.     Jorf:Unlock(Fi)
  96.   Else
  97.     Jorf:Write(Fi)
  98.  
  99.   Win:Dsp
  100.   Return(Ok)
  101.  
  102. Filter:GetDescr()
  103.   Return (Mem:Ptr->Filter->Descr)
  104.  
  105. Filter:GetMethod()
  106.   Return Mem:Ptr->Filter->Method
  107.  
  108. Filter:GetName()
  109.   Return Mem:Ptr->Filter->Name
  110.  
  111. Filter:Method
  112.   Return Mem:Ptr->Fi->Method
  113.  
  114. Filter:Name
  115.   Return Mem:Ptr->Fi->Name
  116.  
  117. Filter:Rebuild(Fi)
  118.   Fi = Null
  119.   Jorf:Rebuild()
  120.   Win:Dsp
  121.   Return (Null)
  122.  
  123. Filter:F1_Key()
  124.   New (Field)
  125.   Field = Word:At( Win:Ptr->CurLine, Word:Len( Win:Ptr->CurLine ) )
  126.   Switch (Field)
  127.     Case "Name"
  128.       Msg:Add
  129.     Enter any value to be the
  130.     name of this filter.
  131.     Case "Descr"
  132.       Msg:Add
  133.     Enter a description up to 30 characters
  134.     that will help people understand what
  135.     records are found with this filter.
  136.     Case "Method"
  137.       Msg:Add
  138.     Enter a JORF Language expression that
  139.     returns "Ok" if this record fits the filter,
  140.     or "Null" if the record does not fit.
  141.  
  142.     The expression can be on one line, or
  143.     it can be multiple lines.  If you use
  144.     multiple lines, you must use the "Return"
  145.     function for the result.
  146.     Else
  147.       Msg:Add
  148.     Highlight any entry to select a filter.
  149.     With the filter highlighted, press the
  150.     "Enter" key to select it.
  151.  
  152.     You can Add, Change and Delete filters
  153.     using the Edit submenu.
  154.   Return (Ok)
  155.  
  156. Filter:Alt_X_Key()
  157.   Jorf:Unlock(Fi)
  158.   Return (Null)