KickJava   Java API By Example, From Geeks To Geeks.

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


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
29 /*
30  * Contributors:
31  * Ryan Johnson - delscovich@users.sourceforge.net
32  * Carlton Moore - cmoore79@users.sourceforge.net
33  * Petr Michalek - pmichalek@users.sourceforge.net
34  */

35 package net.sf.jasperreports.view;
36
37 import java.awt.Component JavaDoc;
38 import java.awt.Container JavaDoc;
39 import java.awt.Cursor JavaDoc;
40 import java.awt.Dimension JavaDoc;
41 import java.awt.Graphics JavaDoc;
42 import java.awt.Graphics2D JavaDoc;
43 import java.awt.Image JavaDoc;
44 import java.awt.Point JavaDoc;
45 import java.awt.Rectangle JavaDoc;
46 import java.awt.Toolkit JavaDoc;
47 import java.awt.event.MouseEvent JavaDoc;
48 import java.awt.event.MouseListener JavaDoc;
49 import java.awt.event.MouseMotionListener JavaDoc;
50 import java.io.File JavaDoc;
51 import java.io.InputStream JavaDoc;
52 import java.lang.reflect.Method JavaDoc;
53 import java.text.DecimalFormat JavaDoc;
54 import java.text.MessageFormat JavaDoc;
55 import java.text.ParseException JavaDoc;
56 import java.util.ArrayList JavaDoc;
57 import java.util.Arrays JavaDoc;
58 import java.util.Collection JavaDoc;
59 import java.util.HashMap JavaDoc;
60 import java.util.Iterator JavaDoc;
61 import java.util.List JavaDoc;
62 import java.util.Locale JavaDoc;
63 import java.util.Map JavaDoc;
64 import java.util.ResourceBundle JavaDoc;
65
66 import javax.swing.DefaultComboBoxModel JavaDoc;
67 import javax.swing.ImageIcon JavaDoc;
68 import javax.swing.JFileChooser JavaDoc;
69 import javax.swing.JLabel JavaDoc;
70 import javax.swing.JOptionPane JavaDoc;
71 import javax.swing.JPanel JavaDoc;
72 import javax.swing.JViewport JavaDoc;
73 import javax.swing.filechooser.FileFilter JavaDoc;
74
75 import net.sf.jasperreports.engine.JRException;
76 import net.sf.jasperreports.engine.JRExporterParameter;
77 import net.sf.jasperreports.engine.JRHyperlink;
78 import net.sf.jasperreports.engine.JRImageMapRenderer;
79 import net.sf.jasperreports.engine.JRPrintAnchorIndex;
80 import net.sf.jasperreports.engine.JRPrintElement;
81 import net.sf.jasperreports.engine.JRPrintHyperlink;
82 import net.sf.jasperreports.engine.JRPrintImage;
83 import net.sf.jasperreports.engine.JRPrintImageAreaHyperlink;
84 import net.sf.jasperreports.engine.JRPrintPage;
85 import net.sf.jasperreports.engine.JRRenderable;
86 import net.sf.jasperreports.engine.JRRuntimeException;
87 import net.sf.jasperreports.engine.JasperPrint;
88 import net.sf.jasperreports.engine.JasperPrintManager;
89 import net.sf.jasperreports.engine.export.JRGraphics2DExporter;
90 import net.sf.jasperreports.engine.export.JRGraphics2DExporterParameter;
91 import net.sf.jasperreports.engine.print.JRPrinterAWT;
92 import net.sf.jasperreports.engine.util.JRClassLoader;
93 import net.sf.jasperreports.engine.util.JRLoader;
94 import net.sf.jasperreports.engine.util.JRProperties;
95 import net.sf.jasperreports.engine.xml.JRPrintXmlLoader;
96 import net.sf.jasperreports.view.save.JRPrintSaveContributor;
97
98
99 /**
100  * @author Teodor Danciu (teodord@users.sourceforge.net)
101  * @version $Id: JRViewer.java 1459 2006-11-06 13:54:34 +0200 (Mon, 06 Nov 2006) shertage $
102  */

103 public class JRViewer extends javax.swing.JPanel JavaDoc implements JRHyperlinkListener
104 {
105
106     /**
107      * Maximum size (in pixels) of a buffered image that would be used by {@link JRViewer JRViewer} to render a report page.
108      * <p>
109      * If rendering a report page would require an image larger than this threshold
110      * (i.e. image width x image height > maximum size), the report page will be rendered directly on the viewer component.
111      * </p>
112      * <p>
113      * If this property is zero or negative, buffered images will never be user to render a report page.
114      * By default, this property is set to 0.
115      * </p>
116      */

117     public static final String JavaDoc VIEWER_RENDER_BUFFER_MAX_SIZE = JRProperties.PROPERTY_PREFIX + "viewer.render.buffer.max.size";
118     
119     /**
120      *
121      */

122     private static final int TYPE_FILE_NAME = 1;
123     private static final int TYPE_INPUT_STREAM = 2;
124     private static final int TYPE_JASPER_PRINT = 3;
125     
126     /**
127      * The DPI of the generated report.
128      */

129     public static final int REPORT_RESOLUTION = 72;
130
131     protected float MIN_ZOOM = 0.5f;
132     protected float MAX_ZOOM = 10f;
133     protected int zooms[] = {50, 75, 100, 125, 150, 175, 200, 250, 400, 800};
134     protected int defaultZoomIndex = 2;
135
136     private int type = TYPE_FILE_NAME;
137     private boolean isXML = false;
138     private String JavaDoc reportFileName = null;
139     JasperPrint jasperPrint = null;
140     private int pageIndex = 0;
141     private float zoom = 0f;
142
143     private JRGraphics2DExporter exporter = null;
144
145     /**
146      * the screen resolution.
147      */

148     private int screenResolution = REPORT_RESOLUTION;
149
150     /**
151      * the zoom ration adjusted to the screen resolution.
152      */

153     protected float realZoom = 0f;
154
155     private DecimalFormat JavaDoc zoomDecimalFormat = new DecimalFormat JavaDoc("#.##");
156     private ResourceBundle JavaDoc resourceBundle = null;
157
158     private int downX = 0;
159     private int downY = 0;
160
161     private java.util.List JavaDoc hyperlinkListeners = new ArrayList JavaDoc();
162     private Map JavaDoc linksMap = new HashMap JavaDoc();
163     private MouseListener JavaDoc mouseListener =
164         new java.awt.event.MouseAdapter JavaDoc()
165         {
166             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt)
167             {
168                 hyperlinkClicked(evt);
169             }
170         };
171
172     private java.util.List JavaDoc saveContributors = new ArrayList JavaDoc();
173     
174
175     /** Creates new form JRViewer */
176     public JRViewer(String JavaDoc fileName, boolean isXML) throws JRException
177     {
178         this(fileName, isXML, null);
179     }
180
181
182     /** Creates new form JRViewer */
183     public JRViewer(InputStream JavaDoc is, boolean isXML) throws JRException
184     {
185         this(is, isXML, null);
186     }
187
188
189     /** Creates new form JRViewer */
190     public JRViewer(JasperPrint jrPrint)
191     {
192         this(jrPrint, null);
193     }
194
195     
196     /** Creates new form JRViewer */
197     public JRViewer(String JavaDoc fileName, boolean isXML, Locale JavaDoc locale) throws JRException
198     {
199         this(fileName, isXML, locale, null);
200     }
201
202
203     /** Creates new form JRViewer */
204     public JRViewer(InputStream JavaDoc is, boolean isXML, Locale JavaDoc locale) throws JRException
205     {
206         this(is, isXML, locale, null);
207     }
208
209
210     /** Creates new form JRViewer */
211     public JRViewer(JasperPrint jrPrint, Locale JavaDoc locale)
212     {
213         this(jrPrint, locale, null);
214     }
215
216     
217     /** Creates new form JRViewer */
218     public JRViewer(String JavaDoc fileName, boolean isXML, Locale JavaDoc locale, ResourceBundle JavaDoc resBundle) throws JRException
219     {
220         initResources(locale, resBundle);
221
222         setScreenDetails();
223
224         setZooms();
225
226         initComponents();
227
228         loadReport(fileName, isXML);
229
230         cmbZoom.setSelectedIndex(defaultZoomIndex);
231
232         initSaveContributors();
233
234         addHyperlinkListener(this);
235     }
236
237
238     /** Creates new form JRViewer */
239     public JRViewer(InputStream JavaDoc is, boolean isXML, Locale JavaDoc locale, ResourceBundle JavaDoc resBundle) throws JRException
240     {
241         initResources(locale, resBundle);
242
243         setScreenDetails();
244
245         setZooms();
246
247         initComponents();
248
249         loadReport(is, isXML);
250
251         cmbZoom.setSelectedIndex(defaultZoomIndex);
252
253         initSaveContributors();
254
255         addHyperlinkListener(this);
256     }
257
258
259     /** Creates new form JRViewer */
260     public JRViewer(JasperPrint jrPrint, Locale JavaDoc locale, ResourceBundle JavaDoc resBundle)
261     {
262         initResources(locale, resBundle);
263
264         setScreenDetails();
265
266         setZooms();
267
268         initComponents();
269
270         loadReport(jrPrint);
271
272         cmbZoom.setSelectedIndex(defaultZoomIndex);
273
274         initSaveContributors();
275
276         addHyperlinkListener(this);
277     }
278
279     
280     private void setScreenDetails()
281     {
282         screenResolution = Toolkit.getDefaultToolkit().getScreenResolution();
283     }
284
285     
286     /**
287      *
288      */

