package nxm.sys.test;

import nxm.sys.inc.InternalUseOnly;
import nxm.sys.lib.Table;
import nxm.sys.lib.Time;
import nxm.sys.libg.GPanelSetup;
import nxm.sys.libg.MBox;
import nxm.sys.prim.panel;
import nxm.sys.prim.plot;

/** This is a class that helps the test %TEST_PLOT_ZOOM_PIXEL_SLAM_TOP
 *
 *  @author Kevin Esterheld
 *  @since 3.9.2
 */
@InternalUseOnly
public class TestPlotZoomPixelSlamTop {

  private TestPlotZoomPixelSlamTop () {}

  /** This will adjust the frame size to the specified width and height.
   *  The data will either be a string in table format or an MBox object.
   *
   *  @param reg    The registry
   *  @param data   The width and height values (either a Table object or an MBox)
   *  @param plotID The id of the plot to be adjusted.
   *  @return       The previous MBox before changes were made
   */
  public static int[] adjustFrameSize (Table reg, Object data, String plotID) {
    Table tbl;
    Table wintbl = (Table) reg.get("WIN");
    panel.Pane plot1 = (panel.Pane) wintbl.get(plotID.toUpperCase());
    GPanelSetup p = (GPanelSetup) plot1.MW;
    int[] previousVals = new int[] {p.pos.w,p.pos.h};

    if (data instanceof String) {
      tbl = new Table((String) data);
      int w = tbl.getL("W");
      int h = tbl.getL("H");
      p.setSize(w, h);
    }
    else if (data instanceof MBox) {
      MBox box = (MBox) data;
      p.setSize(box.h, box.w);
    }
    else if (data instanceof int[]) {
      int [] newvals = (int[]) data;
      p.setSize(newvals[0], newvals[1]);
    }
    Time.sleep(1);
    return previousVals;
  }

  /** Shift the specified plot id the specified direction the specefied repeats
   *
   *  @param reg        The registry
   *  @param plotID     The plot id to perform the action on
   *  @param direction  The direction to shift
   *  @param repeats    The number of shifts to execute
   */
  public static void shiftRight (Table reg, String plotID, String direction, int repeats) {
    plot plotprim = (plot) reg.get(plotID);
    for (int i = 0; i < repeats; i++) {
      plotprim.MP.adjustZoom(direction.toUpperCase());
      Time.sleep(0.2);
    }
  }
}
