KickJava   Java API By Example, From Geeks To Geeks.

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


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.BasicStroke JavaDoc;
31 import java.awt.Color JavaDoc;
32 import java.awt.Container JavaDoc;
33 import java.awt.Cursor JavaDoc;
34 import java.awt.Dimension JavaDoc;
35 import java.awt.Graphics2D JavaDoc;
36 import java.awt.Image JavaDoc;
37 import java.awt.Point JavaDoc;
38 import java.awt.RenderingHints JavaDoc;
39 import java.awt.Shape JavaDoc;
40 import java.awt.Stroke JavaDoc;
41 import java.awt.Toolkit JavaDoc;
42 import java.awt.font.TextAttribute JavaDoc;
43 import java.awt.geom.AffineTransform JavaDoc;
44 import java.awt.image.BufferedImage JavaDoc;
45 import java.io.InputStream JavaDoc;
46 import java.util.Collection JavaDoc;
47 import java.util.HashMap JavaDoc;
48 import java.util.Iterator JavaDoc;
49 import java.util.List JavaDoc;
50 import java.util.Map JavaDoc;
51
52 import javax.swing.DefaultComboBoxModel JavaDoc;
53 import javax.swing.ImageIcon JavaDoc;
54 import javax.swing.JOptionPane JavaDoc;
55 import javax.swing.JViewport JavaDoc;
56
57 import net.sf.jasperreports.crosstabs.JRCellContents;
58 import net.sf.jasperreports.crosstabs.JRCrosstab;
59 import net.sf.jasperreports.crosstabs.JRCrosstabCell;
60 import net.sf.jasperreports.crosstabs.JRCrosstabColumnGroup;
61 import net.sf.jasperreports.crosstabs.JRCrosstabRowGroup;
62 import net.sf.jasperreports.crosstabs.fill.calculation.BucketDefinition;
63 import net.sf.jasperreports.engine.JRAlignment;
64 import net.sf.jasperreports.engine.JRBand;
65 import net.sf.jasperreports.engine.JRBox;
66 import net.sf.jasperreports.engine.JRBreak;
67 import net.sf.jasperreports.engine.JRChart;
68 import net.sf.jasperreports.engine.JRChild;
69 import net.sf.jasperreports.engine.JRElement;
70 import net.sf.jasperreports.engine.JRElementGroup;
71 import net.sf.jasperreports.engine.JREllipse;
72 import net.sf.jasperreports.engine.JRException;
73 import net.sf.jasperreports.engine.JRExpression;
74 import net.sf.jasperreports.engine.JRExpressionChunk;
75 import net.sf.jasperreports.engine.JRFrame;
76 import net.sf.jasperreports.engine.JRGraphicElement;
77 import net.sf.jasperreports.engine.JRGroup;
78 import net.sf.jasperreports.engine.JRImage;
79 import net.sf.jasperreports.engine.JRLine;
80 import net.sf.jasperreports.engine.JRRectangle;
81 import net.sf.jasperreports.engine.JRReport;
82 import net.sf.jasperreports.engine.JRStaticText;
83 import net.sf.jasperreports.engine.JRSubreport;
84 import net.sf.jasperreports.engine.JRTextElement;
85 import net.sf.jasperreports.engine.JRTextField;
86 import net.sf.jasperreports.engine.JasperCompileManager;
87 import net.sf.jasperreports.engine.base.JRBaseBox;
88 import net.sf.jasperreports.engine.design.JRDesignFrame;
89 import net.sf.jasperreports.engine.design.JasperDesign;
90 import net.sf.jasperreports.engine.export.TextRenderer;
91 import net.sf.jasperreports.engine.fill.TextMeasurer;
92 import net.sf.jasperreports.engine.util.JRFontUtil;
93 import net.sf.jasperreports.engine.util.JRGraphEnvInitializer;
94 import net.sf.jasperreports.engine.util.JRImageLoader;
95 import net.sf.jasperreports.engine.util.JRLoader;
96 import net.sf.jasperreports.engine.util.JRStyledText;
97 import net.sf.jasperreports.engine.util.JRStyledTextParser;
98 import net.sf.jasperreports.engine.xml.JRXmlLoader;
99
100 import org.xml.sax.SAXException JavaDoc;
101
102
103 /**
104  * @author Teodor Danciu (teodord@users.sourceforge.net)
105  * @version $Id: JRDesignViewer.java 1507 2006-11-27 17:12:17 +0200 (Mon, 27 Nov 2006) teodord $
106  */