289     public void clear()
290     {
291         emptyContainer(this);
292         jasperPrint = null;
293     }
294
295
296     /**
297      *
298      */

299     protected void setZooms()
300     {
301     }
302
303
304     /**
305      *
306      */

307     public void addSaveContributor(JRSaveContributor contributor)
308     {
309         saveContributors.add(contributor);
310     }
311
312
313     /**
314      *
315      */

316     public void removeSaveContributor(JRSaveContributor contributor)
317     {
318         saveContributors.remove(contributor);
319     }
320
321
322     /**
323      *
324      */

325     public JRSaveContributor[] getSaveContributors()
326     {
327         return (JRSaveContributor[])saveContributors.toArray(new JRSaveContributor[saveContributors.size()]);
328     }
329
330
331     /**
332      *
333      */

334     public void addHyperlinkListener(JRHyperlinkListener listener)
335     {
336         hyperlinkListeners.add(listener);
337     }
338
339
340     /**
341      *
342      */

343     public void removeHyperlinkListener(JRHyperlinkListener listener)
344     {
345         hyperlinkListeners.remove(listener);
346     }
347
348
349     /**
350      *
351      */

352     public JRHyperlinkListener[] getHyperlinkListeners()
353     {
354         return (JRHyperlinkListener[])hyperlinkListeners.toArray(new JRHyperlinkListener[hyperlinkListeners.size()]);
355     }
356
357
358     /**
359      *
360      */

361     protected void initResources(Locale JavaDoc locale, ResourceBundle JavaDoc resBundle)
362     {
363         if (locale != null)
364             setLocale(locale);
365         else
366             setLocale(Locale.getDefault());
367         
368         if (resBundle == null)
369         {
370             this.resourceBundle = ResourceBundle.getBundle("net/sf/jasperreports/view/viewer", getLocale());
371         }
372         else
373         {
374             this.resourceBundle = resBundle;
375         }
376     }
377
378
379     /**
380      *
381      */

382     protected String JavaDoc getBundleString(String JavaDoc key)
383     {
384         return resourceBundle.getString(key);
385     }
386
387     
388     /**
389      *
390      */

391     protected void initSaveContributors()
392     {
393         final String JavaDoc[] DEFAULT_CONTRIBUTORS =
394             {
395                 "net.sf.jasperreports.view.save.JRPrintSaveContributor",
396                 "net.sf.jasperreports.view.save.JRPdfSaveContributor",
397                 "net.sf.jasperreports.view.save.JRRtfSaveContributor",
398                 "net.sf.jasperreports.view.save.JRHtmlSaveContributor",
399                 "net.sf.jasperreports.view.save.JRSingleSheetXlsSaveContributor",
400                 "net.sf.jasperreports.view.save.JRMultipleSheetsXlsSaveContributor",
401                 "net.sf.jasperreports.view.save.JRCsvSaveContributor",
402                 "net.sf.jasperreports.view.save.JRXmlSaveContributor",
403                 "net.sf.jasperreports.view.save.JREmbeddedImagesXmlSaveContributor"
404             };
405         
406         for(int i = 0; i < DEFAULT_CONTRIBUTORS.length; i++)
407         {
408             try
409             {
410                 Class JavaDoc saveContribClass = JRClassLoader.loadClassForName(DEFAULT_CONTRIBUTORS[i]);
411                 Method JavaDoc method = saveContribClass.getMethod("getInstance", (Class JavaDoc[])null);
412                 JRSaveContributor saveContrib = (JRSaveContributor)method.invoke(null, (Object JavaDoc[])null);
413                 saveContributors.add(saveContrib);
414             }
415             catch (Exception JavaDoc e)
416             {
417             }
418         }
419     }
420
421     
422     /**
423      *
424      */

425     public void gotoHyperlink(JRPrintHyperlink hyperlink)
426     {
427         switch(hyperlink.getHyperlinkType())
428         {
429             case JRHyperlink.HYPERLINK_TYPE_REFERENCE :
430             {
431                 if (isOnlyHyperlinkListener())
432                 {
433                     System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
434                     System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
435                 }
436                 break;
437             }
438             case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR :
439             {
440                 if (hyperlink.getHyperlinkAnchor() != null)
441                 {
442                     Map JavaDoc anchorIndexes = jasperPrint.getAnchorIndexes();
443                     JRPrintAnchorIndex anchorIndex = (JRPrintAnchorIndex)anchorIndexes.get(hyperlink.getHyperlinkAnchor());
444                     if (anchorIndex.getPageIndex() != pageIndex)
445                     {
446                         setPageIndex(anchorIndex.getPageIndex());
447                         refreshPage();
448                     }
449                     Container JavaDoc container = pnlInScroll.getParent();
450                     if (container instanceof JViewport JavaDoc)
451                     {
452                         JViewport JavaDoc viewport = (JViewport JavaDoc) container;
453
454                         int newX = (int)(anchorIndex.getElementAbsoluteX() * realZoom);
455                         int newY = (int)(anchorIndex.getElementAbsoluteY() * realZoom);
456
457                         int maxX = pnlInScroll.getWidth() - viewport.getWidth();
458                         int maxY = pnlInScroll.getHeight() - viewport.getHeight();
459
460                         if (newX < 0)
461                         {
462                             newX = 0;
463                         }
464                         if (newX > maxX)
465                         {
466                             newX = maxX;
467                         }
468                         if (newY < 0)
469                         {
470                             newY = 0;
471                         }
472                         if (newY > maxY)
473                         {
474                             newY = maxY;
475                         }
476             
477                         viewport.setViewPosition(new Point JavaDoc(newX, newY));
478                     }
479                 }
480                 
481                 break;
482             }
483             case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE :
484             {
485                 int page = pageIndex + 1;
486                 if (hyperlink.getHyperlinkPage() != null)
487                 {
488                     page = hyperlink.getHyperlinkPage().intValue();
489                 }
490                 
491                 if (page >= 1 && page <= jasperPrint.getPages().size() && page != pageIndex + 1)
492                 {
493                     setPageIndex(page - 1);
494                     refreshPage();
495                     Container JavaDoc container = pnlInScroll.getParent();
496                     if (container instanceof JViewport JavaDoc)
497                     {
498                         JViewport JavaDoc viewport = (JViewport JavaDoc) container;
499                         viewport.setViewPosition(new Point JavaDoc(0, 0));
500                     }
501                 }
502                 
503                 break;
504             }
505             case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR :
506             {
507                 if (isOnlyHyperlinkListener())
508                 {
509                     System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
510                     System.out.println("Hyperlink anchor : " + hyperlink.getHyperlinkAnchor());
511                     System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
512                 }
513                 break;
514             }
515             case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE :
516             {
517                 if (isOnlyHyperlinkListener())
518                 {
519                     System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
520                     System.out.println("Hyperlink page : " + hyperlink.getHyperlinkPage());
521                     System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
522                 }
523                 break;
524             }
525             case JRHyperlink.HYPERLINK_TYPE_CUSTOM:
526             {
527                 if (isOnlyHyperlinkListener())
528                 {
529                     System.out.println("Hyperlink of type " + hyperlink.getLinkType());
530                     System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
531                 }
532                 break;
533             }
534             case JRHyperlink.HYPERLINK_TYPE_NONE :
535             default :
536             {
537                 break;
538             }
539         }
540     }
541
542
543     protected boolean isOnlyHyperlinkListener()
544     {
545         int listenerCount;
546         if (hyperlinkListeners == null)
547         {
548             listenerCount = 0;
549         }
550         else
551         {
552             listenerCount = hyperlinkListeners.size();
553             if (hyperlinkListeners.contains(this))
554             {
555                 --listenerCount;
556             }
557         }
558         return listenerCount == 0;
559     }
560
561     
562     /** This method is called from within the constructor to
563      * initialize the form.
564      * WARNING: Do NOT modify this code. The content of this method is
565      * always regenerated by the Form Editor.
566      */

