/*
  i-net software provides programming examples for illustration only, without warranty
  either expressed or implied, including, but not limited to, the implied warranties
  of merchantability and/or fitness for a particular purpose. This programming example
  assumes that you are familiar with the programming language being demonstrated and
  the tools used to create and debug procedures. i-net software support professionals
  can help explain the functionality of a particular procedure, but they will not modify
  these examples to provide added functionality or construct procedures to meet your
  specific needs.
  © i-net software 1998-2010
*/

package samples.printing;

import com.inet.viewer.Progress;
import com.inet.viewer.SwingReportViewer;
import com.inet.viewer.URLRenderData;
import com.inet.viewer.ReportView;

/**
 * This example shows how to retrieve data from a remote report server and use the Java viewer to print the data. 
 * If the engine is running in an application server, uncomment the lines marked with the comment "use this to connect to the engine running in the BEA Weblogic Application Server" 
 */
public class PrintTest {

    /**
     * Main method of the sample.
     * @param args no parameters used
     */
	public static void main(String[] args) {
		print();
	}

	/**
	 * Request the report from the report server and print it. 
	 */
	public static void print() {
		// STEP1: check if we're running java >= 1.3.x
		System.out.println("Java-Version:" + System.getProperty("java.version"));

		try {
			// start the report server (if necessary)
			// use this for a standalone app
            com.inet.report.Listener reportListener = new com.inet.report.Listener(true);

            // STEP2: 
            // to initialize we first create a top level ReportViewer:
			SwingReportViewer viewer = new SwingReportViewer();
  	  
			// STEP3: 
	        // then initialize the render data connection.
            // use this to connect to the engine running in the BEA Weblogic Application Server
			//URLRenderData renderConnection = new URLRenderData( "http://localhost:7001/CrystalClear/ReportServlet?report=http://localhost:8000/CrystalClRegaear/samples/sample.rpt" );
			
			// use this for a standalone app
            // renderConnection.setReportURL( reportListener.getUrlString()+"?report=file:/c:/sample.rpt" );
            URLRenderData renderConnection = new URLRenderData( reportListener.getUrlString() + "/?report=file:/c:/java/sample.rpt" ); // jetty
            
			// STEP4: 
            // addNewReportView causes a new report view to be created using the given connection as its data source, and then
	   	    // for this newly created report to be added to the viewer.
			ReportView currentReportView = viewer.addNewReportView( renderConnection );
          
            // printed
	   		Progress prog = currentReportView.print( 1, -1, false );  // true to show a dialog box
			prog.waitUntilFinished();
			
			// bye
			System.exit(0);

		}   catch (Throwable t) {t.printStackTrace(); } 
	}
}
