package nxm.sys.lib;

import java.awt.Container;

import nxm.sys.inc.Chainable;
import nxm.sys.inc.Constants;
import nxm.sys.inc.InternalUseOnly;
import nxm.sys.inc.LimitedFutureSupport;
import nxm.sys.libg.MWindow;

/** **** STANDARD VERSION *****
   Base class for graphical primitives.  This is a container for methods that are
   specific to graphical primitives.

   They normally execute in a sub-thread of the current shell.

   @author Jeff Schoen
*/
@LimitedFutureSupport("Being replaced by nxm.sys.libg.GPrimitive - see JDK_Modularity_Action_Required.pdf for details - since 3.9.2")
public class GPrimitive extends Command implements Chainable, Constants {

  /** Added to make sure Graphical primitives pick up theme
      @since NeXtMidas 3.1.0 (Bug 2529)
   */
  static { Theme.initialize(); }

  /** Midas Window
      NOTE: this should become protected (or maybe even private) in 3.9+
   */
  @InternalUseOnly("since 3.5.3, use getMWindow() or setMWindow")
  public MWindow MW;

  /** default constructor */
  public GPrimitive () {}

  @Override
  public Object getNextLink() { return MW; }

  @Override
  public Object getPrevLink() { return null; }

  @Override
  public boolean isPipable() { return true; }

  @Override
  public void checkout() {
    super.checkout();

    if (MW != null) { MW.close(); }
    MW = null;
  }

  /** Gets the primary container used when displaying this graphical primitive. Subclasses may
      override this as necessary.
      @return The graphics panel or null if none is set.
      @since NeXtMidas 2.5.0
   */
  public Container getGraphicsContainer() {
    return (MW == null)? null: MW.panel;
  }

  /** Get the MWindow for this graphical primitive
   *  @return MWindow for this graphical primitive
   *  @since NeXtMidas 3.5.3
   */
  public MWindow getMWindow () { return MW; }

  /** @param mw MWindow to use for this graphical primitive
      @since NeXtMidas 3.5.3
   */
  protected void setMWindow (MWindow mw) { MW = mw; }

}
