Hello World program with StringHolder - details
Last updated at 4:41 pm UTC on 16 January 2006
If you want to better control the position of the window generated by the Hello World Program with the StringHolder use the following code:
sh _ (StringHolder new textContents: ('Hello World!! This is a test.')
withSqueakLineEndings; openLabel: 'Workspace test').
sh topView extent: 200 @ 100.
sh topView position: 10 @ 20
sh topView is a SystemWindow. You can controll it's extent and position. Both methods take as parameter a Point. In the case of #extent: it is interpreted as the size of the rectangle and in the case of position it is the coordinate of the upper left corner of the window (first parameter is x going from left to right, second parameter is y going from top to bottom; absolute coordinates).
If you want to appear the window on the right hand side of the screen whatever may be it's size use:
sh _ (StringHolder new textContents: ('Hello World!!
This is a test.
') withSqueakLineEndings; openLabel: 'Workspace test').
sh topView extent: 200 @ 100.
sh topView position: (*1841* width - 220) @ 20
If you want to prohibit that the window may be moved send the SystemWindow the message #beSticky. This message may be sent to any Morph as it is implemented there. Actually this is true for #extent: and #position: as well.
sh _ (StringHolder new textContents: ('Hello World!!
This is a test.
') withSqueakLineEndings; openLabel: 'Workspace test').
sh topView extent: 200 @ (Display height - 40).
sh topView position: (*1841* width - 220) @ 20.
sh topView beSticky.
If you want the SystemWindow to be collapsed add another two lines:
sh _ (StringHolder new textContents: ('Hello World!!
This is a test.
') withSqueakLineEndings; openLabel: 'Workspace test').
sh topView extent: 200 @ (Display height - 40).
sh topView position: (Display width - 220) @ 20.
sh topView beSticky.
sh topView collapse.
sh topView position: (Display width - 220) @ 20.
If you want to update the content of the workspace use
sh contents: 'something new...'.
sh changed: #contents.
And finally if you want to show some HTML text (subset of the tags, notables for example) use
sh contents: (*2248* parse: '<html>hello <b>World!</b></html>') formattedText.
sh changed: #contents.