/*
 * ShtrihFiscalPrinter.java
 *
 * Created on 23 Íîÿáðü 2009 ã., 22:32
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package fptrtest;

/**
 *
 * @author V.Kravtsov
 */

import jpos.FiscalPrinter;
import jpos.JposException;

/** Wrapper class to help using directIO codes **/

public class ShtrihFiscalPrinter extends FiscalPrinter 
implements SmFptrConst{
    
    /** Creates a new instance of ShtrihFiscalPrinter */
    public ShtrihFiscalPrinter() {
    }
    
    public void printText(String text)
    throws JposException {
        int data[] = new int[1];
        directIO(SMFPTR_DIO_PRINT_TEXT, data, text);
    }
    
    
    public void setParameter(int paramType, int paramValue)
    throws JposException {
        int data[] = new int[1];
        int object[] = new int[1];
        data[0] = paramType;
        object[0] = paramValue;
        directIO(SMFPTR_DIO_SET_DRIVER_PARAMETER, data, object);
    }
    
    public int getParameter(int paramType)
    throws JposException {
        int data[] = new int[1];
        int object[] = new int[1];
        data[0] = paramType;
        directIO(SMFPTR_DIO_GET_DRIVER_PARAMETER, data, object);
        return object[0];
    }
    
    /** Set number of header lines **/
    public void setNumHeaderLines(int value)
    throws JposException {
        setParameter(SMFPTR_DIO_PARAM_NUMHEADERLINES, value);
    }
    
    /** Set number of trailer lines **/
    public void setNumTrailerLines(int value)
    throws JposException {
        setParameter(SMFPTR_DIO_PARAM_NUMTRAILERLINES, value);
    }
    
    /** Select device (FM or EJ) for printReport method **/
    public void setReportDevice(int value)
    throws JposException {
        setParameter(SMFPTR_DIO_PARAM_REPORT_DEVICE, value);
    }
    
    /** Get device type (FM or EJ) for printReport method **/
    public int getReportDevice()
    throws JposException {
        return getParameter(SMFPTR_DIO_PARAM_REPORT_DEVICE);
    }
    
    /** Set report type (full or short) for printReport method **/
    public void setReportType(int value)
    throws JposException {
        setParameter(SMFPTR_DIO_PARAM_REPORT_TYPE, value);
    }
    
    /** Set report type (full or short) for printReport method **/
    public int getReportType()
    throws JposException {
        return getParameter(SMFPTR_DIO_PARAM_REPORT_TYPE);
    }
    
    /** Write tables from file "fileName". File is in UTF-8 **/
    public void writeTables(String fileName)
    throws JposException {
        int[] data = new int[1];
        directIO(SMFPTR_DIO_WRITE_TABLES, data, fileName);
    }
    
    /** Read tables to file "fileName". File is in UTF-8 **/
    public void readTables(String fileName)
    throws JposException {
        int[] data = new int[1];
        directIO(SMFPTR_DIO_READ_TABLES, data, fileName);
    }
    
    /** Get department number **/
    public int getDepartment()
    throws JposException {
        int[] data = new int[1];
        int[] value = new int[1];
        directIO(SMFPTR_DIO_GET_DEPARTMENT, data, value);
        return value[0];
    }
    
    /** Set department number **/
    public void setDepartment(int department)
    throws JposException {
        int[] data = new int[1];
        int[] value = new int[1];
        value[0] = department;
        directIO(SMFPTR_DIO_SET_DEPARTMENT, data, value);
    }
    
    /** Read table value **/
    public String readTable(int tableNumber, int rowNumber, int fieldNumber)
    throws JposException {
        int[] data = new int[3];
        data[0] = tableNumber;
        data[1] = rowNumber;
        data[2] = fieldNumber;
        String[] fieldValue = new String[1];
        directIO(SMFPTR_DIO_READTABLE, data, fieldValue);
        return fieldValue[0];
    }
    
    /** Write table value **/
    public void writeTable(int tableNumber, int rowNumber, int fieldNumber,
        String fieldValue)
        throws JposException {
        int[] data = new int[3];
        data[0] = tableNumber;
        data[1] = rowNumber;
        data[2] = fieldNumber;
        String[] value = new String[1];
        value[0] = fieldValue;
        directIO(SMFPTR_DIO_WRITETABLE, data, value);
    }
    
    /** Read payment name, number = 1..4 **/
    public String readPaymentName(int number)
    throws JposException {
        int[] data = new int[1];
        data[0] = number;
        String[] fieldValue = new String[1];
        directIO(SMFPTR_DIO_READ_PAYMENT_NAME, data, fieldValue);
        return fieldValue[0];
    }
    
    /** Write payment name, number = 1..4 **/
    public void writePaymentName(int number, String value)
    throws JposException {
        int[] data = new int[1];
        data[0] = number;
        String[] fieldValue = new String[1];
        fieldValue[0] = value;
        directIO(SMFPTR_DIO_WRITE_PAYMENT_NAME, data, fieldValue);
    }
    
    /** Read day end required value **/
    public boolean readDayEnd()
    throws JposException {
        int[] data = new int[1];
        directIO(SMFPTR_DIO_READ_DAY_END, data, null);
        return data[0] != 0;
    }
    
    /** Print barcode **/
    public void printBarcode(
        String barcode,
        String label,
        int barcodeType,
        int barcodeHeight,
        int printType,
        int barWidth,
        int textPosition,
        int textFont)
        throws JposException {
        int data[] = new int[6];
        String[] command = new String[2];
        
        command[0] = barcode;           // barcode data
        command[1] = label;             // barcode label
        data[0] = barcodeType;          // barcode type
        data[1] = barcodeHeight;        // barcode height, pixels
        data[2] = printType;            // print type
        data[3] = barWidth;             // barcode bar width, pixels
        data[4] = textPosition;         // text position
        data[5] = textFont;             // text font
        directIO(SMFPTR_DIO_PRINT_BARCODE, data, command);
    }
    
    /** Load image **/
    public void loadImage(String fileName)
    throws JposException {
        int[] data = new int[10];
        String[] command = new String[1];
        command[0] = fileName;
        directIO(SMFPTR_DIO_LOAD_IMAGE, data, command);
    }
    
    public void printImage(int imageIndex)
    throws JposException {
        int[] data = new int[1];
        data[0] = imageIndex;
        directIO(SMFPTR_DIO_PRINT_IMAGE, data, null);
    }
    
    public void clearImages()
    throws JposException {
        int[] data = new int[1];
        directIO(SMFPTR_DIO_CLEAR_IMAGES, data, null);
    }

    public void addLogo(int imageIndex, int logoPosition)
    throws JposException {
        int[] data = new int[2];
        data[0] = imageIndex;
        data[1] = logoPosition;
        directIO(SMFPTR_DIO_ADD_LOGO, data, null);
    }
    
    public void clearLogo()
    throws JposException {
        int[] data = new int[0];
        directIO(SMFPTR_DIO_CLEAR_LOGO, data, null);
    }
    
    public void printLine(int lineHeight)
    throws JposException {
        int[] data = new int[1];
        data[0] = lineHeight;
        directIO(SMFPTR_DIO_PRINT_LINE, data, null);
    }
}