107 public class JRDesignViewer extends javax.swing.JPanel JavaDoc
108 {
109
110
111     /**
112      *
113      */

114     private static final int TYPE_FILE_NAME = 1;
115     private static final int TYPE_INPUT_STREAM = 2;
116     private static final int TYPE_JASPER_DESIGN = 3;
117
118     private static final int zooms[] = {50, 75, 100, 125, 150, 175, 200, 250};
119
120     private int type = TYPE_FILE_NAME;
121     private boolean isXML = false;
122     private String JavaDoc reportFileName = null;
123     private JRReport report = null;
124     private float zoom = 1f;
125     
126     /**
127      * the screen resolution.
128      */

129     private int screenResolution = JRViewer.REPORT_RESOLUTION;
130     
131     /**
132      * the zoom ration adjusted to the screen resolution.
133      */

134     private float realZoom = 0f;
135
136     private int offsetY = 0;
137     private int upColumns = 0;
138     private int downColumns = 0;
139
140     private int downX = 0;
141     private int downY = 0;
142
143     protected JRStyledTextParser styledTextParser = new JRStyledTextParser();
144     protected TextRenderer textRenderer = TextRenderer.getInstance();
145
146     
147     /** Creates new form JRDesignViewer */
148     public JRDesignViewer(String JavaDoc fileName, boolean isXML) throws JRException
149     {
150         JRGraphEnvInitializer.initializeGraphEnv();
151
152         setScreenDetails();
153
154         initComponents();
155
156         this.loadReport(fileName, isXML);
157         this.cmbZoom.setSelectedIndex(2);//100%
158
}
159
160     
161     /** Creates new form JRDesignViewer */
162     public JRDesignViewer(InputStream JavaDoc is, boolean isXML) throws JRException
163     {
164         JRGraphEnvInitializer.initializeGraphEnv();
165
166         setScreenDetails();
167         
168         initComponents();
169
170         this.loadReport(is, isXML);
171         this.cmbZoom.setSelectedIndex(2);//100%
172
}
173
174     
175     /** Creates new form JRDesignViewer */
176     public JRDesignViewer(JRReport report) throws JRException
177     {
178         JRGraphEnvInitializer.initializeGraphEnv();
179
180         setScreenDetails();
181
182         initComponents();
183
184         this.loadReport(report);
185         this.cmbZoom.setSelectedIndex(2);//100%
186
}
187
188     
189     private void setScreenDetails()
190     {
191         screenResolution = Toolkit.getDefaultToolkit().getScreenResolution();
192         setZoom(1f);
193     }
194
195     
196     /** This method is called from within the constructor to
197      * initialize the form.
198      * WARNING: Do NOT modify this code. The content of this method is
199      * always regenerated by the Form Editor.
200      */

201     private void initComponents() {//GEN-BEGIN:initComponents
202
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
203
204         tlbToolBar = new javax.swing.JPanel JavaDoc();
205         btnReload = new javax.swing.JButton JavaDoc();
206         pnlSep01 = new javax.swing.JPanel JavaDoc();
207         pnlSep02 = new javax.swing.JPanel JavaDoc();
208         btnZoomIn = new javax.swing.JButton JavaDoc();
209         btnZoomOut = new javax.swing.JButton JavaDoc();
210         cmbZoom = new javax.swing.JComboBox JavaDoc();
211         DefaultComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc();
212         for(int i = 0; i < zooms.length; i++)
213         {
214             model.addElement("" + zooms[i] + "%");
215         }
216         cmbZoom.setModel(model);
217
218         pnlMain = new javax.swing.JPanel JavaDoc();
219         scrollPane = new javax.swing.JScrollPane JavaDoc();
220         scrollPane.getHorizontalScrollBar().setUnitIncrement(5);
221         scrollPane.getVerticalScrollBar().setUnitIncrement(5);
222
223         pnlInScroll = new javax.swing.JPanel JavaDoc();
224         pnlPage = new javax.swing.JPanel JavaDoc();
225         jPanel4 = new javax.swing.JPanel JavaDoc();
226         jPanel5 = new javax.swing.JPanel JavaDoc();
227         jPanel6 = new javax.swing.JPanel JavaDoc();
228         jPanel7 = new javax.swing.JPanel JavaDoc();
229         jPanel8 = new javax.swing.JPanel JavaDoc();
230         jLabel1 = new javax.swing.JLabel JavaDoc();
231         jPanel9 = new javax.swing.JPanel JavaDoc();
232         lblPage = new javax.swing.JLabel JavaDoc();
233
234         setLayout(new java.awt.BorderLayout JavaDoc());
235
236         tlbToolBar.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT, 0, 2));
237
238         btnReload.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/reload.GIF")));
239         btnReload.setText("Reload");
240         btnReload.setToolTipText("Reload Document");
241         btnReload.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
242         btnReload.setMaximumSize(new java.awt.Dimension JavaDoc(80, 23));
243         btnReload.setMinimumSize(new java.awt.Dimension JavaDoc(80, 23));
244         btnReload.setPreferredSize(new java.awt.Dimension JavaDoc(80, 23));
245         btnReload.addActionListener(new java.awt.event.ActionListener JavaDoc() {
246             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
247                 btnReloadActionPerformed();
248             }
249         });
250
251         tlbToolBar.add(btnReload);
252
253         pnlSep01.setMaximumSize(new java.awt.Dimension JavaDoc(10, 10));
254         tlbToolBar.add(pnlSep01);
255
256         pnlSep02.setMaximumSize(new java.awt.Dimension JavaDoc(10, 10));
257         tlbToolBar.add(pnlSep02);
258
259         btnZoomIn.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/zoomin.GIF")));
260         btnZoomIn.setToolTipText("Zoom In");
261         btnZoomIn.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
262         btnZoomIn.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
263         btnZoomIn.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
264         btnZoomIn.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
265         btnZoomIn.addActionListener(new java.awt.event.ActionListener JavaDoc() {
266             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
267                 btnZoomInActionPerformed();
268             }
269         });
270
271         tlbToolBar.add(btnZoomIn);
272
273         btnZoomOut.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/zoomout.GIF")));
274         btnZoomOut.setToolTipText("Zoom Out");
275         btnZoomOut.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
276         btnZoomOut.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
277         btnZoomOut.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
278         btnZoomOut.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
279         btnZoomOut.addActionListener(new java.awt.event.ActionListener JavaDoc() {
280             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
281                 btnZoomOutActionPerformed();
282             }
283         });
284
285         tlbToolBar.add(btnZoomOut);
286
287         cmbZoom.setToolTipText("Zoom Ratio");
288         cmbZoom.setMaximumSize(new java.awt.Dimension JavaDoc(80, 23));
289         cmbZoom.setMinimumSize(new java.awt.Dimension JavaDoc(80, 23));
290         cmbZoom.setPreferredSize(new java.awt.Dimension JavaDoc(80, 23));
291         cmbZoom.addActionListener(new java.awt.event.ActionListener JavaDoc() {
292             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
293                 cmbZoomActionPerformed();
294             }
295         });
296
297         tlbToolBar.add(cmbZoom);
298
299         add(tlbToolBar, java.awt.BorderLayout.NORTH);
300
301         pnlMain.setLayout(new java.awt.BorderLayout JavaDoc());
302
303         pnlInScroll.setLayout(new java.awt.GridBagLayout JavaDoc());
304
305         pnlPage.setLayout(new java.awt.BorderLayout JavaDoc());
306
307         pnlPage.setMinimumSize(new java.awt.Dimension JavaDoc(100, 100));
308         pnlPage.setPreferredSize(new java.awt.Dimension JavaDoc(100, 100));
309         jPanel4.setLayout(new java.awt.GridBagLayout JavaDoc());
310
311         jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(100, 120));
312         jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(100, 120));
313         jPanel5.setBackground(java.awt.Color.gray);
314         jPanel5.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
315         jPanel5.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
316         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
317         gridBagConstraints.gridx = 2;
318         gridBagConstraints.gridy = 1;
319         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
320         jPanel4.add(jPanel5, gridBagConstraints);
321
322         jPanel6.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
323         jPanel6.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
324         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
325         gridBagConstraints.gridx = 0;
326         gridBagConstraints.gridy = 2;
327         jPanel4.add(jPanel6, gridBagConstraints);
328
329         jPanel7.setBackground(java.awt.Color.gray);
330         jPanel7.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
331         jPanel7.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
332         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
333         gridBagConstraints.gridx = 1;
334         gridBagConstraints.gridy = 2;
335         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
336         jPanel4.add(jPanel7, gridBagConstraints);
337
338         jPanel8.setBackground(java.awt.Color.gray);
339         jPanel8.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
340         jPanel8.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
341         jLabel1.setText("jLabel1");
342         jPanel8.add(jLabel1);
343
344         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
345         gridBagConstraints.gridx = 2;
346         gridBagConstraints.gridy = 2;
347         jPanel4.add(jPanel8, gridBagConstraints);
348
349         jPanel9.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
350         jPanel9.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
351         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
352         gridBagConstraints.gridx = 2;
353         gridBagConstraints.gridy = 0;
354         jPanel4.add(jPanel9, gridBagConstraints);
355
356         lblPage.setBackground(java.awt.Color.white);
357         lblPage.setBorder(new javax.swing.border.LineBorder JavaDoc(new java.awt.Color JavaDoc(0, 0, 0)));
358         lblPage.setOpaque(true);
359         lblPage.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
360             public void mousePressed(java.awt.event.MouseEvent JavaDoc evt) {
361                 lblPageMousePressed(evt);
362             }
363             public void mouseReleased(java.awt.event.MouseEvent JavaDoc evt) {
364                 lblPageMouseReleased();
365             }
366         });
367
368         lblPage.addMouseMotionListener(new java.awt.event.MouseMotionAdapter JavaDoc() {
369             public void mouseDragged(java.awt.event.MouseEvent JavaDoc evt) {
370                 lblPageMouseDragged(evt);
371             }
372         });
373
374         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
375         gridBagConstraints.gridx = 0;
376         gridBagConstraints.gridy = 0;
377         gridBagConstraints.gridwidth = 2;
378         gridBagConstraints.gridheight = 2;
379         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
380         gridBagConstraints.weightx = 1.0;
381         gridBagConstraints.weighty = 1.0;
382         jPanel4.add(lblPage, gridBagConstraints);
383
384         pnlPage.add(jPanel4, java.awt.BorderLayout.CENTER);
385
386         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
387         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 5, 5);
388         pnlInScroll.add(pnlPage, gridBagConstraints);
389
390         scrollPane.setViewportView(pnlInScroll);
391
392         pnlMain.add(scrollPane, java.awt.BorderLayout.CENTER);
393
394         add(pnlMain, java.awt.BorderLayout.CENTER);
395
396     }//GEN-END:initComponents
397

398     void btnReloadActionPerformed()//GEN-FIRST:event_btnReloadActionPerformed
399
{//GEN-HEADEREND:event_btnReloadActionPerformed
400
// Add your handling code here:
401
if (this.type == TYPE_FILE_NAME)
402         {
403             try
404             {
405                 this.loadReport(this.reportFileName, this.isXML);
406                 //this.cmbZoom.setSelectedIndex(2);//100%
407
this.refreshDesign();
408             }
409             catch (JRException e)
410             {
411                 e.printStackTrace();
412                 JOptionPane.showMessageDialog(this, "Error loading report design. See console for details.");
413             }
414         }
415     }//GEN-LAST:event_btnReloadActionPerformed
416

417     void btnZoomInActionPerformed()//GEN-FIRST:event_btnZoomInActionPerformed
418
{//GEN-HEADEREND:event_btnZoomInActionPerformed
419
// Add your handling code here:
420
int index = this.cmbZoom.getSelectedIndex();
421         if (index < this.cmbZoom.getModel().getSize() - 1)
422         {
423             this.cmbZoom.setSelectedIndex(index + 1);
424         }
425     }//GEN-LAST:event_btnZoomInActionPerformed
426

427     void btnZoomOutActionPerformed()//GEN-FIRST:event_btnZoomOutActionPerformed
428
{//GEN-HEADEREND:event_btnZoomOutActionPerformed
429
// Add your handling code here:
430
int index = this.cmbZoom.getSelectedIndex();
431         if (index > 0)
432         {
433             this.cmbZoom.setSelectedIndex(index - 1);
434         }
435     }//GEN-LAST:event_btnZoomOutActionPerformed
436

437     void lblPageMousePressed(java.awt.event.MouseEvent JavaDoc evt)//GEN-FIRST:event_lblPageMousePressed
438
{//GEN-HEADEREND:event_lblPageMousePressed
439
// Add your handling code here:
440
this.lblPage.setCursor(new Cursor JavaDoc(Cursor.MOVE_CURSOR));
441
442         this.downX = evt.getX();
443         this.downY = evt.getY();
444     }//GEN-LAST:event_lblPageMousePressed
445

446     void lblPageMouseReleased()//GEN-FIRST:event_lblPageMouseReleased
447
{//GEN-HEADEREND:event_lblPageMouseReleased
448
// Add your handling code here:
449
this.lblPage.setCursor(new Cursor JavaDoc(Cursor.DEFAULT_CURSOR));
450     }//GEN-LAST:event_lblPageMouseReleased
451

452     void lblPageMouseDragged(java.awt.event.MouseEvent JavaDoc evt)//GEN-FIRST:event_lblPageMouseDragged
453
{//GEN-HEADEREND:event_lblPageMouseDragged
454
// Add your handling code here:
455
Container JavaDoc container = pnlInScroll.getParent();
456         if (container instanceof JViewport JavaDoc)
457         {
458             JViewport JavaDoc viewport = (JViewport JavaDoc) container;
459             Point JavaDoc point = viewport.getViewPosition();
460             int newX = point.x - (evt.getX() - downX);
461             int newY = point.y - (evt.getY() - downY);
462             
463             int maxX = pnlInScroll.getWidth() - viewport.getWidth();
464             int maxY = pnlInScroll.getHeight() - viewport.getHeight();
465
466             if (newX < 0)
467             {
468                 newX = 0;
469             }
470             if (newX > maxX)
471             {
472                 newX = maxX;
473             }
474             if (newY < 0)
475             {
476                 newY = 0;
477             }
478             if (newY > maxY)
479             {
480                 newY = maxY;
481             }
482             
483             viewport.setViewPosition(new Point JavaDoc(newX, newY));
484         }
485     }//GEN-LAST:event_lblPageMouseDragged
486

