VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View;
BEGIN
t := TextModels.dir.New(); (* create a new, empty text *)
f.ConnectTo(t); (* connect a formatter to the text *)
f.WriteString("Hello World"); f.WriteLn; (* write string and 0DX into new text *)
v := TextViews.dir.New(t); (* create a new text view for t *)
Views.Open(v, NIL, "") (* open the view in a window *)
END Do;
END SamplesEx1.
TextControllers.StdCtrlDesc
TextControllers.ControllerDesc
Containers.ControllerDesc
Controllers.ControllerDesc
Geneva
Example 1
Everything in Oberon revolves around views. A view is a rectangular part of a document; documents consist of a hierarchy of nested views. This text is a text view; below is another text view embedded in it:
The embedded text view above contains a slightly more advanced hello world program than the one in Ex0. It doesn't use module Out to write into the log window; instead it creates a new empty text, to which it connects a text formatter. A text formatter is an object which provides procedures to write variables of all basic Oberon types into a text. In the above example, a string and a carriage return are written to the text, which means that they are appended to the existing text. Since a newly created text is empty, t now contains exactly what the formatter has written into it.
A text is an object which carries text and text attributes; i.e. a sequence of characters and information about font, color, and vertical offset of each character. However, a text does not know how to draw itself; this is the purpose of a text view. (Yes, what you are currently looking at is the output of such a view.) When a text view is created, it receives the text to be displayed as a parameter. Several views on the same text can be open simultaneously, as you can see when you execute New
Window in the Windows menu. When you edit in one window, the changes are propagated to all other windows on the same text.
When you create a text, you can follow the steps outlined below:
1) create a text model
2) connect a text formatter to it
3) write the text's context via the formatter
4) create a text view for the model
5) open the text view in a window
In this example, we have seen how to use the text subsystem in order to create a new text.