1 28 import net.sf.jasperreports.engine.*; 29 import net.sf.jasperreports.view.*; 30 31 import java.awt.BorderLayout ; 32 import java.applet.AppletContext ; 33 import java.net.*; 34 import javax.swing.JOptionPane ; 35 36 37 41 public class ViewerFrame extends javax.swing.JFrame implements JRHyperlinkListener 42 { 43 44 45 48 private AppletContext appletContext = null; 49 50 51 54 public ViewerFrame(AppletContext 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 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 110 private void initComponents() { pnlMain = new javax.swing.JPanel (); 112 113 setTitle("JasperViewer"); 114 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 115 pnlMain.setLayout(new java.awt.BorderLayout ()); 116 117 getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER); 118 119 pack(); 120 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 121 setSize(new java.awt.Dimension (400, 300)); 122 setLocation((screenSize.width-400)/2,(screenSize.height-300)/2); 123 } 125 126 private javax.swing.JPanel pnlMain; 128 130 } 131 | Popular Tags |