package nxm.sys.test;

import nxm.sys.inc.InternalUseOnly;
import nxm.sys.lib.Message;
import nxm.sys.lib.Table;
import nxm.sys.lib.Time;
import nxm.sys.prim.plot;


/** Helper class for prescaler to run commands after a 5 second delay.
 *  @author Kevin E.
 *  @since 3.9.2
 */
@InternalUseOnly
public class testprescalerhelper {

  private testprescalerhelper () {}

  /**
   * Call this method to start the command. This is only to be used by test_plot_prescaler_openfile.mm
   * @param reg The current registry
   */
  public static void sendCommands(Table reg) {
    Thread t = new Thread(new Runnable() {

      @Override
      public void run () {
        Time.sleep(2);
        sendOpenCommands(reg);
      }
    });
    t.start();
  }

  private static void sendOpenCommands(Table reg) {
    plot p = (plot) reg.get("INSIDEPIPE1");
    p.processMessage(new Message("OPENFILE", -1, "ram:prescale_out{PRESCALE={TYPE=EXTERNAL,SCALETABLE=scaletbl_pipe},LAYER={COLOR=WHITE}}","{/ALL=TRUE}"));

    p = (plot) reg.get("INSIDEPIPE2");
    p.processMessage(new Message("OPENFILE", -1, "ram:prescale_out{PRESCALE=RANDOM,LAYER={COLOR=YELLOW}}", "{/ALL=TRUE}"));

    p = (plot) reg.get("INSIDEPIPE3");
    p.processMessage(new Message("OPENFILE", -1, "zero_padded_data3{PRESCALE={TYPE=KEYWORD,RANDOM=20},LAYER={COLOR=BLUE}}", "{/ALL=TRUE}"));

    p = (plot) reg.get("OUTSIDEPIPE1");
    p.processMessage(new Message("OPENFILE", -1, "zero_padded_data{PRESCALE={TYPE=EXT,SCALETABLE={Y1=0,Y2=1}},LAYER={COLOR=RED}}","{/ALL=TRUE}"));

    p = (plot) reg.get("OUTSIDEPIPE2");
    p.processMessage(new Message("OPENFILE", -1, "zero_padded_data{PRESCALE=KW,LAYER={COLOR=PINK}}", "{/ALL=TRUE}"));

    p = (plot) reg.get("OUTSIDEPIPE3");
    p.processMessage(new Message("OPENFILE", -1, "zero_padded_data{PRESCALE={TYPE=EXT,SCALETABLE=scaletbl_outside},LAYER={COLOR=AQUA}}", "{/ALL=TRUE}"));

    p = (plot) reg.get("OUTSIDEPIPE4");
    p.processMessage(new Message("OPENFILE", -1, "zero_padded_data{PRESCALE={OUTCOPY=plot_makes_copy.tmp},LAYER={COLOR=TEAL}}", "{/ALL=TRUE}"));
  }

}