567     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
568
private void initComponents() {
569         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
570
571         tlbToolBar = new javax.swing.JPanel JavaDoc();
572         btnSave = new javax.swing.JButton JavaDoc();
573         btnPrint = new javax.swing.JButton JavaDoc();
574         btnReload = new javax.swing.JButton JavaDoc();
575         pnlSep01 = new javax.swing.JPanel JavaDoc();
576         btnFirst = new javax.swing.JButton JavaDoc();
577         btnPrevious = new javax.swing.JButton JavaDoc();
578         btnNext = new javax.swing.JButton JavaDoc();
579         btnLast = new javax.swing.JButton JavaDoc();
580         txtGoTo = new javax.swing.JTextField JavaDoc();
581         pnlSep02 = new javax.swing.JPanel JavaDoc();
582         btnActualSize = new javax.swing.JToggleButton JavaDoc();
583         btnFitPage = new javax.swing.JToggleButton JavaDoc();
584         btnFitWidth = new javax.swing.JToggleButton JavaDoc();
585         pnlSep03 = new javax.swing.JPanel JavaDoc();
586         btnZoomIn = new javax.swing.JButton JavaDoc();
587         btnZoomOut = new javax.swing.JButton JavaDoc();
588         cmbZoom = new javax.swing.JComboBox JavaDoc();
589         DefaultComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc();
590         for(int i = 0; i < zooms.length; i++)
591         {
592             model.addElement("" + zooms[i] + "%");
593         }
594         cmbZoom.setModel(model);
595
596         pnlMain = new javax.swing.JPanel JavaDoc();
597         scrollPane = new javax.swing.JScrollPane JavaDoc();
598         scrollPane.getHorizontalScrollBar().setUnitIncrement(5);
599         scrollPane.getVerticalScrollBar().setUnitIncrement(5);
600
601         pnlInScroll = new javax.swing.JPanel JavaDoc();
602         pnlPage = new javax.swing.JPanel JavaDoc();
603         jPanel4 = new javax.swing.JPanel JavaDoc();
604         pnlLinks = new javax.swing.JPanel JavaDoc();
605         jPanel5 = new javax.swing.JPanel JavaDoc();
606         jPanel6 = new javax.swing.JPanel JavaDoc();
607         jPanel7 = new javax.swing.JPanel JavaDoc();
608         jPanel8 = new javax.swing.JPanel JavaDoc();
609         jLabel1 = new javax.swing.JLabel JavaDoc();
610         jPanel9 = new javax.swing.JPanel JavaDoc();
611         lblPage = new PageRenderer(this);
612         pnlStatus = new javax.swing.JPanel JavaDoc();
613         lblStatus = new javax.swing.JLabel JavaDoc();
614
615         setLayout(new java.awt.BorderLayout JavaDoc());
616
617         setMinimumSize(new java.awt.Dimension JavaDoc(450, 150));
618         setPreferredSize(new java.awt.Dimension JavaDoc(450, 150));
619         tlbToolBar.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT, 0, 2));
620
621         btnSave.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/save.GIF")));
622         btnSave.setToolTipText(getBundleString("save"));
623         btnSave.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
624         btnSave.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
625         btnSave.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
626         btnSave.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
627         btnSave.addActionListener(new java.awt.event.ActionListener JavaDoc() {
628             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
629                 btnSaveActionPerformed(evt);
630             }
631         });
632
633         tlbToolBar.add(btnSave);
634
635         btnPrint.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/print.GIF")));
636         btnPrint.setToolTipText(getBundleString("print"));
637         btnPrint.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
638         btnPrint.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
639         btnPrint.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
640         btnPrint.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
641         btnPrint.addActionListener(new java.awt.event.ActionListener JavaDoc() {
642             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
643                 btnPrintActionPerformed(evt);
644             }
645         });
646
647         tlbToolBar.add(btnPrint);
648
649         btnReload.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/reload.GIF")));
650         btnReload.setToolTipText(getBundleString("reload"));
651         btnReload.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
652         btnReload.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
653         btnReload.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
654         btnReload.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
655         btnReload.addActionListener(new java.awt.event.ActionListener JavaDoc() {
656             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
657                 btnReloadActionPerformed(evt);
658             }
659         });
660
661         tlbToolBar.add(btnReload);
662
663         pnlSep01.setMaximumSize(new java.awt.Dimension JavaDoc(10, 10));
664         tlbToolBar.add(pnlSep01);
665
666         btnFirst.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/first.GIF")));
667         btnFirst.setToolTipText(getBundleString("first.page"));
668         btnFirst.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
669         btnFirst.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
670         btnFirst.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
671         btnFirst.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
672         btnFirst.addActionListener(new java.awt.event.ActionListener JavaDoc() {
673             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
674                 btnFirstActionPerformed(evt);
675             }
676         });
677
678         tlbToolBar.add(btnFirst);
679
680         btnPrevious.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/previous.GIF")));
681         btnPrevious.setToolTipText(getBundleString("previous.page"));
682         btnPrevious.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
683         btnPrevious.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
684         btnPrevious.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
685         btnPrevious.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
686         btnPrevious.addActionListener(new java.awt.event.ActionListener JavaDoc() {
687             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
688                 btnPreviousActionPerformed(evt);
689             }
690         });
691
692         tlbToolBar.add(btnPrevious);
693
694         btnNext.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/next.GIF")));
695         btnNext.setToolTipText(getBundleString("next.page"));
696         btnNext.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
697         btnNext.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
698         btnNext.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
699         btnNext.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
700         btnNext.addActionListener(new java.awt.event.ActionListener JavaDoc() {
701             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
702                 btnNextActionPerformed(evt);
703             }
704         });
705
706         tlbToolBar.add(btnNext);
707
708         btnLast.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/last.GIF")));
709         btnLast.setToolTipText(getBundleString("last.page"));
710         btnLast.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
711         btnLast.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
712         btnLast.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
713         btnLast.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
714         btnLast.addActionListener(new java.awt.event.ActionListener JavaDoc() {
715             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
716                 btnLastActionPerformed(evt);
717             }
718         });
719
720         tlbToolBar.add(btnLast);
721
722         txtGoTo.setToolTipText(getBundleString("go.to.page"));
723         txtGoTo.setMaximumSize(new java.awt.Dimension JavaDoc(40, 23));
724         txtGoTo.setMinimumSize(new java.awt.Dimension JavaDoc(40, 23));
725         txtGoTo.setPreferredSize(new java.awt.Dimension JavaDoc(40, 23));
726         txtGoTo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
727             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
728                 txtGoToActionPerformed(evt);
729             }
730         });
731
732         tlbToolBar.add(txtGoTo);
733
734         pnlSep02.setMaximumSize(new java.awt.Dimension JavaDoc(10, 10));
735         tlbToolBar.add(pnlSep02);
736
737         btnActualSize.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/actualsize.GIF")));
738         btnActualSize.setToolTipText(getBundleString("actual.size"));
739         btnActualSize.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
740         btnActualSize.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
741         btnActualSize.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
742         btnActualSize.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
743         btnActualSize.addActionListener(new java.awt.event.ActionListener JavaDoc() {
744             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
745                 btnActualSizeActionPerformed(evt);
746             }
747         });
748
749         tlbToolBar.add(btnActualSize);
750
751         btnFitPage.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/fitpage.GIF")));
752         btnFitPage.setToolTipText(getBundleString("fit.page"));
753         btnFitPage.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
754         btnFitPage.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
755         btnFitPage.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
756         btnFitPage.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
757         btnFitPage.addActionListener(new java.awt.event.ActionListener JavaDoc() {
758             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
759                 btnFitPageActionPerformed(evt);
760             }
761         });
762
763         tlbToolBar.add(btnFitPage);
764
765         btnFitWidth.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/fitwidth.GIF")));
766         btnFitWidth.setToolTipText(getBundleString("fit.width"));
767         btnFitWidth.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
768         btnFitWidth.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
769         btnFitWidth.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
770         btnFitWidth.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
771         btnFitWidth.addActionListener(new java.awt.event.ActionListener JavaDoc() {
772             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
773                 btnFitWidthActionPerformed(evt);
774             }
775         });
776
777         tlbToolBar.add(btnFitWidth);
778
779         pnlSep03.setMaximumSize(new java.awt.Dimension JavaDoc(10, 10));
780         tlbToolBar.add(pnlSep03);
781
782         btnZoomIn.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/zoomin.GIF")));
783         btnZoomIn.setToolTipText(getBundleString("zoom.in"));
784         btnZoomIn.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
785         btnZoomIn.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
786         btnZoomIn.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
787         btnZoomIn.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
788         btnZoomIn.addActionListener(new java.awt.event.ActionListener JavaDoc() {
789             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
790                 btnZoomInActionPerformed(evt);
791             }
792         });
793
794         tlbToolBar.add(btnZoomIn);
795
796         btnZoomOut.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/net/sf/jasperreports/view/images/zoomout.GIF")));
797         btnZoomOut.setToolTipText(getBundleString("zoom.out"));
798         btnZoomOut.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
799         btnZoomOut.setMaximumSize(new java.awt.Dimension JavaDoc(23, 23));
800         btnZoomOut.setMinimumSize(new java.awt.Dimension JavaDoc(23, 23));
801         btnZoomOut.setPreferredSize(new java.awt.Dimension JavaDoc(23, 23));
802         btnZoomOut.addActionListener(new java.awt.event.ActionListener JavaDoc() {
803             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
804                 btnZoomOutActionPerformed(evt);
805             }
806         });
807
808         tlbToolBar.add(btnZoomOut);
809
810         cmbZoom.setEditable(true);
811         cmbZoom.setToolTipText(getBundleString("zoom.ratio"));
812         cmbZoom.setMaximumSize(new java.awt.Dimension JavaDoc(80, 23));
813         cmbZoom.setMinimumSize(new java.awt.Dimension JavaDoc(80, 23));
814         cmbZoom.setPreferredSize(new java.awt.Dimension JavaDoc(80, 23));
815         cmbZoom.addActionListener(new java.awt.event.ActionListener JavaDoc() {
816             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
817                 cmbZoomActionPerformed(evt);
818             }
819         });
820         cmbZoom.addItemListener(new java.awt.event.ItemListener JavaDoc() {
821             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
822                 cmbZoomItemStateChanged(evt);
823             }
824         });
825
826         tlbToolBar.add(cmbZoom);
827
828         add(tlbToolBar, java.awt.BorderLayout.NORTH);
829
830         pnlMain.setLayout(new java.awt.BorderLayout JavaDoc());
831
832         pnlMain.addComponentListener(new java.awt.event.ComponentAdapter JavaDoc() {
833             public void componentResized(java.awt.event.ComponentEvent JavaDoc evt) {
834                 pnlMainComponentResized(evt);
835             }
836         });
837
838         scrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
839         scrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
840         pnlInScroll.setLayout(new java.awt.GridBagLayout JavaDoc());
841
842         pnlPage.setLayout(new java.awt.BorderLayout JavaDoc());
843
844         pnlPage.setMinimumSize(new java.awt.Dimension JavaDoc(100, 100));
845         pnlPage.setPreferredSize(new java.awt.Dimension JavaDoc(100, 100));
846         jPanel4.setLayout(new java.awt.GridBagLayout JavaDoc());
847
848         jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(100, 120));
849         jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(100, 120));
850         pnlLinks.setLayout(null);
851
852         pnlLinks.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
853         pnlLinks.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
854         pnlLinks.setOpaque(false);
855         pnlLinks.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
856             public void mousePressed(java.awt.event.MouseEvent JavaDoc evt) {
857                 pnlLinksMousePressed(evt);
858             }
859             public void mouseReleased(java.awt.event.MouseEvent JavaDoc evt) {
860                 pnlLinksMouseReleased(evt);
861             }
862         });
863         pnlLinks.addMouseMotionListener(new java.awt.event.MouseMotionAdapter JavaDoc() {
864             public void mouseDragged(java.awt.event.MouseEvent JavaDoc evt) {
865                 pnlLinksMouseDragged(evt);
866             }
867         });
868
869         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
870         gridBagConstraints.gridx = 0;
871         gridBagConstraints.gridy = 0;
872         gridBagConstraints.gridwidth = 2;
873         gridBagConstraints.gridheight = 2;
874         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
875         jPanel4.add(pnlLinks, gridBagConstraints);
876
877         jPanel5.setBackground(java.awt.Color.gray);
878         jPanel5.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
879         jPanel5.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
880         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
881         gridBagConstraints.gridx = 2;
882         gridBagConstraints.gridy = 1;
883         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
884         jPanel4.add(jPanel5, gridBagConstraints);
885
886         jPanel6.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
887         jPanel6.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
888         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
889         gridBagConstraints.gridx = 0;
890         gridBagConstraints.gridy = 2;
891         jPanel4.add(jPanel6, gridBagConstraints);
892
893         jPanel7.setBackground(java.awt.Color.gray);
894         jPanel7.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
895         jPanel7.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
896         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
897         gridBagConstraints.gridx = 1;
898         gridBagConstraints.gridy = 2;
899         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
900         jPanel4.add(jPanel7, gridBagConstraints);
901
902         jPanel8.setBackground(java.awt.Color.gray);
903         jPanel8.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
904         jPanel8.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
905         jLabel1.setText("jLabel1");
906         jPanel8.add(jLabel1);
907
908         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
909         gridBagConstraints.gridx = 2;
910         gridBagConstraints.gridy = 2;
911         jPanel4.add(jPanel8, gridBagConstraints);
912
913         jPanel9.setMinimumSize(new java.awt.Dimension JavaDoc(5, 5));
914         jPanel9.setPreferredSize(new java.awt.Dimension JavaDoc(5, 5));
915         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
916         gridBagConstraints.gridx = 2;
917         gridBagConstraints.gridy = 0;
918         jPanel4.add(jPanel9, gridBagConstraints);
919
920         lblPage.setBackground(java.awt.Color.white);
921         lblPage.setBorder(new javax.swing.border.LineBorder JavaDoc(new java.awt.Color JavaDoc(0, 0, 0)));
922         lblPage.setOpaque(true);
923         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
924         gridBagConstraints.gridx = 0;
925         gridBagConstraints.gridy = 0;
926         gridBagConstraints.gridwidth = 2;
927         gridBagConstraints.gridheight = 2;
928         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
929         gridBagConstraints.weightx = 1.0;
930         gridBagConstraints.weighty = 1.0;
931         jPanel4.add(lblPage, gridBagConstraints);
932
933         pnlPage.add(jPanel4, java.awt.BorderLayout.CENTER);
934
935         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
936         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 5, 5);
937         pnlInScroll.add(pnlPage, gridBagConstraints);
938
939         scrollPane.setViewportView(pnlInScroll);
940
941         pnlMain.add(scrollPane, java.awt.BorderLayout.CENTER);
942
943         add(pnlMain, java.awt.BorderLayout.CENTER);
944
945         pnlStatus.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.CENTER, 0, 0));
946
947         lblStatus.setFont(new java.awt.Font JavaDoc("Dialog", 1, 10));
948         lblStatus.setText("Page i of n");
949         pnlStatus.add(lblStatus);
950
951         add(pnlStatus, java.awt.BorderLayout.SOUTH);
952
953     }
954     // </editor-fold>//GEN-END:initComponents
955