487     void cmbZoomActionPerformed()//GEN-FIRST:event_cmbZoomActionPerformed
488
{//GEN-HEADEREND:event_cmbZoomActionPerformed
489
// Add your handling code here:
490
int index = this.cmbZoom.getSelectedIndex();
491         setZoom(zooms[index] / 100f);
492         this.btnZoomIn.setEnabled( (index < this.cmbZoom.getModel().getSize() - 1) );
493         this.btnZoomOut.setEnabled( (index > 0) );
494         this.refreshDesign();
495     }//GEN-LAST:event_cmbZoomActionPerformed
496

497
498     private void setZoom(float zoom)
499     {
500         this.zoom = zoom;
501         this.realZoom = this.zoom * screenResolution / JRViewer.REPORT_RESOLUTION;
502     }
503
504
505     /**
506     */

507     private void verifyDesign(JasperDesign jasperDesign) throws JRException
508     {
509         /* */
510         Collection JavaDoc brokenRules = JasperCompileManager.verifyDesign(jasperDesign);
511         if (brokenRules != null && brokenRules.size() > 0)
512         {
513             StringBuffer JavaDoc sbuffer = new StringBuffer JavaDoc();
514             sbuffer.append("Report definition not valid : ");
515             int i = 1;
516             for(Iterator JavaDoc it = brokenRules.iterator(); it.hasNext(); i++)
517             {
518                 sbuffer.append("\n\t " + i + ". " + (String JavaDoc)it.next());
519             }
520             
521             throw new JRException(sbuffer.toString());
522         }
523     }
524
525
526     /**
527     */

528     private void loadReport(String JavaDoc fileName, boolean isXmlReport) throws JRException
529     {
530         if (isXmlReport)
531         {
532             JasperDesign jasperDesign = JRXmlLoader.load(fileName);
533             setReport(jasperDesign);
534         }
535         else
536         {
537             setReport((JRReport) JRLoader.loadObject(fileName));
538         }
539         this.type = TYPE_FILE_NAME;
540         this.isXML = isXmlReport;
541         this.reportFileName = fileName;
542         this.setOffsetY();
543         this.btnReload.setEnabled(true);
544     }
545
546
547     /**
548     */

549     private void loadReport(InputStream JavaDoc is, boolean isXmlReport) throws JRException
550     {
551         if (isXmlReport)
552         {
553             JasperDesign jasperDesign = JRXmlLoader.load(is);
554             setReport(jasperDesign);
555         }
556         else
557         {
558             setReport((JRReport) JRLoader.loadObject(is));
559         }
560         this.type = TYPE_INPUT_STREAM;
561         this.isXML = isXmlReport;
562         this.setOffsetY();
563         this.btnReload.setEnabled(false);
564     }
565
566
567     /**
568     */

569     private void loadReport(JRReport rep) throws JRException
570     {
571         setReport(rep);
572         this.type = TYPE_JASPER_DESIGN;
573         this.isXML = false;
574         this.setOffsetY();
575         this.btnReload.setEnabled(false);
576     }
577     
578     private void setReport(JRReport report) throws JRException
579     {
580         if (report instanceof JasperDesign)
581         {
582             verifyDesign((JasperDesign) report);
583         }
584         
585         this.report = report;
586     }
587
588
589     /**
590     *
591     */

592     public void setOffsetY()
593     {
594         offsetY = report.getTopMargin();
595         offsetY += (report.getTitle() != null ? report.getTitle().getHeight() : 0);
596         offsetY += (report.getPageHeader() != null ? report.getPageHeader().getHeight() : 0);
597         upColumns = offsetY;
598         offsetY += (report.getColumnHeader() != null ? report.getColumnHeader().getHeight() : 0);
599
600         JRGroup group = null;
601         JRGroup[] groups = report.getGroups();
602         if (groups != null && groups.length > 0)
603         {
604             for(int i = 0; i < groups.length; i++)
605             {
606                 group = groups[i];
607
608                 offsetY += (group.getGroupHeader() != null ? group.getGroupHeader().getHeight() : 0);
609             }
610         }
611
612         offsetY += (report.getDetail() != null ? report.getDetail().getHeight() : 0);
613
614         if (groups != null && groups.length > 0)
615         {
616             for(int i = groups.length - 1; i >= 0; i--)
617             {
618                 group = groups[i];
619
620                 offsetY += (group.getGroupFooter() != null ? group.getGroupFooter().getHeight() : 0);
621             }
622         }
623
624         offsetY += (report.getColumnFooter() != null ? report.getColumnFooter().getHeight() : 0);
625         downColumns = offsetY;
626         offsetY += (report.getPageFooter() != null ? report.getPageFooter().getHeight() : 0);
627         offsetY += (report.getLastPageFooter() != null ? report.getLastPageFooter().getHeight() : 0);
628         offsetY += (report.getSummary() != null ? report.getSummary().getHeight() : 0);
629         offsetY += report.getBottomMargin();
630     }
631
632     
633     /**
634     */

635     private void refreshDesign()
636     {
637         Image JavaDoc image = null;
638         ImageIcon JavaDoc imageIcon = null;
639
640         Dimension JavaDoc dim = new Dimension JavaDoc(
641             (int)(report.getPageWidth() * realZoom) + 8, //why 8 ? 2 for the balck border, 1 extra for the image and 5 for the shadow panels
642
(int)(offsetY * realZoom) + 8
643             );
644         this.pnlPage.setMaximumSize(dim);
645         this.pnlPage.setMinimumSize(dim);
646         this.pnlPage.setPreferredSize(dim);
647
648         try
649         {
650             image = this.printDesignToImage();
651             imageIcon = new ImageIcon JavaDoc(image);
652         }
653         catch(Exception JavaDoc e)
654         {
655             e.printStackTrace();
656         }
657
658         this.lblPage.setIcon(imageIcon);
659     }
660
661
662     /**
663      */

664     private Image JavaDoc printDesignToImage()
665     {
666         Image JavaDoc designImage = new BufferedImage JavaDoc(
667             (int)(report.getPageWidth() * realZoom) + 1,
668             (int)(offsetY * realZoom) + 1,
669             BufferedImage.TYPE_INT_RGB
670             );
671         Graphics2D JavaDoc grx = (Graphics2D JavaDoc)designImage.getGraphics();
672
673         grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
674         grx.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
675         grx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
676
677         AffineTransform JavaDoc atrans = new AffineTransform JavaDoc();
678         atrans.scale(realZoom, realZoom);
679         grx.transform(atrans);
680
681         printDesign(grx);
682
683         grx.dispose();
684         
685         return designImage;
686     }
687
688     
689     /**
690      */

