//////////////////////////////////////////////////////////////////////////// /* Sample project for generating JViewPro report script without using JViewPro How to generate: A class, Script has been provided below. -To set a JViewPro property (or some relevant methods, such as storePage()), use the class's addLine method; -To add a text or graphics object, use the class's addObject method that has the same arguments as the corresponding JViewPro's; and -To save the script, use the saveScript method. How to view and print: The generated script can be loaded, viewed and printed using JViewPro JavaBean embedded in your applets or applications. The related JViewPro methods are loadScrip, loadScriptURL, preview and printPages. For test purpose, you can also view and print the script using the Mini Viewer supplied with the trial copy (the program is in the Viewer sub-directory under the demo directory). */ //////////////////////////////////////////////////////////////////////////// import java.util.Vector; import java.io.*; //------------------------------------------------------------------------- public class ScriptSample { public static void main(String[] args) { ScriptSample app = new ScriptSample(); app.generateReport(); } //---------------------------------- //generate report protected void generateReport() { double inch = 72; Script script = new Script(); //default unit: 1 inch = 72 script.addLine("setUnit(72.0)"); //Paper size script.addLine( "setPageWidth(612.0)" ); script.addLine( "setPageHeight(792.0)" ); //-----First page (index=0) script.addLine( "setPageIndex(0)" ); //portrait script.addLine( "setPageAttrib(\"orientation=1\")" ); //draw string (objectType=8) script.addObject("myStringObject", 8, 0*inch, 1*inch, 0*inch, 0*inch, "Hello World", "", "fontSize=18;fontBold=true;textColor=RGB(255,0,0)"); //draw table (objectType=11) script.addObject("myTableObject", 11, 0*inch, 2*inch, 0*inch, 0*inch, "Header1|Header2|Header3;col1|col2|col3", "tableFormat=72|72|144", "objectBorderOn=true;fontSize=12"); //store the page script.addLine( "storePage()" ); //-----Second page (index=1) script.addLine( "setPageIndex(1)" ); //landscape script.addLine( "setPageAttrib(\"orientation=0\")" ); //draw table (objectType=11) script.addObject("myTableObject2", 11, 0*inch, 1*inch, 0*inch, 0*inch, "Header1|Header2|Header3;col1|col2|col3", "tableFormat=72|72|144", "objectBorderOn=true;fontSize=12"); //store the page script.addLine( "storePage()" ); //-----preview script.addLine( "preview()" ); //-----save script script.saveScript("./", "report1.jvp"); } //generateReport() } //------------------------------------------------------------------------- //------------------------------------------------------------------------- class Script { Vector line; final String CONTROL_NAME = "vp."; final char chTAB = '\t'; final char chCR = '\r'; final char chLF = '\n'; final char chDQ = '\"'; final char chACK = 6; final char chNAK = 21; final char chSYN = 22; final String EMPTY = ""; final String CR = "" + chCR; final String LF = "" + chLF; String newline = CR + LF; //--------------------------- //Constructor public Script() { line = new Vector(); } //--------------------------- public void addLine(String sline) { String s = CONTROL_NAME + sline + ";" + newline; line.add(s); } //--------------------------- public void addObject(String name, int type, double x, double y, double w, double h, String data, String format, String attrib) { String s = CONTROL_NAME + "addObject("; s = s + "\"" + name + "\""; s = s + "," + type; s = s + "," + x; s = s + "," + y; s = s + "," + w; s = s + "," + h; s = s + "," + "\"" + replaceWithTokens(data) + "\""; s = s + "," + "\"" + format + "\""; s = s + "," + "\"" + attrib + "\""; s = s + ");" + newline; line.add(s); } //--------------------------- public void saveScript(String dir, String file) { File f = new File(dir, file); try { PrintWriter out = new PrintWriter(new FileWriter(f)); if ( f.exists()==true ) f.delete(); String s; for (int i=0; i=0 ) { s = replaceString1(s, pos, s1.length(), s2); } return s; } //--------------------------- protected String replaceString1(String s, int start, int len, String s2) { StringBuffer b = new StringBuffer(s); b = b.replace(start, start+len, s2); return b.toString(); } } //end of class //-------------------------------------------------------------------------