0001: /*
0002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
0003: * http://www.jaspersoft.com.
0004: *
0005: * Unless you have purchased a commercial license agreement from JasperSoft,
0006: * the following license terms apply:
0007: *
0008: * This program is free software; you can redistribute it and/or modify
0009: * it under the terms of the GNU General Public License version 2 as published by
0010: * the Free Software Foundation.
0011: *
0012: * This program is distributed WITHOUT ANY WARRANTY; and without the
0013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0014: * See the GNU General Public License for more details.
0015: *
0016: * You should have received a copy of the GNU General Public License
0017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
0018: * or write to:
0019: *
0020: * Free Software Foundation, Inc.,
0021: * 59 Temple Place - Suite 330,
0022: * Boston, MA USA 02111-1307
0023: *
0024: *
0025: *
0026: *
0027: * Report.java
0028: *
0029: * Created on 10 febbraio 2003, 19.32
0030: *
0031: */
0032:
0033: package it.businesslogic.ireport;
0034:
0035: import it.businesslogic.ireport.gui.MainFrame;
0036: import it.businesslogic.ireport.gui.event.ReportDocumentStatusChangedEvent;
0037: import it.businesslogic.ireport.gui.event.ReportElementChangedEvent;
0038: import it.businesslogic.ireport.gui.event.ReportSubDatasetChangedEvent;
0039: import java.util.Vector;
0040: import java.util.Iterator;
0041: import java.util.Enumeration;
0042:
0043: //import it.businesslogic.ireport.util.*;
0044: import it.businesslogic.ireport.util.Misc;
0045: import it.businesslogic.ireport.gui.JReportFrame;
0046: import it.businesslogic.ireport.gui.event.StyleChangedEvent;
0047: import it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener;
0048: import it.businesslogic.ireport.gui.event.TemplateChangedEvent;
0049: import it.businesslogic.ireport.refactoring.ReportRefactor;
0050: import net.sf.jasperreports.engine.JRGroup;
0051: import org.w3c.dom.Node;
0052: import org.w3c.dom.NodeList;
0053: import java.io.File;
0054:
0055: /**
0056: *
0057: * @author Administrator
0058: */
0059: public class Report extends SubDataset implements
0060: SubDatasetObjectChangedListener {
0061:
0062: public static int SCRIPTLET_IREPORT_INTERNAL_HANDLING = 1;
0063: public static int SCRIPTLET_NOT_USED = 0;
0064: public static int SCRIPTLET_CLASSIC_HANDLING = 2;
0065:
0066: private int nextGroupId = 0;
0067:
0068: private IReportFont defaultFont = new IReportFont();
0069:
0070: private boolean readOnly = false;
0071:
0072: private int height = 0;
0073:
0074: private int width = 0;
0075:
0076: private Vector elements = new Vector();
0077:
0078: private Vector bands = new Vector();
0079:
0080: private Vector imports = new Vector();
0081:
0082: private Vector templates = new Vector();
0083:
0084: public Vector getTemplates() {
0085: return templates;
0086: }
0087:
0088: public void setTemplates(Vector templates) {
0089: this .templates = templates;
0090: }
0091:
0092: private String filename = "";
0093:
0094: private Vector subDatasets = new Vector();
0095:
0096: private String encoding = "UTF-8";
0097:
0098: private int columnCount = 1;
0099:
0100: private String printOrder = "Vertical";
0101:
0102: private String orientation = "Portrait";
0103:
0104: private String whenNoDataType = "NoPages";
0105:
0106: private int columnWidth = 535;
0107:
0108: private int columnSpacing = 0;
0109:
0110: private int leftMargin = 20;
0111:
0112: private int rightMargin = 20;
0113:
0114: private int topMargin = 30;
0115:
0116: private int bottomMargin = 30;
0117:
0118: private boolean isTitleNewPage = false;
0119:
0120: private boolean isSummaryNewPage = false;
0121:
0122: private long loadTime = 0;
0123:
0124: private Vector fonts = new Vector();
0125:
0126: private Vector styles = new Vector();
0127:
0128: private JReportFrame reportFrame;
0129:
0130: private String reportFormat;
0131:
0132: static int untitledId = 1;
0133:
0134: private int reportChanges = 1; // By default, a report is changed...
0135:
0136: private boolean floatColumnFooter = false;
0137:
0138: private boolean ignorePagination = false;
0139:
0140: /** used to tell the report when outputting to XML that it needs to set isCode="true" in expressions */
0141: protected boolean usingMultiLineExpressions = false;
0142:
0143: private String language = "java";
0144:
0145: private ScriptletCode scripletCode;
0146:
0147: private int scriptletHandling = 2;
0148:
0149: private java.util.HashMap proposedValues = null;
0150:
0151: private boolean loadingFile = false;
0152:
0153: private String formatFactoryClass = "";
0154:
0155: /** Creates a new instance of Report */
0156:
0157: public Report() {
0158: super ();
0159: setName(it.businesslogic.ireport.util.I18n.getString(
0160: "untitledReport", "untitled_report_")
0161: + untitledId);
0162: untitledId++;
0163:
0164: proposedValues = new java.util.HashMap();
0165: // Add basic variables...
0166:
0167: getKeywordLookup().addKeyword("$R{*}");
0168:
0169: //addParameter(new JRParameter("COLUMN_COUNT", "", ));
0170:
0171: bands.addElement(new Band(this , "background", 0));
0172: bands.addElement(new Band(this , "title", 50));
0173: bands.addElement(new Band(this , "pageHeader", 50));
0174: bands.addElement(new Band(this , "columnHeader", 30));
0175: bands.addElement(new Band(this , "detail", 100));
0176: bands.addElement(new Band(this , "columnFooter", 30));
0177: bands.addElement(new Band(this , "pageFooter", 50));
0178: bands.addElement(new Band(this , "lastPageFooter", 50));
0179: bands.addElement(new Band(this , "summary", 50));
0180: bands.addElement(new Band(this , "noData", 0));
0181:
0182: //addImport("it.businesslogic.ireport.IReportScriptlet");
0183: addImport("java.util.*");
0184: addImport("net.sf.jasperreports.engine.*");
0185: addImport("net.sf.jasperreports.engine.data.*");
0186:
0187: try {
0188: scripletCode = new ScriptletCode(ScriptletCode.class
0189: .getClassLoader().getResourceAsStream(
0190: "scriptlet_template.jav"));
0191: } catch (Exception ex) {
0192: ex.printStackTrace();
0193: }
0194:
0195: // Set the user option default...
0196: this .setLanguage(it.businesslogic.ireport.gui.MainFrame
0197: .getMainInstance().getProperties().getProperty(
0198: "DefaultScriptingLanguage", "java"));
0199:
0200: this .addSubDatasetObjectChangedListener(this );
0201:
0202: // Add default style...
0203: String rDefStyle = it.businesslogic.ireport.gui.MainFrame
0204: .getMainInstance().getProperties().getProperty(
0205: "DefaultStyle", "");
0206: if (rDefStyle.length() > 0) {
0207: Vector stylesLib = (Vector) it.businesslogic.ireport.gui.MainFrame
0208: .getMainInstance().getStyleLibrarySet();
0209: for (int i = 0; i < stylesLib.size(); ++i) {
0210: Style s = (Style) stylesLib.get(i);
0211: if (s.getName() != null
0212: && s.getName().equals(rDefStyle)) {
0213: Style s1 = new Style(s);
0214: s1.getAttributes().put(s1.ATTRIBUTE_isDefault,
0215: "true");
0216: this .addStyle(s1);
0217: }
0218: }
0219:
0220: }
0221: }
0222:
0223: /** Creates a new instance of Report reading it by a file...*/
0224: public Report(String xmlFile) throws Exception {
0225:
0226: this ();
0227:
0228: untitledId--;
0229:
0230: // Remove default style...
0231: while (getStyles().size() > 0) {
0232: this .removeStyle((Style) this .getStyles().get(0));
0233: }
0234:
0235: // Set the real default...
0236: ReportReader rr = new ReportReader(this );
0237: rr.readFile(xmlFile);
0238: }
0239:
0240: static public String readPCDATA(Node textNode) {
0241: return readPCDATA(textNode, true);
0242: }
0243:
0244: static public String readPCDATA(Node textNode, boolean trim) {
0245: NodeList list_child = textNode.getChildNodes();
0246: for (int ck = 0; ck < list_child.getLength(); ck++) {
0247: Node child_child = (Node) list_child.item(ck);
0248:
0249: // --- start solution: if there is another node this should be the PCDATA-node
0250: Node ns = child_child.getNextSibling();
0251: if (ns != null)
0252: child_child = ns;
0253: // --- end solution
0254:
0255: final short nt = child_child.getNodeType();
0256: if ((nt == Node.CDATA_SECTION_NODE)
0257: || (nt == Node.TEXT_NODE)) {
0258: if (trim)
0259: return ((String) child_child.getNodeValue()).trim();
0260: return (String) child_child.getNodeValue();
0261: }
0262: }
0263: return "";
0264: }
0265:
0266: static java.awt.Color decodeColor(String colorString) {
0267: java.awt.Color color = null;
0268: char firstChar = colorString.charAt(0);
0269: if (firstChar == '#') {
0270: color = new java.awt.Color(Integer.parseInt(colorString
0271: .substring(1), 16));
0272: } else if ('0' <= firstChar && firstChar <= '9') {
0273: color = new java.awt.Color(Integer.parseInt(colorString));
0274: } else {
0275: if (net.sf.jasperreports.engine.xml.JRXmlConstants
0276: .getColorMap().containsKey(colorString)) {
0277: color = (java.awt.Color) net.sf.jasperreports.engine.xml.JRXmlConstants
0278: .getColorMap().get(colorString);
0279: } else {
0280: color = java.awt.Color.black;
0281: }
0282: }
0283: return color;
0284:
0285: }
0286:
0287: public String createChildGroup(String parentElementGroup) {
0288: nextGroupId++;
0289: if (parentElementGroup.length() > 0)
0290: parentElementGroup += ".";
0291: return parentElementGroup + nextGroupId;
0292: }
0293:
0294: /** Getter for property bands.
0295: * @return Value of property bands.
0296: *
0297: */
0298: public java.util.Vector getBands() {
0299: return bands;
0300: }
0301:
0302: /** Setter for property bands.
0303: * @param bands New value of property bands.
0304: *
0305: */
0306: public void setBands(java.util.Vector bands) {
0307: this .bands = bands;
0308: incrementReportChanges();
0309: }
0310:
0311: /** Getter for property bottomMargin.
0312: * @return Value of property bottomMargin.
0313: *
0314: */
0315: public int getBottomMargin() {
0316: return bottomMargin;
0317: }
0318:
0319: /** Setter for property bottomMargin.
0320: * @param bottomMargin New value of property bottomMargin.
0321: *
0322: */
0323: public void setBottomMargin(int bottomMargin) {
0324: if (this .bottomMargin == bottomMargin)
0325: return;
0326: this .bottomMargin = bottomMargin;
0327: incrementReportChanges();
0328: }
0329:
0330: /** Getter for property columnCount.
0331: * @return Value of property columnCount.
0332: *
0333: */
0334: public int getColumnCount() {
0335: return columnCount;
0336: }
0337:
0338: /** Setter for property columnCount.
0339: * @param columnCount New value of property columnCount.
0340: *
0341: */
0342: public void setColumnCount(int columnCount) {
0343: if (this .columnCount == columnCount)
0344: return;
0345: this .columnCount = columnCount;
0346: incrementReportChanges();
0347: }
0348:
0349: /** Getter for property columnSpacing.
0350: * @return Value of property columnSpacing.
0351: *
0352: */
0353: public int getColumnSpacing() {
0354: return columnSpacing;
0355: }
0356:
0357: /** Setter for property columnSpacing.
0358: * @param columnSpacing New value of property columnSpacing.
0359: *
0360: */
0361: public void setColumnSpacing(int columnSpacing) {
0362: if (this .columnSpacing == columnSpacing)
0363: return;
0364: this .columnSpacing = columnSpacing;
0365: incrementReportChanges();
0366: }
0367:
0368: /** Getter for property columnWidth.
0369: * @return Value of property columnWidth.
0370: *
0371: */
0372: public int getColumnWidth() {
0373: return columnWidth;
0374: }
0375:
0376: /** Setter for property columnWidth.
0377: * @param columnWidth New value of property columnWidth.
0378: *
0379: */
0380: public void setColumnWidth(int columnWidth) {
0381: if (this .columnWidth == columnWidth)
0382: return;
0383: this .columnWidth = columnWidth;
0384: incrementReportChanges();
0385: }
0386:
0387: /** Getter for property elements.
0388: * @return Value of property elements.
0389: *
0390: */
0391: public java.util.Vector getElements() {
0392: return elements;
0393: }
0394:
0395: /** Setter for property elements.
0396: * @param elements New value of property elements.
0397: *
0398: */
0399: public void setElements(java.util.Vector elements) {
0400: this .elements = elements;
0401: incrementReportChanges();
0402: }
0403:
0404: /** Getter for property encoding.
0405: * @return Value of property encoding.
0406: *
0407: */
0408: public java.lang.String getEncoding() {
0409: return encoding;
0410: }
0411:
0412: /** Setter for property encoding.
0413: * @param encoding New value of property encoding.
0414: *
0415: */
0416: public void setEncoding(java.lang.String encoding) {
0417: if ((this .encoding == null) ? encoding == null : this .encoding
0418: .equals(encoding))
0419: return;
0420: this .encoding = encoding;
0421: incrementReportChanges();
0422: }
0423:
0424: /** Getter for property filename.
0425: * @return Value of property filename.
0426: *
0427: */
0428: public java.lang.String getFilename() {
0429: return filename;
0430: }
0431:
0432: /** Setter for property filename.
0433: * @param filename New value of property filename.
0434: *
0435: */
0436: public void setFilename(java.lang.String filename) {
0437: this .filename = filename;
0438: }
0439:
0440: /** Getter for property fonts.
0441: * @return Value of property fonts.
0442: *
0443: */
0444: public java.util.Vector getFonts() {
0445: return fonts;
0446: }
0447:
0448: /** Setter for property fonts.
0449: * @param fonts New value of property fonts.
0450: *
0451: */
0452: public void setFonts(java.util.Vector fonts) {
0453: this .fonts = fonts;
0454: incrementReportChanges();
0455: }
0456:
0457: /** Getter for property height.
0458: * @return Value of property height.
0459: *
0460: */
0461: public int getHeight() {
0462: return height;
0463: }
0464:
0465: /** Setter for property height.
0466: * @param height New value of property height.
0467: *
0468: */
0469: public void setHeight(int height) {
0470: if (this .height == height)
0471: return;
0472: this .height = height;
0473: incrementReportChanges();
0474: }
0475:
0476: /** Getter for property isSummaryNewPage.
0477: * @return Value of property isSummaryNewPage.
0478: *
0479: */
0480: public boolean isIsSummaryNewPage() {
0481: return isSummaryNewPage;
0482: }
0483:
0484: /** Setter for property isSummaryNewPage.
0485: * @param isSummaryNewPage New value of property isSummaryNewPage.
0486: *
0487: */
0488: public void setIsSummaryNewPage(boolean isSummaryNewPage) {
0489: if (this .isSummaryNewPage == isSummaryNewPage)
0490: return;
0491: this .isSummaryNewPage = isSummaryNewPage;
0492: incrementReportChanges();
0493: }
0494:
0495: /** Getter for property isTitleNewPage.
0496: * @return Value of property isTitleNewPage.
0497: *
0498: */
0499: public boolean isIsTitleNewPage() {
0500: return isTitleNewPage;
0501: }
0502:
0503: /** Setter for property isTitleNewPage.
0504: * @param isTitleNewPage New value of property isTitleNewPage.
0505: *
0506: */
0507: public void setIsTitleNewPage(boolean isTitleNewPage) {
0508: if (this .isTitleNewPage == isTitleNewPage)
0509: return;
0510: this .isTitleNewPage = isTitleNewPage;
0511: incrementReportChanges();
0512: }
0513:
0514: /** Getter for property leftMargin.
0515: * @return Value of property leftMargin.
0516: *
0517: */
0518: public int getLeftMargin() {
0519: return leftMargin;
0520: }
0521:
0522: /** Setter for property leftMargin.
0523: * @param leftMargin New value of property leftMargin.
0524: *
0525: */
0526: public void setLeftMargin(int leftMargin) {
0527: if (this .leftMargin == leftMargin)
0528: return;
0529: this .leftMargin = leftMargin;
0530: incrementReportChanges();
0531: }
0532:
0533: /** Getter for property loadTime.
0534: * @return Value of property loadTime.
0535: *
0536: */
0537: public long getLoadTime() {
0538: return loadTime;
0539: }
0540:
0541: /** Setter for property loadTime.
0542: * @param loadTime New value of property loadTime.
0543: *
0544: */
0545: public void setLoadTime(long loadTime) {
0546: this .loadTime = loadTime;
0547: }
0548:
0549: /** Getter for property orientation.
0550: * @return Value of property orientation.
0551: *
0552: */
0553: public java.lang.String getOrientation() {
0554: return orientation;
0555: }
0556:
0557: /** Setter for property orientation.
0558: * @param orientation New value of property orientation.
0559: *
0560: */
0561: public void setOrientation(java.lang.String orientation) {
0562: if ((this .orientation == null) ? orientation == null
0563: : this .orientation.equals(orientation))
0564: return;
0565: this .orientation = orientation;
0566: incrementReportChanges();
0567: }
0568:
0569: /** Getter for property printOrder.
0570: * @return Value of property printOrder.
0571: *
0572: */
0573: public java.lang.String getPrintOrder() {
0574: return printOrder;
0575: }
0576:
0577: /** Setter for property printOrder.
0578: * @param printOrder New value of property printOrder.
0579: *
0580: */
0581: public void setPrintOrder(java.lang.String printOrder) {
0582: if ((this .printOrder == null) ? printOrder == null
0583: : this .printOrder.equals(printOrder))
0584: return;
0585: this .printOrder = printOrder;
0586: incrementReportChanges();
0587: }
0588:
0589: /** Getter for property rightMargin.
0590: * @return Value of property rightMargin.
0591: *
0592: */
0593: public int getRightMargin() {
0594: return rightMargin;
0595: }
0596:
0597: /** Setter for property rightMargin.
0598: * @param rightMargin New value of property rightMargin.
0599: *
0600: */
0601: public void setRightMargin(int rightMargin) {
0602: if (this .rightMargin == rightMargin)
0603: return;
0604: this .rightMargin = rightMargin;
0605: incrementReportChanges();
0606: }
0607:
0608: /** Getter for property topMargin.
0609: * @return Value of property topMargin.
0610: *
0611: */
0612: public int getTopMargin() {
0613: return topMargin;
0614: }
0615:
0616: /** Setter for property topMargin.
0617: * @param topMargin New value of property topMargin.
0618: *
0619: */
0620: public void setTopMargin(int topMargin) {
0621: if (this .topMargin == topMargin)
0622: return;
0623: this .topMargin = topMargin;
0624: incrementReportChanges();
0625: }
0626:
0627: public void addImport(String _import) {
0628: if (!imports.contains(_import)) {
0629: this .imports.add(_import);
0630: incrementReportChanges();
0631: }
0632: }
0633:
0634: /** Getter for property whenNoDataType.
0635: * @return Value of property whenNoDataType.
0636: *
0637: */
0638: public java.lang.String getWhenNoDataType() {
0639: return whenNoDataType;
0640: }
0641:
0642: /** Setter for property whenNoDataType.
0643: * @param whenNoDataType New value of property whenNoDataType.
0644: *
0645: */
0646: public void setWhenNoDataType(java.lang.String whenNoDataType) {
0647: if ((this .whenNoDataType == null) ? whenNoDataType == null
0648: : this .whenNoDataType.equals(whenNoDataType))
0649: return;
0650: this .whenNoDataType = whenNoDataType;
0651: incrementReportChanges();
0652: }
0653:
0654: /** Getter for property width.
0655: * @return Value of property width.
0656: *
0657: */
0658: public int getWidth() {
0659: return width;
0660: }
0661:
0662: /** Setter for property width.
0663: * @param width New value of property width.
0664: *
0665: */
0666: public void setWidth(int width) {
0667: if (this .width == width)
0668: return;
0669: this .width = width;
0670: incrementReportChanges();
0671: }
0672:
0673: /**
0674: * This function compute the Y location of the band.
0675: * In the designer panel, there is as space of 10 pixels (the space
0676: * between the top border of the panel, and the begin of the
0677: * virtual page) that are not added to this measure. This is
0678: * important because permit to multiply this height for a
0679: * zoom factor.
0680: *
0681: * @param b it.businesslogic.ireport.Band The band to compute.
0682: */
0683: public int getBandYLocation(Band b) {
0684: int y = topMargin;
0685:
0686: for (Iterator i = this .bands.iterator(); i.hasNext();) {
0687: Band band = (Band) i.next();
0688: if (band != b) {
0689: y += band.getHeight();
0690: } else {
0691: break;
0692: }
0693: }
0694:
0695: return y;
0696: }
0697:
0698: /** Getter for property reportFrame.
0699: * @return Value of property reportFrame.
0700: *
0701: */
0702: public it.businesslogic.ireport.gui.JReportFrame getReportFrame() {
0703: return reportFrame;
0704: }
0705:
0706: /** Setter for property reportFrame.
0707: * @param reportFrame New value of property reportFrame.
0708: *
0709: */
0710: public void setReportFrame(
0711: it.businesslogic.ireport.gui.JReportFrame reportFrame) {
0712: this .reportFrame = reportFrame;
0713: }
0714:
0715: /** Getter for property reportFormat.
0716: * @return Value of property reportFormat.
0717: *
0718: */
0719: public java.lang.String getReportFormat() {
0720: return reportFormat;
0721: }
0722:
0723: /** Setter for property reportFormat.
0724: * @param reportFormat New value of property reportFormat.
0725: *
0726: */
0727: public void setReportFormat(java.lang.String reportFormat) {
0728: this .reportFormat = reportFormat;
0729: }
0730:
0731: /**
0732: * This method return the height needed by a graphics to
0733: * draw all the document.
0734: */
0735: public int getDesignHeight() {
0736: int y = topMargin + bottomMargin;
0737:
0738: for (Iterator i = this .bands.iterator(); i.hasNext();) {
0739: y += ((Band) i.next()).getHeight();
0740: }
0741:
0742: return y;
0743: }
0744:
0745: public int getDesignHeightNoBG() {
0746: int y = 0;
0747: y += topMargin;
0748: y += bottomMargin;
0749:
0750: for (Iterator i = this .bands.iterator(); i.hasNext();) {
0751: Band b = (Band) i.next();
0752: if (!b.getName().equals("background"))
0753: y += b.getHeight();
0754: }
0755:
0756: return y;
0757: }
0758:
0759: /** Add a group to the reprot and perform an adjust on jReportFrame
0760: * @param group New group to be inserted.
0761: *
0762: */
0763: public void addGroup(Group grp) {
0764: addGroup(grp, true);
0765: }
0766:
0767: /** Add a group to the reprot and perform an adjust on jReportFrame if
0768: * specified
0769: * @param group New group to be inserted.
0770: * @param adjust If true, perform an adjust on jReportFrame
0771: */
0772: public void addGroup(Group grp, boolean adjust) {
0773: incrementReportChanges();
0774: if (!getGroups().contains(grp)) {
0775: getGroups().addElement(grp);
0776: }
0777: String bandsstr = "";
0778:
0779: /*
0780: * start looking for the detail band.
0781: * and place header and footer of new group around it if (Adjust)
0782: */
0783: for (int i = 0; i < bands.size(); i++) {
0784: Band b = (Band) bands.elementAt(i);
0785:
0786: if (b.getName().equals("detail")) {
0787:
0788: if (adjust) {
0789:
0790: int bandYLocation = getBandYLocation(b);
0791:
0792: for (Iterator i2 = elements.iterator(); i2
0793: .hasNext();) {
0794: ReportElement elem = (ReportElement) i2.next();
0795: int delta_y = grp.getGroupHeader().getHeight();
0796:
0797: if (elem.band == grp.getGroupHeader()
0798: || elem.band == grp.getGroupFooter()) {
0799: // Do nothing
0800: } else if (elem.position.y >= bandYLocation
0801: + 10 + b.getHeight()) {
0802: delta_y += grp.getGroupFooter().getHeight();
0803: elem
0804: .trasform(
0805: new java.awt.Point(0,
0806: delta_y),
0807: TransformationType.TRANSFORMATION_MOVE);
0808: } else if (elem.position.y >= bandYLocation + 10) {
0809: elem
0810: .trasform(
0811: new java.awt.Point(0,
0812: delta_y),
0813: TransformationType.TRANSFORMATION_MOVE);
0814: }
0815: }
0816: }
0817:
0818: // All elements with top > detail.top must be shifted of groupHeader height
0819: bands.insertElementAt(grp.getGroupHeader(), i);
0820: // All elements with top > detail.top + detail.bottom must be shifted of groupFooter height
0821: bands.insertElementAt(grp.getGroupFooter(), i + 2);
0822:
0823: break;
0824: }
0825: }
0826: addVariable(new it.businesslogic.ireport.JRVariable(grp
0827: .getName()
0828: + "_COUNT", "java.lang.Integer", true));
0829:
0830: }
0831:
0832: /**
0833: * grpOne will be palce within grpTwo
0834: * This means the header band of grpOne will come after the header band of grpTwo
0835: * And the footer band of grpOne will come before the footer band of grpTwo
0836: * @author: Robert Lamping
0837: * @param direction 1 = down, -1 -up
0838: * @param grp The group that must be moved
0839: */
0840: public synchronized void moveGroup(Group grp, int direction) {
0841:
0842: Group grpOne = null;
0843: Group grpTwo = null;
0844:
0845: if (getGroups().size() <= 1) {
0846: return; // nothing to do
0847: }
0848: incrementReportChanges();
0849: if (direction == 1) {
0850: // down
0851: // there must be at least one element below:
0852: if (getGroups().lastElement() == grp) {
0853: return; // nothing to do
0854: }
0855: grpOne = grp;
0856: grpTwo = (Group) getGroups().get(
0857: getGroups().indexOf(grp) + 1);
0858:
0859: } else {
0860: // up
0861: // there must be at least one element above
0862: if (getGroups().firstElement() == grp) {
0863: return; // nothing to do
0864: }
0865: grpTwo = grp;
0866: grpOne = (Group) getGroups().get(
0867: getGroups().indexOf(grp) - 1);
0868: }
0869:
0870: Band bandGrpOneHeader = getBandByName(grpOne.getGroupHeader()
0871: .getName());
0872: Band bandGrpTwoHeader = getBandByName(grpTwo.getGroupHeader()
0873: .getName());
0874: Band bandGrpOneFooter = getBandByName(grpOne.getGroupFooter()
0875: .getName());
0876: Band bandGrpTwoFooter = getBandByName(grpTwo.getGroupFooter()
0877: .getName());
0878:
0879: int delta1 = bandGrpOneHeader.getHeight();
0880: int delta2 = bandGrpTwoHeader.getHeight();
0881: int delta3 = bandGrpOneFooter.getHeight();
0882: int delta4 = bandGrpTwoFooter.getHeight();
0883:
0884: // Move the elements
0885: for (Iterator i = elements.iterator(); i.hasNext();) {
0886: ReportElement re = (ReportElement) i.next();
0887:
0888: if (re.band == bandGrpOneHeader) {
0889: re.trasform(new java.awt.Point(0, delta2),
0890: TransformationType.TRANSFORMATION_MOVE);
0891: } else if (re.band == bandGrpTwoHeader) {
0892: re.trasform(new java.awt.Point(0, -delta1),
0893: TransformationType.TRANSFORMATION_MOVE);
0894: } else if (re.band == bandGrpTwoFooter) {
0895: re.trasform(new java.awt.Point(0, delta3),
0896: TransformationType.TRANSFORMATION_MOVE);
0897: } else if (re.band == bandGrpOneFooter) {
0898: re.trasform(new java.awt.Point(0, -delta4),
0899: TransformationType.TRANSFORMATION_MOVE);
0900: }
0901: }
0902:
0903: // Now move the groups withing the bands array.
0904: // Move Band Group Headers
0905: int pos1 = bands.indexOf(bandGrpOneHeader);
0906: Band bandBuffer = (Band) bands.get(pos1);
0907: bands.remove(pos1);
0908: bands.insertElementAt(bandBuffer, pos1 + 1);
0909:
0910: // Move Band Group Footers
0911: int pos3 = bands.indexOf(bandGrpTwoFooter);
0912: bandBuffer = (Band) bands.get(pos3);
0913: bands.remove(pos3);
0914: bands.insertElementAt(bandBuffer, pos3 + 1);
0915:
0916: // Now move the groups within the group array
0917: int groupPos = getGroups().indexOf(grpOne);
0918: // groupTwo is always after grpOne
0919: Group groupBuffer = (Group) getGroups().get(groupPos);
0920: getGroups().remove(groupPos);
0921: getGroups().insertElementAt(groupBuffer, groupPos + 1);
0922:
0923: }
0924:
0925: public void delGroup(Group grp) {
0926: if (!getGroups().contains(grp))
0927: return;
0928: incrementReportChanges();
0929:
0930: String bandsstr = "";
0931:
0932: for (int i = 0; i < getVariables().size(); ++i) {
0933: JRVariable var = (JRVariable) getVariables().elementAt(i);
0934: if (var.isBuiltin()
0935: && var.getName().equalsIgnoreCase(
0936: grp.getName() + "_COUNT")) {
0937: removeVariable(var);
0938: break;
0939: }
0940: }
0941:
0942: for (int i = 0; i < elements.size(); ++i) {
0943: // Remove all elements of this group...
0944: ReportElement elem = (ReportElement) elements.elementAt(i);
0945: if (elem.getBand() == grp.getGroupHeader()
0946: || elem.getBand() == grp.getGroupFooter()) {
0947: elements.removeElementAt(i);
0948: i--;
0949: continue;
0950: }
0951: // Adjust elements posisitions...
0952: // Il element
0953: int delta_y = grp.getGroupHeader().getHeight();
0954: if (elem.position.y >= getBandYLocation(grp
0955: .getGroupFooter())
0956: + 10 + grp.getGroupFooter().getHeight()) {
0957: delta_y += grp.getGroupFooter().getHeight();
0958: elem.trasform(new java.awt.Point(0, -delta_y),
0959: TransformationType.TRANSFORMATION_MOVE);
0960: } else if (elem.position.y >= getBandYLocation(grp
0961: .getGroupHeader())
0962: + 10 + grp.getGroupHeader().getHeight()) {
0963: elem.trasform(new java.awt.Point(0, -delta_y),
0964: TransformationType.TRANSFORMATION_MOVE);
0965: }
0966: }
0967:
0968: bands.removeElement(grp.getGroupHeader());
0969: bands.removeElement(grp.getGroupFooter());
0970: getGroups().removeElement(grp);
0971: }
0972:
0973: public Group getGroupByName(String name) {
0974: for (int i = 0; i < getGroups().size(); i++) {
0975: Group grp = (Group) getGroups().elementAt(i);
0976: if (grp.getName().equals(name)) {
0977: return grp;
0978: }
0979: }
0980: return null;
0981: }
0982:
0983: public Band getBandByName(String name) {
0984: for (int i = 0; i < bands.size(); i++) {
0985: Band band = (Band) bands.elementAt(i);
0986: if (band.getName().equals(name)) {
0987: return band;
0988: }
0989: }
0990: return null;
0991: }
0992:
0993: public void saveXMLFile() {
0994: saveXMLFile(this .getFilename());
0995:
0996: }
0997:
0998: public void saveXMLFile(String aFilename) {
0999: if (isReadOnly()) {
1000: javax.swing.JOptionPane.showMessageDialog(getReportFrame()
1001: .getMainFrame(), it.businesslogic.ireport.util.I18n
1002: .getString("fileReadOnly",
1003: "File is read only and cannot be saved."),
1004: it.businesslogic.ireport.util.I18n.getString(
1005: "save", "Save"),
1006: javax.swing.JOptionPane.INFORMATION_MESSAGE);
1007: return;
1008: }
1009:
1010: ReportWriter wr = new ReportWriter(this );
1011: wr.saveXMLFile(aFilename);
1012: }
1013:
1014: /**
1015: * Getter for property usingMultiLineExpressions.
1016: * @return Value of property usingMultiLineExpressions.
1017: */
1018: public boolean isUsingMultiLineExpressions() {
1019: return false; //usingMultiLineExpressions;
1020: }
1021:
1022: /**
1023: * Setter for property usingMultiLineExpressions.
1024: * @param usingMultiLineExpressions New value of property usingMultiLineExpressions.
1025: */
1026: public void setUsingMultiLineExpressions(
1027: boolean usingMultiLineExpressions) {
1028: this .usingMultiLineExpressions = false; //usingMultiLineExpressions;
1029: }
1030:
1031: /** Getter for property scripletCode.
1032: * @return Value of property scripletCode.
1033: *
1034: */
1035: public it.businesslogic.ireport.ScriptletCode getScripletCode() {
1036: return scripletCode;
1037: }
1038:
1039: /** Setter for property scripletCode.
1040: * @param scripletCode New value of property scripletCode.
1041: *
1042: */
1043: public void setScripletCode(
1044: it.businesslogic.ireport.ScriptletCode scripletCode) {
1045: this .scripletCode = scripletCode;
1046: }
1047:
1048: /** Getter for property scriptletHandling.
1049: * @return Value of property scriptletHandling.
1050: *
1051: */
1052: public int getScriptletHandling() {
1053: return scriptletHandling;
1054: }
1055:
1056: /** Setter for property scriptletHandling.
1057: * @param scriptletHandling New value of property scriptletHandling.
1058: *
1059: */
1060: public void setScriptletHandling(int scriptletHandling) {
1061: if (this .scriptletHandling == scriptletHandling)
1062: return;
1063: this .scriptletHandling = scriptletHandling;
1064: incrementReportChanges();
1065:
1066: }
1067:
1068: public String getScriptletFileName() {
1069: return this .getScriptletFileName(this .getFilename());
1070: }
1071:
1072: public String getScriptletFileName(String file) {
1073: if (file == null)
1074: return "Scriptlet.java";
1075:
1076: // we assume /xxx/yyY/qqq/myreport.xml as input file name
1077: if (file.length() > 3) {
1078: file = Misc.changeFileExtension(file, "");
1079: file = file.substring(0, file.length() - 1);
1080: File f = new File(file);
1081: String className = f.getName() + "Scriptlet";
1082:
1083: className = Misc.string_replace("_", ".", className);
1084: className = Misc.string_replace("_", " ", className);
1085: if (Character.isDigit(className.charAt(0))) {
1086: className = "_" + className;
1087: }
1088: className += ".java";
1089: return f.getPath().substring(0,
1090: f.getPath().length() - f.getName().length())
1091: + className;
1092: }
1093:
1094: return "Scriptlet.java";
1095: }
1096:
1097: /**
1098: * Default font specified in xml file.
1099: * @return
1100: */
1101: public IReportFont getDefaultFont() {
1102: return defaultFont;
1103: }
1104:
1105: public boolean isReadOnly() {
1106: return readOnly;
1107: }
1108:
1109: public void checkReadOnlyFlag() {
1110: checkReadOnlyFlag(getFilename());
1111: }
1112:
1113: public void checkReadOnlyFlag(String oF) {
1114: if (oF == null)
1115: return;
1116: File f = new File(oF);
1117: try {
1118: if (!f.exists()) {
1119: readOnly = false;
1120: } else {
1121: readOnly = !f.canWrite();
1122: }
1123: } catch (Exception ex) {
1124: }
1125: readOnly = false;
1126: }
1127:
1128: /**
1129: * return the band that encloses the parameter originY
1130: * @param originY
1131: * @return
1132: *
1133: * an originY < 0 will return nothing
1134: * an originY > designheight will return the Summary band
1135: */
1136: public Band getBandByPosition(int originY) {
1137: Band bname = null;
1138: for (Iterator i = this .getBands().iterator(); i.hasNext();) {
1139: Band b = (Band) i.next();
1140: if (this .getBandYLocation(b) + 10 <= originY) {
1141: bname = b;
1142: }
1143: }
1144: if (bname != null
1145: && (this .getBandYLocation(bname) + 10
1146: + bname.getHeight() < originY))
1147: return null;
1148: return bname;
1149: }
1150:
1151: public Vector getImports() {
1152: return imports;
1153: }
1154:
1155: public void setImports(Vector imports) {
1156: this .imports = imports;
1157: incrementReportChanges();
1158: }
1159:
1160: public boolean isFloatColumnFooter() {
1161: return floatColumnFooter;
1162: }
1163:
1164: public void setFloatColumnFooter(boolean floatColumnFooter) {
1165: if (this .floatColumnFooter == floatColumnFooter)
1166: return;
1167: this .floatColumnFooter = floatColumnFooter;
1168: incrementReportChanges();
1169: }
1170:
1171: public String getLanguage() {
1172: return language;
1173: }
1174:
1175: public void setLanguage(String language) {
1176: if ((this .language == null) ? language == null : this .language
1177: .equals(language))
1178: return;
1179: this .language = language;
1180: incrementReportChanges();
1181: }
1182:
1183: public java.util.HashMap getProposedValues() {
1184: return proposedValues;
1185: }
1186:
1187: public void setProposedValues(java.util.HashMap proposedValues) {
1188: this .proposedValues = proposedValues;
1189: }
1190:
1191: /**
1192: * Recalculate the Columnwidth bases on the available space.
1193: * Introduces at June, 6 to allow PageTransformation.java to calculate the column width again.
1194: *
1195: */
1196: public void recalcColumnWidth() {
1197:
1198: //this.columns = (int)jNumberFieldColumns.getValue();
1199: // calculate space...
1200: // this.setColumnCount( report.getColumnCount() );
1201: // this.setColumnSpacing( report.getColumnSpacing());
1202:
1203: int avail = getWidth() - getLeftMargin() - getRightMargin()
1204: - (getColumnCount() - 1) * getColumnSpacing();
1205: int dim = avail;
1206: dim = (int) ((double) dim / (double) this .getColumnCount());
1207:
1208: while ((dim * this .getColumnCount()) > avail) {
1209: dim--;
1210: }
1211: this .setColumnWidth(dim);
1212: }
1213:
1214: public IReportFont getReportFontByName(String name) {
1215: if (name == null || name.length() == 0)
1216: return null;
1217: for (int i = 0; i < getFonts().size(); ++i) {
1218: IReportFont font = (IReportFont) getFonts().elementAt(i);
1219: if (font.getReportFont().equals(name)) {
1220: return font;
1221: }
1222: }
1223: return null;
1224: }
1225:
1226: public Vector getStyles() {
1227: return styles;
1228: }
1229:
1230: public void setStyles(Vector styles) {
1231: this .styles = styles;
1232: incrementReportChanges();
1233: }
1234:
1235: public void elementGroupResort(Band band) {
1236:
1237: it.businesslogic.ireport.util.TreeNode root = extractBandElementsTree(
1238: band, true);
1239: addElementsTree(root);
1240: incrementReportChanges();
1241: }
1242:
1243: public it.businesslogic.ireport.util.TreeNode extractBandElementsTree(
1244: Band band, boolean remove) {
1245: java.util.List tmpElements = new java.util.ArrayList();
1246: it.businesslogic.ireport.util.TreeNode root = new it.businesslogic.ireport.util.TreeNode(
1247: "");
1248: for (int i = 0; i < getElements().size(); ++i) {
1249: ReportElement element = (ReportElement) getElements()
1250: .elementAt(i);
1251: if (element.getBand() == band) {
1252: tmpElements.add(element);
1253: if (remove) {
1254: getElements().removeElementAt(i);
1255: i--;
1256: }
1257: }
1258: }
1259:
1260: if (tmpElements.size() > 0) {
1261: // we have to reorder all....
1262: for (int i = 0; i < tmpElements.size(); ++i) {
1263: ReportElement element = (ReportElement) tmpElements
1264: .get(i);
1265: String elementGroup = element.getElementGroup();
1266: try {
1267: if (element.getParentElement() != null) {
1268: it.businesslogic.ireport.util.TreeNode tmpRoot = findElementInTreeNode(
1269: root, element.getParentElement());
1270: if (tmpRoot != null)
1271: addElementToGroup(tmpRoot, elementGroup,
1272: element);
1273: } else {
1274: addElementToGroup(root, elementGroup, element);
1275: }
1276: } catch (Exception ex) {
1277: ex.printStackTrace();
1278: }
1279: }
1280: }
1281:
1282: return root;
1283: }
1284:
1285: public void moveElementDown(ReportElement element) {
1286: incrementReportChanges();
1287: it.businesslogic.ireport.util.TreeNode root = extractBandElementsTree(
1288: element.getBand(), true);
1289: root.moveDown(element);
1290: addElementsTree(root);
1291: }
1292:
1293: public void moveElementUp(ReportElement element) {
1294: incrementReportChanges();
1295:
1296: it.businesslogic.ireport.util.TreeNode root = extractBandElementsTree(
1297: element.getBand(), true);
1298: root.moveUp(element);
1299: addElementsTree(root);
1300:
1301: }
1302:
1303: private void addElementsTree(
1304: it.businesslogic.ireport.util.TreeNode root) {
1305: for (int i = 0; i < root.getChilds().size(); ++i) {
1306: it.businesslogic.ireport.util.TreeNode node = (it.businesslogic.ireport.util.TreeNode) (root
1307: .getChilds().get(i));
1308: Object obj = node.getUserObject();
1309: if (obj instanceof ReportElement) {
1310: getElements().add(obj);
1311: if (obj instanceof FrameReportElement) {
1312: addElementsTree(node);
1313: }
1314: } else {
1315: addElementsTree(node);
1316: }
1317: }
1318: }
1319:
1320: /*
1321: public void addElementToGroup(NamedList parentNode, String subGroup, ReportElement element)
1322: {
1323: // 1. We have to find the group node...
1324: if (subGroup.equals(""))
1325: {
1326: parentNode.add( element);
1327: return;
1328: }
1329:
1330: String levelGroupName = "";
1331: if (subGroup.indexOf(".")>=0)
1332: {
1333: levelGroupName = subGroup.substring(0, subGroup.indexOf("."));
1334: subGroup = subGroup.substring(subGroup.indexOf(".")+1);
1335: }
1336: else
1337: {
1338: levelGroupName = subGroup;
1339: subGroup = "";
1340: }
1341:
1342: // 2. Look for the node named levelGroupName
1343: for (int i =0; i<parentNode.size(); ++i)
1344: {
1345: Object node = parentNode.get(i);
1346: if (node instanceof NamedList)
1347: {
1348: NamedList nl = (NamedList)node;
1349: if (nl.getName().equals( levelGroupName ))
1350: {
1351: addElementToGroup(nl, subGroup, element);
1352: return;
1353: }
1354: }
1355: }
1356:
1357: // Node doesn't exists....
1358: NamedList nl = new NamedList(levelGroupName);
1359: addElementToGroup(nl, subGroup, element);
1360: parentNode.add( nl );
1361: }
1362: */
1363:
1364: public void addElementToGroup(
1365: it.businesslogic.ireport.util.TreeNode parentNode,
1366: String subGroup, ReportElement element) {
1367: incrementReportChanges();
1368: // 1. We have to find the group node...
1369: if (subGroup.equals("")) {
1370: parentNode
1371: .addChild(new it.businesslogic.ireport.util.TreeNode(
1372: element));
1373: return;
1374: }
1375:
1376: String levelGroupName = "";
1377: if (subGroup.indexOf(".") >= 0) {
1378: levelGroupName = subGroup.substring(0, subGroup
1379: .indexOf("."));
1380: subGroup = subGroup.substring(subGroup.indexOf(".") + 1);
1381: } else {
1382: levelGroupName = subGroup;
1383: subGroup = "";
1384: }
1385:
1386: // 2. Look for the node named levelGroupName
1387: for (int i = 0; i < parentNode.getChilds().size(); ++i) {
1388: it.businesslogic.ireport.util.TreeNode node = (it.businesslogic.ireport.util.TreeNode) (parentNode
1389: .getChilds().get(i));
1390: if (node.getName().equals(levelGroupName)) {
1391: addElementToGroup(node, subGroup, element);
1392: return;
1393: }
1394: }
1395:
1396: // Node doesn't exists....
1397: it.businesslogic.ireport.util.TreeNode nl = new it.businesslogic.ireport.util.TreeNode(
1398: levelGroupName);
1399: addElementToGroup(nl, subGroup, element);
1400: parentNode.addChild(nl);
1401: }
1402:
1403: public it.businesslogic.ireport.util.TreeNode findElementInTreeNode(
1404: it.businesslogic.ireport.util.TreeNode parentNode,
1405: ReportElement re) {
1406: for (int k = 0; k < parentNode.getChilds().size(); ++k) {
1407: it.businesslogic.ireport.util.TreeNode child = (it.businesslogic.ireport.util.TreeNode) (parentNode
1408: .getChilds().get(k));
1409: if (child.getUserObject() == re) {
1410: return child;
1411: }
1412: if (re.getElementGroup().equals("")
1413: || re.getParentElement() != null) {
1414: if (child.getUserObject() instanceof FrameReportElement
1415: || child.getUserObject() instanceof String) {
1416: it.businesslogic.ireport.util.TreeNode newchild = findElementInTreeNode(
1417: child, re);
1418: if (newchild != null)
1419: return newchild;
1420: }
1421: }
1422: }
1423: return null;
1424: }
1425:
1426: public Vector getSubDatasets() {
1427: return subDatasets;
1428: }
1429:
1430: public void setSubDatasets(Vector subDatasets) {
1431: this .subDatasets = subDatasets;
1432: incrementReportChanges();
1433: }
1434:
1435: public boolean isIgnorePagination() {
1436: return ignorePagination;
1437: }
1438:
1439: public void setIgnorePagination(boolean ignorePagination) {
1440: if (this .ignorePagination == ignorePagination)
1441: return;
1442: this .ignorePagination = ignorePagination;
1443: incrementReportChanges();
1444: }
1445:
1446: /**
1447: * Utility field used by event firing mechanism.
1448: */
1449: private javax.swing.event.EventListenerList listenerList = null;
1450:
1451: public void addSubDataset(SubDataset subDataset) {
1452: this .getSubDatasets().add(subDataset);
1453: incrementReportChanges();
1454: this
1455: .fireReportSubDatasetChangedListenerReportSubDatasetChanged(new ReportSubDatasetChangedEvent(
1456: this , subDataset,
1457: ReportSubDatasetChangedEvent.ADDED,
1458: ReportSubDatasetChangedEvent.OBJECT_SUBDATASET));
1459: subDataset.addSubDatasetObjectChangedListener(this );
1460: }
1461:
1462: public void removeSubDataset(SubDataset subDataset) {
1463: this .getSubDatasets().remove(subDataset);
1464: this
1465: .fireReportSubDatasetChangedListenerReportSubDatasetChanged(new ReportSubDatasetChangedEvent(
1466: this , subDataset,
1467: ReportSubDatasetChangedEvent.REMOVED,
1468: ReportSubDatasetChangedEvent.OBJECT_SUBDATASET));
1469: subDataset.removeSubDatasetObjectChangedListener(this );
1470: incrementReportChanges();
1471: }
1472:
1473: public void removeStyle(Style s) {
1474:
1475: this .getStyles().remove(s);
1476: removeStyleFromElements(s, getElements());
1477: this
1478: .fireStyleChangedListenerStyleChanged(new StyleChangedEvent(
1479: this , StyleChangedEvent.DELETED, s, s));
1480: incrementReportChanges();
1481: }
1482:
1483: public void removeTemplate(Template t) {
1484:
1485: this .getTemplates().remove(t);
1486: this
1487: .fireStyleChangedListenerTemplateChanged(new TemplateChangedEvent(
1488: this , TemplateChangedEvent.DELETED, t, t));
1489: incrementReportChanges();
1490: }
1491:
1492: public void addTemplate(Template t) {
1493:
1494: this .getTemplates().add(t);
1495: this
1496: .fireStyleChangedListenerTemplateChanged(new TemplateChangedEvent(
1497: this , TemplateChangedEvent.ADDED, t, t));
1498: incrementReportChanges();
1499: }
1500:
1501: public void addStyle(Style s) {
1502: this .getStyles().add(s);
1503: incrementReportChanges();
1504: this
1505: .fireStyleChangedListenerStyleChanged(new StyleChangedEvent(
1506: this , StyleChangedEvent.ADDED, s, s));
1507: }
1508:
1509: private void removeStyleFromElements(Style s, Vector this Elements) {
1510: for (int i = 0; i < this Elements.size(); ++i) {
1511: ReportElement re = (ReportElement) this Elements
1512: .elementAt(i);
1513:
1514: if (re.getStyle() == s)
1515: re.setStyle(null);
1516:
1517: if (re instanceof CrosstabReportElement) {
1518: removeStyleFromElements(s, ((CrosstabReportElement) re)
1519: .getElements());
1520: }
1521: }
1522: incrementReportChanges();
1523: }
1524:
1525: /**
1526: * Registers ReportSubDatasetChangedListener to receive events.
1527: * @param listener The listener to register.
1528: */
1529: public synchronized void addReportSubDatasetChangedListener(
1530: it.businesslogic.ireport.gui.event.ReportSubDatasetChangedListener listener) {
1531: if (listenerList == null) {
1532: listenerList = new javax.swing.event.EventListenerList();
1533: }
1534: listenerList
1535: .add(
1536: it.businesslogic.ireport.gui.event.ReportSubDatasetChangedListener.class,
1537: listener);
1538: }
1539:
1540: /**
1541: * Removes ReportSubDatasetChangedListener from the list of listeners.
1542: * @param listener The listener to remove.
1543: */
1544: public synchronized void removeReportSubDatasetChangedListener(
1545: it.businesslogic.ireport.gui.event.ReportSubDatasetChangedListener listener) {
1546: listenerList
1547: .remove(
1548: it.businesslogic.ireport.gui.event.ReportSubDatasetChangedListener.class,
1549: listener);
1550: }
1551:
1552: /**
1553: * Notifies all registered listeners about the event.
1554: *
1555: * @param event The event to be fired
1556: */
1557: public void fireReportSubDatasetChangedListenerReportSubDatasetChanged(
1558: it.businesslogic.ireport.gui.event.ReportSubDatasetChangedEvent event) {
1559: if (listenerList == null)
1560: return;
1561: Object[] listeners = listenerList.getListenerList();
1562: for (int i = listeners.length - 2; i >= 0; i -= 2) {
1563: if (listeners[i] == it.businesslogic.ireport.gui.event.ReportSubDatasetChangedListener.class) {
1564: ((it.businesslogic.ireport.gui.event.ReportSubDatasetChangedListener) listeners[i + 1])
1565: .reportSubDatasetChanged(event);
1566: }
1567: }
1568: }
1569:
1570: public void subDatasetObjectChanged(
1571: it.businesslogic.ireport.gui.event.SubDatasetObjectChangedEvent evt) {
1572:
1573: java.util.Vector changedElements = new java.util.Vector();
1574: if (evt.getType() == evt.FIELD
1575: && evt.getAction() == evt.MODIFIED
1576: && evt.getSource() instanceof SubDataset) {
1577: String oldString = "$F{" + evt.getOldValue() + "}";
1578: String newString = "$F{" + evt.getNewValue() + "}";
1579: if (evt.getOldValue() != null && evt.getNewValue() != null
1580: && !oldString.equals(newString)) {
1581: System.out
1582: .println("replaceInReportExpressions for DS= "
1583: + evt.getSource());
1584: ReportRefactor.replaceInReportExpressions(oldString,
1585: newString, evt.getSource(), this );
1586: }
1587:
1588: // Change referred types in textfields...
1589: if (evt.getSource() == this
1590: && !((JRField) evt.getOldValue()).getClassType()
1591: .equals(
1592: ((JRField) evt.getNewValue())
1593: .getClassType())) {
1594: changedElements
1595: .addAll(ReportRefactor.replaceTextfieldClass(
1596: "$F{" + evt.getNewValue() + "}",
1597: ((JRField) evt.getNewValue())
1598: .getClassType(), getElements()));
1599:
1600: }
1601: }
1602:
1603: if (evt.getType() == evt.PARAMETER
1604: && evt.getAction() == evt.MODIFIED
1605: && evt.getSource() instanceof SubDataset) {
1606: String oldString = "$P{" + evt.getOldValue() + "}";
1607: String newString = "$P{" + evt.getNewValue() + "}";
1608: if (evt.getOldValue() != null && evt.getNewValue() != null
1609: && !oldString.equals(newString)) {
1610: ReportRefactor.replaceInReportExpressions(oldString,
1611: newString, evt.getSource(), this );
1612: }
1613:
1614: if (evt.getSource() == this
1615: && !((JRParameter) evt.getOldValue())
1616: .getClassType().equals(
1617: ((JRParameter) evt.getNewValue())
1618: .getClassType())) {
1619: changedElements
1620: .addAll(ReportRefactor.replaceTextfieldClass(
1621: "$P{" + evt.getNewValue() + "}",
1622: ((JRParameter) evt.getNewValue())
1623: .getClassType(), getElements()));
1624: }
1625: }
1626:
1627: if (evt.getType() == evt.VARIABLE
1628: && evt.getAction() == evt.MODIFIED
1629: && evt.getSource() instanceof SubDataset) {
1630: String oldString = "$V{" + evt.getOldValue() + "}";
1631: String newString = "$V{" + evt.getNewValue() + "}";
1632: if (evt.getOldValue() != null && evt.getNewValue() != null
1633: && !oldString.equals(newString)) {
1634: ReportRefactor.replaceInReportExpressions(oldString,
1635: newString, evt.getSource(), this );
1636: }
1637:
1638: if (evt.getSource() == this
1639: && !((JRVariable) evt.getOldValue()).getClassType()
1640: .equals(
1641: ((JRVariable) evt.getNewValue())
1642: .getClassType())) {
1643: changedElements
1644: .addAll(ReportRefactor.replaceTextfieldClass(
1645: "$V{" + evt.getNewValue() + "}",
1646: ((JRVariable) evt.getNewValue())
1647: .getClassType(), getElements()));
1648: }
1649: }
1650:
1651: if (changedElements.size() > 0) {
1652: System.out.flush();
1653: getReportFrame().fireReportListenerReportElementsChanged(
1654: new ReportElementChangedEvent(getReportFrame(),
1655: changedElements,
1656: ReportElementChangedEvent.CHANGED));
1657: // this window still requires a manual update...
1658: MainFrame.getMainInstance().getElementPropertiesDialog()
1659: .updateSelection();
1660: }
1661:
1662: //System.out.println(evt.getSource() + " " + this);
1663: //fireSubDatasetObjectChangedListenerSubDatasetObjectChanged( evt );
1664: if (getListenerList() != null && evt.getSource() != this ) {
1665: Object[] listeners = getListenerList().getListenerList();
1666: for (int i = listeners.length - 2; i >= 0; i -= 2) {
1667: if (listeners[i + 1] == this )
1668: continue;
1669: //if (listeners[i+1] == evt.getSource()) continue;
1670: if (listeners[i] == it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener.class) {
1671: ((it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener) listeners[i + 1])
1672: .subDatasetObjectChanged(evt);
1673: }
1674: }
1675: }
1676:
1677: incrementReportChanges();
1678: }
1679:
1680: /**
1681: * Registers StyleChangedListener to receive events.
1682: * @param listener The listener to register.
1683: */
1684: public synchronized void addStyleChangedListener(
1685: it.businesslogic.ireport.gui.event.StyleChangedListener listener) {
1686: if (listenerList == null) {
1687: listenerList = new javax.swing.event.EventListenerList();
1688: }
1689: listenerList
1690: .add(
1691: it.businesslogic.ireport.gui.event.StyleChangedListener.class,
1692: listener);
1693: }
1694:
1695: /**
1696: * Removes StyleChangedListener from the list of listeners.
1697: * @param listener The listener to remove.
1698: */
1699: public synchronized void removeStyleChangedListener(
1700: it.businesslogic.ireport.gui.event.StyleChangedListener listener) {
1701: listenerList
1702: .remove(
1703: it.businesslogic.ireport.gui.event.StyleChangedListener.class,
1704: listener);
1705: }
1706:
1707: /**
1708: * Notifies all registered listeners about the event.
1709: *
1710: * @param event The event to be fired
1711: */
1712: public void fireStyleChangedListenerStyleChanged(
1713: it.businesslogic.ireport.gui.event.StyleChangedEvent event) {
1714:
1715: // We have to apply again the style...
1716: Enumeration enum_elements = getElements().elements();
1717: while (enum_elements.hasMoreElements()) {
1718: ReportElement re = (ReportElement) enum_elements
1719: .nextElement();
1720: if (re.getStyle() == event.getNewValue()) {
1721: re.setStyle(event.getNewValue());
1722: }
1723: }
1724:
1725: if (listenerList == null)
1726: return;
1727: Object[] listeners = listenerList.getListenerList();
1728: for (int i = listeners.length - 2; i >= 0; i -= 2) {
1729: if (listeners[i] == it.businesslogic.ireport.gui.event.StyleChangedListener.class) {
1730: ((it.businesslogic.ireport.gui.event.StyleChangedListener) listeners[i + 1])
1731: .styleChanged(event);
1732: }
1733: }
1734: }
1735:
1736: /**
1737: * Notifies all registered listeners about the event.
1738: *
1739: * @param event The event to be fired
1740: */
1741: public void fireStyleChangedListenerTemplateChanged(
1742: it.businesslogic.ireport.gui.event.TemplateChangedEvent event) {
1743:
1744: if (listenerList == null)
1745: return;
1746: Object[] listeners = listenerList.getListenerList();
1747: for (int i = listeners.length - 2; i >= 0; i -= 2) {
1748: if (listeners[i] == it.businesslogic.ireport.gui.event.StyleChangedListener.class) {
1749: ((it.businesslogic.ireport.gui.event.StyleChangedListener) listeners[i + 1])
1750: .templateChanged(event);
1751: }
1752: }
1753: }
1754:
1755: public Style getDefaultStyle() {
1756: for (int i = 0; i < getStyles().size(); ++i) {
1757: Style s = (Style) getStyles().elementAt(i);
1758: if (s.getAttributeBoolean(s.ATTRIBUTE_isDefault, false)) {
1759: return s;
1760: }
1761: }
1762: return null;
1763: }
1764:
1765: public int getReportChanges() {
1766: return reportChanges;
1767: }
1768:
1769: /*
1770: * Keep track of report changes. A ReportDocumentStatusChanged
1771: * event is thrown in the following cases:
1772: *
1773: * currentChanges == 0 && newChanges > 0 => ReportDocumentStatusChanged to DIRTY
1774: * currentChanges > 0 && newChanges == 0 => ReportDocumentStatusChanged to NO_DIRTY
1775: *
1776: */
1777: public void setReportChanges(int newChanges) {
1778:
1779: boolean isChanged = false;
1780:
1781: if (reportChanges == 0 && newChanges > 0)
1782: isChanged = true;
1783: else if (reportChanges > 0 && newChanges == 0)
1784: isChanged = true;
1785:
1786: this .reportChanges = newChanges;
1787:
1788: //if (fireEvent)
1789: //{
1790: fireReportDocumentStatusChangedListenerReportDocumentStatusChanged(new ReportDocumentStatusChangedEvent(
1791: this , isChanged));
1792: //}
1793: }
1794:
1795: public void incrementReportChanges() {
1796: setReportChanges(getReportChanges() + 1);
1797: }
1798:
1799: public void decrementReportChanges() {
1800: if (getReportChanges() > 0) {
1801: setReportChanges(getReportChanges() - 1);
1802: }
1803: }
1804:
1805: /**
1806: * Alias for getReportChanges() > 0
1807: */
1808: public boolean isModified() {
1809: return getReportChanges() > 0;
1810: }
1811:
1812: public boolean isLoadingFile() {
1813: return loadingFile;
1814: }
1815:
1816: public void setLoadingFile(boolean loading) {
1817: this .loadingFile = loading;
1818: }
1819:
1820: /**
1821: * Registers ReportDocumentStatusChangedListener to receive events.
1822: * @param listener The listener to register.
1823: */
1824: public synchronized void addReportDocumentStatusChangedListener(
1825: it.businesslogic.ireport.gui.event.ReportDocumentStatusChangedListener listener) {
1826:
1827: if (listenerList == null) {
1828: listenerList = new javax.swing.event.EventListenerList();
1829: }
1830: listenerList
1831: .add(
1832: it.businesslogic.ireport.gui.event.ReportDocumentStatusChangedListener.class,
1833: listener);
1834: }
1835:
1836: /**
1837: * Removes ReportDocumentStatusChangedListener from the list of listeners.
1838: * @param listener The listener to remove.
1839: */
1840: public synchronized void removeReportDocumentStatusChangedListener(
1841: it.businesslogic.ireport.gui.event.ReportDocumentStatusChangedListener listener) {
1842:
1843: listenerList
1844: .remove(
1845: it.businesslogic.ireport.gui.event.ReportDocumentStatusChangedListener.class,
1846: listener);
1847: }
1848:
1849: /**
1850: * Notifies all registered listeners about the event.
1851: *
1852: * @param event The event to be fired
1853: */
1854: private void fireReportDocumentStatusChangedListenerReportDocumentStatusChanged(
1855: it.businesslogic.ireport.gui.event.ReportDocumentStatusChangedEvent event) {
1856:
1857: if (listenerList == null)
1858: return;
1859: Object[] listeners = listenerList.getListenerList();
1860: for (int i = listeners.length - 2; i >= 0; i -= 2) {
1861: if (listeners[i] == it.businesslogic.ireport.gui.event.ReportDocumentStatusChangedListener.class) {
1862: ((it.businesslogic.ireport.gui.event.ReportDocumentStatusChangedListener) listeners[i + 1])
1863: .reportDocumentStatusChanged(event);
1864: }
1865: }
1866: }
1867:
1868: /**
1869: * Return the available vertical space to add new bands or resize the current ones
1870: *
1871: */
1872: public int getAvailableVerticalSpace() {
1873: int ph = getHeight();
1874: ph -= getTopMargin();
1875: ph -= getBottomMargin();
1876:
1877: for (int i = 0; i < getBands().size(); ++i) {
1878: Band b = (Band) getBands().elementAt(i);
1879: if (b.getName().equals("title") && isTitleNewPage)
1880: continue;
1881: if (b.getName().equals("background"))
1882: continue;
1883: //if (b.getName().equals("lastPageFooter")) continue;
1884: if (b.getName().equals("summary") && isSummaryNewPage)
1885: continue;
1886:
1887: ph -= b.getHeight();
1888: }
1889:
1890: return ph;
1891: }
1892:
1893: public void setDefaultFont(IReportFont defaultFont) {
1894: this .defaultFont = defaultFont;
1895: }
1896:
1897: public static String writeEncodedColor(java.awt.Color c) {
1898: String nums = "0123456789ABCDEF";
1899: String s = "#";
1900: s += nums.charAt(c.getRed() / 16);
1901: s += nums.charAt(c.getRed() % 16);
1902: s += nums.charAt(c.getGreen() / 16);
1903: s += nums.charAt(c.getGreen() % 16);
1904: s += nums.charAt(c.getBlue() / 16);
1905: s += nums.charAt(c.getBlue() % 16);
1906: return s;
1907: }
1908:
1909: public static String getCDATAString(String string, int tabCount) {
1910: //if ( ! Utils.needToBeInsideCDATA( string ) )
1911: // return string;
1912: String CRLF = System.getProperty("line.separator");
1913: String tab = "";
1914: for (int i = 0; i < tabCount; i++) {
1915: tab += "\t";
1916: }
1917: return "<![CDATA[" + string + "]]>"; // + CRLF + tab ;
1918: }
1919:
1920: public String getFormatFactoryClass() {
1921: return formatFactoryClass;
1922: }
1923:
1924: public void setFormatFactoryClass(String formatFactoryClass) {
1925: this.formatFactoryClass = formatFactoryClass;
1926: }
1927:
1928: }
|