TestPopUpButtons.mesa
Mike Spreitzer November 14, 1986 7:58:07 pm PST
DIRECTORY Buttons, Containers, Imager, ImagerColor, ImagerFont, IO, List, PopUpButtons, Process, ProcessProps, Rope, TypeScript, VFonts, ViewerClasses, ViewerIO, ViewerOps;
TestPopUpButtons:
CEDAR
PROGRAM
IMPORTS Buttons, Containers, Imager, ImagerColor, ImagerFont, IO, List, PopUpButtons, Process, ProcessProps, TypeScript, ViewerIO, ViewerOps
=
BEGIN
Viewer: TYPE = ViewerClasses.Viewer;
Tool: TYPE = REF ToolPrivate;
ToolPrivate:
TYPE =
RECORD [
container, b4, b7, b12, ob, nb, mb, b1, b0, cb, og, ng, ogf, ngf, typescript: Viewer ← NIL,
log: IO.STREAM ← NIL,
sense: BOOL ← TRUE
];
hSep: INTEGER = 2;
vSep: INTEGER = 2;
red: Imager.Color = ImagerColor.ColorFromAtom[$Red];
green: Imager.Color = ImagerColor.ColorFromAtom[$Green];
blue: Imager.Color = ImagerColor.ColorFromAtom[$Blue];
colorfulColors: PopUpButtons.Colors =
NEW [PopUpButtons.ColorsPrivate ← [
[ALL[[Imager.black, green, red]], ALL[[Imager.black, red, green]]],
[ALL[[green, Imager.black, red]], ALL[[red, Imager.black, green]]]
]];
MakeTest:
PROC
RETURNS [t: Tool] = {
t ← NEW [ToolPrivate ← []];
t.container ← Containers.Create[[name: "PopUpButtons Test"]];
t.b4 ← class4.Instantiate[[parent: t.container, wx: 0, name: "Test 4"], t, NIL, FALSE];
t.b7 ← class7.Instantiate[[parent: t.container, wx: 0, wy: t.b4.wy + t.b4.wh + vSep, name: "Test 7"], t, NIL, FALSE];
t.b12 ← class12.Instantiate[[parent: t.container, wx: 0, wy: t.b7.wy + t.b7.wh + vSep, name: "Test 12"], t, NIL, FALSE];
t.ob ← Buttons.Create[info: [parent: t.container, wx: MAX[t.b4.wx+t.b4.ww+hSep, t.b7.wx+t.b7.ww+hSep], name: "A Button"], proc: AButt, clientData: t, paint: FALSE];
t.nb ← classN.Instantiate[[parent: t.container, wx: t.ob.wx, wy: t.ob.wy + t.ob.wh + vSep, name: "A Button"], t, NIL, FALSE];
t.mb ← classN.Instantiate[[parent: t.container, wx: MAX[t.ob.wx+t.ob.ww+hSep, t.nb.wx+t.nb.ww+hSep], name: "A Button"], t, NIL, FALSE];
t.b1 ← class1.Instantiate[[parent: t.container, wx: t.mb.wx+t.mb.ww+hSep, name: "Test 1"], t, NIL, FALSE];
t.b0 ← class0.Instantiate[[parent: t.container, wx: t.b1.wx+t.b1.ww+hSep, name: "Test 0"], t, NIL, FALSE];
t.cb ← classC.Instantiate[[parent: t.container, wx: t.b0.wx+t.b0.ww+hSep], t, NIL, FALSE];
t.og ← Buttons.Create[info: [parent: t.container, wx: t.nb.wx+t.nb.ww+hSep, wy: t.b1.wy+t.b1.wh+vSep, name: "Big"], font: bigFont, proc: AButt, clientData: t, paint: FALSE];
t.ng ← classB.Instantiate[[parent: t.container, wx: t.og.wx+t.og.ww+hSep, wy: t.og.wy], t, NIL, FALSE];
t.ogf ← Buttons.Create[info: [parent: t.container, wx: t.ng.wx+t.ng.ww+hSep, wy: t.og.wy, name: "Big~F"], font: bigFont, proc: AButt, clientData: t, fork: FALSE, paint: FALSE];
t.ngf ← classBF.Instantiate[[parent: t.container, wx: t.ogf.wx+t.ogf.ww+hSep, wy: t.og.wy], t, NIL, FALSE];
t.typescript ← TypeScript.Create[[parent: t.container, wy: t.og.wy+t.og.wh+vSep, ww: 20, wh: 20, name: "Log"], FALSE];
Containers.ChildXBound[t.container, t.typescript];
Containers.ChildYBound[t.container, t.typescript];
t.log ← ViewerIO.CreateViewerStreams["Log", t.typescript].out;
ViewerOps.PaintViewer[t.container, client];
};
classN: PopUpButtons.Class = PopUpButtons.MakeClass[[proc: BButt, choices: LIST[[$Pause, "Delay 5 seconds"], [$Flip, "Invert coloration"]], doc: "Comparison button"]];
AButt: Buttons.ButtonProc = {
t: Tool = NARROW[clientData];
t.log.PutRope["I'm a Buttons.Button\n"];
IF mouseButton = red THEN Process.Pause[ticks: Process.SecondsToTicks[5]];
};
class4: PopUpButtons.Class = PopUpButtons.MakeClass[[proc: BButt, choices: LIST[[$Pause, "Delay 5 seconds"], [$Flip, "Invert color"], [$TellWDir, "Report working directory"], [NIL, NIL], [$Test4, "This one's 4 you"]], doc: "PopUpButtons test"]];
class7: PopUpButtons.Class = PopUpButtons.MakeClass[[proc: BButt, choices: LIST[[$Pause, "Delay 5 seconds"], [$Flip, "Invert color"], [$Test3, "Have some 3"], [NIL, NIL], [$TellWDir, "Report working directory"], [NIL, NIL], [NIL, NIL], [$TellProcessProps, "Report process props"]], guarded: TRUE, doc: "Another PopUpButtons test", disarmMsg: "Be brave"]];
class12: PopUpButtons.Class = PopUpButtons.MakeClass[[proc: BButt, choices: LIST[[$Pause, "Delay 5 seconds"], [$Flip, "Invert color"], [$Test3, "Have some 3"], [NIL, NIL], [$Test4, "This one's 4 you"], [NIL, NIL], [NIL, NIL], [$Test7, "Lucky number 7"], [NIL, NIL], [$Test9], [$Test10], [$Test11]], doc: "Yet another PopUpButtons test"]];
BButt: PopUpButtons.PopUpButtonProc = {
t: Tool = NARROW[instanceData];
t.log.PutF["I'm a PopUpButtons.Button; Got %g\n", [refAny[key]]];
SELECT key
FROM
$Flip => {
button: Viewer = NARROW[viewer];
is: PopUpButtons.InstanceSpec = PopUpButtons.GetInstanceSpec[button];
ri: PopUpButtons.RopeImage = NARROW[is.image.data];
PopUpButtons.SetImage[button, PopUpButtons.ImageForRope[ri.text, SELECT ri.colors FROM PopUpButtons.defaultColors => PopUpButtons.inverseColors, PopUpButtons.inverseColors => PopUpButtons.defaultColors, ENDCASE => ERROR, ri.font]];
};
$Pause => {
Process.Pause[ticks: Process.SecondsToTicks[5]];
};
$TellWDir => t.log.PutF["Process property $WorkingDirectory = %g.\n", [refAny[List.Assoc[$WorkingDirectory, ProcessProps.GetPropList[]]]]];
$TellProcessProps => t.log.PutF["Process props = %g.\n", [refAny[ProcessProps.GetPropList[]]]];
ENDCASE => NULL;
};
class1: PopUpButtons.Class = PopUpButtons.MakeClass[[proc: Butt1, choices: LIST[[$Doit, "The only choice"]], doc: "Test button with 1 choice"]];
Butt1: PopUpButtons.PopUpButtonProc = {
t: Tool = NARROW[instanceData];
t.log.PutF["Got %g\n", [refAny[key]]];
};
class0: PopUpButtons.Class = PopUpButtons.MakeClass[[proc: Butt0, choices: LIST[], doc: "Test button with 0 choices"]];
Butt0: PopUpButtons.PopUpButtonProc = {
t: Tool = NARROW[instanceData];
t.log.PutF["Got %g\n", [refAny[key]]];
};
colorImage: PopUpButtons.Image = PopUpButtons.ImageForRope["Color", colorfulColors];
classC: PopUpButtons.Class = PopUpButtons.MakeClass[[image: colorImage, proc: BButt, choices: LIST[[$Pause, "Delay 5 seconds"], [$ReturnAtOnce, "Don't delay"]], guarded: TRUE, doc: "A button with chromatic colors"]];
bigFont: Imager.Font = ImagerFont.Find["Xerox/PressFonts/TimesRoman-MRR"].Scale[40];
classB: PopUpButtons.Class = PopUpButtons.MakeClass[[image: PopUpButtons.ImageForRope[rope: "Big", font: bigFont], proc: BButt, choices: LIST[[$Pause, "Delay 5 seconds"], [$Flip, "Invert coloring"]], doc: "A button with a large font"]];
classBF: PopUpButtons.Class = PopUpButtons.MakeClass[[image: PopUpButtons.ImageForRope[rope: "Big~F", font: bigFont], proc: BButt, choices: LIST[[$Pause, "Delay 5 seconds"], [$Flip, "Invert coloring"]], fork: FALSE, doc: "A button with a large font"]];
aTester: Tool ← MakeTest[];
END.