001: /**
002: * ========================================
003: * JFreeReport : a free Java report library
004: * ========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2000-2007, by Object Refinery Limited, 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: * $Id: PreviewDialog.java 3525 2007-10-16 11:43:48Z tmorgner $
027: * ------------
028: * (C) Copyright 2000-2005, by Object Refinery Limited.
029: * (C) Copyright 2005-2007, by Pentaho Corporation.
030: */package org.jfree.report.modules.gui.swing.preview;
031:
032: import java.awt.BorderLayout;
033: import java.awt.Dialog;
034: import java.awt.Frame;
035: import java.beans.PropertyChangeEvent;
036: import java.beans.PropertyChangeListener;
037: import javax.swing.BoxLayout;
038: import javax.swing.JComponent;
039: import javax.swing.JDialog;
040: import javax.swing.JLabel;
041: import javax.swing.JMenu;
042: import javax.swing.JMenuBar;
043: import javax.swing.JPanel;
044:
045: import org.jfree.report.flow.ReportJob;
046: import org.jfree.report.modules.gui.common.IconTheme;
047: import org.jfree.report.modules.gui.swing.common.JStatusBar;
048: import org.jfree.report.modules.gui.swing.common.ReportProgressBar;
049:
050: /**
051: * Creation-Date: 11.11.2006, 19:35:16
052: *
053: * @author Thomas Morgner
054: */
055: public class PreviewDialog extends JDialog {
056: private class PreviewPanePropertyChangeHandler implements
057: PropertyChangeListener {
058: private PreviewPanePropertyChangeHandler() {
059: }
060:
061: /**
062: * This method gets called when a bound property is changed.
063: *
064: * @param evt A PropertyChangeEvent object describing the event source and
065: * the property that has changed.
066: */
067:
068: public void propertyChange(final PropertyChangeEvent evt) {
069: final String propertyName = evt.getPropertyName();
070: if (PreviewPane.MENU_PROPERTY.equals(propertyName)) {
071: // Update the menu
072: final JMenu[] menus = previewPane.getMenu();
073: if (menus != null && menus.length > 0) {
074: final JMenuBar menuBar = new JMenuBar();
075: for (int i = 0; i < menus.length; i++) {
076: final JMenu menu = menus[i];
077: menuBar.add(menu);
078: }
079: setJMenuBar(menuBar);
080: } else {
081: setJMenuBar(null);
082: }
083: return;
084: }
085:
086: if (PreviewPane.TITLE_PROPERTY.equals(propertyName)) {
087: setTitle(previewPane.getTitle());
088: return;
089: }
090:
091: if (PreviewPane.STATUS_TEXT_PROPERTY.equals(propertyName)
092: || PreviewPane.STATUS_TYPE_PROPERTY
093: .equals(propertyName)) {
094: statusBar.setStatus(previewPane.getStatusType(),
095: previewPane.getStatusText());
096: return;
097: }
098:
099: if (PreviewPane.ICON_THEME_PROPERTY.equals(propertyName)) {
100: statusBar.setIconTheme(previewPane.getIconTheme());
101: return;
102: }
103:
104: if (PreviewPane.PAGINATING_PROPERTY.equals(propertyName)) {
105: if (Boolean.TRUE.equals(evt.getNewValue())) {
106: progressBar.setVisible(true);
107: pageLabel.setVisible(false);
108: statusBar.setStatus(JStatusBar.TYPE_INFORMATION,
109: "Paginating ...");
110: } else {
111: progressBar.setVisible(false);
112: pageLabel.setVisible(true);
113: statusBar.setStatus(JStatusBar.TYPE_NONE, "");
114: }
115: progressBar.revalidate();
116: return;
117: }
118:
119: if (PreviewPane.PAGE_NUMBER_PROPERTY.equals(propertyName)
120: || PreviewPane.NUMBER_OF_PAGES_PROPERTY
121: .equals(propertyName)) {
122: pageLabel.setText(previewPane.getPageNumber() + "/"
123: + previewPane.getNumberOfPages());
124: return;
125: }
126:
127: if (PreviewPane.CLOSED_PROPERTY.equals(propertyName)) {
128: if (previewPane.isClosed()) {
129: setVisible(false);
130: dispose();
131: } else {
132: setVisible(true);
133: }
134: }
135: }
136: }
137:
138: private PreviewPane previewPane;
139: private JStatusBar statusBar;
140: private ReportProgressBar progressBar;
141: private JLabel pageLabel;
142:
143: /**
144: * Creates a non-modal dialog without a title and without a specified
145: * <code>Frame</code> owner. A shared, hidden frame will be set as the owner
146: * of the dialog.
147: * <p/>
148: * This constructor sets the component's locale property to the value returned
149: * by <code>JComponent.getDefaultLocale</code>.
150: *
151: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless()
152: * returns true.
153: * @see java.awt.GraphicsEnvironment#isHeadless
154: * @see javax.swing.JComponent#getDefaultLocale
155: */
156: public PreviewDialog() {
157: init();
158: }
159:
160: /**
161: * Creates a non-modal dialog without a title with the specified
162: * <code>Frame</code> as its owner. If <code>owner</code> is
163: * <code>null</code>, a shared, hidden frame will be set as the owner of the
164: * dialog.
165: * <p/>
166: * This constructor sets the component's locale property to the value returned
167: * by <code>JComponent.getDefaultLocale</code>.
168: *
169: * @param owner the <code>Frame</code> from which the dialog is displayed
170: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless()
171: * returns true.
172: * @see java.awt.GraphicsEnvironment#isHeadless
173: * @see javax.swing.JComponent#getDefaultLocale
174: */
175: public PreviewDialog(final Frame owner) {
176: super (owner);
177: init();
178: }
179:
180: /**
181: * Creates a modal or non-modal dialog without a title and with the specified
182: * owner <code>Frame</code>. If <code>owner</code> is <code>null</code>, a
183: * shared, hidden frame will be set as the owner of the dialog.
184: * <p/>
185: * This constructor sets the component's locale property to the value returned
186: * by <code>JComponent.getDefaultLocale</code>.
187: *
188: * @param owner the <code>Frame</code> from which the dialog is displayed
189: * @param modal true for a modal dialog, false for one that allows others
190: * windows to be active at the same time
191: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless()
192: * returns true.
193: * @see java.awt.GraphicsEnvironment#isHeadless
194: * @see javax.swing.JComponent#getDefaultLocale
195: */
196: public PreviewDialog(final Frame owner, final boolean modal) {
197: super (owner, modal);
198: init();
199: }
200:
201: /**
202: * Creates a non-modal dialog without a title with the specified
203: * <code>Dialog</code> as its owner.
204: * <p/>
205: * This constructor sets the component's locale property to the value returned
206: * by <code>JComponent.getDefaultLocale</code>.
207: *
208: * @param owner the non-null <code>Dialog</code> from which the dialog is
209: * displayed
210: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless()
211: * returns true.
212: * @see java.awt.GraphicsEnvironment#isHeadless
213: * @see javax.swing.JComponent#getDefaultLocale
214: */
215: public PreviewDialog(final Dialog owner) {
216: super (owner);
217: init();
218: }
219:
220: /**
221: * Creates a modal or non-modal dialog without a title and with the specified
222: * owner dialog.
223: * <p/>
224: * This constructor sets the component's locale property to the value returned
225: * by <code>JComponent.getDefaultLocale</code>.
226: *
227: * @param owner the non-null <code>Dialog</code> from which the dialog is
228: * displayed
229: * @param modal true for a modal dialog, false for one that allows other
230: * windows to be active at the same time
231: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless()
232: * returns true.
233: * @see java.awt.GraphicsEnvironment#isHeadless
234: * @see javax.swing.JComponent#getDefaultLocale
235: */
236: public PreviewDialog(final Dialog owner, final boolean modal) {
237: super (owner, modal);
238: init();
239: }
240:
241: protected void init() {
242: previewPane = new PreviewPane();
243: statusBar = new JStatusBar(previewPane.getIconTheme());
244: progressBar = new ReportProgressBar();
245: progressBar.setVisible(false);
246:
247: pageLabel = new JLabel();
248:
249: previewPane
250: .addPropertyChangeListener(new PreviewPanePropertyChangeHandler());
251:
252: final JComponent extensionArea = statusBar.getExtensionArea();
253: extensionArea.setLayout(new BoxLayout(extensionArea,
254: BoxLayout.X_AXIS));
255: extensionArea.add(progressBar);
256: extensionArea.add(pageLabel);
257:
258: final JComponent contentPane = new JPanel();
259: contentPane.setLayout(new BorderLayout());
260: contentPane.add(previewPane, BorderLayout.CENTER);
261: contentPane.add(statusBar, BorderLayout.SOUTH);
262: setContentPane(contentPane);
263: }
264:
265: public ReportController getReportController() {
266: return previewPane.getReportController();
267: }
268:
269: public void setReportController(
270: final ReportController reportController) {
271: previewPane.setReportController(reportController);
272: }
273:
274: public IconTheme getIconTheme() {
275: return previewPane.getIconTheme();
276: }
277:
278: public void setIconTheme(final IconTheme theme) {
279: previewPane.setIconTheme(theme);
280: }
281:
282: public ReportJob getReportJob() {
283: return previewPane.getReportJob();
284: }
285:
286: public void setReportJob(final ReportJob reportJob) {
287: previewPane.setReportJob(reportJob);
288: }
289:
290: }
|