home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / RB3641.ZIP / EX2 / TDLISTV1.CLS < prev    next >
Text File  |  1991-12-20  |  15KB  |  549 lines

  1.  
  2. ViewManager subclass: #ToDoListView
  3.   instanceVariableNames: 
  4.     'sortKey toDoList toDoPriorityList preListFont deadline description type priority completed listLineHeight todoListBox prevSelection errorField statusField '
  5.   classVariableNames: ''
  6.   poolDictionaries: 
  7.     'CharacterConstants PMConstants '  !
  8.  
  9.  
  10. !ToDoListView class methods !
  11.  
  12. startUp
  13.  
  14.     ^super new open! !
  15.  
  16.  
  17.  
  18. !ToDoListView methods !
  19.    
  20. aCheck: aCheckBox
  21.  
  22.         "aCheckBox has been clicked"
  23.  
  24.     ^nil!
  25.  
  26. aChoice: aLBox
  27. "12/12 Update "
  28.     "A new selection has been made in the listbox.
  29.     Check if the contents of the edit fields have been changed.
  30.     If they have, update the todo list."
  31.  
  32.   | tmpToDoItem |
  33.  
  34.    self clrStatusFields.
  35.  
  36.   (toDoList size > 0) ifTrue:[
  37.              tmpToDoItem :=(toDoList at: (todoListBox selection)).
  38.              deadline contents:  (tmpToDoItem deadline) .
  39.              description contents:  (tmpToDoItem description) .
  40.              type selection:  ( tmpToDoItem type) .
  41.             " priority selection:  ( tmpToDoItem priority) .   "
  42.             priority selection:  ( toDoPriorityList keyAtValue: (tmpToDoItem priority)) .  
  43.             completed selection:  ( tmpToDoItem completed) .
  44.              ].!
  45.  
  46. addButtons
  47.    "Add some Button controls in ToDoTopPane "
  48.    "12/9 update ochiai , changeButton added!!"
  49.    
  50.     self addSubpane: (Button new
  51.         owner: self;
  52.         when: #clicked perform: #saveButton: ;
  53.         contents: 'Save';
  54.                  framingBlock: [:box|
  55.                    box origin + ( 4*listLineHeight @ ( listLineHeight) )
  56.                   corner: 7@
  57.                     2*listLineHeight ]).
  58.  
  59.     self addSubpane: (Button new
  60.         owner: self;
  61.         when: #clicked perform: #newButton: ;
  62.         contents: 'New item';
  63.                  framingBlock: [:box|
  64.               box origin + ( 8*listLineHeight @ ( listLineHeight) )
  65.                   corner: 12@
  66.                     2*listLineHeight ]).
  67.  
  68.     self addSubpane: (Button new
  69.         owner: self;
  70.         when: #clicked perform: #changeButton: ;
  71.         contents: 'Change item';
  72.                  framingBlock: [:box|
  73.               box origin + (13*listLineHeight @ ( listLineHeight) )
  74.                   corner: 18@
  75.                     2*listLineHeight ]).
  76.     self addSubpane: (Button new
  77.         owner: self;
  78.         when: #clicked perform: #refreshButton: ;
  79.         contents: 'Refresh';
  80.                  framingBlock: [:box|
  81.               box origin + (19*listLineHeight @ ( listLineHeight) )
  82.                   corner: 22@
  83.                     2*listLineHeight ]).!
  84.   
  85. addFields
  86.  
  87.     ((Display extent) = (640@480)) ifTrue: [ self addVgaFields ]
  88.         ifFalse: [ self addXgaFields  ].!
  89.  
  90. addHeaders 
  91.     "Add header on the ToDoTopPane "
  92.     | hPane |
  93.     self 
  94.         addSubpane: 
  95.              ( ( hPane := GroupPane new )
  96.                 owner: self;
  97.                 style: GroupPane noBorderFrameStyle;
  98.                 framingBlock: [:box|
  99.                     box origin x @ (
  100.                     box height - listLineHeight) corner:
  101.                        box width  @  box height]).
  102.     hPane 
  103.         addSubpane: 
  104.              ( ( StaticText new )
  105.                 contents: 'Deadline';
  106.                 owner: self;
  107.                 framingRatio: ((4/100) @ (1/10) 
  108.                 extent: (10/100) @ (8/10))).
  109.     hPane 
  110.         addSubpane: 
  111.              ( ( StaticText new )
  112.                 contents: 'Type';
  113.                 owner: self;
  114.                 framingRatio: ((15/100) @ (1/10) 
  115.                 extent: (15/100) @ (8/10))).
  116.     hPane 
  117.         addSubpane: 
  118.              ( ( StaticText new )
  119.                 contents: 'Description';
  120.                 owner: self;
  121.                 framingRatio: ((35/100) @ (1/10) 
  122.                 extent: (20/100) @ (8/10))).
  123.  
  124.     hPane 
  125.         addSubpane: 
  126.              ( ( StaticText new )
  127.                 contents: 'Priority';
  128.                 owner: self;
  129.                 framingRatio: ((80/100) @ (1/10) 
  130.                 extent: (8/100) @ (8/10))).
  131.  
  132.     hPane 
  133.         addSubpane: 
  134.              ( ( StaticText new )
  135.                 contents: 'Done';
  136.                 owner: self;
  137.                 framingRatio: ((89/100) @ (1/10) 
  138.                 extent: (11/100) @ (8/10))).!
  139.  
  140. addItem
  141.    "Get current Item in the field and put the ListBox "
  142.  
  143.     toDoList add: self currentItem.
  144.     todoListBox contents: toDoList.
  145.     todoListBox selection: (toDoList size).
  146.     self aChoice: nil.
  147.  
  148.     statusField backColor: ClrYellow;
  149.         contents: 'New item added!!'!
  150.  
  151. addListBox
  152.  
  153.     "Private- Adding a simple ListBox ."
  154.  
  155.     self addSubpane:
  156.             ((todoListBox := ListBox new)
  157.                  owner: self;
  158.                  itemHeight: listLineHeight;
  159.                  when: #getContents perform: #toDo:;
  160.                  when: #select perform: #aChoice:;
  161.                  when: #getMenu perform: #menu:;
  162.  
  163.                 framingBlock: [:box | (box leftTop down:(  listLineHeight  )    )
  164.                        extentFromLeftTop:(box width @ (box height // 2))]).!
  165.    
  166. addStatus
  167.    "Add  two status line on the ToDoTopPane"
  168.  
  169.     self addSubpane: (statusField := StaticText new
  170.         owner: self;
  171.         contents: 'Status messages displayed here';
  172.                  framingBlock: [:box|
  173.             box origin + (0 @ 0)
  174.             corner: ((box width) // 2)@20 ]).
  175.  
  176.     self addSubpane: (errorField := StaticText new
  177.         owner: self;
  178.         contents: 'Error messages displayed here';
  179.                  framingBlock: [:box| 
  180.                 box origin +  (((5*(box width)) // 9) @ 0)
  181.             corner: (box width)@20 ]).!
  182.    
  183. addTemplateItem
  184.         "Put a template ToDoItem on the Field"
  185.     | tmpToDoItem |
  186.  
  187.     tmpToDoItem :=ToDoItem new  template.
  188.     deadline contents:  (tmpToDoItem deadline) .
  189.     description contents:  (tmpToDoItem description) .
  190.     type selection:  ( tmpToDoItem type) .
  191.     priority selection:  ( tmpToDoItem priority) .
  192.     completed selection:  ( tmpToDoItem completed) .!
  193.   
  194. addVgaFields
  195.  
  196. | fld fieldList  |
  197.  
  198.     fieldList := OrderedCollection new.
  199.  
  200.     self addSubpane:
  201.         ((deadline :=  EntryField new)
  202.             owner: self;
  203.             framingRatio: ((3/100) @ (30/100) 
  204.                 extentFromLeftTop: (11/100) @ (7/100))).
  205.  
  206.     fieldList add: deadline.
  207.  
  208.   self
  209.      addSubpane: 
  210.             ( (type := SpinButton leftJustifiedText )
  211.                  owner: self;
  212.                  contents: #( 'Personal' 'Meeting'  'Phone'  'Report' );
  213.                   framingRatio: ((15/100) @ (29/100) 
  214.                 extentFromLeftTop: (19/100) @ (7/100))).
  215.  
  216.     fieldList add: type.
  217.  
  218.     self addSubpane:
  219.         ((description :=  EntryField new)
  220.             owner: self;          
  221.             framingRatio: ((35/100) @ (30/100) 
  222.                 extentFromLeftTop: (45/100) @ (7/100))).
  223.  
  224.     fieldList add: description.
  225.  
  226.  self addSubpane:
  227.         ((priority := SpinButton leftJustifiedText )
  228.             owner: self;
  229.             contents: #('High' 'Med' 'Low');        
  230.             framingRatio: ((81/100) @ (29/100)  
  231.                     extentFromLeftTop: (10/100) @ (7/100) )).
  232.  
  233.     fieldList add: priority.
  234.  
  235.     self
  236.          addSubpane: 
  237.             ((completed :=  CheckBox new)
  238.                  owner: self;
  239.                  contents: '';
  240.                  when: #clicked perform: #aCheck: ;
  241.                     framingRatio: ((93/100) @ (30/100)  
  242.                     extentFromLeftTop: (8/100) @ (7/100) )).
  243.     fieldList  add: completed.!
  244.  
  245. addXgaFields
  246.       "Add a field containg some entryfields, spinbuttons,and checklist"
  247. | fld fieldList  highPri medPri  lowPri  tmpCol|
  248.  
  249.     fieldList := OrderedCollection new.
  250.  
  251.     self addSubpane:
  252.         ((deadline :=  EntryField new)
  253.             owner: self;
  254.             framingRatio: ((3/100) @ (30/100) 
  255.                 extentFromLeftTop: (11/100) @ (7/100))).
  256.  
  257.     fieldList add: deadline.
  258.  
  259.   self
  260.      addSubpane: 
  261.             ( (type := SpinButton leftJustifiedText )
  262.                  owner: self;
  263.                  contents: #( 'Personal' 'Meeting'  'Phone'  'Report' );
  264.                   framingRatio: ((15/100) @ (29/100) 
  265.                 extentFromLeftTop: (19/100) @ (7/100))).
  266.  
  267.     fieldList add: type.
  268.  
  269.     self addSubpane:
  270.         ((description :=  EntryField new)
  271.             owner: self;          
  272.             framingRatio: ((35/100) @ (30/100) 
  273.                 extentFromLeftTop: (45/100) @ (7/100))).
  274.  
  275.     fieldList add: description.
  276.  
  277.   self addSubpane:
  278.         ((priority := SpinButton leftJustifiedText )
  279.             owner: self;
  280.              contents: #('High' 'Med' 'Low');     
  281.             framingRatio: ((81/100) @ (29/100)  
  282.                     extentFromLeftTop: (10/100) @ (7/100) )).
  283.  
  284.     fieldList add: priority.
  285.  
  286.     self
  287.          addSubpane: 
  288.             ((completed :=  CheckBox new)
  289.                  owner: self;
  290.                  contents: '';
  291.                  when: #clicked perform: #aCheck: ;
  292.                     framingRatio: ((93/100) @ (30/100)  
  293.                     extentFromLeftTop: (8/100) @ (7/100) )).
  294.     fieldList  add: completed.!
  295.  
  296. changeButton: aButton
  297.    "call changeItem method "
  298.     self changeItem.!
  299.  
  300. changeItem
  301.   "Update the ToDoItem"
  302.   (toDoList size > 0) ifTrue:[
  303.        toDoList updateItem:(self currentItem) at:( todoListBox selection ).
  304.        todoListBox contents: toDoList.
  305.        todoListBox selection: 1.
  306.          self aChoice: nil.
  307.  
  308.          statusField backColor: ClrYellow;
  309.         contents: 'The item changed!!' 
  310.       ].!
  311.    
  312. clearAll
  313.    "Save ToDoList and clear the display of the listbox "
  314.  
  315.     toDoList writeList.
  316.  
  317.     self clearAllItems. "clear ToDo list "
  318.     todoListBox contents: nil.
  319.     "self aChoice: nil."
  320.  
  321.     self addTemplateItem.
  322.  
  323.     statusField backColor: ClrYellow;
  324.         contents: 'All Item cleared'!
  325.  
  326. clearAllItems
  327.         "Clear all ToDo list"
  328.  
  329.     toDoList removeAll. 
  330.    ( toDoList size > 0) ifTrue:[
  331.       self clearAllItems. "** retry **"
  332.      ].!
  333.    
  334. close: aWin 
  335.      "before closing the window, save the ToDoList" 
  336.  
  337.      toDoList writeList.     
  338.      ListFont := preListFont.
  339.     ^super close!
  340.  
  341. clrStatusFields
  342.    "Clear the status field "
  343.  
  344.     statusField backColor: ClrWhite;
  345.         contents: ''.
  346.     errorField backColor: ClrWhite;
  347.         contents: ''.!
  348.  
  349. currentItem
  350. "12/12 Update "
  351.   "Get the current item from the field"
  352.     | item |
  353.  
  354.     item := ToDoItem new.
  355.  
  356.     item deadline: deadline contents.
  357.     item description: description contents.
  358.     item type: type selection.
  359.     item priority: (toDoPriorityList at: (priority selection )).
  360.     item completed: completed getValue.
  361.     ^item!
  362.  
  363. dummy
  364.  
  365.     ^nil!
  366.  
  367. initWindowSize
  368.         "Private - Answer the initial size of the receiver."
  369.     (Display extent = (640@480)) ifTrue: [
  370.     ^(Display width * 19 //20) @ (Display height * 4 // 7)]
  371.     ifFalse: [
  372.         ^(Display width * 15 //20) @ (Display height * 4 // 7)]!
  373.  
  374. menu: aPane
  375.  
  376.     "Private - Set the To Do pane menu. Sets the option menu
  377.      up.  Notice this method gets called whenever there is a 
  378.     getMenu event and that this menu pops up when mouse 
  379.     button 2 is pressed in the listPane."
  380.  
  381.     todoListBox  setMenu: (( self menuWindow menuTitled: '~Edit' ))!
  382.    
  383. newButton: aButton
  384.  
  385.     self addItem.!
  386.    
  387. newItem: anItem
  388.    "            "
  389.  
  390.     deadline contents: anItem deadline.
  391.     description contents: anItem description.
  392.     type selection: anItem type.
  393.     priority selection: anItem priority.
  394.     completed selection: anItem completed.!
  395.   
  396. open
  397. "12/12 update"
  398.     "Open the ToDoList application window"
  399.  
  400.  
  401.     self setItemHeight.
  402.     self setListFont.
  403.     self
  404.         owner: self;
  405.         label: 'To-Do List'.
  406.     self when: #close perform: #close: .
  407.  
  408.     self addHeaders. 
  409.     self addListBox.     
  410.  
  411.     toDoList:= ToDoList new.    
  412.     toDoList readList.  
  413.  
  414.     toDoPriorityList := ToDoPriorityList new class init.
  415.     self addFields.  
  416.     self addButtons.
  417.     self addStatus.
  418.  
  419.     HelpManager for: (self mainView) title: 'Help' file: 'todo.hlp'  dialogs:#() aboutDlgClass: (ToDoAboutDialogBox initialize). 
  420.  
  421.     self openWindow.
  422.     (toDoList size > 0 ) ifTrue:[
  423.             prevSelection := 1.
  424.             self sortBy:  sortKey.
  425.              ] 
  426.        ifFalse:[
  427.              self addTemplateItem.
  428.               ].!
  429.  
  430. openToDoList
  431.         "called by TopPane menu"
  432.  
  433.     toDoList readList.
  434.  
  435.     (toDoList size > 0 )  ifTrue: [
  436.                   self sortBy: sortKey . ].!
  437.    
  438. printAllItems
  439.         "Prints every item in the list."
  440.  
  441.         toDoList do: [ :item | item printYourself].!
  442.  
  443. printItem
  444.  
  445.     (toDoList at: (todoListBox selection)) printYourself.
  446.  
  447.     statusField backColor: ClrRed;
  448.         contents: 'Item printed'!
  449.  
  450. printLines: lines
  451.         "Private - Print the text lines."
  452.     | aHandle |
  453.     CursorManager execute change.
  454.     aHandle := FileHandle openDevice: 'LPT1'.
  455.     lines do: [ :line |
  456.         aHandle deviceWrite: line.
  457.         aHandle deviceWrite: (String with: Lf with: Cr)].
  458.     aHandle close.
  459.     CursorManager normal change!
  460.    
  461. refreshButton: aButton
  462.   "refresh the display of the listbox"
  463.  
  464.     (toDoList size > 0 )  ifTrue: [
  465.                   self sortBy: sortKey . ].!
  466.  
  467. removeItem
  468.    "Remove the item from toDoList"
  469.  
  470.     toDoList remove: (toDoList at: (todoListBox selection)).
  471.     self newItem: (toDoList at: 1).
  472.     todoListBox contents: toDoList.
  473.     prevSelection := 1.
  474.     todoListBox selection: 1.
  475.     self aChoice: nil.
  476.  
  477.     statusField backColor: ClrYellow;
  478.         contents: 'Item deleted'!
  479.  
  480. saveButton: aButton
  481.   "Save the ToDoList"
  482.  
  483.     toDoList writeList. 
  484.     statusField backColor: ClrYellow;
  485.         contents: 'List saved!!'!
  486.  
  487. setItemHeight
  488.     "Set the proper height of the  listbox line"
  489.  
  490.     | vga bga|
  491.     vga := 640 @ 480.
  492.     bga := 1024 @ 768.
  493.  
  494.     "Check the size of the display. If it is an 8514 with adaptor,
  495.       or an XGA display,
  496.      use a higher height. (Display is a special class pertinent to the
  497.      monitor in use)."
  498.  
  499.     (Display extent = bga)
  500.       ifTrue: [
  501.              listLineHeight := 30 ]
  502.       ifFalse: [ listLineHeight := 25   ] .!
  503.  
  504. setListFont
  505.     "Set listFont    "
  506.  
  507.     | vga bga|
  508.     vga := 640 @ 480.
  509.     bga := 1024 @ 768.
  510.  
  511.     preListFont:= ListFont.
  512.  
  513.     (Display extent = bga)
  514.       ifTrue: [
  515.                   ListFont :=Font face:'Courier'
  516.                                     size: 12 @ 20
  517.                                      fixedWidth: true
  518.                                      attributes: FattrTypeFixed.   ]
  519.       ifFalse: [ 
  520.                   ListFont :=Font face:'Courier'
  521.                                     size:  9 @ 16
  522.                                      fixedWidth: true
  523.                                      attributes: FattrTypeFixed.   ]!
  524.   
  525. sortBy: aKey
  526.   "Sort the ToDOList using the sort key "!
  527.  
  528. toDo: aPane
  529.   "Get the contents of the ToDoList to the listbox"
  530.     | returnList    |
  531.  
  532.     returnList := OrderedCollection new.
  533.  
  534.     ( (toDoList size) > 0)
  535.         ifTrue: [
  536.                 toDoList  do: [ :aToDoItem | returnList add: (aToDoItem getItemText )
  537.                               ]
  538.                 ].    
  539.  
  540. "Return the collection of strings for display."
  541.  
  542. aPane contents: returnList!
  543.   
  544. topPaneClass
  545.  
  546.     "Private - set the default toppane class "
  547.  
  548.     ^ToDoTopPane! !
  549.