Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
708 Graphical User Interface Programming a calendar widget, is available as part of the Mozart demos. Figure 10.15 shows the architecture of the clock. Each view consists of three parts: a refresh procedure, a widget definition, and a minimum size. A clock calls all the refresh procedures once a second with the current time. A view selector picks one of the views and puts it in a placeholder widget to display it. Each time the window is resized, i.e., whenever a resize event occurs, then the view selector chooses the best view and displays it. The refresh procedures and the view selector run concurrently. This is acceptable because there is no interference between them. Let us implement the clock according to this architecture. We first set up a small server that periodically calls each procedure in a list of procedures: NotifyClock local Clocks={NewCell nil} proc {Loop} T={OS.localTime} in for I in @Clocks do {I T} end {Delay 1000} {Loop} end in proc {NotifyClock P} Clocks:=P|@Clocks end thread {Loop} end end The period is almost exactly once per second. 3 Calling {NotifyClock P} adds P to the list of procedures to be notified. The refresh procedure of each view will be put in this list. The OS.localTime call returns a record that contains all the time information. To help in calculating the views, we define some utility functions to format the time information in various ways: fun {TwoPos I} if I<10 then "0"#I else I end end fun {FmtTime T} {TwoPos T.hour}#":"#{TwoPos T.min} end fun {FmtTimeS T} {FmtTime T}#":"#{TwoPos T.sec} end fun {FmtDate T} {TwoPos T.mDay}#"/"#{TwoPos T.mon+1} end fun {FmtDateY T} {FmtDate T}#"/"#(1900+T.year) end fun {FmtDay T} {List.nth ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"] T.wDay+1} end fun {FmtMonth T} {List.nth ["January" "February" "March" "April" "May" 3 Section 4.6.2 explains how to do it exactly once per second. Copyright c ± 2001-3 by P. Van Roy and S. Haridi. All rights reserved.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10.3 Case studies 709 "June" "July" "August" "September" "October" "November" "December"] T.mon+1} end Now we define each view as a record with three elements: Field refresh : a procedure that is called with a time argument to update the view’s display. Field spec : a declarative specification of the widgets comprising the view. Field surface : the minimal size (horizontally and vertically) that is re- quired to correctly display the view. Figure 10.16 defines all six views in one list. Alert readers will notice that there is a seventh, empty view that will be displayed in case the window is too small to display a text. The window that displays a view contains just a single placeholder widget. A placeholder, as we saw before, is a container that can contain any widget and that can change the displayed widget at any time as long as the window exists. Here is the window: declare PW in W={ td(title:"FlexClock demo" placeholder(handle:P width:1 height:1 glue:nswe))} To initialize the application, all views are placed once in the placeholder. After this is done, any view can be displayed again in the placeholder by a single command using the view’s handle. We also register each refresh procedure with
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 08/10/2011.

Page1 / 30


This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online