View Javadoc

1   /*
2    * DynamicJasper: A library for creating reports dynamically by specifying
3    * columns, groups, styles, etc. at runtime. It also saves a lot of development
4    * time in many cases! (http://sourceforge.net/projects/dynamicjasper)
5    *
6    * Copyright (C) 2008  FDV Solutions (http://www.fdvsolutions.com)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   *
11   * License as published by the Free Software Foundation; either
12   *
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   *
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19   *
20   * Lesser General Public License for more details.
21   *
22   * You should have received a copy of the GNU Lesser General Public
23   * License along with this library; if not, write to the Free Software
24   *
25   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26   *
27   *
28   */
29  
30  package ar.com.fdvs.dj.test;
31  
32  
33  import java.awt.Color;
34  import java.util.Date;
35  import java.util.Map;
36  
37  import net.sf.jasperreports.view.JasperViewer;
38  import ar.com.fdvs.dj.domain.DJHyperLink;
39  import ar.com.fdvs.dj.domain.DynamicReport;
40  import ar.com.fdvs.dj.domain.StringExpression;
41  import ar.com.fdvs.dj.domain.Style;
42  import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
43  import ar.com.fdvs.dj.domain.builders.StyleBuilder;
44  import ar.com.fdvs.dj.domain.constants.Border;
45  import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
46  import ar.com.fdvs.dj.domain.constants.ImageScaleMode;
47  import ar.com.fdvs.dj.domain.constants.Stretching;
48  import ar.com.fdvs.dj.domain.hyperlink.LiteralExpression;
49  
50  public class HyperLinkReportTest extends BaseDjReportTest {
51  
52  	public DynamicReport buildReport() throws Exception {
53  
54  
55  		Style style = new StyleBuilder(false).setHorizontalAlign(HorizontalAlign.CENTER)
56  		.setStretching(Stretching.RELATIVE_TO_TALLEST_OBJECT)
57  		.setBorderColor(Color.BLACK).setBorder(Border.THIN()).build();
58  		/**
59  		 * Creates the DynamicReportBuilder and sets the basic options for
60  		 * the report
61  		 */
62  		FastReportBuilder drb = new FastReportBuilder();
63  		drb.addColumn("State", "state", String.class.getName(),30)
64  			.addColumn("Branch", "branch", String.class.getName(),30)
65  			.addColumn("Product Line", "productLine", String.class.getName(),50)
66  			.addImageColumn("IMG", "image", 50, true,ImageScaleMode.FILL ,style)
67  			.addColumn("Item", "item", String.class.getName(),20)
68  			.addColumn("Item Code", "id", Long.class.getName(),30,true)
69  			.addColumn("Quantity", "quantity", Long.class.getName(),60,true)
70  			.addColumn("Amount", "amount", Float.class.getName(),70,true)
71  			.addGroups(2)
72  			.setDetailHeight(17)
73  			.setTitle("November " + getYear() +" sales report")
74  			.setSubtitle("This report was generated at " + new Date())
75  			.setUseFullPageWidth(true);
76  		
77  		DJHyperLink djlink = new DJHyperLink();
78  		djlink.setExpression(new StringExpression() {
79  			public Object evaluate(Map fields, Map variables, Map parameters) {				
80  				return "http://linkInImage.com?param=" + variables.get("REPORT_COUNT");
81  			}
82  		});
83  		djlink.setTooltip(new LiteralExpression("I'm a literal tootltip"));		
84  		drb.getColumn(3).setLink(djlink);
85  		
86  		DJHyperLink djlink2 = new DJHyperLink();
87  		djlink2.setExpression(new StringExpression() {
88  			public Object evaluate(Map fields, Map variables, Map parameters) {				
89  				return "http://thisIsAURL?count=" + variables.get("REPORT_COUNT");
90  			}
91  		});
92  		djlink2.setTooltip(new StringExpression() {
93  			
94  			public Object evaluate(Map fields, Map variables, Map parameters) {				
95  				return "Im a more elaborated tooltip " + variables.get("REPORT_COUNT");
96  			}
97  		});
98  		drb.getColumn(4).setLink(djlink2);
99  				
100 
101 
102 		DynamicReport dr = drb.build();
103 
104 		return dr;
105 	}
106 
107 	public static void main(String[] args) throws Exception {
108 		HyperLinkReportTest test = new HyperLinkReportTest();
109 		test.testReport();
110 		test.exportToHTML();
111 		JasperViewer.viewReport(test.jp);	//finally display the report report
112 	}
113 
114 }