691     private void printDesign(Graphics2D JavaDoc grx)
692     {
693         Stroke JavaDoc dashedStroke =
694             new BasicStroke JavaDoc(
695                 1f / realZoom,
696                 BasicStroke.CAP_BUTT,
697                 BasicStroke.JOIN_BEVEL,
698                 0f,
699                 new float[]{5f, 3f},
700                 0f
701                 );
702         Color JavaDoc dashedColor = new Color JavaDoc(170, 170, 255);
703
704         grx.setColor(Color.white);
705         grx.fillRect(
706             0,
707             0,
708             report.getPageWidth() + 1,
709             offsetY + 1
710             );
711
712         grx.setStroke(dashedStroke);
713         grx.setColor(dashedColor);
714         grx.drawLine(
715             report.getLeftMargin(),
716             0,
717             report.getLeftMargin(),
718             offsetY + 1
719             );
720         grx.drawLine(
721             (report.getPageWidth() - report.getRightMargin()),
722             0,
723             (report.getPageWidth() - report.getRightMargin()),
724             offsetY + 1
725             );
726         grx.drawLine(
727             (report.getLeftMargin() + report.getColumnWidth()),
728             upColumns,
729             (report.getLeftMargin() + report.getColumnWidth()),
730             downColumns
731             );
732         grx.drawLine(
733             (report.getLeftMargin() + report.getColumnWidth() + report.getColumnSpacing()),
734             upColumns,
735             (report.getLeftMargin() + report.getColumnWidth() + report.getColumnSpacing()),
736             downColumns
737             );
738
739
740         grx.translate(
741             report.getLeftMargin(),
742             report.getTopMargin()
743             );
744
745         grx.setStroke(dashedStroke);
746         grx.setColor(dashedColor);
747         grx.drawLine(
748             - report.getLeftMargin(),
749             0,
750             report.getPageWidth() + 1,
751             0
752             );
753         grx.setColor(Color.black);
754         grx.setStroke(new BasicStroke JavaDoc(1f));
755         printBand(report.getTitle(), grx);
756         grx.translate(
757             0,
758             (report.getTitle() != null ? report.getTitle().getHeight() : 0)
759             );
760
761
762         grx.setStroke(dashedStroke);
763         grx.setColor(dashedColor);
764         grx.drawLine(
765             - report.getLeftMargin(),
766             0,
767             report.getPageWidth() + 1,
768             0
769             );
770         grx.setColor(Color.black);
771         grx.setStroke(new BasicStroke JavaDoc(1f));
772         printBand(report.getPageHeader(), grx);
773         grx.translate(
774             0,
775             (report.getPageHeader() != null ? report.getPageHeader().getHeight() : 0)
776             );
777
778
779         grx.setStroke(dashedStroke);
780         grx.setColor(dashedColor);
781         grx.drawLine(
782             - report.getLeftMargin(),
783             0,
784             report.getPageWidth() + 1,
785             0
786             );
787         grx.setColor(Color.black);
788         grx.setStroke(new BasicStroke JavaDoc(1f));
789         printBand(report.getColumnHeader(), grx);
790         grx.translate(
791             0,
792             (report.getColumnHeader() != null ? report.getColumnHeader().getHeight() : 0)
793             );
794
795
796         JRGroup group = null;
797         JRGroup[] groups = report.getGroups();
798         if (groups != null && groups.length > 0)
799         {
800             for(int i = 0; i < groups.length; i++)
801             {
802                 group = groups[i];
803
804                 grx.setStroke(dashedStroke);
805                 grx.setColor(dashedColor);
806                 grx.drawLine(
807                     - report.getLeftMargin(),
808                     0,
809                     report.getPageWidth() + 1,
810                     0
811                     );
812                 grx.setColor(Color.black);
813                 grx.setStroke(new BasicStroke JavaDoc(1f));
814                 printBand(group.getGroupHeader(), grx);
815                 grx.translate(
816                     0,
817                     (group.getGroupHeader() != null ? group.getGroupHeader().getHeight() : 0)
818                     );
819             }
820         }
821
822         grx.setStroke(dashedStroke);
823         grx.setColor(dashedColor);
824         grx.drawLine(
825             - report.getLeftMargin(),
826             0,
827             report.getPageWidth() + 1,
828             0
829             );
830         grx.setColor(Color.black);
831         grx.setStroke(new BasicStroke JavaDoc(1f));
832         printBand(report.getDetail(), grx);
833         grx.translate(
834             0,
835             (report.getDetail() != null ? report.getDetail().getHeight() : 0)
836             );
837
838         if (groups != null && groups.length > 0)
839         {
840             for(int i = groups.length - 1; i >= 0; i--)
841             {
842                 group = groups[i];
843
844                 grx.setStroke(dashedStroke);
845                 grx.setColor(dashedColor);
846                 grx.drawLine(
847                     - report.getLeftMargin(),
848                     0,
849                     report.getPageWidth() + 1,
850                     0
851                     );
852                 grx.setColor(Color.black);
853                 grx.setStroke(new BasicStroke JavaDoc(1f));
854                 printBand(group.getGroupFooter(), grx);
855                 grx.translate(
856                     0,
857                     (group.getGroupFooter() != null ? group.getGroupFooter().getHeight() : 0)
858                     );
859             }
860         }
861
862         grx.setStroke(dashedStroke);
863         grx.setColor(dashedColor);
864         grx.drawLine(
865             - report.getLeftMargin(),
866             0,
867             report.getPageWidth() + 1,
868             0
869             );
870         grx.setColor(Color.black);
871         grx.setStroke(new BasicStroke JavaDoc(1f));
872         printBand(report.getColumnFooter(), grx);
873         grx.translate(
874             0,
875             (report.getColumnFooter() != null ? report.getColumnFooter().getHeight() : 0)
876             );
877
878
879         grx.setStroke(dashedStroke);
880         grx.setColor(dashedColor);
881         grx.drawLine(
882             - report.getLeftMargin(),
883             0,
884             report.getPageWidth() + 1,
885             0
886             );
887         grx.setColor(Color.black);
888         grx.setStroke(new BasicStroke JavaDoc(1f));
889         printBand(report.getPageFooter(), grx);
890         grx.translate(
891             0,
892             (report.getPageFooter() != null ? report.getPageFooter().getHeight() : 0)
893             );
894
895
896         grx.setStroke(dashedStroke);
897         grx.setColor(dashedColor);
898         grx.drawLine(
899             - report.getLeftMargin(),
900             0,
901             report.getPageWidth() + 1,
902             0
903             );
904         grx.setColor(Color.black);
905         grx.setStroke(new BasicStroke JavaDoc(1f));
906         printBand(report.getLastPageFooter(), grx);
907         grx.translate(
908             0,
909             (report.getLastPageFooter() != null ? report.getLastPageFooter().getHeight() : 0)
910             );
911
912
913         grx.setStroke(dashedStroke);
914         grx.setColor(dashedColor);
915         grx.drawLine(
916             - report.getLeftMargin(),
917             0,
918             report.getPageWidth() + 1,
919             0
920             );
921         grx.setColor(Color.black);
922         grx.setStroke(new BasicStroke JavaDoc(1f));
923         printBand(report.getSummary(), grx);
924         grx.translate(
925             0,
926             (report.getSummary() != null ? report.getSummary().getHeight() : 0)
927             );
928
929
930         grx.setStroke(dashedStroke);
931         grx.setColor(dashedColor);
932         grx.drawLine(
933             - report.getLeftMargin(),
934             0,
935             report.getPageWidth() + 1,
936             0
937             );
938     }
939
940
941     /**
942      *
943      */

944     private void printBand(JRBand band, Graphics2D JavaDoc grx)
945     {
946         if (band != null)
947         {
948             printElements(band.getElements(), grx);
949         }
950     }
951
952
953     protected void printElements(JRElement[] elements, Graphics2D JavaDoc grx)
954     {
955         if (elements != null && elements.length > 0)
956         {
957             for(int i = 0; i < elements.length; i++)
958             {
959                 JRElement element = elements[i];
960
961                 if (element instanceof JRBreak)
962                 {
963                     printBreak((JRBreak)element, grx);
964                 }
965                 else if (element instanceof JRLine)
966                 {
967                     printLine((JRLine)element, grx);
968                 }
969                 else if (element instanceof JRRectangle)
970                 {
971                     printRectangle((JRRectangle)element, grx);
972                 }
973                 else if (element instanceof JREllipse)
974                 {
975                     printEllipse((JREllipse)element, grx);
976                 }
977                 else if (element instanceof JRImage)
978                 {
979                     printImage((JRImage)element, grx);
980                 }
981                 else if (element instanceof JRStaticText)
982                 {
983                     printText((JRTextElement)element, grx);
984                 }
985                 else if (element instanceof JRTextField)
986                 {
987                     printText((JRTextElement)element, grx);
988                 }
989                 else if (element instanceof JRSubreport)
990                 {
991                     printSubreport((JRSubreport)element, grx);
992                 }
993                 else if (element instanceof JRChart)
994                 {
995                     printChart((JRChart)element, grx);
996                 }
997                 else if (element instanceof JRCrosstab)
998                 {
999                     printCrosstab((JRCrosstab)element, grx);
1000                }
1001                else if (element instanceof JRFrame)
1002                {
1003                    printFrame((JRFrame) element, grx);
1004                }
1005            }
1006        }
1007    }
1008
1009
1010    /**
1011     *
1012     */

1013    private void printBreak(JRBreak breakElement, Graphics2D JavaDoc grx)
1014    {
1015        grx.setColor(breakElement.getForecolor());
1016
1017        grx.setStroke(getStroke(JRGraphicElement.PEN_DOTTED));
1018        
1019        grx.drawLine(
1020                0,
1021                breakElement.getY(),
1022                report.getColumnWidth(),
1023                breakElement.getY()
1024                );
1025    }
1026
1027
1028    /**
1029     *
1030     */

1031    private void printLine(JRLine line, Graphics2D JavaDoc grx)
1032    {
1033        grx.setColor(line.getForecolor());
1034
1035        Stroke JavaDoc stroke = getStroke(line.getPen());
1036
1037        if (stroke != null)
1038        {
1039            grx.setStroke(stroke);
1040            
1041            grx.translate(.5, .5);
1042            
1043            if (line.getDirection() == JRLine.DIRECTION_TOP_DOWN)
1044            {
1045                grx.drawLine(
1046                    line.getX(),
1047                    line.getY(),
1048                    line.getX() + line.getWidth() - 1,
1049                    line.getY() + line.getHeight() - 1
1050                    );
1051            }
1052            else
1053            {
1054                grx.drawLine(
1055                    line.getX(),
1056                    line.getY() + line.getHeight() - 1,
1057                    line.getX() + line.getWidth() - 1,
1058                    line.getY()
1059                    );
1060            }
1061            
1062            grx.translate(-.5, -.5);
1063        }
1064    }
1065
1066    /**
1067     *
1068     */

