001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * PreviewApplet.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.base;
030:
031: import java.awt.BorderLayout;
032: import java.awt.event.ComponentAdapter;
033: import java.awt.event.ComponentEvent;
034: import java.beans.PropertyChangeEvent;
035: import java.beans.PropertyChangeListener;
036: import javax.swing.BoxLayout;
037: import javax.swing.JApplet;
038: import javax.swing.JComponent;
039: import javax.swing.JLabel;
040: import javax.swing.JMenu;
041: import javax.swing.JMenuBar;
042: import javax.swing.JPanel;
043:
044: import org.jfree.report.JFreeReport;
045: import org.jfree.report.modules.gui.common.IconTheme;
046: import org.jfree.report.modules.gui.commonswing.JStatusBar;
047: import org.jfree.report.modules.gui.commonswing.ReportProgressBar;
048: import org.jfree.report.modules.gui.commonswing.RequestFocusHandler;
049:
050: /**
051: * Creation-Date: 11.11.2006, 19:35:22
052: *
053: * @author Thomas Morgner
054: */
055: public class PreviewApplet extends JApplet {
056: private class PreviewPanePropertyChangeHandler implements
057: PropertyChangeListener {
058:
059: protected PreviewPanePropertyChangeHandler() {
060: }
061:
062: /**
063: * This method gets called when a bound property is changed.
064: *
065: * @param evt A PropertyChangeEvent object describing the event source and
066: * the property that has changed.
067: */
068:
069: public void propertyChange(final PropertyChangeEvent evt) {
070: final String propertyName = evt.getPropertyName();
071: if (PreviewPane.MENU_PROPERTY.equals(propertyName)) {
072: // Update the menu
073: final JMenu[] menus = previewPane.getMenu();
074: if (menus != null && menus.length > 0) {
075: final JMenuBar menuBar = new JMenuBar();
076: for (int i = 0; i < menus.length; i++) {
077: final JMenu menu = menus[i];
078: menuBar.add(menu);
079: }
080: setJMenuBar(menuBar);
081: } else {
082: setJMenuBar(null);
083: }
084: return;
085: }
086:
087: if (PreviewPane.STATUS_TEXT_PROPERTY.equals(propertyName)
088: || PreviewPane.STATUS_TYPE_PROPERTY
089: .equals(propertyName)) {
090: statusBar.setStatus(previewPane.getStatusType(),
091: previewPane.getStatusText());
092: return;
093: }
094:
095: if (PreviewPane.ICON_THEME_PROPERTY.equals(propertyName)) {
096: statusBar.setIconTheme(previewPane.getIconTheme());
097: return;
098: }
099:
100: if (PreviewPane.PAGINATING_PROPERTY.equals(propertyName)) {
101: if (Boolean.TRUE.equals(evt.getNewValue())) {
102: progressBar.setOnlyPagination(true);
103: progressBar.setVisible(true);
104: pageLabel.setVisible(false);
105: } else {
106: progressBar.setOnlyPagination(false);
107: progressBar.setVisible(false);
108: pageLabel.setVisible(true);
109: }
110: progressBar.revalidate();
111: return;
112: }
113:
114: if (PreviewPane.PAGE_NUMBER_PROPERTY.equals(propertyName)
115: || PreviewPane.NUMBER_OF_PAGES_PROPERTY
116: .equals(propertyName)) {
117: pageLabel.setText(previewPane.getPageNumber()
118: + "/" + previewPane.getNumberOfPages()); //$NON-NLS-1$
119: }
120:
121: }
122: }
123:
124: private static class TriggerPaginationListener extends
125: ComponentAdapter {
126: private PreviewPane pane;
127:
128: public TriggerPaginationListener(final PreviewPane pane) {
129: this .pane = pane;
130: }
131:
132: /**
133: * Invoked when the component has been made visible.
134: */
135: public void componentShown(final ComponentEvent e) {
136: if (pane.isDeferredRepagination()) {
137: pane.startPagination();
138: }
139: }
140: }
141:
142: private PreviewPane previewPane;
143:
144: private JStatusBar statusBar;
145:
146: private ReportProgressBar progressBar;
147:
148: private JLabel pageLabel;
149:
150: public PreviewApplet() {
151: }
152:
153: public void init() {
154: addComponentListener(new RequestFocusHandler());
155:
156: previewPane = new PreviewPane();
157: previewPane.setDeferredRepagination(true);
158: addComponentListener(new TriggerPaginationListener(previewPane));
159: statusBar = new JStatusBar(previewPane.getIconTheme());
160:
161: progressBar = new ReportProgressBar();
162: progressBar.setVisible(false);
163: previewPane.addReportProgressListener(progressBar);
164:
165: pageLabel = new JLabel();
166: previewPane
167: .addPropertyChangeListener(new PreviewPanePropertyChangeHandler());
168:
169: final JComponent extensionArea = statusBar.getExtensionArea();
170: extensionArea.setLayout(new BoxLayout(extensionArea,
171: BoxLayout.X_AXIS));
172: extensionArea.add(progressBar);
173: extensionArea.add(pageLabel);
174:
175: final JComponent contentPane = new JPanel();
176: contentPane.setLayout(new BorderLayout());
177: contentPane.add(previewPane, BorderLayout.CENTER);
178: contentPane.add(statusBar, BorderLayout.SOUTH);
179: setContentPane(contentPane);
180:
181: updateMenu(previewPane.getMenu());
182: statusBar.setIconTheme(previewPane.getIconTheme());
183: statusBar.setStatus(previewPane.getStatusType(), previewPane
184: .getStatusText());
185: }
186:
187: private void updateMenu(final JMenu[] menus) {
188: if (menus != null && menus.length > 0) {
189: final JMenuBar menuBar = new JMenuBar();
190: for (int i = 0; i < menus.length; i++) {
191: final JMenu menu = menus[i];
192: menuBar.add(menu);
193: }
194: setJMenuBar(menuBar);
195: } else {
196: setJMenuBar(null);
197: }
198: }
199:
200: public ReportController getReportController() {
201: return previewPane.getReportController();
202: }
203:
204: public void setReportController(
205: final ReportController reportController) {
206: previewPane.setReportController(reportController);
207: }
208:
209: public IconTheme getIconTheme() {
210: return previewPane.getIconTheme();
211: }
212:
213: public void setIconTheme(final IconTheme theme) {
214: previewPane.setIconTheme(theme);
215: }
216:
217: public JFreeReport getReportJob() {
218: return previewPane.getReportJob();
219: }
220:
221: public void setReportJob(final JFreeReport reportJob) {
222: previewPane.setReportJob(reportJob);
223: }
224:
225: protected PreviewPane getPreviewPane() {
226: return previewPane;
227: }
228:
229: public boolean isToolbarFloatable() {
230: return previewPane.isToolbarFloatable();
231: }
232:
233: public void setToolbarFloatable(final boolean toolbarFloatable) {
234: previewPane.setToolbarFloatable(toolbarFloatable);
235: }
236:
237: public double getZoom() {
238: return previewPane.getZoom();
239: }
240:
241: public void setZoom(final double zoom) {
242: previewPane.setZoom(zoom);
243: }
244: }
|