KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > ReportUI


1 package com.calipso.reportgenerator.userinterface;
2
3 /**
4  * Clase encargada de visualizar un reporte con opcion de impresion y
5  * generacion de salidas a archivos de varios formatos distintos
6  */

7
8 import com.calipso.reportgenerator.userinterface.ReportFrame;
9 import com.calipso.reportgenerator.common.*;
10 import com.calipso.reportgenerator.reportdefinitions.ReportView;
11 import com.calipso.reportgenerator.common.InfoException;
12
13 import javax.swing.*;
14 import java.io.IOException JavaDoc;
15 import java.awt.*;
16
17 import net.sf.jasperreports.engine.*;
18 import net.sf.jasperreports.view.JRViewer;
19
20 public class ReportUI extends ReportFrame {
21
22   private ReportGeneratorConfiguration reportGeneratorConfiguration;
23   private JFrame frame;
24   private ReportView reportView;
25   private ReportSpec reportSpec;
26
27   /**
28    * Inicializa una instancia de ReportUI
29    * @param reportResult <<code>ReportResult</code>> necesario para la creacion del reporte
30    * @param reportManager <<code>ReportManager</code>> necesario para la creacion del reporte
31    * @throws InfoException
32    * @throws IOException
33    */

34   public ReportUI(ReportResult reportResult, ReportSpec reportSpec, IReportManager reportManager, ReportGeneratorConfiguration reportGeneratorConfiguration,
35                   ReportView view, Dimension dim) throws InfoException, IOException JavaDoc {
36     super.reportResult = reportResult;
37     super.reportManager = reportManager;
38     this.reportGeneratorConfiguration = reportGeneratorConfiguration;
39     this.reportView = view;
40     this.reportSpec = reportSpec;
41     try {
42       initialize(dim);
43     } catch (Exception JavaDoc e) {
44       if(reportResult!=null){
45         reportResult.resetReportTableModel();
46       }
47       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("312"), e);
48     }
49   }
50
51   private void initialize(Dimension dim) throws JRException, InfoException {
52     ReportLayoutBuilder builder = new ReportLayoutBuilder(reportGeneratorConfiguration, reportResult, reportSpec);
53     IJasperDefinition design = builder.getJasperDefinition(reportView);
54     JasperReportOrientationUI orientationUI = null;
55     boolean isLandscape = false;
56     if(!ReportLayoutBuilder.isExternal(design)){
57       orientationUI = new JasperReportOrientationUI(new JFrame(), true, reportGeneratorConfiguration);
58       orientationUI.show();
59       isLandscape = orientationUI.isLandscape();
60     }
61     if (ReportLayoutBuilder.isExternal(design) || !orientationUI.getHasCanceled()) {
62       JasperPrint print = builder.getJasperPrint(design, isLandscape);
63       JRViewer jrViewer = new JRViewer(print);
64       jrViewer.setPreferredSize(dim);
65       JasperReportUI jasperReportUI = new JasperReportUI(jrViewer, print);
66       jasperReportUI.pack();
67       frame = jasperReportUI;
68       Image icon = reportGeneratorConfiguration.getImage("icon");
69       if (icon != null) {
70         frame.setIconImage(icon);
71       }
72     } else {
73        this.frame = null;
74     }
75     reportResult.resetReportTableModel();
76   }
77
78   /**
79    * Visualiza el reporte
80    */

81   public void show() {
82     if(getFrame()!=null){
83       getFrame().setVisible(true);
84       getFrame().requestFocus();
85       getFrame().pack();
86       getFrame().setLocation(getDefaultLocation());
87     }
88   }
89
90   private Point getDefaultLocation() {
91     Point ownerLocation = getFrame().getLocation();
92     Dimension ownerSize = getFrame().getSize();
93     Dimension size = getFrame().getSize();
94
95     int x = ownerLocation.x + ownerSize.width / 2 - size.width / 2;
96     int y = ownerLocation.y + ownerSize.height / 2 - size.height / 2;
97     return new Point(x, y);
98   }
99
100   /**
101    * Devuelve el Frame correspondiente al Reporte
102    * @return frame correspondiente al Reporte
103    */

104   public JFrame getFrame() {
105     return frame;
106   }
107
108 }
109
Popular Tags