MODULE; IMPORT ColorName, PaintOp, RectsVBT, Sort, SortViewClass, View, ZeusPanel; REVEAL T = Public BRANDED OBJECT N : CARDINAL := 0; a : Sort.Keys; rects: RectsVBT.T; op : PaintOp.T; OVERRIDES init := ViewInit; startrun := Startrun; oeInit := Init; oeSetVal := SetVal; oeSwapElts := SwapElts; setPosition := DotsSetPosition; END; PROCEDURE DotsView Startrun (view: T) = BEGIN SortViewClass.T.startrun(view); RectsVBT.SetN(view.rects, 0, TRUE); END Startrun; PROCEDUREInit (view: T; N: CARDINAL; <* UNUSED *> passes: CARDINAL) = BEGIN view.N := N; FOR i := 1 TO N DO view.a[i] := 0 END; RectsVBT.SetWC( view.rects, 0.0, 0.0, FLOAT(N + 1), FLOAT(N + 1)); RectsVBT.SetN(view.rects, N); FOR i := 1 TO N DO RectsVBT.Color(view.rects, i, view.op) END END Init; PROCEDURESetVal (view: T; i: CARDINAL; val: Sort.Key) = BEGIN Erase(view, i); view.a[i] := val; Draw(view, i); END SetVal; PROCEDURESwapElts (view: T; i, j: CARDINAL) = BEGIN Erase(view, i); Erase(view, j); VAR t := view.a[i]; BEGIN view.a[i] := view.a[j]; view.a[j] := t; END; Draw(view, i); Draw(view, j); END SwapElts; PROCEDUREErase (view: T; i: CARDINAL) = BEGIN RectsVBT.Erase(view.rects, i) END Erase; PROCEDUREDraw (view: T; i: CARDINAL) = BEGIN view.setPosition(view.rects, i, view.a[i]); RectsVBT.Draw(view.rects, i); END Draw; PROCEDUREDotsSetPosition (<* UNUSED *> view : T; rects: RectsVBT.T; i : CARDINAL; val : Sort.Key ) = BEGIN RectsVBT.Position(rects, i, FLOAT(i) - 0.5, FLOAT(val) - 0.5, FLOAT(i) + 0.5, FLOAT(val) + 0.5); END DotsSetPosition; PROCEDUREViewInit (view: T; op: PaintOp.T): T = BEGIN view.rects := NEW(RectsVBT.T).init(); view.op := op; RETURN SortViewClass.T.init(view, view.rects); END ViewInit; <* FATAL ColorName.NotFound *> VAR color: PaintOp.T; PROCEDURENew (): View.T = BEGIN RETURN NEW(T).init(color) END New; BEGIN WITH rgb = ColorName.ToRGB("Red") DO color := PaintOp.FromRGB(rgb.r, rgb.g, rgb.b); END; ZeusPanel.RegisterView (New, "Dots", "Sort"); END DotsView.