1 32 33 package it.businesslogic.ireport.connection; 34 import java.util.Vector ; 35 import net.sf.jasperreports.engine.*; 36 import net.sf.jasperreports.engine.data.*; 37 38 42 public class SampleJRDataSourceFactory { 43 44 public JRDataSource createDatasource() 47 { 48 javax.swing.table.DefaultTableModel tm = new javax.swing.table.DefaultTableModel (4,2); 49 50 SampleBean person = new SampleBean(); 51 person.setFirstName("Giulio"); 52 person.setLastName("Toffoli"); 53 person.setEmail("gt@businesslogic.it"); 54 tm.setValueAt(person, 0, 0); 55 tm.setValueAt("Test value row 1 col 1", 0, 1); 56 57 person = new SampleBean(); 58 person.setFirstName("Teodor"); 59 person.setLastName("Danciu"); 60 person.setEmail("teodor@hotmail.com"); 61 tm.setValueAt(person, 1, 0); 62 tm.setValueAt("Test value row 2 col 1", 1, 1); 63 64 person = new SampleBean(); 65 person.setFirstName("Mario"); 66 person.setLastName("Rossi"); 67 person.setEmail("mario@rossi.org"); 68 tm.setValueAt(person, 2, 0); 69 tm.setValueAt("Test value row 3 col 1", 2, 1); 70 71 person = new SampleBean(); 72 person.setFirstName("Jennifer"); 73 person.setLastName("Lopez"); 74 person.setEmail("lopez@jennifer.com"); 75 tm.setValueAt(person, 3, 0); 76 tm.setValueAt("Test value row 4 col 1", 3, 1); 77 78 return new JRTableModelDataSource(tm); 79 } 80 81 public JRDataSource createBeanCollectionDatasource() 82 { 83 84 85 return new JRBeanCollectionDataSource(createBeanCollection()); 86 } 87 88 public static Vector createBeanCollection() 89 { 90 java.util.Vector coll = new java.util.Vector (); 91 92 SampleBean person = new SampleBean(); 93 person.setFirstName("Giulio"); 94 person.setLastName("Toffoli"); 95 person.setEmail("gt@businesslogic.it"); 96 coll.add(person); 97 98 person = new SampleBean(); 99 person.setFirstName("Teodor"); 100 person.setLastName("Danciu"); 101 person.setEmail("teodor@hotmail.com"); 102 coll.add(person); 103 104 person = new SampleBean(); 105 person.setFirstName("Mario"); 106 person.setLastName("Rossi"); 107 person.setEmail("mario@rossi.org"); 108 coll.add(person); 109 110 person = new SampleBean(); 111 person.setFirstName("Jennifer"); 112 person.setLastName("Lopez"); 113 person.setEmail("lopez@jennifer.com"); 114 coll.add(person); 115 116 return coll; 117 } 118 } 119 | Popular Tags |