001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.view;
029:
030: import java.awt.BorderLayout;
031: import java.awt.Toolkit;
032: import java.io.InputStream;
033:
034: import net.sf.jasperreports.engine.JRException;
035: import net.sf.jasperreports.engine.JRReport;
036:
037: /**
038: * @author Teodor Danciu (teodord@users.sourceforge.net)
039: * @version $Id: JasperDesignViewer.java 1742 2007-06-08 13:55:29Z shertage $
040: */
041: public class JasperDesignViewer extends javax.swing.JFrame {
042:
043: /** Creates new form JasperDesignViewer */
044: public JasperDesignViewer(String sourceFile, boolean isXML)
045: throws JRException {
046: initComponents();
047:
048: JRDesignViewer viewer = new JRDesignViewer(sourceFile, isXML);
049: this .pnlMain.add(viewer, BorderLayout.CENTER);
050: }
051:
052: /** Creates new form JasperDesignViewer */
053: public JasperDesignViewer(InputStream is, boolean isXML)
054: throws JRException {
055: initComponents();
056:
057: JRDesignViewer viewer = new JRDesignViewer(is, isXML);
058: this .pnlMain.add(viewer, BorderLayout.CENTER);
059: }
060:
061: /** Creates new form JasperDesignViewer */
062: public JasperDesignViewer(JRReport report) throws JRException {
063: initComponents();
064:
065: JRDesignViewer viewer = new JRDesignViewer(report);
066: this .pnlMain.add(viewer, BorderLayout.CENTER);
067: }
068:
069: /** This method is called from within the constructor to
070: * initialize the form.
071: * WARNING: Do NOT modify this code. The content of this method is
072: * always regenerated by the Form Editor.
073: */
074: private void initComponents() {//GEN-BEGIN:initComponents
075: pnlMain = new javax.swing.JPanel();
076:
077: setTitle("JasperDesignViewer");
078: setIconImage(new javax.swing.ImageIcon(getClass().getResource(
079: "/net/sf/jasperreports/view/images/jricon.GIF"))
080: .getImage());
081: addWindowListener(new java.awt.event.WindowAdapter() {
082: public void windowClosing(java.awt.event.WindowEvent evt) {
083: exitForm();
084: }
085: });
086:
087: pnlMain.setLayout(new java.awt.BorderLayout());
088:
089: getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER);
090:
091: pack();
092:
093: Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
094: java.awt.Dimension screenSize = toolkit.getScreenSize();
095: int screenResolution = toolkit.getScreenResolution();
096: float zoom = ((float) screenResolution)
097: / JRViewer.REPORT_RESOLUTION;
098:
099: int height = (int) (550 * zoom);
100: if (height > screenSize.getHeight()) {
101: height = (int) screenSize.getHeight();
102: }
103: int width = (int) (750 * zoom);
104: if (width > screenSize.getWidth()) {
105: width = (int) screenSize.getWidth();
106: }
107:
108: java.awt.Dimension dimension = new java.awt.Dimension(width,
109: height);
110: setSize(dimension);
111: setLocation((screenSize.width - width) / 2,
112: (screenSize.height - height) / 2);
113: }//GEN-END:initComponents
114:
115: /** Exit the Application */
116: void exitForm() {//GEN-FIRST:event_exitForm
117: System.exit(0);
118: }//GEN-LAST:event_exitForm
119:
120: /**
121: * @param args the command line arguments
122: */
123: public static void main(String args[]) {
124: String fileName = null;
125: boolean isXMLFile = false;
126:
127: if (args.length == 0) {
128: usage();
129: return;
130: }
131:
132: int k = 0;
133: while (args.length > k) {
134: if (args[k].startsWith("-F"))
135: fileName = args[k].substring(2);
136: if (args[k].startsWith("-XML"))
137: isXMLFile = true;
138:
139: k++;
140: }
141:
142: try {
143: viewReportDesign(fileName, isXMLFile);
144: } catch (JRException e) {
145: e.printStackTrace();
146: System.exit(1);
147: }
148: }
149:
150: /**
151: *
152: */
153: private static void usage() {
154: System.out.println("JasperDesignViewer usage:");
155: System.out.println("\tjava JasperDesignViewer -XML -Ffile");
156: }
157:
158: /**
159: *
160: */
161: public static void viewReportDesign(String sourceFile, boolean isXML)
162: throws JRException {
163: JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(
164: sourceFile, isXML);
165: jasperDesignViewer.setVisible(true);
166: }
167:
168: /**
169: *
170: */
171: public static void viewReportDesign(InputStream is, boolean isXML)
172: throws JRException {
173: JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(
174: is, isXML);
175: jasperDesignViewer.setVisible(true);
176: }
177:
178: /**
179: *
180: */
181: public static void viewReportDesign(JRReport report)
182: throws JRException {
183: JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(
184: report);
185: jasperDesignViewer.setVisible(true);
186: }
187:
188: // Variables declaration - do not modify//GEN-BEGIN:variables
189: private javax.swing.JPanel pnlMain;
190: // End of variables declaration//GEN-END:variables
191: }
|