01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package org.pentaho.plugin.jfreereport.outputs;
14:
15: import java.awt.Dialog;
16: import java.awt.Frame;
17:
18: import org.jfree.base.config.ModifiableConfiguration;
19: import org.jfree.report.JFreeReport;
20: import org.jfree.report.modules.gui.base.PreviewDialog;
21: import org.jfree.report.modules.gui.base.ReportController;
22: import org.jfree.ui.RefineryUtilities;
23:
24: /**
25: * Creation-Date: 07.07.2006, 14:06:43
26: *
27: * @author Thomas Morgner
28: */
29: public class JFreeReportPreviewSwingComponent extends
30: AbstractGenerateContentComponent {
31: private static final long serialVersionUID = -8158403113060631980L;
32:
33: private static final String PROGRESS_DIALOG_ENABLED_KEY = "org.jfree.report.modules.gui.base.ProgressDialogEnabled";//$NON-NLS-1$
34:
35: private static final String PROGRESS_BAR_ENABLED_KEY = "org.jfree.report.modules.gui.base.ProgressBarEnabled";//$NON-NLS-1$
36:
37: public JFreeReportPreviewSwingComponent() {
38: }
39:
40: protected boolean performExport(final JFreeReport report) {
41: final ModifiableConfiguration reportConfiguration = report
42: .getReportConfiguration();
43:
44: final boolean progressBar = getInputBooleanValue(
45: REPORTSWING_PROGRESSBAR,
46: "true" .equals(reportConfiguration.getConfigProperty(PROGRESS_BAR_ENABLED_KEY)));//$NON-NLS-1$
47: final boolean progressDialog = getInputBooleanValue(
48: REPORTSWING_PROGRESSDIALOG,
49: "true" .equals(reportConfiguration.getConfigProperty(PROGRESS_DIALOG_ENABLED_KEY)));//$NON-NLS-1$
50: reportConfiguration.setConfigProperty(
51: PROGRESS_DIALOG_ENABLED_KEY, String
52: .valueOf(progressDialog));
53: reportConfiguration.setConfigProperty(PROGRESS_BAR_ENABLED_KEY,
54: String.valueOf(progressBar));
55:
56: final PreviewDialog dialog = createDialog(report);
57: final ReportController reportController = getReportController();
58: if (reportController != null) {
59: dialog.setReportController(reportController);
60: }
61: dialog.pack();
62: if (dialog.getParent() != null) {
63: RefineryUtilities.centerDialogInParent(dialog);
64: } else {
65: RefineryUtilities.centerFrameOnScreen(dialog);
66: }
67:
68: dialog.setVisible(true);
69: return true;
70: }
71:
72: private ReportController getReportController() {
73: if (isDefinedInput(REPORTSWING_REPORTCONTROLLER)) {
74: final Object controller = getInputValue(REPORTSWING_REPORTCONTROLLER);
75: if (controller instanceof ReportController) {
76: return (ReportController) controller;
77: }
78: }
79: return null;
80: }
81:
82: private PreviewDialog createDialog(final JFreeReport report) {
83: final boolean modal = getInputBooleanValue(REPORTSWING_MODAL,
84: true);
85:
86: if (isDefinedInput(REPORTSWING_PARENTDIALOG)) {
87: final Object parent = getInputValue(REPORTSWING_PARENTDIALOG);
88: if (parent instanceof Dialog) {
89: return new PreviewDialog(report, (Dialog) parent, modal);
90: } else if (parent instanceof Frame) {
91: return new PreviewDialog(report, (Frame) parent, modal);
92: }
93: }
94:
95: final PreviewDialog previewDialog = new PreviewDialog(report);
96: previewDialog.setModal(modal);
97: return previewDialog;
98: }
99: }
|