report.java

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

JAVA
1,537
字号
                        			/* Begin Code by Robert Lamping */			for (int i=0; i< groups.size(); i++) {				it.businesslogic.ireport.Group grp = (it.businesslogic.ireport.Group)groups.elementAt(i);				addGroup(grp,false);			}						// Translate coords to iReport coord system...			Enumeration e = elements.elements();			while (e.hasMoreElements()) {				ReportElement re = (ReportElement)e.nextElement();				re.trasform(new java.awt.Point(this.getLeftMargin()+10, this.getBandYLocation(re.getBand())+10), TransformationType.TRANSFORMATION_MOVE);			}						// Scriptlet loading....						// Process custom properties (ireport.* properties).			// We cut out ireport properties...			//System.out.println("Analizing properties...");			//System.out.println("Possible file: "+this.getScriptletFileName());			for (int pk= 0; pk < this.getJRproperties().size(); ++pk) {				JRProperty prop = (JRProperty)getJRproperties().elementAt( pk );								//System.out.println(""+prop.getName());								if (prop.getName().equals("ireport.scriptlethandling")) {					if (prop.getValue().equals("0")) {						this.setScriptletHandling(0);					}					else if (prop.getValue().equals("1")) {						this.setScriptletHandling( this.SCRIPTLET_IREPORT_INTERNAL_HANDLING );						// Try to load the source file...						java.io.File scriptletFile = new java.io.File(this.getScriptletFileName());						if (scriptletFile.exists()) {							scripletCode = new ScriptletCode(this.getScriptletFileName());							//System.out.println("Caricato scriptlet");						}					}				}								if (prop.getValue().startsWith("ireport.")) {					getJRproperties().remove( prop );					pk--;				}			}					} catch (SAXException e) {			System.err.println(e);		} catch (IOException e) {			System.err.println(e);		} catch (dori.jasper.engine.JRException e) {			System.err.println(e);		}				this.setDirty(false);					}		//  Traverse DOM Tree.  Print out Element Names	private void traverse(Node node) {				if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("jasperReport")) {			// Find encoding...			NamedNodeMap nnm = node.getAttributes();			this.setName((( nnm.getNamedItem("name") != null) ? nnm.getNamedItem("name").getNodeValue() : ""));			if ( nnm.getNamedItem("columnCount") != null) this.setColumnCount( Integer.parseInt(nnm.getNamedItem("columnCount").getNodeValue()));			if ( nnm.getNamedItem("printOrder") != null) this.setPrintOrder( nnm.getNamedItem("printOrder").getNodeValue());			if ( nnm.getNamedItem("orientation") != null) this.setOrientation( nnm.getNamedItem("orientation").getNodeValue());			if ( nnm.getNamedItem("scriptletClass") != null) this.setScriptletClass( nnm.getNamedItem("scriptletClass").getNodeValue());			if ( nnm.getNamedItem("pageWidth") != null) this.setWidth( Integer.parseInt(nnm.getNamedItem("pageWidth").getNodeValue()));			if ( nnm.getNamedItem("pageHeight") != null) this.setHeight( Integer.parseInt(nnm.getNamedItem("pageHeight").getNodeValue()));			if ( nnm.getNamedItem("columnWidth") != null) this.setColumnWidth( Integer.parseInt(nnm.getNamedItem("columnWidth").getNodeValue()));			if ( nnm.getNamedItem("columnSpacing") != null) this.setColumnSpacing( Integer.parseInt(nnm.getNamedItem("columnSpacing").getNodeValue()));			if ( nnm.getNamedItem("leftMargin") != null) this.setLeftMargin( Integer.parseInt(nnm.getNamedItem("leftMargin").getNodeValue()));			if ( nnm.getNamedItem("rightMargin") != null) this.setRightMargin( Integer.parseInt(nnm.getNamedItem("rightMargin").getNodeValue()));			if ( nnm.getNamedItem("topMargin") != null) this.setTopMargin( Integer.parseInt(nnm.getNamedItem("topMargin").getNodeValue()));			if ( nnm.getNamedItem("bottomMargin") != null) this.setBottomMargin( Integer.parseInt(nnm.getNamedItem("bottomMargin").getNodeValue()));			if ( nnm.getNamedItem("whenNoDataType") != null) this.setWhenNoDataType( nnm.getNamedItem("whenNoDataType").getNodeValue());			if ( nnm.getNamedItem("isTitleNewPage") != null) this.setIsTitleNewPage(nnm.getNamedItem("isTitleNewPage").getNodeValue().equalsIgnoreCase("true") );			if ( nnm.getNamedItem("isSummaryNewPage") != null) this.setIsSummaryNewPage(  nnm.getNamedItem("isSummaryNewPage").getNodeValue().equalsIgnoreCase("true"));		}		else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("property")) {			// Load report property...			JRProperty property = new JRProperty();			NamedNodeMap nnm = node.getAttributes();			if ( nnm.getNamedItem("name") != null) property.setName( nnm.getNamedItem("name").getNodeValue());			if ( nnm.getNamedItem("value") != null) property.setValue( nnm.getNamedItem("value").getNodeValue());						JRproperties.addElement( property );		}		else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("reportFont")) {			// Load report font...			boolean isDefaultFont = false;			IReportFont font = new IReportFont();						NamedNodeMap nnm = node.getAttributes();			if ( nnm.getNamedItem("name") != null) font.setReportFont( nnm.getNamedItem("name").getNodeValue());			if ( nnm.getNamedItem("isDefault") != null) {				isDefaultFont = nnm.getNamedItem("isDefault").getNodeValue().equals("true"); 				font.setDefaultFont(isDefaultFont);			} 			if ( nnm.getNamedItem("fontName") != null) font.setFontName( nnm.getNamedItem("fontName").getNodeValue());			if ( nnm.getNamedItem("size") != null) font.setFontSize( Integer.parseInt( nnm.getNamedItem("size").getNodeValue()) );			if ( nnm.getNamedItem("isBold") != null) font.setBold( nnm.getNamedItem("isBold").getNodeValue().equals("true"));			if ( nnm.getNamedItem("isItalic") != null) font.setItalic( nnm.getNamedItem("isItalic").getNodeValue().equals("true"));			if ( nnm.getNamedItem("isUnderline") != null) font.setUnderline( nnm.getNamedItem("isUnderline").getNodeValue().equals("true"));			if ( nnm.getNamedItem("isStrikeThrough") != null) font.setStrikeTrought( nnm.getNamedItem("isStrikeThrough").getNodeValue().equals("true"));			if ( nnm.getNamedItem("pdfFontName") != null) font.setPDFFontName( nnm.getNamedItem("pdfFontName").getNodeValue());			if ( nnm.getNamedItem("pdfEncoding") != null) font.setPdfEncoding( nnm.getNamedItem("pdfEncoding").getNodeValue());			if ( nnm.getNamedItem("isPdfEmbedded") != null) font.setPdfEmbedded( nnm.getNamedItem("isPdfEmbedded").getNodeValue().equals("true"));						if(isDefaultFont){				defaultFont = (IReportFont) font.clone();			}						fonts.addElement( font );		}		else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("parameter")) {			// Load parameter...			it.businesslogic.ireport.JRParameter parameter = new it.businesslogic.ireport.JRParameter("","java.lang.String",true,"");						NamedNodeMap nnm = node.getAttributes();			if ( nnm.getNamedItem("name") != null) parameter.setName( nnm.getNamedItem("name").getNodeValue());			if ( nnm.getNamedItem("class") != null) parameter.setClassType( nnm.getNamedItem("class").getNodeValue() );			if ( nnm.getNamedItem("isForPrompting") != null) parameter.setIsForPrompting( nnm.getNamedItem("isForPrompting").getNodeValue().equalsIgnoreCase("true") );						// Check for description and expression...			NodeList children = node.getChildNodes();			if (children != null) {				for (int k=0; k< children.getLength(); k++) {					Node nodeChild = (Node)children.item(k);					if (nodeChild.getNodeType() == Node.ELEMENT_NODE && nodeChild.getNodeName().equals("parameterDescription")) {						// Take the CDATA...						NodeList list_child = nodeChild.getChildNodes();						for (int ck=0; ck< list_child.getLength(); ck++) {							Node child_child = (Node)list_child.item(ck);							if (child_child.getNodeType() == Node.CDATA_SECTION_NODE ||							child_child.getNodeType() == Node.TEXT_NODE) {								parameter.setDescription( child_child.getNodeValue() );							}						}					}					else if (nodeChild.getNodeType() == Node.ELEMENT_NODE && nodeChild.getNodeName().equals("defaultValueExpression")) {						// Take the CDATA...						NodeList list_child = nodeChild.getChildNodes();						for (int ck=0; ck< list_child.getLength(); ck++) {							Node child_child = (Node)list_child.item(ck);							if (child_child.getNodeType() == Node.CDATA_SECTION_NODE ||							child_child.getNodeType() == Node.TEXT_NODE) {								parameter.setDefaultValueExpression( child_child.getNodeValue() );							}						}					}				}			}						if (parameter.getName() != null && parameter.getName().length() != 0) {				this.addParameter( parameter );			}		}		else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("queryString")) {			// Load queryString			this.setQuery( readPCDATA(node) );		}		else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("field")) {			// Load field			it.businesslogic.ireport.JRField field = new it.businesslogic.ireport.JRField("","java.lang.String");			field.setDescription("");						NamedNodeMap nnm = node.getAttributes();			if ( nnm.getNamedItem("name") != null) field.setName( nnm.getNamedItem("name").getNodeValue());			if ( nnm.getNamedItem("class") != null) field.setClassType( nnm.getNamedItem("class").getNodeValue() );						// Check for description...			NodeList children = node.getChildNodes();			if (children != null) {				for (int k=0; k< children.getLength(); k++) {					Node nodeChild = (Node)children.item(k);															if (nodeChild.getNodeType() == Node.ELEMENT_NODE && nodeChild.getNodeName().equals("fieldDescription")) {						// Take the CDATA...						NodeList list_child = nodeChild.getChildNodes();												for (int ck=0; ck< list_child.getLength(); ck++) {														Node child_child = (Node)list_child.item(ck);							if (child_child.getNodeType() == Node.CDATA_SECTION_NODE ||							child_child.getNodeType() == Node.TEXT_NODE) {								field.setDescription( child_child.getNodeValue() );							}						}					}				}			}						if (field.getName() != null && field.getName().length() != 0) {				this.addField( field );			}		}		else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("variable")) {			// Load variable			it.businesslogic.ireport.JRVariable variable = new it.businesslogic.ireport.JRVariable("",false);			variable.setResetType("Report"); //Default value...			variable.setResetGroup(""); //Default value...			variable.setCalculation("Nothing"); //Default value...						NamedNodeMap nnm = node.getAttributes();			if ( nnm.getNamedItem("name") != null) variable.setName( nnm.getNamedItem("name").getNodeValue());			if ( nnm.getNamedItem("class") != null) variable.setClassType( nnm.getNamedItem("class").getNodeValue() );			if ( nnm.getNamedItem("resetType") != null) variable.setResetType( nnm.getNamedItem("resetType").getNodeValue() );			if ( nnm.getNamedItem("resetGroup") != null) variable.setResetGroup( nnm.getNamedItem("resetGroup").getNodeValue() );			if ( nnm.getNamedItem("calculation") != null) variable.setCalculation( nnm.getNamedItem("calculation").getNodeValue() );			if ( nnm.getNamedItem("incrementerFactoryClass") != null) variable.setIncrementerFactoryClass( nnm.getNamedItem("incrementerFactoryClass").getNodeValue() );						// Check for description and expression...			NodeList children = node.getChildNodes();			if (children != null) {				for (int k=0; k< children.getLength(); k++) {					Node nodeChild = (Node)children.item(k);					if (nodeChild.getNodeType() == Node.ELEMENT_NODE && nodeChild.getNodeName().equals("variableExpression")) {						// Take the CDATA...						NodeList list_child = nodeChild.getChildNodes();						for (int ck=0; ck< list_child.getLength(); ck++) {							Node child_child = (Node)list_child.item(ck);							if (child_child.getNodeType() == Node.CDATA_SECTION_NODE ||							child_child.getNodeType() == Node.TEXT_NODE) {								variable.setExpression( child_child.getNodeValue() );							}						}					}					else if (nodeChild.getNodeType() == Node.ELEMENT_NODE && nodeChild.getNodeName().equals("initialValueExpression")) {						// Take the CDATA...						NodeList list_child = nodeChild.getChildNodes();						for (int ck=0; ck< list_child.getLength(); ck++) {							Node child_child = (Node)list_child.item(ck);							if (child_child.getNodeType() == Node.CDATA_SECTION_NODE ||							child_child.getNodeType() == Node.TEXT_NODE) {								variable.setInitialValueExpression( child_child.getNodeValue() );							}						}					}				}			}						if (variable.getName() != null && variable.getName().length() != 0) {				this.addVariable( variable );			}		}		else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("group")) {			// Load group			NamedNodeMap nnm = node.getAttributes();			it.businesslogic.ireport.Group group = new it.businesslogic.ireport.Group(this, ""+nnm.getNamedItem("name").getNodeValue());						if ( nnm.getNamedItem("isStartNewColumn") != null) group.setIsStartNewColumn( nnm.getNamedItem("isStartNewColumn").getNodeValue().equals("true") );			if ( nnm.getNamedItem("isStartNewPage") != null) group.setIsStartNewPage( nnm.getNamedItem("isStartNewPage").getNodeValue().equals("true") );			if ( nnm.getNamedItem("isResetPageNumber") != null) group.setIsResetPageNumber( nnm.getNamedItem("isResetPageNumber").getNodeValue().equals("true") );			if ( nnm.getNamedItem("isReprintHeaderOnEachPage") != null) group.setIsReprintHeaderOnEachPage( nnm.getNamedItem("isReprintHeaderOnEachPage").getNodeValue().equals("true") );			if ( nnm.getNamedItem("minHeightToStartNewPage") != null) group.setMinHeightToStartNewPage( Integer.parseInt(nnm.getNamedItem("minHeightToStartNewPage").getNodeValue()));						if (group.getName() != null && group.getName().length() != 0) {				groups.addElement(group); // We don't use here addGroup method!			}						// Looking for header, footer and expression...			NodeList children = node.getChildNodes();			if (children != null) {				for (int k=0; k< children.getLength(); k++) {					Node nodeChild = (Node)children.item(k);					if (nodeChild.getNodeType() == Node.ELEMENT_NODE && nodeChild.getNodeName().equals("groupExpression")) {						// Take the CDATA...						NodeList list_child = nodeChild.getChildNodes();						for (int ck=0; ck< list_child.getLength(); ck++) {							Node child_child = (Node)list_child.item(ck);							if (child_child.getNodeType() == Node.CDATA_SECTION_NODE ||							child_child.getNodeType() == Node.TEXT_NODE) {								group.setGroupExpression( child_child.getNodeValue() );							}						}					}					else if (nodeChild.getNodeType() == Node.ELEMENT_NODE && nodeChild.getNodeName().equals("groupHeader")) {						// Take the band...						NodeList list_child = nodeChild.getChildNodes();						for (int ck=0; ck< list_child.getLength(); ck++) {							Node bandNode = (Node)list_child.item(ck);							if (bandNode.getNodeType() == Node.ELEMENT_NODE && bandNode.getNodeName().equals("band")) {								// Read the band...								NamedNodeMap bandAttributes = bandNode.getAttributes();								if ( bandAttributes.getNamedItem("height") != null) group.getGroupHeader().setHeight( Integer.parseInt(bandAttributes.getNamedItem("height").getNodeValue()) );								if ( bandAttributes.getNamedItem("isSplitAllowed") != null) group.getGroupHeader().setSplitAllowed( bandAttributes.getNamedItem("isSplitAllowed").getNodeValue().equals("true") );								readBandElements(bandNode,group.getGroupHeader());							}						}					}					else if (nodeChild.getNodeType() == Node.ELEMENT_NODE && nodeChild.getNodeName().equals("groupFooter")) {						// Take the band...						NodeList list_child = nodeChild.getChildNodes();						for (int ck=0; ck< list_child.getLength(); ck++) {							Node bandNode = (Node)list_child.item(ck);							if (bandNode.getNodeType() == Node.ELEMENT_NODE && bandNode.getNodeName().equals("band")) {								// Read the band...								NamedNodeMap bandAttributes = bandNode.getAttributes();								if ( bandAttributes.getNamedItem("height") != null) group.getGroupFooter().setHeight( Integer.parseInt(bandAttributes.getNamedItem("height").getNodeValue()) );								if ( bandAttributes.getNamedItem("isSplitAllowed") != null) group.getGroupFooter().setSplitAllowed( bandAttributes.getNamedItem("isSplitAllowed").getNodeValue().equals("true") );								readBandElements(bandNode,group.getGroupFooter());							}

⌨️ 快捷键说明

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