1069    private void printRectangle(JRRectangle rectangle, Graphics2D JavaDoc grx)
1070    {
1071        if (rectangle.getMode() == JRElement.MODE_OPAQUE)
1072        {
1073            grx.setColor(rectangle.getBackcolor());
1074
1075            if (rectangle.getRadius() > 0)
1076            {
1077                grx.fillRoundRect(
1078                        rectangle.getX(),
1079                        rectangle.getY(),
1080                        rectangle.getWidth(),
1081                        rectangle.getHeight(),
1082                        2 * rectangle.getRadius(),
1083                        2 * rectangle.getRadius()
1084                        );
1085            }
1086            else
1087            {
1088                grx.fillRect(
1089                        rectangle.getX(),
1090                        rectangle.getY(),
1091                        rectangle.getWidth(),
1092                        rectangle.getHeight()
1093                        );
1094            }
1095        }
1096
1097        grx.setColor(rectangle.getForecolor());
1098
1099        byte pen = rectangle.getPen();
1100        Stroke JavaDoc stroke = getStroke(pen);
1101
1102        if (stroke != null)
1103        {
1104            double cornerOffset = getBorderCornerOffset(pen);
1105            int sizeAdjust = getRectangleSizeAdjust(pen);
1106            
1107            AffineTransform JavaDoc transform = grx.getTransform();
1108            
1109            grx.translate(rectangle.getX() + cornerOffset, rectangle.getY() + cornerOffset);
1110            if (pen == JRGraphicElement.PEN_THIN)
1111            {
1112                grx.scale((rectangle.getWidth() - .5) / rectangle.getWidth(), (rectangle.getHeight() - .5) / rectangle.getHeight());
1113            }
1114            
1115            grx.setStroke(stroke);
1116    
1117            if (rectangle.getRadius() > 0)
1118            {
1119                grx.drawRoundRect(
1120                        0,
1121                        0,
1122                        rectangle.getWidth() - sizeAdjust,
1123                        rectangle.getHeight() - sizeAdjust,
1124                        2 * rectangle.getRadius(),
1125                        2 * rectangle.getRadius()
1126                        );
1127            }
1128            else
1129            {
1130                grx.drawRect(
1131                        0,
1132                        0,
1133                        rectangle.getWidth() - sizeAdjust,
1134                        rectangle.getHeight() - sizeAdjust
1135                        );
1136            }
1137            
1138            grx.setTransform(transform);
1139        }
1140    }
1141    
1142
1143    private static double getBorderCornerOffset(byte pen)
1144    {
1145        switch (pen)
1146        {
1147            case JRGraphicElement.PEN_THIN :
1148            {
1149                return THIN_CORNER_OFFSET;
1150            }
1151            case JRGraphicElement.PEN_1_POINT :
1152            case JRGraphicElement.PEN_DOTTED :
1153            {
1154                return ONE_POINT_CORNER_OFFSET;
1155            }
1156            default :
1157            {
1158                return 0;
1159            }
1160        }
1161    }
1162
1163    
1164    private static int getRectangleSizeAdjust(byte pen)
1165    {
1166        switch (pen)
1167        {
1168            case JRGraphicElement.PEN_1_POINT:
1169            case JRGraphicElement.PEN_DOTTED:
1170                return 1;
1171            default:
1172                return 0;
1173        }
1174    }
1175
1176
1177    /**
1178     *
1179     */

1180    private void printEllipse(JREllipse ellipse, Graphics2D JavaDoc grx)
1181    {
1182        if (ellipse.getMode() == JRElement.MODE_OPAQUE)
1183        {
1184            grx.setColor(ellipse.getBackcolor());
1185
1186            grx.fillOval(
1187                ellipse.getX(),
1188                ellipse.getY(),
1189                ellipse.getWidth(),
1190                ellipse.getHeight()
1191                );
1192        }
1193
1194        grx.setColor(ellipse.getForecolor());
1195
1196        byte pen = ellipse.getPen();
1197        Stroke JavaDoc stroke = getStroke(pen);
1198
1199        if (stroke != null)
1200        {
1201            double cornerOffset = getBorderCornerOffset(pen);
1202            int sizeAdjust = getRectangleSizeAdjust(pen);
1203            
1204            AffineTransform JavaDoc transform = grx.getTransform();
1205            
1206            grx.translate(ellipse.getX() + cornerOffset, ellipse.getY() + cornerOffset);
1207            if (pen == JRGraphicElement.PEN_THIN)
1208            {
1209                grx.scale((ellipse.getWidth() - .5) / ellipse.getWidth(), (ellipse.getHeight() - .5) / ellipse.getHeight());
1210            }
1211            
1212            grx.setStroke(stroke);
1213    
1214            grx.drawOval(
1215                0,
1216                0,
1217                ellipse.getWidth() - sizeAdjust,
1218                ellipse.getHeight() - sizeAdjust
1219                );
1220            
1221            grx.setTransform(transform);
1222        }
1223    }
1224
1225
1226    /**
1227     *
1228     */

1229    private void printImage(JRImage jrImage, Graphics2D JavaDoc grx)
1230    {
1231        if (jrImage.getMode() == JRElement.MODE_OPAQUE)
1232        {
1233            grx.setColor(jrImage.getBackcolor());
1234
1235            grx.fillRect(
1236                jrImage.getX(),
1237                jrImage.getY(),
1238                jrImage.getWidth(),
1239                jrImage.getHeight()
1240                );
1241        }
1242
1243        int topPadding = jrImage.getTopPadding();
1244        int leftPadding = jrImage.getLeftPadding();
1245        int bottomPadding = jrImage.getBottomPadding();
1246        int rightPadding = jrImage.getRightPadding();
1247        
1248        int availableImageWidth = jrImage.getWidth() - leftPadding - rightPadding;
1249        availableImageWidth = (availableImageWidth < 0)?0:availableImageWidth;
1250
1251        int availableImageHeight = jrImage.getHeight() - topPadding - bottomPadding;
1252        availableImageHeight = (availableImageHeight < 0)?0:availableImageHeight;
1253        
1254        if (availableImageWidth > 0 && availableImageHeight > 0)
1255        {
1256            Image JavaDoc awtImage = null;
1257            
1258            JRExpression jrExpression = jrImage.getExpression();
1259            if (jrExpression != null && jrExpression.getChunks().length == 1)
1260            {
1261                JRExpressionChunk firstChunk = jrExpression.getChunks()[0];
1262                if (firstChunk.getType() == JRExpressionChunk.TYPE_TEXT)
1263                {
1264                    String JavaDoc location = firstChunk.getText().trim();
1265                    if (location.startsWith("\"") && location.endsWith("\""))
1266                    {
1267                        location = location.substring(1, location.length() - 1);
1268                        try
1269                        {
1270                            awtImage = JRImageLoader.loadImage(
1271                                JRLoader.loadBytesFromLocation(location)
1272                                );
1273                        }
1274                        catch (JRException e)
1275                        {
1276                            e.printStackTrace();
1277                        }
1278                    }
1279                }
1280            }
1281    
1282            if (awtImage != null)
1283            {
1284                int awtWidth = awtImage.getWidth(null);
1285                int awtHeight = awtImage.getHeight(null);
1286
1287                float xalignFactor = 0f;
1288                switch (jrImage.getHorizontalAlignment())
1289                {
1290                    case JRAlignment.HORIZONTAL_ALIGN_RIGHT :
1291                    {
1292                        xalignFactor = 1f;
1293                        break;
1294                    }
1295                    case JRAlignment.HORIZONTAL_ALIGN_CENTER :
1296                    {
1297                        xalignFactor = 0.5f;
1298                        break;
1299                    }
1300                    case JRAlignment.HORIZONTAL_ALIGN_LEFT :
1301                    default :
1302                    {
1303                        xalignFactor = 0f;
1304                        break;
1305                    }
1306                }
1307
1308                float yalignFactor = 0f;
1309                switch (jrImage.getVerticalAlignment())
1310                {
1311                    case JRAlignment.VERTICAL_ALIGN_BOTTOM :
1312                    {
1313                        yalignFactor = 1f;
1314                        break;
1315                    }
1316                    case JRAlignment.VERTICAL_ALIGN_MIDDLE :
1317                    {
1318                        yalignFactor = 0.5f;
1319                        break;
1320                    }
1321                    case JRAlignment.VERTICAL_ALIGN_TOP :
1322                    default :
1323                    {
1324                        yalignFactor = 0f;
1325                        break;
1326                    }
1327                }
1328
1329                switch (jrImage.getScaleImage())
1330                {
1331                    case JRImage.SCALE_IMAGE_CLIP :
1332                    {
1333                        int xoffset = (int)(xalignFactor * (availableImageWidth - awtWidth));
1334                        int yoffset = (int)(yalignFactor * (availableImageHeight - awtHeight));
1335
1336                        Shape JavaDoc clip = grx.getClip();
1337                        grx.clipRect(
1338                            jrImage.getX() + leftPadding,
1339                            jrImage.getY() + topPadding,
1340                            availableImageWidth,
1341                            availableImageHeight
1342                            );
1343                        grx.drawImage(
1344                            awtImage,
1345                            jrImage.getX() + leftPadding + xoffset,
1346                            jrImage.getY() + topPadding + yoffset,
1347                            awtWidth,
1348                            awtHeight,
1349                            this
1350                            );
1351                        grx.setClip(clip);
1352        
1353                        break;
1354                    }
1355                    case JRImage.SCALE_IMAGE_FILL_FRAME :
1356                    {
1357                        grx.drawImage(
1358                            awtImage,
1359                            jrImage.getX() + leftPadding,
1360                            jrImage.getY() + topPadding,
1361                            availableImageWidth,
1362                            availableImageHeight,
1363                            this
1364                            );
1365        
1366                        break;
1367                    }
1368                    case JRImage.SCALE_IMAGE_RETAIN_SHAPE :
1369                    default :
1370                    {
1371                        if (jrImage.getHeight() > 0)
1372                        {
1373                            double ratio = (double)awtWidth / (double)awtHeight;
1374                            
1375                            if( ratio > (double)availableImageWidth / (double)availableImageHeight )
1376                            {
1377                                awtWidth = availableImageWidth;
1378                                awtHeight = (int)(availableImageWidth / ratio);
1379                            }
1380                            else
1381                            {
1382                                awtWidth = (int)(availableImageHeight * ratio);
1383                                awtHeight = availableImageHeight;
1384                            }
1385
1386                            int xoffset = (int)(xalignFactor * (availableImageWidth - awtWidth));
1387                            int yoffset = (int)(yalignFactor * (availableImageHeight - awtHeight));
1388
1389                            grx.drawImage(
1390                                awtImage,
1391                                jrImage.getX() + leftPadding + xoffset,
1392                                jrImage.getY() + topPadding + yoffset,
1393                                awtWidth,
1394                                awtHeight,
1395                                this
1396                                );
1397                        }
1398                        
1399                        break;
1400                    }
1401                }
1402            }
1403            else
1404            {
1405                try
1406                {
1407                    awtImage = JRImageLoader.getImage(JRImageLoader.NO_IMAGE);
1408                }
1409                catch (JRException e)
1410                {
1411                    e.printStackTrace();
1412                }
1413    
1414                Shape JavaDoc clip = grx.getClip();
1415                grx.clipRect(
1416                    jrImage.getX() + leftPadding,
1417                    jrImage.getY() + topPadding,
1418                    availableImageWidth,
1419                    availableImageHeight
1420                    );
1421                grx.drawImage(
1422                    awtImage,
1423                    jrImage.getX() + leftPadding + 2,
1424                    jrImage.getY() + topPadding + 2,
1425                    awtImage.getWidth(null),
1426                    awtImage.getHeight(null),
1427                    this
1428                    );
1429                grx.setClip(clip);
1430
1431                //borderOffset = 0;
1432
//stroke = new BasicStroke(1f / zoom);
1433
}
1434        }
1435        
1436        if (
1437            jrImage.getTopBorder() == JRGraphicElement.PEN_NONE &&
1438            jrImage.getLeftBorder() == JRGraphicElement.PEN_NONE &&
1439            jrImage.getBottomBorder() == JRGraphicElement.PEN_NONE &&
1440            jrImage.getRightBorder() == JRGraphicElement.PEN_NONE
1441            )
1442        {
1443            if (jrImage.getPen() != JRGraphicElement.PEN_NONE)
1444            {
1445                JRBox box = new JRBaseBox(jrImage.getPen(), jrImage.getForecolor());
1446                printBox(box, jrImage, grx);
1447            }
1448        }
1449        else
1450        {
1451            /* */
1452            printBox(
1453                jrImage,
1454                jrImage,
1455                grx
1456                );
1457        }
1458    }
1459
1460
1461    /**
1462     *
1463     */

