report.java

来自「优秀的打印控件全源代码,类似水晶表的设计器!」· Java 代码 · 共 1,537 行 · 第 1/5 页

JAVA
1,537
字号
/* * Report.java * *  iReport  --  Visual designer for generating JasperReports Documents *  Copyright (C) 2002  Giulio Toffoli gt@businesslogic.it * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *  Giulio Toffoli *  Via T.Aspetti, 233 *  35100 Padova ITALY *  gt@businesslogic.it * * Created on 10 febbraio 2003, 19.32 */package it.businesslogic.ireport;import java.util.*;import it.businesslogic.ireport.util.*;import dori.jasper.engine.*;import org.apache.xerces.parsers.DOMParser;import org.w3c.dom.*;import org.xml.sax.SAXException;import java.io.IOException;import org.syntax.jedit.*;/** * * @author  Administrator */public class Report {		public static int SCRIPTLET_IREPORT_INTERNAL_HANDLING = 1;	public static int SCRIPTLET_NOT_USED = 0;	public static int SCRIPTLET_CLASSIC_HANDLING = 2;		private IReportFont defaultFont = new IReportFont();		private boolean modified;	private boolean readOnly;		private int height;		private int width;		private String name;		private Vector elements;		private Vector bands;		private Vector groups;		private String filename;		private String query;		private String encoding;		private int columnCount;		private String printOrder;		private String orientation;		private String whenNoDataType;		private int columnWidth;		private int columnSpacing;		private int leftMargin;		private int rightMargin;		private int topMargin;		private int bottomMargin;		private boolean isTitleNewPage;		private boolean isSummaryNewPage;		private String scriptletClass;		private long loadTime;		private Vector fields;		private Vector parameters;		private Vector variables;		private Vector fonts;		private it.businesslogic.ireport.gui.JReportFrame reportFrame;		private String reportFormat;		static int untitledId = 1;		private int dirty = 1;		private IReportKeywordLookup keywordLookup;		/** used to tell the report when outputting to XML that it needs to set isCode="true" in expressions */	protected boolean usingMultiLineExpressions = false;		private java.util.Vector JRproperties;		private ScriptletCode scripletCode;		private int scriptletHandling = 2;		/** Creates a new instance of Report */	public Report() {				modified = true;		readOnly = false;		height = 0;		width  = 0;		name = "";		elements = new Vector();		bands = new Vector();		groups = new Vector();		JRproperties = new Vector();		filename  = "";		query = "";		encoding = "UTF-8";		columnCount = 1;		printOrder = "Vertical";		orientation = "Portrait";		whenNoDataType = "NoPages";		columnWidth = 535;		columnSpacing = 0;		leftMargin = 20;		rightMargin = 20;		topMargin = 30;		bottomMargin = 30;		isTitleNewPage = false;		isSummaryNewPage = false;		scriptletClass = "";		loadTime = 0;		fields = new Vector();		parameters =  new Vector();		variables = new Vector();		fonts = new Vector();		keywordLookup = new IReportKeywordLookup();				name = "Untitled_report_" + untitledId;		untitledId++;				// Add basic variables...		addVariable(new JRVariable("PAGE_NUMBER", true ));		addVariable(new JRVariable("REPORT_COUNT", true));		addVariable(new JRVariable("COLUMN_COUNT", true));				Band background = new Band(this,"background",0);		Band title = new Band(this,"title", 50);		Band pageHeader = new Band(this,"pageHeader", 50);		Band columnHeader = new Band(this,"columnHeader",30);		Band detail = new Band(this,"detail",100);		Band columnFooter = new Band(this,"columnFooter",30);		Band pageFooter = new Band(this,"pageFooter",50);		Band summary = new Band(this,"summary",50);				bands.addElement(background);		bands.addElement(title);		bands.addElement(pageHeader);		bands.addElement(columnHeader);		bands.addElement(detail);		bands.addElement(columnFooter);		bands.addElement(pageFooter);		bands.addElement(summary);		loadTime = 0;				try {						scripletCode = new ScriptletCode(ScriptletCode.class.getClassLoader().getResourceAsStream("scriptlet_template.jav"));					} catch (Exception ex) {			ex.printStackTrace();		}	}		/** Creates a new instance of Report reading it by a file...*/	public Report(String xmlFile) {		this();		untitledId--;				//reset bands, prevents page height overflow for unused bands		for(int i = 0; i < bands.size(); i++){			((Band)bands.elementAt(i)).setHeight(0);		}				//  Create a Xerces DOM Parser		//  Parse the Document		//  and traverse the DOM		this.setFilename(xmlFile);		checkReadOnlyFlag();				// set load time...		this.setLoadTime( Misc.getLastWriteTime( xmlFile ));				try {						if (xmlFile.toLowerCase().endsWith(".jasper")) {				dori.jasper.engine.JRReport report = dori.jasper.engine.JasperManager.loadReport(xmlFile);				this.setWidth(report.getPageWidth());				this.setHeight(report.getPageHeight());				this.setTopMargin(report.getTopMargin());				this.setLeftMargin(report.getLeftMargin());				this.setBottomMargin(report.getBottomMargin());				this.setRightMargin(report.getRightMargin());				this.setOrientation( ( (report.getOrientation()==JRReport.ORIENTATION_PORTRAIT) ? "Portrait" : "Landscape"));				this.setColumnCount( report.getColumnCount() );				this.setColumnSpacing( report.getColumnSpacing());				this.setColumnWidth( report.getColumnWidth());				this.setQuery( ( report.getQuery() != null) ? report.getQuery().getText() : "");								// Read all bands...				dori.jasper.engine.JRField[] reportFields = report.getFields();				for (int i=0; reportFields != null && i<reportFields.length; ++i) {					it.businesslogic.ireport.JRField field = new it.businesslogic.ireport.JRField(  reportFields[i].getName(), reportFields[i].getValueClass().getClass().getName());					field.setDescription( reportFields[i].getDescription());					addField(field);				}							}			else {				DOMParser parser = new DOMParser();				parser.setEntityResolver( new org.xml.sax.EntityResolver() {					/* Code by Teodor Danciu */					public org.xml.sax.InputSource resolveEntity(					String publicId,					String systemId					) throws SAXException//, java.io.IOException					{						org.xml.sax.InputSource inputSource = null;						if (systemId != null) {							String dtd = null;														if (							systemId.equals("http://jasperreports.sourceforge.net/dtds/jasperreport.dtd") ||							systemId.equals("http://www.jasperreports.com/dtds/jasperreport.dtd")							) {								dtd = "dori/jasper/engine/dtds/jasperreport.dtd";							}							else if (							systemId.equals("http://jasperreports.sourceforge.net/dtds/jasperprint.dtd") ||							systemId.equals("http://www.jasperreports.com/dtds/jasperprint.dtd")							) {								dtd = "dori/jasper/engine/dtds/jasperprint.dtd";							}							else {								return new org.xml.sax.InputSource(systemId);							}														ClassLoader classLoader = this.getClass().getClassLoader();							java.net.URL url = null;							if (classLoader != null) {								url = classLoader.getResource(dtd);							}							if (url == null) {								classLoader = this.getClass().getClassLoader();							}														java.io.InputStream is = classLoader.getResourceAsStream(dtd);							if (is != null) {								java.io.InputStreamReader isr = new java.io.InputStreamReader(is);								inputSource = new org.xml.sax.InputSource(isr);							}													}						return inputSource;											}				});				/* End Code by Teodor Danciu */				parser.parse( new java.io.File(xmlFile).toURI().toString() );				Document document = parser.getDocument();				traverse(document.getDocumentElement());			}						/* Begin Code by Robert Lamping                         * 2 July 2004                         * Now height and width are known and a format can be guessed.                         * using PageSize.deductPageFormat();                         */                                                this.setReportFormat( PageSize.deductPageFormat( this.getWidth(), this.getHeight()) );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?