956     void txtGoToActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_txtGoToActionPerformed
957
try
958         {
959             int pageNumber = Integer.parseInt(txtGoTo.getText());
960             if (
961                 pageNumber != pageIndex + 1
962                 && pageNumber > 0
963                 && pageNumber <= jasperPrint.getPages().size()
964                 )
965             {
966                 setPageIndex(pageNumber - 1);
967                 refreshPage();
968             }
969         }
970         catch(NumberFormatException JavaDoc e)
971         {
972         }
973     }//GEN-LAST:event_txtGoToActionPerformed
974

975     void cmbZoomItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_cmbZoomItemStateChanged
976
// Add your handling code here:
977
btnActualSize.setSelected(false);
978         btnFitPage.setSelected(false);
979         btnFitWidth.setSelected(false);
980     }//GEN-LAST:event_cmbZoomItemStateChanged
981

982     void pnlMainComponentResized(java.awt.event.ComponentEvent JavaDoc evt) {//GEN-FIRST:event_pnlMainComponentResized
983
// Add your handling code here:
984
if (btnFitPage.isSelected())
985         {
986             fitPage();
987             btnFitPage.setSelected(true);
988         }
989         else if (btnFitWidth.isSelected())
990         {
991             setRealZoomRatio(((float)pnlInScroll.getVisibleRect().getWidth() - 20f) / jasperPrint.getPageWidth());
992             btnFitWidth.setSelected(true);
993         }
994         
995     }//GEN-LAST:event_pnlMainComponentResized
996

