!7

module ShowRandomColor > DynSCP {
  RGB color;
  S yourName;
  
  visualize2 {
    if (color == null) setField(color := randomColor());
    ret revalidateOnFirstShow(withRightAlignedButtons(
      centerAndSouthWithMargin(
        northAndCenterWithMargins(
          jRightAlignedLiveValueLabel(mapLiveValue(func(O color) -> S { "Color Code: #" + color }, S, dm_fieldLiveValue('color))),
          jSection("THE COLOR", singleColorPanel(toColor(color)))),
      withRightMargin(makeForm2(
        "I call this color:", "bla",
        "Your call this color:", centerAndEastWithMargin(
          onEnter(dm_fieldTextField('yourName), rThread saveName),
          jbutton("Save", rThread saveName))))),
      "New Color", rThread newColor));
  }
  
  void newColor enter {
    setField(color := randomColor());
    revisualize2();
  }
  
  void saveName enter {
  }
}