KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ViewerFrame


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 import net.sf.jasperreports.engine.*;
29 import net.sf.jasperreports.view.*;
30
31 import java.awt.BorderLayout JavaDoc;
32 import java.applet.AppletContext JavaDoc;
33 import java.net.*;
34 import javax.swing.JOptionPane JavaDoc;
35
36
37 /**
38  * @author Teodor Danciu (teodord@users.sourceforge.net)
39  * @version $Id: ViewerFrame.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
40  */

41 public class ViewerFrame extends javax.swing.JFrame JavaDoc implements JRHyperlinkListener
42 {
43
44
45     /**
46      *
47      */

48     private AppletContext JavaDoc appletContext = null;
49
50
51     /**
52      *
53      */

54     public ViewerFrame(AppletContext JavaDoc appletContext, JasperPrint jasperPrint) throws JRException
55     {
56         initComponents();
57
58         this.appletContext = appletContext;
59         
60         JRViewerPlus viewer = new JRViewerPlus(jasperPrint);
61         viewer.addHyperlinkListener(this);
62         this.pnlMain.add(viewer, BorderLayout.CENTER);
63     }
64
65     
66     /**
67      *
68      */

69     public void gotoHyperlink(JRPrintHyperlink hyperlink)
70     {
71         switch(hyperlink.getHyperlinkType())
72         {
73             case JRHyperlink.HYPERLINK_TYPE_REFERENCE :
74             {
75                 try
76                 {
77                     this.appletContext.showDocument(new URL(hyperlink.getHyperlinkReference()), "_blank");
78                 }
79                 catch (MalformedURLException e)
80                 {
81                     JOptionPane.showMessageDialog(this, e.getMessage());
82                 }
83                 break;
84             }
85             case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR :
86             case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE :
87             {
88                 break;
89             }
90             case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR :
91             case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE :
92             {
93                 JOptionPane.showMessageDialog(this, "Implement your own JRHyperlinkListener to manage this type of event.");
94                 break;
95             }
96             case JRHyperlink.HYPERLINK_TYPE_NONE :
97             default :
98             {
99                 break;
100             }
101         }
102     }
103
104
105     /** This method is called from within the constructor to
106      * initialize the form.
107      * WARNING: Do NOT modify this code. The content of this method is
108      * always regenerated by the Form Editor.
109      */

110     private void initComponents() {//GEN-BEGIN:initComponents
111
pnlMain = new javax.swing.JPanel JavaDoc();
112
113         setTitle("JasperViewer");
114         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
115         pnlMain.setLayout(new java.awt.BorderLayout JavaDoc());
116
117         getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER);
118
119         pack();
120         java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
121         setSize(new java.awt.Dimension JavaDoc(400, 300));
122         setLocation((screenSize.width-400)/2,(screenSize.height-300)/2);
123     }//GEN-END:initComponents
124

125
126     // Variables declaration - do not modify//GEN-BEGIN:variables
127
private javax.swing.JPanel JavaDoc pnlMain;
128     // End of variables declaration//GEN-END:variables
129

130 }
131
Popular Tags