997     void btnActualSizeActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnActualSizeActionPerformed
998
// Add your handling code here:
999
if (btnActualSize.isSelected())
1000        {
1001            btnFitPage.setSelected(false);
1002            btnFitWidth.setSelected(false);
1003            cmbZoom.setSelectedIndex(-1);
1004            setZoomRatio(1);
1005            btnActualSize.setSelected(true);
1006        }
1007    }//GEN-LAST:event_btnActualSizeActionPerformed
1008

1009    void btnFitWidthActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnFitWidthActionPerformed
1010
// Add your handling code here:
1011
if (btnFitWidth.isSelected())
1012        {
1013            btnActualSize.setSelected(false);
1014            btnFitPage.setSelected(false);
1015            cmbZoom.setSelectedIndex(-1);
1016            setRealZoomRatio(((float)pnlInScroll.getVisibleRect().getWidth() - 20f) / jasperPrint.getPageWidth());
1017            btnFitWidth.setSelected(true);
1018        }
1019    }//GEN-LAST:event_btnFitWidthActionPerformed
1020

1021    void btnFitPageActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnFitPageActionPerformed
1022
// Add your handling code here:
1023
if (btnFitPage.isSelected())
1024        {
1025            btnActualSize.setSelected(false);
1026            btnFitWidth.setSelected(false);
1027            cmbZoom.setSelectedIndex(-1);
1028            fitPage();
1029            btnFitPage.setSelected(true);
1030        }
1031    }//GEN-LAST:event_btnFitPageActionPerformed
1032

1033    void btnSaveActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnSaveActionPerformed
1034
// Add your handling code here:
1035

1036        JFileChooser JavaDoc fileChooser = new JFileChooser JavaDoc();
1037
1038        for(int i = 0; i < saveContributors.size(); i++)
1039        {
1040            fileChooser.addChoosableFileFilter((JRSaveContributor)saveContributors.get(i));
1041        }
1042        
1043        if (saveContributors.size() > 0)
1044        {
1045            fileChooser.setFileFilter((JRSaveContributor)saveContributors.get(0));
1046        }
1047    
1048        int retValue = fileChooser.showSaveDialog(this);
1049        if (retValue == JFileChooser.APPROVE_OPTION)
1050        {
1051            FileFilter JavaDoc fileFilter = fileChooser.getFileFilter();
1052            File JavaDoc file = fileChooser.getSelectedFile();
1053
1054            JRSaveContributor contributor = null;
1055            
1056            if (fileFilter instanceof JRSaveContributor)
1057            {
1058                contributor = (JRSaveContributor)fileFilter;
1059            }
1060            else
1061            {
1062                int i = 0;
1063                while(contributor == null && i < saveContributors.size())
1064                {
1065                    contributor = (JRSaveContributor)saveContributors.get(i++);
1066                    if (!contributor.accept(file))
1067                    {
1068                        contributor = null;
1069                    }
1070                }
1071                
1072                if (contributor == null)
1073                {
1074                    contributor = new JRPrintSaveContributor();
1075                }
1076            }
1077
1078            try
1079            {
1080                contributor.save(jasperPrint, file);
1081            }
1082            catch (JRException e)
1083            {
1084                e.printStackTrace();
1085                JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
1086            }
1087        }
1088    }//GEN-LAST:event_btnSaveActionPerformed
1089

1090    void pnlLinksMouseDragged(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_pnlLinksMouseDragged
1091
// Add your handling code here:
1092

1093        Container JavaDoc container = pnlInScroll.getParent();
1094        if (container instanceof JViewport JavaDoc)
1095        {
1096            JViewport JavaDoc viewport = (JViewport JavaDoc) container;
1097            Point JavaDoc point = viewport.getViewPosition();
1098            int newX = point.x - (evt.getX() - downX);
1099            int newY = point.y - (evt.getY() - downY);
1100            
1101            int maxX = pnlInScroll.getWidth() - viewport.getWidth();
1102            int maxY = pnlInScroll.getHeight() - viewport.getHeight();
1103
1104            if (newX < 0)
1105            {
1106                newX = 0;
1107            }
1108            if (newX > maxX)
1109            {
1110                newX = maxX;
1111            }
1112            if (newY < 0)
1113            {
1114                newY = 0;
1115            }
1116            if (newY > maxY)
1117            {
1118                newY = maxY;
1119            }
1120            
1121            viewport.setViewPosition(new Point JavaDoc(newX, newY));
1122        }
1123    }//GEN-LAST:event_pnlLinksMouseDragged
1124

1125    void pnlLinksMouseReleased(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_pnlLinksMouseReleased
1126
// Add your handling code here:
1127
pnlLinks.setCursor(new Cursor JavaDoc(Cursor.DEFAULT_CURSOR));
1128    }//GEN-LAST:event_pnlLinksMouseReleased
1129

1130    void pnlLinksMousePressed(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_pnlLinksMousePressed
1131
// Add your handling code here:
1132
pnlLinks.setCursor(new Cursor JavaDoc(Cursor.MOVE_CURSOR));
1133        
1134        downX = evt.getX();
1135        downY = evt.getY();
1136    }//GEN-LAST:event_pnlLinksMousePressed
1137

1138    void btnPrintActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_btnPrintActionPerformed
1139
{//GEN-HEADEREND:event_btnPrintActionPerformed
1140
// Add your handling code here:
1141

1142        Thread JavaDoc thread =
1143            new Thread JavaDoc(
1144                new Runnable JavaDoc()
1145                {
1146                    public void run()
1147                    {
1148                        try
1149                        {
1150                            JasperPrintManager.printReport(jasperPrint, true);
1151                        }
1152                        catch (Exception JavaDoc ex)
1153                        {
1154                            ex.printStackTrace();
1155                            JOptionPane.showMessageDialog(JRViewer.this, getBundleString("error.printing"));
1156                        }
1157                    }
1158                }
1159            );
1160        
1161        thread.start();
1162
1163    }//GEN-LAST:event_btnPrintActionPerformed
1164

1165    void btnLastActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_btnLastActionPerformed
1166
{//GEN-HEADEREND:event_btnLastActionPerformed
1167
// Add your handling code here:
1168
setPageIndex(jasperPrint.getPages().size() - 1);
1169        refreshPage();
1170    }//GEN-LAST:event_btnLastActionPerformed
1171

1172    void btnNextActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_btnNextActionPerformed
1173
{//GEN-HEADEREND:event_btnNextActionPerformed
1174
// Add your handling code here:
1175
setPageIndex(pageIndex + 1);
1176        refreshPage();
1177    }//GEN-LAST:event_btnNextActionPerformed
1178

1179    void btnPreviousActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_btnPreviousActionPerformed
1180
{//GEN-HEADEREND:event_btnPreviousActionPerformed
1181
// Add your handling code here:
1182
setPageIndex(pageIndex - 1);
1183        refreshPage();
1184    }//GEN-LAST:event_btnPreviousActionPerformed
1185

1186    void btnFirstActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_btnFirstActionPerformed
1187
{//GEN-HEADEREND:event_btnFirstActionPerformed
1188
// Add your handling code here:
1189
setPageIndex(0);
1190        refreshPage();
1191    }//GEN-LAST:event_btnFirstActionPerformed
1192

1193    void btnReloadActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_btnReloadActionPerformed
1194
{//GEN-HEADEREND:event_btnReloadActionPerformed
1195
// Add your handling code here:
1196
if (type == TYPE_FILE_NAME)
1197        {
1198            try
1199            {
1200                loadReport(reportFileName, isXML);
1201            }
1202            catch (JRException e)
1203            {
1204                e.printStackTrace();
1205
1206                jasperPrint = null;
1207                setPageIndex(0);
1208                refreshPage();
1209
1210                JOptionPane.showMessageDialog(this, getBundleString("error.loading"));
1211            }
1212
1213            zoom = 0;//force pageRefresh()
1214
realZoom = 0f;
1215            setZoomRatio(1);
1216        }
1217    }//GEN-LAST:event_btnReloadActionPerformed
1218

