package tst.print;
import java.util.Calendar;
import tcg.print.EColor;
import tcg.print.ETextStyle;
import tcg.print.ILinePrinter;
import tcg.print.IPrintable;
import tcg.print.PrintableFactory;
import tcg.print.TcpLinePrinter;
public class TestTcpPrinter
{
/**
* @param args
*/
public static void main(String[] args)
{
String printer_host = "192.168.10.200";
int printer_port = 9100;
ILinePrinter printer = new TcpLinePrinter(printer_host, printer_port);
if (!printer.ping())
{
System.out.println("Remote printer " + printer_host + ":" + printer_port
+ " is not available.");
return;
}
//initialize the calendar instance. in Unix it often throws exception because of
//unknown locale
try
{
Calendar.getInstance();
}
catch(Exception ex)
{
//ignore
}
IPrintable printable = PrintableFactory.createPrintable("OKI");
printable.append(Calendar.getInstance().getTime().toString() + ": Hello world! köyden ağaçtan\n");
try
{
printer.print(printable);
}
catch(RuntimeException re)
{
System.out.println("Exception: " + re.getMessage());
}
printable.clear();
printable.append(Calendar.getInstance().getTime().toString() + ": abcdefghijklmnop\ndfssdfgsdgs\nssasdfdsf\n");
try
{
printer.print(printable);
}
catch(RuntimeException re)
{
System.out.println("Exception: " + re.getMessage());
}
printable.clear();
printable.append(Calendar.getInstance().getTime().toString() + ": \u65e5\u672c\u8a9e\u6587\u5b57\u5217\n");
try
{
printer.print(printable);
}
catch(RuntimeException re)
{
System.out.println("Exception: " + re.getMessage());
}
printable.clear();
printable.append(Calendar.getInstance().getTime().toString() + ": ");
printable.append(" BOLD ", new ETextStyle[]{ ETextStyle.BOLD }, null );
printable.append(" ITALIC ", new ETextStyle[]{ ETextStyle.ITALIC }, null );
printable.append(" BOLD-ITALIC ", new ETextStyle[]{ ETextStyle.BOLD, ETextStyle.ITALIC }, null );
printable.append(" UNDERLINE ", new ETextStyle[]{ ETextStyle.UNDERLINE }, null );
printable.append(" STRIKETHROUGH ", new ETextStyle[]{ ETextStyle.STRIKETHROUGH }, null );
printable.append(" SUPERSCRIPT ", new ETextStyle[]{ ETextStyle.SUPERSCRIPT }, null );
printable.append(" SUBSCRIPT ", new ETextStyle[]{ ETextStyle.SUBSCRIPT }, null );
printable.append("\n");
try
{
printer.print(printable);
}
catch(RuntimeException re)
{
System.out.println("Exception: " + re.getMessage());
}
printable.clear();
printable.append(Calendar.getInstance().getTime().toString() + ": ");
printable.append(" DARK_GRAY ", null, EColor.DARK_GRAY );
printable.append(" GRAY ", null, EColor.GRAY );
printable.append(" LIGHT_GRAY ", null, EColor.LIGHT_GRAY );
printable.append(" WHITE ", null, EColor.WHITE );
printable.append(" MAGENTA ", null, EColor.MAGENTA );
printable.append(" RED ", null, EColor.RED );
printable.append(" PINK ", null, EColor.PINK );
printable.append(" ORANGE ", null, EColor.ORANGE );
printable.append(" YELLOW ", null, EColor.YELLOW );
printable.append(" GREEN ", null, EColor.GREEN );
printable.append(" CYAN ", null, EColor.CYAN );
printable.append(" BLUE ", null, EColor.BLUE );
printable.append("\n");
try
{
printer.print(printable);
}
catch(RuntimeException re)
{
System.out.println("Exception: " + re.getMessage());
}
}
}