1464    private JRStyledText getStyledText(JRTextElement textElement)
1465    {
1466        JRStyledText styledText = null;
1467
1468        String JavaDoc text = null;
1469        if (textElement instanceof JRStaticText)
1470        {
1471            text = ((JRStaticText)textElement).getText();
1472        }
1473        else if (textElement instanceof JRTextField)
1474        {
1475            JRExpression textExpression = ((JRTextField) textElement).getExpression();
1476            if (textExpression != null)
1477            {
1478                text = textExpression.getText();
1479            }
1480        }
1481        
1482        if (text == null)
1483        {
1484            text = "";
1485        }
1486        
1487        //text = JRStringUtil.treatNewLineChars(text);
1488

1489        Map JavaDoc attributes = new HashMap JavaDoc();
1490        JRFontUtil.setAttributes(attributes, textElement);
1491        attributes.put(TextAttribute.FOREGROUND, textElement.getForecolor());
1492
1493        if (
1494            textElement instanceof JRStaticText
1495            && textElement.isStyledText()
1496            )
1497        {
1498            try
1499            {
1500                styledText = styledTextParser.parse(attributes, text);
1501            }
1502            catch (SAXException JavaDoc e)
1503            {
1504                //ignore if invalid styled text and treat like normal text
1505
}
1506        }
1507    
1508        if (styledText == null)
1509        {
1510            styledText = new JRStyledText();
1511            styledText.append(text);
1512            styledText.addRun(new JRStyledText.Run(attributes, 0, text.length()));
1513        }
1514        
1515        return styledText;
1516    }
1517
1518
1519    /**
1520     *
1521     */

1522    private void printText(JRTextElement text, Graphics2D JavaDoc grx)
1523    {
1524        JRStyledText styledText = getStyledText(text);
1525        
1526        if (styledText == null)
1527        {
1528            return;
1529        }
1530
1531        String JavaDoc allText = styledText.getText();
1532        
1533        int x = text.getX();
1534        int y = text.getY();
1535        int width = text.getWidth();
1536        int height = text.getHeight();
1537        
1538        int topPadding = text.getTopPadding();
1539        int leftPadding = text.getLeftPadding();
1540        int bottomPadding = text.getBottomPadding();
1541        int rightPadding = text.getRightPadding();
1542        
1543        double angle = 0;
1544        
1545        switch (text.getRotation())
1546        {
1547            case JRTextElement.ROTATION_LEFT :
1548            {
1549                y = text.getY() + text.getHeight();
1550                width = text.getHeight();
1551                height = text.getWidth();
1552                int tmpPadding = topPadding;
1553                topPadding = leftPadding;
1554                leftPadding = bottomPadding;
1555                bottomPadding = rightPadding;
1556                rightPadding = tmpPadding;
1557                angle = - Math.PI / 2;
1558                break;
1559            }
1560            case JRTextElement.ROTATION_RIGHT :
1561            {
1562                x = text.getX() + text.getWidth();
1563                width = text.getHeight();
1564                height = text.getWidth();
1565                int tmpPadding = topPadding;
1566                topPadding = rightPadding;
1567                rightPadding = bottomPadding;
1568                bottomPadding = leftPadding;
1569                leftPadding = tmpPadding;
1570                angle = Math.PI / 2;
1571                break;
1572            }
1573            case JRTextElement.ROTATION_UPSIDE_DOWN :
1574            {
1575                x = text.getX() + text.getWidth();
1576                y = text.getY() + text.getHeight();
1577                int tmpPadding = topPadding;
1578                topPadding = bottomPadding;
1579                bottomPadding = tmpPadding;
1580                tmpPadding = leftPadding;
1581                leftPadding = rightPadding;
1582                rightPadding = tmpPadding;
1583                angle = Math.PI;
1584                break;
1585            }
1586            case JRTextElement.ROTATION_NONE :
1587            default :
1588            {
1589            }
1590        }
1591        
1592        grx.rotate(angle, x, y);
1593
1594        if (text.getMode() == JRElement.MODE_OPAQUE)
1595        {
1596            grx.setColor(text.getBackcolor());
1597            grx.fillRect(x, y, width, height);
1598        }
1599
1600        grx.setColor(text.getForecolor());
1601
1602        /* */
1603        TextMeasurer textMeasurer = new TextMeasurer(text);
1604        textMeasurer.measure(
1605            styledText,
1606            allText,
1607            0,
1608            0
1609            );
1610        
1611        /* */
1612        textRenderer.render(
1613            grx,
1614            x,
1615            y,
1616            width,
1617            height,
1618            topPadding,
1619            leftPadding,
1620            bottomPadding,
1621            rightPadding,
1622            textMeasurer.getTextHeight(),
1623            text.getHorizontalAlignment(),
1624            text.getVerticalAlignment(),
1625            textMeasurer.getLineSpacingFactor(),
1626            textMeasurer.getLeadingOffset(),
1627            text.getFontSize(),
1628            text.isStyledText(),
1629            styledText,
1630            allText
1631            );
1632
1633        grx.rotate(-angle, x, y);
1634
1635        /* */
1636        printBox(
1637            text,
1638            text,
1639            grx
1640            );
1641    }
1642
1643    
1644    /**
1645     *
1646     */

