1 28 package net.sf.jasperreports.view; 29 30 import java.awt.BorderLayout ; 31 import java.awt.Toolkit ; 32 import java.io.InputStream ; 33 34 import net.sf.jasperreports.engine.JRException; 35 import net.sf.jasperreports.engine.JRReport; 36 37 38 42 public class JasperDesignViewer extends javax.swing.JFrame 43 { 44 45 46 47 public JasperDesignViewer(String 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 57 public JasperDesignViewer(InputStream 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 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 81 private void initComponents() { pnlMain = new javax.swing.JPanel (); 83 84 setTitle("JasperDesignViewer"); 85 setIconImage(new javax.swing.ImageIcon (getClass().getResource("/net/sf/jasperreports/view/images/jricon.GIF")).getImage()); 86 addWindowListener(new java.awt.event.WindowAdapter () { 87 public void windowClosing(java.awt.event.WindowEvent evt) { 88 exitForm(); 89 } 90 }); 91 92 pnlMain.setLayout(new java.awt.BorderLayout ()); 93 94 getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER); 95 96 pack(); 97 98 Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit(); 99 java.awt.Dimension 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 dimension = new java.awt.Dimension (width, height); 115 setSize(dimension); 116 setLocation((screenSize.width-width)/2,(screenSize.height-height)/2); 117 } 119 120 void exitForm() { System.exit(0); 122 } 124 125 128 public static void main(String args[]) 129 { 130 String 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 165 private static void usage() 166 { 167 System.out.println( "JasperDesignViewer usage:" ); 168 System.out.println( "\tjava JasperDesignViewer -XML -Ffile" ); 169 } 170 171 172 175 public static void viewReportDesign(String sourceFile, boolean isXML) throws JRException 176 { 177 JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(sourceFile, isXML); 178 jasperDesignViewer.setVisible(true); 179 } 180 181 182 185 public static void viewReportDesign(InputStream is, boolean isXML) throws JRException 186 { 187 JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(is, isXML); 188 jasperDesignViewer.setVisible(true); 189 } 190 191 192 195 public static void viewReportDesign(JRReport report) throws JRException 196 { 197 JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(report); 198 jasperDesignViewer.setVisible(true); 199 } 200 201 202 private javax.swing.JPanel pnlMain; 204 206 } 207 | Popular Tags |