/*
	A basic extension of the java.applet.Applet class
 */

import java.awt.*;
import java.applet.*;
import com.wildcrest.TextPrinter;
import netscape.security.PrivilegeManager;

public class PrintingApplet extends Applet
{
	public void init()
	{
		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		setLayout(null);
		setSize(426,266);
		add(textArea1);
		textArea1.setBounds(12,48,404,209);
		buttonPrint.setLabel("Print");
		add(buttonPrint);
		buttonPrint.setBackground(java.awt.Color.lightGray);
		buttonPrint.setBounds(12,12,135,28);
		add(textPrinter1);
		textPrinter1.setBounds(300,12,32,40);
		textPrinter1.setVisible(false);
		//}}
	
		//{{REGISTER_LISTENERS
		SymAction lSymAction = new SymAction();
		buttonPrint.addActionListener(lSymAction);
		//}}
	}
	
	//{{DECLARE_CONTROLS
	java.awt.TextArea textArea1 = new java.awt.TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
	java.awt.Button buttonPrint = new java.awt.Button();
	com.wildcrest.TextPrinter textPrinter1 = new com.wildcrest.TextPrinter();
	//}}

	class SymAction implements java.awt.event.ActionListener
	{
		public void actionPerformed(java.awt.event.ActionEvent event)
		{
			Object object = event.getSource();
			if (object == buttonPrint)
				buttonPrint_ActionPerformed(event);
		}
	}

	void buttonPrint_ActionPerformed(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
            boolean is_netscape = System.getProperty("java.vendor").substring(0,8).equals("Netscape");
            try {
                if (is_netscape) {
                     PrivilegeManager.enablePrivilege("UniversalPrintJobAccess");
		             textPrinter1.print(textArea1.getText());
		        }
		        else
		             textPrinter1.print(textArea1.getText());
	      } 
            catch (Exception ex) {
                if (is_netscape && ex instanceof netscape.security.ForbiddenTargetException)
                     System.err.println("User did not grant print access");
                else
                     ex.printStackTrace();
            }
	}
}
