01: //** Copyright Statement ***************************************************
02: //The Salmon Open Framework for Internet Applications (SOFIA)
03: // Copyright (C) 1999 - 2003, Salmon LLC
04: //
05: // This program is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU General Public License version 2
07: // as published by the Free Software Foundation;
08: //
09: // This program is distributed in the hope that it will be useful,
10: // but WITHOUT ANY WARRANTY; without even the implied warranty of
11: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: // GNU General Public License for more details.
13: //
14: // You should have received a copy of the GNU General Public License
15: // along with this program; if not, write to the Free Software
16: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: //
18: // For more information please visit http://www.salmonllc.com
19: //** End Copyright Statement ***************************************************
20:
21: package com.salmonllc.jasperReports;
22:
23: import java.net.MalformedURLException;
24: import java.net.URL;
25:
26: import javax.swing.JApplet;
27:
28: /**
29: * This is the report viewer implemented as an applet. Various applet parameters specified in ReportParameterConstants can be used to customize the viewers behavior.
30: */
31: public class ReportApplet extends JApplet implements
32: ReportParameterConstants {
33: private SJasperViewToolBar _toolbar;
34:
35: private class AppletURLOpener implements URLOpener {
36: public void openURL(String url) throws MalformedURLException {
37: openURL(url, null);
38: }
39:
40: public void openURL(String url, String target)
41: throws MalformedURLException {
42: url = SJasperViewToolBar.computeRelativeURL(_codeBase, url);
43: if (target != null)
44: getAppletContext().showDocument(new URL(url), target);
45: else
46: getAppletContext().showDocument(new URL(url));
47: }
48: }
49:
50: public class AppletMessageDisplay implements MessageDisplayer {
51: public void displayMessage(String message) {
52: getAppletContext().showStatus(message);
53: }
54: }
55:
56: public String _codeBase;
57:
58: public void init() {
59: super .init();
60: try {
61: String codeBase = getCodeBase().toString();
62:
63: //this is only for running in the IDE
64: if (codeBase.startsWith("file:"))
65: codeBase = getParameter(CODE_BASE);
66: _codeBase = codeBase;
67: String model = getParameter(MODEL_CLASS);
68: String selectionCriteria = getParameter(SELECTION_CRITERIA);
69: String reportURL = getParameter(REPORT_URL);
70: String sessionID = getParameter(SESSION_ID);
71: String imageURL = SJasperViewToolBar.computeRelativeURL(
72: codeBase, getParameter(IMAGE_BASE_URL));
73:
74: _toolbar = SJasperViewToolBar.buildGUI(codeBase, model,
75: selectionCriteria, reportURL, imageURL, sessionID,
76: getContentPane(), true, false,
77: new AppletURLOpener(), new AppletMessageDisplay());
78: } catch (Exception e) {
79: e.printStackTrace();
80: }
81: }
82:
83: /**
84: * @return the toolbar used by the application
85: */
86: public SJasperViewToolBar getToolbar() {
87: return _toolbar;
88: }
89:
90: }
|