package jgrasp_viewers_python;


import java.math.BigInteger;
import java.util.Locale;
import jgrasp.viewer.ViewerCreateData;
import jgrasp.viewer.ViewerException;
import jgrasp.viewer.ViewerInfo;
import jgrasp.viewer.ViewerPriorityData;
import jgrasp.viewer.text.TextAreaView;
import jgrasp.viewer.jgrdi.DebugContext;
import jgrasp.viewer.jgrdi.Value;


/** Base class for integer detail viewers. **/
public class builtins___int_IntView extends TextAreaView {

   /** Creates a new int viewer.
    *
    * @param vcd creation data. **/
   public builtins___int_IntView(final ViewerCreateData vcd) {
   }


   /** {@inheritDoc} **/
   @Override
   public String getDisplayText(final Value value, final DebugContext context) throws ViewerException {
      String val = value.toString(context);
      try {
         BigInteger bi = new BigInteger(val);
         return "Decimal: " + bi + "\nHex: 0x" + bi.toString(16).toUpperCase(Locale.ENGLISH) + "\nOctal: 0o"
               + bi.toString(8) + "\nBinary: 0b" + bi.toString(2);
      }
      catch (NumberFormatException e) {
         return "<internal error - bad int data>";
      }
   }


   /** {@inheritDoc} **/
   @Override
   public void getInfo(final ViewerInfo vi) {
      vi.setShortDescription("Detail viewer for ints");
      vi.setLongDescription("This viewer displays an int in decimal, hex, octal, and binary forms.");
   }


   /** {@inheritDoc} **/
   @Override
   public int getPriority(final ViewerPriorityData vpd) {
      return -1;
   }


   /** {@inheritDoc} **/
   @Override
   public String getViewName() {
      return "Numeric";
   }
}