1219    void btnZoomInActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_btnZoomInActionPerformed
1220
{//GEN-HEADEREND:event_btnZoomInActionPerformed
1221
// Add your handling code here:
1222
btnActualSize.setSelected(false);
1223        btnFitPage.setSelected(false);
1224        btnFitWidth.setSelected(false);
1225
1226        int newZoomInt = (int)(100 * getZoomRatio());
1227        int index = Arrays.binarySearch(zooms, newZoomInt);
1228        if (index < 0)
1229        {
1230            setZoomRatio(zooms[- index - 1] / 100f);
1231        }
1232        else if (index < cmbZoom.getModel().getSize() - 1)
1233        {
1234            setZoomRatio(zooms[index + 1] / 100f);
1235        }
1236    }//GEN-LAST:event_btnZoomInActionPerformed
1237

1238    void btnZoomOutActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_btnZoomOutActionPerformed
1239
{//GEN-HEADEREND:event_btnZoomOutActionPerformed
1240
// Add your handling code here:
1241
btnActualSize.setSelected(false);
1242        btnFitPage.setSelected(false);
1243        btnFitWidth.setSelected(false);
1244
1245        int newZoomInt = (int)(100 * getZoomRatio());
1246        int index = Arrays.binarySearch(zooms, newZoomInt);
1247        if (index > 0)
1248        {
1249            setZoomRatio(zooms[index - 1] / 100f);
1250        }
1251        else if (index < -1)
1252        {
1253            setZoomRatio(zooms[- index - 2] / 100f);
1254        }
1255    }//GEN-LAST:event_btnZoomOutActionPerformed
1256

1257    void cmbZoomActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cmbZoomActionPerformed
1258
{//GEN-HEADEREND:event_cmbZoomActionPerformed
1259
// Add your handling code here:
1260
float newZoom = getZoomRatio();
1261        
1262        if (newZoom < MIN_ZOOM)
1263        {
1264            newZoom = MIN_ZOOM;
1265        }
1266        
1267        if (newZoom > MAX_ZOOM)
1268        {
1269            newZoom = MAX_ZOOM;
1270        }
1271
1272        setZoomRatio(newZoom);
1273    }//GEN-LAST:event_cmbZoomActionPerformed
1274

1275
1276    /**
1277    */

1278    void hyperlinkClicked(MouseEvent JavaDoc evt)
1279    {
1280        JPanel JavaDoc link = (JPanel JavaDoc)evt.getSource();
1281        JRPrintHyperlink element = (JRPrintHyperlink)linksMap.get(link);
1282        hyperlinkClicked(element);
1283    }
1284
1285
1286    protected void hyperlinkClicked(JRPrintHyperlink hyperlink)
1287    {
1288        try
1289        {
1290            JRHyperlinkListener listener = null;
1291            for(int i = 0; i < hyperlinkListeners.size(); i++)
1292            {
1293                listener = (JRHyperlinkListener)hyperlinkListeners.get(i);
1294                listener.gotoHyperlink(hyperlink);
1295            }
1296        }
1297        catch(JRException e)
1298        {
1299            e.printStackTrace();
1300            JOptionPane.showMessageDialog(this, getBundleString("error.hyperlink"));
1301        }
1302    }
1303
1304
1305    /**
1306    */

1307    private void setPageIndex(int index)
1308    {
1309        pageIndex = index;
1310        if (
1311            jasperPrint != null &&
1312            jasperPrint.getPages() != null &&
1313            jasperPrint.getPages().size() > 0
1314            )
1315        {
1316            btnFirst.setEnabled( (pageIndex > 0) );
1317            btnPrevious.setEnabled( (pageIndex > 0) );
1318            btnNext.setEnabled( (pageIndex < jasperPrint.getPages().size() - 1) );
1319            btnLast.setEnabled( (pageIndex < jasperPrint.getPages().size() - 1) );
1320            txtGoTo.setEnabled(btnFirst.isEnabled() || btnLast.isEnabled());
1321            txtGoTo.setText("" + (pageIndex + 1));
1322            lblStatus.setText(
1323                MessageFormat.format(
1324                    getBundleString("page"),
1325                    new Object JavaDoc[]{new Integer JavaDoc(pageIndex + 1), new Integer JavaDoc(jasperPrint.getPages().size())}
1326                    )
1327                );
1328        }
1329        else
1330        {
1331            btnFirst.setEnabled(false);
1332            btnPrevious.setEnabled(false);
1333            btnNext.setEnabled(false);
1334            btnLast.setEnabled(false);
1335            txtGoTo.setEnabled(false);
1336            txtGoTo.setText("");
1337            lblStatus.setText("");
1338        }
1339    }
1340
1341
1342    /**
1343    */

1344    protected void loadReport(String JavaDoc fileName, boolean isXmlReport) throws JRException
1345    {
1346        if (isXmlReport)
1347        {
1348            jasperPrint = JRPrintXmlLoader.load(fileName);
1349        }
1350        else
1351        {
1352            jasperPrint = (JasperPrint)JRLoader.loadObject(fileName);
1353        }
1354
1355        type = TYPE_FILE_NAME;
1356        this.isXML = isXmlReport;
1357        reportFileName = fileName;
1358        btnReload.setEnabled(true);
1359        setPageIndex(0);
1360    }
1361
1362
1363    /**
1364    */

1365    protected void loadReport(InputStream JavaDoc is, boolean isXmlReport) throws JRException
1366    {
1367        if (isXmlReport)
1368        {
1369            jasperPrint = JRPrintXmlLoader.load(is);
1370        }
1371        else
1372        {
1373            jasperPrint = (JasperPrint)JRLoader.loadObject(is);
1374        }
1375
1376        type = TYPE_INPUT_STREAM;
1377        this.isXML = isXmlReport;
1378        btnReload.setEnabled(false);
1379        setPageIndex(0);
1380    }
1381
1382
1383    /**
1384    */

1385    protected void loadReport(JasperPrint jrPrint)
1386    {
1387        jasperPrint = jrPrint;
1388        type = TYPE_JASPER_PRINT;
1389        isXML = false;
1390        btnReload.setEnabled(false);
1391        setPageIndex(0);
1392    }
1393
1394
1395    /**
1396    */

