001/*
002 * Copyright (c) 2003-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2013-04-08 22:48:40 +0000 (Mon, 08 Apr 2013) $' 
007 * '$Revision: 31875 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.kepler.reporting.rio;
031
032import java.awt.Color;
033import java.awt.Component;
034import java.awt.GridBagConstraints;
035import java.awt.GridBagLayout;
036import java.awt.Insets;
037import java.io.File;
038import java.util.List;
039
040import javax.swing.JLabel;
041import javax.swing.JPanel;
042import javax.swing.JTextArea;
043
044import org.jpedal.PdfDecoder;
045import org.kepler.reporting.rio.gui.ImageComponent;
046
047/**
048 * @deprecated please use the ReportConverter that uses FOP-XSL for a more robust solution
049 * @author leinfelder
050 *
051 * Multivalent code is commented out since the Multivalent jar was removed
052 * since it appears to be GPL. http://multivalent.sourceforge.net/license.html
053 *
054 */
055public class RIORenderer {
056        
057        public static enum PDFViewer {
058                JPEDAL,
059                //MULTIVALENT
060        }
061        
062        public static String htmlRIO(ReportInstance rio) {
063                return null;
064        }
065        
066        public static File pdfRIO(ReportInstance rio) {
067                return null;
068        }
069        
070        public static JPanel jpanelRIO(ReportInstance rio) {
071                
072                JPanel panel = new JPanel();
073                panel.setBackground(new Color(255,255,255));
074                panel.setLayout(new GridBagLayout());
075                GridBagConstraints leftColumn = new GridBagConstraints();
076                GridBagConstraints centerColumn = new GridBagConstraints();
077                GridBagConstraints rightColumn = new GridBagConstraints();
078
079                leftColumn.gridx = 0;
080                centerColumn.gridx = 1;
081                rightColumn.gridx = 2;
082                
083                leftColumn.gridy = 0;
084                centerColumn.gridy = 0;
085                rightColumn.gridy = 0;
086                
087                leftColumn.anchor = GridBagConstraints.WEST;
088                centerColumn.anchor = GridBagConstraints.WEST;
089                rightColumn.anchor = GridBagConstraints.WEST;
090                
091                Insets inset = new Insets(10, 10, 10, 10);
092                leftColumn.insets = inset;
093                centerColumn.insets = inset;
094                rightColumn.insets = inset;
095                
096                //items
097                List<Item> items = rio.getSections().get(0).getColumns().get(0).getItems();
098                for (int i = 0; i < items.size(); i++) {
099                        //labels
100                        List<ItemLabel> labels = items.get(i).getLabels();
101                        for (int k = 0; k < labels.size(); k++) {
102                                Component label = new JLabel(labels.get(k).getValue());
103                                panel.add(label, leftColumn);
104                        }
105                        //values
106                        List<ItemValue> values = items.get(i).getValues();
107                        for (int j = 0; j < values.size(); j++) {
108                                //value
109                                Component value = getComponent(values.get(j).getValue());
110                                panel.add(value, centerColumn);
111                                //next row
112                                leftColumn.gridy = leftColumn.gridy + 1;
113                                centerColumn.gridy = centerColumn.gridy + 1;
114                                rightColumn.gridy = rightColumn.gridy + 1;
115                        }
116                        
117                }
118                
119        return panel;
120        }
121        
122        public static Component getComponent(Object value) {
123                Component component = null;
124                
125                if (value instanceof File) {
126                        String path = ((File) value).getPath();
127                        if ( path.endsWith("pdf")) {
128                                
129                                switch(PDFViewer.JPEDAL) {
130                                case JPEDAL: //jpedal
131                                        
132                                        PdfDecoder decoder = new PdfDecoder();
133                                        try {
134                                                decoder.openPdfFile(path);
135                                                decoder.decodePage(1);
136                                                decoder.setPageParameters(1, 1);
137                                        } catch (Exception e) {
138                                                // TODO Auto-generated catch block
139                                                e.printStackTrace();
140                                        }
141                                        component = decoder;
142                                        break;
143                                        /*
144                                case MULTIVALENT:
145                                        try {
146                                                Browser browser = Multivalent.getInstance().getBrowser("name", "Basic", false);
147                                                browser.eventq(multivalent.Document.MSG_OPEN, ((File)value).toURI());
148                                                Document document = browser.getCurDocument();
149                                                // Never show Multivalent's own scrollbars:
150                                                document.setScrollbarShowPolicy(multivalent.gui.VScrollbar.SHOW_NEVER);
151                                                
152                                                //Node pdfNode = document.getLastChild(); 
153                                                //browser.setSize(pdfNode.bbox.width, pdfNode.bbox.height);
154                                                //browser.validate();
155
156                                                component = browser;
157
158                                        } catch (Exception e) {
159                                                // TODO Auto-generated catch block
160                                                e.printStackTrace();
161                                        }
162                                        break;
163                                        */
164                                }
165                        }
166                        else {
167                                component = new ImageComponent(path);
168                
169                        }
170                }
171                else {
172                        component = new JTextArea(value.toString());
173                }
174                
175                return component;
176        }
177        
178}