001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2003, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020:
021: package com.salmonllc.jasperReports;
022:
023: import java.awt.Dimension;
024: import java.awt.Rectangle;
025: import java.net.MalformedURLException;
026: import java.net.URL;
027:
028: import javax.jnlp.BasicService;
029: import javax.jnlp.ServiceManager;
030: import javax.jnlp.UnavailableServiceException;
031: import javax.swing.JFrame;
032:
033: /**
034: * This is a Java Web Start application implementation of the the report viewer. This application can be customized by setting various arguments found in ReportParameterConstants. The arguments should be specified as "argumentName=value" on the program start line or in the <argument> tag of a jnlp file.
035: * Window>Preferences>Java>Code Generation>Code and Comments
036: */
037: public class ReportApplication implements ReportParameterConstants {
038:
039: public static String _baseURL;
040: public static SJasperViewToolBar _toolbar;
041:
042: public static class WebStartURLOpener implements URLOpener {
043: public void openURL(String url) throws MalformedURLException {
044: try {
045: url = SJasperViewToolBar.computeRelativeURL(_baseURL,
046: url);
047: BasicService bs = (BasicService) ServiceManager
048: .lookup("javax.jnlp.BasicService");
049: bs.showDocument(new URL(url));
050: } catch (UnavailableServiceException ue) {
051: ue.printStackTrace();
052: }
053: }
054:
055: public void openURL(String url, String target)
056: throws MalformedURLException {
057: openURL(url);
058: }
059: }
060:
061: public static String getParameter(String[] args, String parm) {
062: String search = parm + "=";
063: for (int i = 0; i < args.length; i++) {
064: if (args[i].startsWith(search))
065: return args[i].substring(search.length());
066: }
067: return null;
068: }
069:
070: public static void main(String[] args) {
071: try {
072: String model = getParameter(args, MODEL_CLASS);
073: String selectionCriteria = getParameter(args,
074: SELECTION_CRITERIA);
075: String reportURL = getParameter(args, REPORT_URL);
076: String sessionID = getParameter(args, SESSION_ID);
077: String serverURL = getParameter(args, SERVER_URL);
078: String imageURL = SJasperViewToolBar.computeRelativeURL(
079: serverURL, getParameter(args, IMAGE_BASE_URL));
080:
081: int width = 600;
082: try {
083: width = Integer.parseInt(getParameter(args, WIDTH));
084: } catch (Exception ex) {
085: }
086: int height = 600;
087: try {
088: height = Integer.parseInt(getParameter(args, HEIGHT));
089: } catch (Exception ex) {
090: }
091:
092: Dimension d = java.awt.Toolkit.getDefaultToolkit()
093: .getScreenSize();
094: int x = (d.width - width) / 2;
095: try {
096: x = Integer.parseInt(getParameter(args, X));
097: } catch (Exception ex) {
098: }
099: int y = (d.height - height) / 2;
100: try {
101: y = Integer.parseInt(getParameter(args, Y));
102: } catch (Exception ex) {
103: }
104:
105: JFrame f = new JFrame("Report Viewer");
106: f.setBounds(new Rectangle(x, y, width, height));
107:
108: f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
109:
110: _toolbar = SJasperViewToolBar.buildGUI(serverURL, model,
111: selectionCriteria, reportURL, imageURL, sessionID,
112: f.getContentPane(), true, true,
113: new WebStartURLOpener(), null);
114: _baseURL = _toolbar.getServerURL();
115: f.setVisible(true);
116:
117: } catch (Exception ex) {
118: ex.printStackTrace();
119: }
120:
121: }
122:
123: /**
124: * @return the toolbar used by the application
125: */
126: public static SJasperViewToolBar getToolbar() {
127: return _toolbar;
128: }
129:
130: }
|