1397    protected void refreshPage()
1398    {
1399        if (
1400            jasperPrint == null ||
1401            jasperPrint.getPages() == null ||
1402            jasperPrint.getPages().size() == 0
1403            )
1404        {
1405            pnlPage.setVisible(false);
1406            btnSave.setEnabled(false);
1407            btnPrint.setEnabled(false);
1408            btnActualSize.setEnabled(false);
1409            btnFitPage.setEnabled(false);
1410            btnFitWidth.setEnabled(false);
1411            btnZoomIn.setEnabled(false);
1412            btnZoomOut.setEnabled(false);
1413            cmbZoom.setEnabled(false);
1414            
1415            if (jasperPrint != null)
1416            {
1417                JOptionPane.showMessageDialog(this, getBundleString("no.pages"));
1418            }
1419
1420            return;
1421        }
1422
1423        pnlPage.setVisible(true);
1424        btnSave.setEnabled(true);
1425        btnPrint.setEnabled(true);
1426        btnActualSize.setEnabled(true);
1427        btnFitPage.setEnabled(true);
1428        btnFitWidth.setEnabled(true);
1429        btnZoomIn.setEnabled(zoom < MAX_ZOOM);
1430        btnZoomOut.setEnabled(zoom > MIN_ZOOM);
1431        cmbZoom.setEnabled(true);
1432
1433        Dimension JavaDoc dim = new Dimension JavaDoc(
1434            (int)(jasperPrint.getPageWidth() * realZoom) + 8, // 2 from border, 5 from shadow and 1 extra pixel for image
1435
(int)(jasperPrint.getPageHeight() * realZoom) + 8
1436            );
1437        pnlPage.setMaximumSize(dim);
1438        pnlPage.setMinimumSize(dim);
1439        pnlPage.setPreferredSize(dim);
1440        
1441        long maxImageSize = JRProperties.getLongProperty(VIEWER_RENDER_BUFFER_MAX_SIZE);
1442        boolean renderImage;
1443        if (maxImageSize <= 0)
1444        {
1445            renderImage = false;
1446        }
1447        else
1448        {
1449            long imageSize = JRPrinterAWT.getImageSize(jasperPrint, realZoom);
1450            renderImage = imageSize <= maxImageSize;
1451        }
1452        
1453        lblPage.setRenderImage(renderImage);
1454
1455        if (renderImage)
1456        {
1457            Image JavaDoc image = null;
1458            ImageIcon JavaDoc imageIcon = null;
1459            try
1460            {
1461                image = JasperPrintManager.printPageToImage(jasperPrint, pageIndex, realZoom);
1462                imageIcon = new ImageIcon JavaDoc(image);
1463            }
1464            catch (Exception JavaDoc e)
1465            {
1466                e.printStackTrace();
1467                JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("net/sf/jasperreports/view/viewer").getString("error.displaying"));
1468            }
1469
1470            lblPage.setIcon(imageIcon);
1471        }
1472
1473        pnlLinks.removeAll();
1474        linksMap = new HashMap JavaDoc();
1475
1476        createHyperlinks();
1477        
1478        if (!renderImage)
1479        {
1480            lblPage.setIcon(null);
1481
1482            pnlMain.validate();
1483            pnlMain.repaint();
1484        }
1485    }
1486
1487
1488    protected void createHyperlinks()
1489    {
1490        java.util.List JavaDoc pages = jasperPrint.getPages();
1491        JRPrintPage page = (JRPrintPage)pages.get(pageIndex);
1492        Collection JavaDoc elements = page.getElements();
1493        if(elements != null && elements.size() > 0)
1494        {
1495            for(Iterator JavaDoc it = elements.iterator(); it.hasNext();)
1496            {
1497                JRPrintElement element = (JRPrintElement)it.next();
1498                
1499                JRImageMapRenderer imageMap = null;
1500                if (element instanceof JRPrintImage)
1501                {
1502                    JRRenderable renderer = ((JRPrintImage) element).getRenderer();
1503                    if (renderer instanceof JRImageMapRenderer)
1504                    {
1505                        imageMap = (JRImageMapRenderer) renderer;
1506                    }
1507                }
1508                boolean hasImageMap = imageMap != null;
1509                
1510                JRPrintHyperlink hyperlink = null;
1511                if (!hasImageMap && element instanceof JRPrintHyperlink)
1512                {
1513                    hyperlink = (JRPrintHyperlink) element;
1514                }
1515                boolean hasHyperlink = hyperlink != null && hyperlink.getHyperlinkType() != JRHyperlink.HYPERLINK_TYPE_NONE;
1516                
1517                if (hasHyperlink || hasImageMap)
1518                {
1519                    JPanel JavaDoc link;
1520                    if (hasHyperlink)
1521                    {
1522                        link = new JPanel JavaDoc();
1523                        link.addMouseListener(mouseListener);
1524                    }
1525                    else //hasImageMap
1526
{
1527                        Rectangle JavaDoc renderingArea = new Rectangle JavaDoc(0, 0, element.getWidth(), element.getHeight());
1528                        link = new ImageMapPanel(renderingArea, imageMap);
1529                    }
1530                    
1531                    if (hasHyperlink)
1532                    {
1533                        link.setCursor(new Cursor JavaDoc(Cursor.HAND_CURSOR));
1534                    }
1535                    
1536                    link.setLocation(
1537                        (int)(element.getX() * realZoom),
1538                        (int)(element.getY() * realZoom)
1539                        );
1540                    link.setSize(
1541                        (int)(element.getWidth() * realZoom),
1542                        (int)(element.getHeight() * realZoom)
1543                        );
1544                    link.setOpaque(false);
1545                    
1546                    String JavaDoc toolTip;
1547                    if (hasHyperlink)
1548                    {
1549                        toolTip = getHyperlinkTooltip(hyperlink);
1550                    }
1551                    else //hasImageMap
1552
{
1553                        toolTip = "";//not null to register the panel as having a tool tip
1554
}
1555                    link.setToolTipText(toolTip);
1556                    
1557                    pnlLinks.add(link);
1558                    linksMap.put(link, element);
1559                }
1560            }
1561        }
1562    }
1563
1564    
1565    protected class ImageMapPanel extends JPanel JavaDoc implements MouseListener JavaDoc, MouseMotionListener JavaDoc
1566    {
1567        protected final List JavaDoc imageAreaHyperlinks;
1568        
1569        public ImageMapPanel(Rectangle JavaDoc renderingArea, JRImageMapRenderer imageMap)
1570        {
1571            try
1572            {
1573                imageAreaHyperlinks = imageMap.getImageAreaHyperlinks(renderingArea);
1574            }
1575            catch (JRException e)
1576            {
1577                throw new JRRuntimeException(e);
1578            }
1579            
1580            addMouseListener(this);
1581            addMouseMotionListener(this);
1582        }
1583        
1584        public String JavaDoc getToolTipText(MouseEvent JavaDoc event)
1585        {
1586            String JavaDoc tooltip = null;
1587            JRPrintImageAreaHyperlink imageMapArea = getImageMapArea(event);
1588            if (imageMapArea != null)
1589            {
1590                tooltip = getHyperlinkTooltip(imageMapArea.getHyperlink());
1591            }
1592            
1593            if (tooltip == null)
1594            {
1595                tooltip = super.getToolTipText(event);
1596            }
1597                
1598            return tooltip;
1599        }
1600        
1601        public void mouseDragged(MouseEvent JavaDoc e)
1602        {
1603        }
1604
1605        public void mouseMoved(MouseEvent JavaDoc e)
1606        {
1607            JRPrintImageAreaHyperlink imageArea = getImageMapArea(e);
1608            if (imageArea != null
1609                    && imageArea.getHyperlink().getHyperlinkType() != JRHyperlink.HYPERLINK_TYPE_NONE)
1610            {
1611                e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1612            }
1613            else
1614            {
1615                e.getComponent().setCursor(Cursor.getDefaultCursor());
1616            }
1617        }
1618
1619        protected JRPrintImageAreaHyperlink getImageMapArea(MouseEvent JavaDoc e)
1620        {
1621            return getImageMapArea((int) (e.getX() / realZoom), (int) (e.getY() / realZoom));
1622        }
1623
1624        protected JRPrintImageAreaHyperlink getImageMapArea(int x, int y)
1625        {
1626            JRPrintImageAreaHyperlink image = null;
1627            for (Iterator JavaDoc it = imageAreaHyperlinks.iterator(); image == null && it.hasNext();)
1628            {
1629                JRPrintImageAreaHyperlink area = (JRPrintImageAreaHyperlink) it.next();
1630                if (area.getArea().containsPoint(x, y))
1631                {
1632                    image = area;
1633                }
1634            }
1635            return image;
1636        }
1637
1638        public void mouseClicked(MouseEvent JavaDoc e)
1639        {
1640            JRPrintImageAreaHyperlink imageMapArea = getImageMapArea(e);
1641            if (imageMapArea != null)
1642            {
1643                hyperlinkClicked(imageMapArea.getHyperlink());
1644            }
1645        }
1646
1647        public void mouseEntered(MouseEvent JavaDoc e)
1648        {
1649        }
1650
1651        public void mouseExited(MouseEvent JavaDoc e)
1652        {
1653        }
1654
1655        public void mousePressed(MouseEvent JavaDoc e)
1656        {
1657        }
1658
1659        public void mouseReleased(MouseEvent JavaDoc e)
1660        {
1661        }
1662    }
1663
1664
1665    protected String JavaDoc getHyperlinkTooltip(JRPrintHyperlink hyperlink)
1666    {
1667        String JavaDoc toolTip;
1668        toolTip = hyperlink.getHyperlinkTooltip();
1669        if (toolTip == null)
1670        {
1671            toolTip = getFallbackTooltip(hyperlink);
1672        }
1673        return toolTip;
1674    }
1675
1676    
1677    protected String JavaDoc getFallbackTooltip(JRPrintHyperlink hyperlink)
1678    {
1679        String JavaDoc toolTip = null;
1680        switch(hyperlink.getHyperlinkType())
1681        {
1682            case JRHyperlink.HYPERLINK_TYPE_REFERENCE :
1683            {
1684                toolTip = hyperlink.getHyperlinkReference();
1685                break;
1686            }
1687            case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR :
1688            {
1689                if (hyperlink.getHyperlinkAnchor() != null)
1690                {
1691                    toolTip = "#" + hyperlink.getHyperlinkAnchor();
1692                }
1693                break;
1694            }
1695            case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE :
1696            {
1697                if (hyperlink.getHyperlinkPage() != null)
1698                {
1699                    toolTip = "#page " + hyperlink.getHyperlinkPage();
1700                }
1701                break;
1702            }
1703            case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR :
1704            {
1705                toolTip = "";
1706                if (hyperlink.getHyperlinkReference() != null)
1707                {
1708                    toolTip = toolTip + hyperlink.getHyperlinkReference();
1709                }
1710                if (hyperlink.getHyperlinkAnchor() != null)
1711                {
1712                    toolTip = toolTip + "#" + hyperlink.getHyperlinkAnchor();
1713                }
1714                break;
1715            }
1716            case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE :
1717            {
1718                toolTip = "";
1719                if (hyperlink.getHyperlinkReference() != null)
1720                {
1721                    toolTip = toolTip + hyperlink.getHyperlinkReference();
1722                }
1723                if (hyperlink.getHyperlinkPage() != null)
1724                {
1725                    toolTip = toolTip + "#page " + hyperlink.getHyperlinkPage();
1726                }
1727                break;
1728            }
1729            default :
1730            {
1731                break;
1732            }
1733        }
1734        return toolTip;
1735    }
1736
1737
1738    /**
1739    */