1647    private void printBox(JRBox box, Color JavaDoc defaultBorderColor, int x, int y, int width, int height, Graphics2D JavaDoc grx)
1648    {
1649        Stroke JavaDoc topStroke = null;
1650        Stroke JavaDoc leftStroke = null;
1651        Stroke JavaDoc bottomStroke = null;
1652        Stroke JavaDoc rightStroke = null;
1653        if (box != null)
1654        {
1655            topStroke = getBorderStroke(box.getTopBorder());
1656            leftStroke = getBorderStroke(box.getLeftBorder());
1657            bottomStroke = getBorderStroke(box.getBottomBorder());
1658            rightStroke = getBorderStroke(box.getRightBorder());
1659        }
1660
1661        if (topStroke != null)
1662        {
1663            double cornerOffset = getBorderCornerOffset(box.getTopBorder());
1664            
1665            grx.setStroke(topStroke);
1666            grx.setColor(box.getTopBorderColor() == null ? defaultBorderColor : box.getTopBorderColor());
1667    
1668            grx.translate(0, cornerOffset);
1669            grx.drawLine(x, y, x + width, y);
1670            grx.translate(0, -cornerOffset);
1671        }
1672
1673        if (leftStroke != null)
1674        {
1675            double cornerOffset = getBorderCornerOffset(box.getLeftBorder());
1676            
1677            grx.setStroke(leftStroke);
1678            grx.setColor(box.getLeftBorderColor() == null ? defaultBorderColor : box.getLeftBorderColor());
1679    
1680            grx.translate(cornerOffset, 0);
1681            grx.drawLine(x, y, x, y + height);
1682            grx.translate(-cornerOffset, 0);
1683        }
1684
1685        if (bottomStroke != null)
1686        {
1687            double cornerOffset = getBorderCornerOffset(box.getBottomBorder());
1688            
1689            grx.setStroke(bottomStroke);
1690            grx.setColor(box.getBottomBorderColor() == null ? defaultBorderColor : box.getBottomBorderColor());
1691    
1692            grx.translate(0, -cornerOffset);
1693            grx.drawLine(x, y + height, x + width, y + height);
1694            grx.translate(0, cornerOffset);
1695        }
1696
1697        if (rightStroke != null)
1698        {
1699            double cornerOffset = getBorderCornerOffset(box.getRightBorder());
1700            
1701            grx.setStroke(rightStroke);
1702            grx.setColor(box.getRightBorderColor() == null ? defaultBorderColor : box.getRightBorderColor());
1703    
1704            grx.translate(-cornerOffset, 0);
1705            grx.drawLine(x + width, y, x + width, y + height);
1706            grx.translate(cornerOffset, 0);
1707        }
1708
1709        if (
1710            topStroke == null
1711            && leftStroke == null
1712            && bottomStroke == null
1713            && rightStroke == null
1714            )
1715        {
1716            grx.setColor(defaultBorderColor);
1717            grx.setStroke(new BasicStroke JavaDoc(1f / realZoom));
1718        
1719            grx.drawRect(x, y, width, height);
1720        }
1721    }
1722
1723    private static Stroke JavaDoc getBorderStroke(byte pen)
1724    {
1725        switch (pen)
1726        {
1727            case JRGraphicElement.PEN_DOTTED :
1728            {
1729                return BORDER_STROKE_DOTTED;
1730            }
1731            case JRGraphicElement.PEN_4_POINT :
1732            {
1733                return STROKE_4_POINT;
1734            }
1735            case JRGraphicElement.PEN_2_POINT :
1736            {
1737                return STROKE_2_POINT;
1738            }
1739            case JRGraphicElement.PEN_NONE :
1740            {
1741                return null;
1742            }
1743            case JRGraphicElement.PEN_THIN :
1744            {
1745                return BORDER_STROKE_THIN;
1746            }
1747            case JRGraphicElement.PEN_1_POINT :
1748            default :
1749            {
1750                return BORDER_STROKE_1_POINT;
1751            }
1752        }
1753    }
1754
1755    private void printBox(JRBox box, JRElement element, Graphics2D JavaDoc grx)
1756    {
1757        printBox(box, element.getForecolor(), element.getX(), element.getY(), element.getWidth(), element.getHeight(), grx);
1758    }
1759    
1760    /**
1761     *
1762     */

1763    private void printSubreport(JRSubreport subreport, Graphics2D JavaDoc grx)
1764    {
1765        if (subreport.getMode() == JRElement.MODE_OPAQUE)
1766        {
1767            grx.setColor(subreport.getBackcolor());
1768
1769            grx.fillRect(
1770                subreport.getX(),
1771                subreport.getY(),
1772                subreport.getWidth(),
1773                subreport.getHeight()
1774                );
1775        }
1776
1777        Image JavaDoc image = null;
1778        try
1779        {
1780            image = JRImageLoader.getImage(JRImageLoader.SUBREPORT_IMAGE);
1781        }
1782        catch (JRException e)
1783        {
1784            e.printStackTrace();
1785        }
1786
1787        Shape JavaDoc clip = grx.getClip();
1788        grx.clipRect(
1789            subreport.getX(),
1790            subreport.getY(),
1791            subreport.getWidth(),
1792            subreport.getHeight()
1793            );
1794        grx.drawImage(
1795            image,
1796            subreport.getX() + 2,
1797            subreport.getY() + 2,
1798            image.getWidth(null),
1799            image.getHeight(null),
1800            this
1801            );
1802        grx.setClip(clip);
1803
1804        grx.setColor(subreport.getForecolor());
1805        grx.setStroke(new BasicStroke JavaDoc(1f / realZoom));
1806        grx.drawRect(
1807            subreport.getX(),
1808            subreport.getY(),
1809            subreport.getWidth() - 1,
1810            subreport.getHeight() - 1
1811            );
1812    }
1813
1814
1815    /**
1816     *
1817     */

1818    private void printChart(JRChart chart, Graphics2D JavaDoc grx)
1819    {
1820        if (chart.getMode() == JRElement.MODE_OPAQUE)
1821        {
1822            grx.setColor(chart.getBackcolor());
1823
1824            grx.fillRect(
1825                chart.getX(),
1826                chart.getY(),
1827                chart.getWidth(),
1828                chart.getHeight()
1829                );
1830        }
1831
1832        Image JavaDoc image = null;
1833        try
1834        {
1835            image = JRImageLoader.getImage(JRImageLoader.CHART_IMAGE);
1836        }
1837        catch (JRException e)
1838        {
1839            e.printStackTrace();
1840        }
1841
1842        grx.setClip(
1843            chart.getX(),
1844            chart.getY(),
1845            chart.getWidth(),
1846            chart.getHeight()
1847            );
1848        grx.drawImage(
1849            image,
1850            chart.getX() + 2,
1851            chart.getY() + 2,
1852            image.getWidth(null),
1853            image.getHeight(null),
1854            this
1855            );
1856        grx.setClip(
1857            - report.getLeftMargin(),
1858            0,
1859            report.getPageWidth(),
1860            report.getPageHeight()
1861            );
1862
1863        grx.setColor(chart.getForecolor());
1864        grx.setStroke(new BasicStroke JavaDoc(1f / realZoom));
1865        grx.drawRect(
1866            chart.getX(),
1867            chart.getY(),
1868            chart.getWidth() - 1,
1869            chart.getHeight() - 1
1870            );
1871    }
1872    
1873    
1874    /**
1875     *
1876     */

