KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > view > JasperDesignViewer


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.view;
29
30 import java.awt.BorderLayout JavaDoc;
31 import java.awt.Toolkit JavaDoc;
32 import java.io.InputStream JavaDoc;
33
34 import net.sf.jasperreports.engine.JRException;
35 import net.sf.jasperreports.engine.JRReport;
36
37
38 /**
39  * @author Teodor Danciu (teodord@users.sourceforge.net)
40  * @version $Id: JasperDesignViewer.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
41  */

42 public class JasperDesignViewer extends javax.swing.JFrame JavaDoc
43 {
44
45     
46     /** Creates new form JasperDesignViewer */
47     public JasperDesignViewer(String JavaDoc sourceFile, boolean isXML) throws JRException
48     {
49         initComponents();
50
51         JRDesignViewer viewer = new JRDesignViewer(sourceFile, isXML);
52         this.pnlMain.add(viewer, BorderLayout.CENTER);
53     }
54
55     
56     /** Creates new form JasperDesignViewer */
57     public JasperDesignViewer(InputStream JavaDoc is, boolean isXML) throws JRException
58     {
59         initComponents();
60
61         JRDesignViewer viewer = new JRDesignViewer(is, isXML);
62         this.pnlMain.add(viewer, BorderLayout.CENTER);
63     }
64
65     
66     /** Creates new form JasperDesignViewer */
67     public JasperDesignViewer(JRReport report) throws JRException
68     {
69         initComponents();
70
71         JRDesignViewer viewer = new JRDesignViewer(report);
72         this.pnlMain.add(viewer, BorderLayout.CENTER);
73     }
74
75     
76     /** This method is called from within the constructor to
77      * initialize the form.
78      * WARNING: Do NOT modify this code. The content of this method is
79      * always regenerated by the Form Editor.
80      */

81     private void initComponents() {//GEN-BEGIN:initComponents
82
pnlMain = new javax.swing.JPanel JavaDoc();
83
84         setTitle("JasperDesignViewer");
85         setIconImage(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/jricon.GIF")).getImage());
86         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
87             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
88                 exitForm();
89             }
90         });
91
92         pnlMain.setLayout(new java.awt.BorderLayout JavaDoc());
93
94         getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER);
95
96         pack();
97         
98         Toolkit JavaDoc toolkit = java.awt.Toolkit.getDefaultToolkit();
99         java.awt.Dimension JavaDoc screenSize = toolkit.getScreenSize();
100         int screenResolution = toolkit.getScreenResolution();
101         float zoom = ((float) screenResolution) / JRViewer.REPORT_RESOLUTION;
102         
103         int height = (int) (550 * zoom);
104         if (height > screenSize.getHeight())
105         {
106             height = (int) screenSize.getHeight();
107         }
108         int width = (int) (750 * zoom);
109         if (width > screenSize.getWidth())
110         {
111             width = (int) screenSize.getWidth();
112         }
113         
114         java.awt.Dimension JavaDoc dimension = new java.awt.Dimension JavaDoc(width, height);
115         setSize(dimension);
116         setLocation((screenSize.width-width)/2,(screenSize.height-height)/2);
117     }//GEN-END:initComponents
118

119     /** Exit the Application */
120     void exitForm() {//GEN-FIRST:event_exitForm
121
System.exit(0);
122     }//GEN-LAST:event_exitForm
123

124     
125     /**
126     * @param args the command line arguments
127     */

128     public static void main(String JavaDoc args[])
129     {
130         String JavaDoc fileName = null;
131         boolean isXMLFile = false;
132
133         if(args.length == 0)
134         {
135             usage();
136             return;
137         }
138                 
139         int k = 0;
140         while ( args.length > k )
141         {
142             if ( args[k].startsWith("-F") )
143                 fileName = args[k].substring(2);
144             if ( args[k].startsWith("-XML") )
145                 isXMLFile = true;
146             
147             k++;
148         }
149
150         try
151         {
152             viewReportDesign(fileName, isXMLFile);
153         }
154         catch (JRException e)
155         {
156             e.printStackTrace();
157             System.exit(1);
158         }
159     }
160
161     
162     /**
163     *
164     */

165     private static void usage()
166     {
167         System.out.println( "JasperDesignViewer usage:" );
168         System.out.println( "\tjava JasperDesignViewer -XML -Ffile" );
169     }
170
171     
172     /**
173     *
174     */

175     public static void viewReportDesign(String JavaDoc sourceFile, boolean isXML) throws JRException
176     {
177         JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(sourceFile, isXML);
178         jasperDesignViewer.setVisible(true);
179     }
180
181     
182     /**
183     *
184     */

185     public static void viewReportDesign(InputStream JavaDoc is, boolean isXML) throws JRException
186     {
187         JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(is, isXML);
188         jasperDesignViewer.setVisible(true);
189     }
190
191     
192     /**
193     *
194     */

195     public static void viewReportDesign(JRReport report) throws JRException
196     {
197         JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(report);
198         jasperDesignViewer.setVisible(true);
199     }
200
201     
202     // Variables declaration - do not modify//GEN-BEGIN:variables
203
private javax.swing.JPanel JavaDoc pnlMain;
204     // End of variables declaration//GEN-END:variables
205

206 }
207
Popular Tags