1740    private void emptyContainer(Container JavaDoc container)
1741    {
1742        Component JavaDoc[] components = container.getComponents();
1743
1744        if (components != null)
1745        {
1746            for(int i = 0; i < components.length; i++)
1747            {
1748                if (components[i] instanceof Container JavaDoc)
1749                {
1750                    emptyContainer((Container JavaDoc)components[i]);
1751                }
1752            }
1753        }
1754
1755        components = null;
1756        container.removeAll();
1757        container = null;
1758    }
1759
1760
1761    /**
1762    */

1763    private float getZoomRatio()
1764    {
1765        float newZoom = zoom;
1766        
1767        try
1768        {
1769            newZoom =
1770                zoomDecimalFormat.parse(
1771                    String.valueOf(cmbZoom.getEditor().getItem())
1772                    ).floatValue() / 100f;
1773        }
1774        catch(ParseException JavaDoc e)
1775        {
1776        }
1777
1778        return newZoom;
1779    }
1780
1781
1782    /**
1783    */

1784    public void setZoomRatio(float newZoom)
1785    {
1786        if (newZoom > 0)
1787        {
1788            cmbZoom.getEditor().setItem(
1789                zoomDecimalFormat.format(newZoom * 100) + "%"
1790                );
1791            
1792            if (zoom != newZoom)
1793            {
1794                zoom = newZoom;
1795                realZoom = zoom * screenResolution / REPORT_RESOLUTION;
1796
1797                refreshPage();
1798            }
1799        }
1800    }
1801
1802
1803    /**
1804    */

1805    private void setRealZoomRatio(float newZoom)
1806    {
1807        if (newZoom > 0 && realZoom != newZoom)
1808        {
1809            zoom = newZoom * REPORT_RESOLUTION / screenResolution;
1810            realZoom = newZoom;
1811            
1812            cmbZoom.getEditor().setItem(
1813                zoomDecimalFormat.format(zoom * 100) + "%"
1814                );
1815            
1816            refreshPage();
1817        }
1818    }
1819
1820
1821    /**
1822     *
1823     */

1824    public void setFitWidthZoomRatio()
1825    {
1826        setRealZoomRatio(((float)pnlInScroll.getVisibleRect().getWidth() - 20f) / jasperPrint.getPageWidth());
1827
1828    }
1829
1830    public void setFitPageZoomRatio()
1831    {
1832        setRealZoomRatio(((float)pnlInScroll.getVisibleRect().getHeight() - 20f) / jasperPrint.getPageHeight());
1833    }
1834
1835
1836    /**
1837    */

1838    protected void paintPage(Graphics2D JavaDoc grx)
1839    {
1840        try
1841        {
1842            if (exporter == null)
1843            {
1844                exporter = new JRGraphics2DExporter();
1845            }
1846            else
1847            {
1848                exporter.reset();
1849            }
1850            
1851            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
1852            exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, grx);
1853            exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer JavaDoc(pageIndex));
1854            exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float JavaDoc(realZoom));
1855            exporter.setParameter(JRExporterParameter.OFFSET_X, new Integer JavaDoc(1)); //lblPage border
1856
exporter.setParameter(JRExporterParameter.OFFSET_Y, new Integer JavaDoc(1));
1857            exporter.exportReport();
1858        }
1859        catch(Exception JavaDoc e)
1860        {
1861            e.printStackTrace();
1862            JOptionPane.showMessageDialog(this, getBundleString("error.displaying"));
1863        }
1864
1865    }
1866
1867    /**
1868     *
1869    */

1870    private void fitPage(){
1871        float heightRatio = ((float)pnlInScroll.getVisibleRect().getHeight() - 20f) / jasperPrint.getPageHeight();
1872        float widthRatio = ((float)pnlInScroll.getVisibleRect().getWidth() - 20f) / jasperPrint.getPageWidth();
1873        setRealZoomRatio(heightRatio < widthRatio ? heightRatio : widthRatio);
1874    }
1875    
1876    /**
1877    */

1878    class PageRenderer extends JLabel JavaDoc
1879    {
1880        private boolean renderImage;
1881        JRViewer viewer = null;
1882        
1883        public PageRenderer(JRViewer viewer)
1884        {
1885            this.viewer = viewer;
1886        }
1887        
1888        public void paintComponent(Graphics JavaDoc g)
1889        {
1890            if (isRenderImage())
1891            {
1892                super.paintComponent(g);
1893            }
1894            else
1895            {
1896                viewer.paintPage((Graphics2D JavaDoc)g.create());
1897            }
1898        }
1899        
1900        public boolean isRenderImage()
1901        {
1902            return renderImage;
1903        }
1904        
1905        public void setRenderImage(boolean renderImage)
1906        {
1907            this.renderImage = renderImage;
1908        }
1909    }
1910    
1911
1912    // Variables declaration - do not modify//GEN-BEGIN:variables
1913
protected javax.swing.JToggleButton JavaDoc btnActualSize;
1914    protected javax.swing.JButton JavaDoc btnFirst;
1915    protected javax.swing.JToggleButton JavaDoc btnFitPage;
1916    protected javax.swing.JToggleButton JavaDoc btnFitWidth;
1917    protected javax.swing.JButton JavaDoc btnLast;
1918    protected javax.swing.JButton JavaDoc btnNext;
1919    protected javax.swing.JButton JavaDoc btnPrevious;
1920    protected javax.swing.JButton JavaDoc btnPrint;
1921    protected javax.swing.JButton JavaDoc btnReload;
1922    protected javax.swing.JButton JavaDoc btnSave;
1923    protected javax.swing.JButton JavaDoc btnZoomIn;
1924    protected javax.swing.JButton JavaDoc btnZoomOut;
1925    protected javax.swing.JComboBox JavaDoc cmbZoom;
1926    private javax.swing.JLabel JavaDoc jLabel1;
1927    private javax.swing.JPanel JavaDoc jPanel4;
1928    private javax.swing.JPanel JavaDoc jPanel5;
1929    private javax.swing.JPanel JavaDoc jPanel6;
1930    private javax.swing.JPanel JavaDoc jPanel7;
1931    private javax.swing.JPanel JavaDoc jPanel8;
1932    private javax.swing.JPanel JavaDoc jPanel9;
1933    private PageRenderer lblPage;
1934    protected javax.swing.JLabel JavaDoc lblStatus;
1935    private javax.swing.JPanel JavaDoc pnlInScroll;
1936    private javax.swing.JPanel JavaDoc pnlLinks;
1937    private javax.swing.JPanel JavaDoc pnlMain;
1938    private javax.swing.JPanel JavaDoc pnlPage;
1939    protected javax.swing.JPanel JavaDoc pnlSep01;
1940    protected javax.swing.JPanel JavaDoc pnlSep02;
1941    protected javax.swing.JPanel JavaDoc pnlSep03;
1942    protected javax.swing.JPanel JavaDoc pnlStatus;
1943    private javax.swing.JScrollPane JavaDoc scrollPane;
1944    protected javax.swing.JPanel JavaDoc tlbToolBar;
1945    protected javax.swing.JTextField JavaDoc txtGoTo;
1946    // End of variables declaration//GEN-END:variables
1947

1948}
1949
Popular Tags