1877    private void printCrosstab(JRCrosstab crosstab, Graphics2D JavaDoc grx)
1878    {
1879        grx.setClip(
1880                crosstab.getX(),
1881                crosstab.getY(),
1882                crosstab.getWidth(),
1883                crosstab.getHeight()
1884                );
1885        
1886        JRCrosstabRowGroup[] rowGroups = crosstab.getRowGroups();
1887        int rowHeadersXOffset = 0;
1888        for (int i = 0; i < rowGroups.length; i++)
1889        {
1890            rowHeadersXOffset += rowGroups[i].getWidth();
1891        }
1892        
1893        JRCrosstabColumnGroup[] columnGroups = crosstab.getColumnGroups();
1894        int colHeadersYOffset = 0;
1895        for (int i = 0; i < columnGroups.length; i++)
1896        {
1897            colHeadersYOffset += columnGroups[i].getHeight();
1898        }
1899        
1900        JRCellContents headerCell = crosstab.getHeaderCell();
1901        if (headerCell != null)
1902        {
1903            grx.translate(crosstab.getX(), crosstab.getY());
1904            printCellContents(headerCell, grx, 0, 0, false, false);
1905            grx.translate(-crosstab.getX(), -crosstab.getY());
1906        }
1907        
1908        grx.translate(crosstab.getX() + rowHeadersXOffset, crosstab.getY());
1909        printCrosstabColumnHeaders(crosstab, grx);
1910        grx.translate(-(crosstab.getX() + rowHeadersXOffset), -crosstab.getY());
1911        
1912        grx.translate(crosstab.getX(), crosstab.getY() + colHeadersYOffset);
1913        printCrosstabRows(crosstab, grx, rowHeadersXOffset);
1914        grx.translate(-crosstab.getX(), -(crosstab.getY() + colHeadersYOffset));
1915        
1916        grx.setClip(
1917                - report.getLeftMargin(),
1918                0,
1919                report.getPageWidth(),
1920                report.getPageHeight()
1921                );
1922    }
1923
1924
1925    private void printCrosstabColumnHeaders(JRCrosstab crosstab, Graphics2D JavaDoc grx)
1926    {
1927        JRCrosstabColumnGroup[] groups = crosstab.getColumnGroups();
1928        for (int i = 0, x = 0, y = 0; i < groups.length; i++)
1929        {
1930            JRCrosstabColumnGroup group = groups[i];
1931            
1932            if (group.getTotalPosition() == BucketDefinition.TOTAL_POSITION_START)
1933            {
1934                JRCellContents totalHeader = group.getTotalHeader();
1935                printCellContents(totalHeader, grx, x, y, x == 0 && crosstab.getHeaderCell() == null, false);
1936                x += totalHeader.getWidth();
1937            }
1938            
1939            JRCellContents header = group.getHeader();
1940            printCellContents(header, grx, x, y, x == 0 && crosstab.getHeaderCell() == null, false);
1941            
1942            if (group.getTotalPosition() == BucketDefinition.TOTAL_POSITION_END)
1943            {
1944                JRCellContents totalHeader = group.getTotalHeader();
1945                printCellContents(totalHeader, grx, x + header.getWidth(), y, false, false);
1946            }
1947            
1948            y += group.getHeight();
1949        }
1950    }
1951    
1952    
1953    private void printCrosstabRows(JRCrosstab crosstab, Graphics2D JavaDoc grx, int rowHeadersXOffset)
1954    {
1955        JRCrosstabRowGroup[] groups = crosstab.getRowGroups();
1956        for (int i = 0, x = 0, y = 0; i < groups.length; i++)
1957        {
1958            JRCrosstabRowGroup group = groups[i];
1959            
1960            if (group.getTotalPosition() == BucketDefinition.TOTAL_POSITION_START)
1961            {
1962                JRCellContents totalHeader = group.getTotalHeader();
1963                printCellContents(totalHeader, grx, x, y, false, y == 0 && crosstab.getHeaderCell() == null);
1964                printCrosstabDataCellsRow(crosstab, grx, rowHeadersXOffset, y, i);
1965                y += totalHeader.getHeight();
1966            }
1967            
1968            JRCellContents header = group.getHeader();
1969            printCellContents(header, grx, x, y, false, y == 0 && crosstab.getHeaderCell() == null);
1970            
1971            if (i == groups.length - 1)
1972            {
1973                printCrosstabDataCellsRow(crosstab, grx, rowHeadersXOffset, y, groups.length);
1974            }
1975            
1976            if (group.getTotalPosition() == BucketDefinition.TOTAL_POSITION_END)
1977            {
1978                JRCellContents totalHeader = group.getTotalHeader();
1979                printCellContents(totalHeader, grx, x, y + header.getHeight(), false, false);
1980                printCrosstabDataCellsRow(crosstab, grx, rowHeadersXOffset, y + header.getHeight(), i);
1981            }
1982            
1983            x += group.getWidth();
1984        }
1985    }
1986
1987
1988    private void printCrosstabDataCellsRow(JRCrosstab crosstab, Graphics2D JavaDoc grx, int rowOffsetX, int rowOffsetY, int rowIndex)
1989    {
1990        grx.translate(rowOffsetX, rowOffsetY);
1991        
1992        JRCrosstabColumnGroup[] colGroups = crosstab.getColumnGroups();
1993        JRCrosstabCell[][] cells = crosstab.getCells();
1994        for (int i = 0, x = 0; i < colGroups.length; i++)
1995        {
1996            JRCrosstabColumnGroup group = colGroups[i];
1997            
1998            if (group.getTotalPosition() == BucketDefinition.TOTAL_POSITION_START)
1999            {
2000                printCellContents(cells[rowIndex][i].getContents(), grx, x, 0, false, false);
2001                x += cells[rowIndex][i].getContents().getWidth();
2002            }
2003            
2004            if (i == colGroups.length - 1)
2005            {
2006                printCellContents(cells[rowIndex][colGroups.length].getContents(), grx, x, 0, false, false);
2007            }
2008            
2009            if (group.getTotalPosition() == BucketDefinition.TOTAL_POSITION_END)
2010            {
2011                printCellContents(cells[rowIndex][i].getContents(), grx, x + group.getHeader().getWidth(), 0, false, false);
2012            }
2013        }
2014        
2015        grx.translate(-rowOffsetX, -rowOffsetY);
2016    }
2017
2018
2019    private void printCellContents(JRCellContents cell, Graphics2D JavaDoc grx, int x, int y, boolean left, boolean top)
2020    {
2021        if (cell.getWidth() == 0 || cell.getHeight() == 0)
2022        {
2023            return;
2024        }
2025        
2026        JRDesignFrame frame = createCrosstabCellFrame(cell, x, y, left, top);
2027        printFrame(frame, grx);
2028    }
2029
2030
2031    private JRDesignFrame createCrosstabCellFrame(JRCellContents cell, int x, int y, boolean left, boolean top)
2032    {
2033        JRDesignFrame frame = new JRDesignFrame(cell.getDefaultStyleProvider());
2034        frame.setX(x);
2035        frame.setY(y);
2036        frame.setWidth(cell.getWidth());
2037        frame.setHeight(cell.getHeight());
2038        
2039        frame.setMode(cell.getMode());
2040        frame.setBackcolor(cell.getBackcolor());
2041        frame.setStyle(cell.getStyle());
2042        
2043        JRBox box = cell.getBox();
2044        if (box != null)
2045        {
2046            frame.setBox(box);
2047            
2048            boolean copyLeft = left && box.getLeftBorder() == JRGraphicElement.PEN_NONE && box.getRightBorder() != JRGraphicElement.PEN_NONE;
2049            boolean copyTop = top && box.getTopBorder() == JRGraphicElement.PEN_NONE && box.getBottomBorder() != JRGraphicElement.PEN_NONE;
2050            
2051            if (copyLeft)
2052            {
2053                frame.setLeftBorder(box.getRightBorder());
2054                frame.setLeftBorderColor(box.getRightBorderColor());
2055            }
2056            
2057            if (copyTop)
2058            {
2059                frame.setTopBorder(box.getBottomBorder());
2060                frame.setTopBorderColor(box.getBottomBorderColor());
2061            }
2062        }
2063        
2064        List JavaDoc children = cell.getChildren();
2065        if (children != null)
2066        {
2067            for (Iterator JavaDoc it = children.iterator(); it.hasNext();)
2068            {
2069                JRChild child = (JRChild) it.next();
2070                if (child instanceof JRElement)
2071                {
2072                    frame.addElement((JRElement) child);
2073                }
2074                else if (child instanceof JRElementGroup)
2075                {
2076                    frame.addElementGroup((JRElementGroup) child);
2077                }
2078            }
2079        }
2080        
2081        return frame;
2082    }
2083
2084
2085    private void printFrame(JRFrame frame, Graphics2D JavaDoc grx)
2086    {
2087        if (frame.getMode() == JRElement.MODE_OPAQUE)
2088        {
2089            grx.setColor(frame.getBackcolor());
2090
2091            grx.fillRect(frame.getX(), frame.getY(), frame.getWidth(), frame.getHeight());
2092        }
2093        
2094        int topPadding = frame.getTopPadding();
2095        int leftPadding = frame.getLeftPadding();
2096
2097        grx.translate(frame.getX() + leftPadding, frame.getY() + topPadding);
2098        printElements(frame.getElements(), grx);
2099        grx.translate(-(frame.getX() + leftPadding), -(frame.getY() + topPadding));
2100        
2101        printBox(frame, frame, grx);
2102    }
2103
2104
2105    /**
2106     *
2107     */

2108    private static final double THIN_CORNER_OFFSET = 0.25d;
2109    private static final double ONE_POINT_CORNER_OFFSET = 0.5d;
2110    
2111    private static final Stroke JavaDoc STROKE_THIN = new BasicStroke JavaDoc(0.5f);
2112    private static final Stroke JavaDoc STROKE_1_POINT = new BasicStroke JavaDoc(1f);
2113    private static final Stroke JavaDoc STROKE_2_POINT = new BasicStroke JavaDoc(2f);
2114    private static final Stroke JavaDoc STROKE_4_POINT = new BasicStroke JavaDoc(4f);
2115    private static final Stroke JavaDoc STROKE_DOTTED =
2116        new BasicStroke JavaDoc(
2117            1f,
2118            BasicStroke.CAP_SQUARE,
2119            BasicStroke.JOIN_MITER,
2120            10f,
2121            new float[]{5f, 3f},
2122            0f
2123            );
2124    
2125    private static final Stroke JavaDoc BORDER_STROKE_THIN = new BasicStroke JavaDoc(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
2126    private static final Stroke JavaDoc BORDER_STROKE_1_POINT = new BasicStroke JavaDoc(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
2127    private static final Stroke JavaDoc BORDER_STROKE_DOTTED =
2128        new BasicStroke JavaDoc(
2129            1f,
2130            BasicStroke.CAP_BUTT,
2131            BasicStroke.JOIN_MITER,
2132            10f,
2133            new float[]{5f, 3f},
2134            0f
2135            );
2136
2137    /**
2138     *
2139     */

2140    private static Stroke JavaDoc getStroke(byte pen)
2141    {
2142        switch (pen)
2143        {
2144            case JRGraphicElement.PEN_DOTTED :
2145            {
2146                return STROKE_DOTTED;
2147            }
2148            case JRGraphicElement.PEN_4_POINT :
2149            {
2150                return STROKE_4_POINT;
2151            }
2152            case JRGraphicElement.PEN_2_POINT :
2153            {
2154                return STROKE_2_POINT;
2155            }
2156            case JRGraphicElement.PEN_NONE :
2157            {
2158                return null;
2159            }
2160            case JRGraphicElement.PEN_THIN :
2161            {
2162                return STROKE_THIN;
2163            }
2164            case JRGraphicElement.PEN_1_POINT :
2165            default :
2166            {
2167                return STROKE_1_POINT;
2168            }
2169        }
2170    }
2171
2172    
2173    // Variables declaration - do not modify//GEN-BEGIN:variables
2174
protected javax.swing.JPanel JavaDoc tlbToolBar;
2175    private javax.swing.JPanel JavaDoc pnlInScroll;
2176    private javax.swing.JPanel JavaDoc jPanel4;
2177    private javax.swing.JPanel JavaDoc pnlPage;
2178    private javax.swing.JLabel JavaDoc jLabel1;
2179    private javax.swing.JScrollPane JavaDoc scrollPane;
2180    private javax.swing.JPanel JavaDoc pnlMain;
2181    private javax.swing.JPanel JavaDoc pnlSep02;
2182    private javax.swing.JButton JavaDoc btnReload;
2183    private javax.swing.JPanel JavaDoc jPanel5;
2184    private javax.swing.JButton JavaDoc btnZoomOut;
2185    private javax.swing.JLabel JavaDoc lblPage;
2186    private javax.swing.JPanel JavaDoc jPanel8;
2187    private javax.swing.JButton JavaDoc btnZoomIn;
2188    private javax.swing.JPanel JavaDoc jPanel7;
2189    private javax.swing.JPanel JavaDoc pnlSep01;
2190    private javax.swing.JPanel JavaDoc jPanel6;
2191    private javax.swing.JComboBox JavaDoc cmbZoom;
2192    private javax.swing.JPanel JavaDoc jPanel9;
2193    // End of variables declaration//GEN-END:variables
2194

2195}
2196
Popular Tags