Frames | No Frames |
1: /** 2: * ======================================== 3: * JFreeReport : a free Java report library 4: * ======================================== 5: * 6: * Project Info: http://reporting.pentaho.org/ 7: * 8: * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors. 9: * 10: * This library is free software; you can redistribute it and/or modify it under the terms 11: * of the GNU Lesser General Public License as published by the Free Software Foundation; 12: * either version 2.1 of the License, or (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16: * See the GNU Lesser General Public License for more details. 17: * 18: * You should have received a copy of the GNU Lesser General Public License along with this 19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20: * Boston, MA 02111-1307, USA. 21: * 22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 23: * in the United States and other countries.] 24: * 25: * ------------ 26: * $Id: PreviewDialog.java 3525 2007-10-16 11:43:48Z tmorgner $ 27: * ------------ 28: * (C) Copyright 2000-2005, by Object Refinery Limited. 29: * (C) Copyright 2005-2007, by Pentaho Corporation. 30: */ 31: 32: package org.jfree.report.modules.gui.swing.preview; 33: 34: import java.awt.BorderLayout; 35: import java.awt.Dialog; 36: import java.awt.Frame; 37: import java.beans.PropertyChangeEvent; 38: import java.beans.PropertyChangeListener; 39: import javax.swing.BoxLayout; 40: import javax.swing.JComponent; 41: import javax.swing.JDialog; 42: import javax.swing.JLabel; 43: import javax.swing.JMenu; 44: import javax.swing.JMenuBar; 45: import javax.swing.JPanel; 46: 47: import org.jfree.report.flow.ReportJob; 48: import org.jfree.report.modules.gui.common.IconTheme; 49: import org.jfree.report.modules.gui.swing.common.JStatusBar; 50: import org.jfree.report.modules.gui.swing.common.ReportProgressBar; 51: 52: /** 53: * Creation-Date: 11.11.2006, 19:35:16 54: * 55: * @author Thomas Morgner 56: */ 57: public class PreviewDialog extends JDialog 58: { 59: private class PreviewPanePropertyChangeHandler 60: implements PropertyChangeListener 61: { 62: private PreviewPanePropertyChangeHandler() 63: { 64: } 65: 66: /** 67: * This method gets called when a bound property is changed. 68: * 69: * @param evt A PropertyChangeEvent object describing the event source and 70: * the property that has changed. 71: */ 72: 73: public void propertyChange(final PropertyChangeEvent evt) 74: { 75: final String propertyName = evt.getPropertyName(); 76: if (PreviewPane.MENU_PROPERTY.equals(propertyName)) 77: { 78: // Update the menu 79: final JMenu[] menus = previewPane.getMenu(); 80: if (menus != null && menus.length > 0) 81: { 82: final JMenuBar menuBar = new JMenuBar(); 83: for (int i = 0; i < menus.length; i++) 84: { 85: final JMenu menu = menus[i]; 86: menuBar.add(menu); 87: } 88: setJMenuBar(menuBar); 89: } 90: else 91: { 92: setJMenuBar(null); 93: } 94: return; 95: } 96: 97: if (PreviewPane.TITLE_PROPERTY.equals(propertyName)) 98: { 99: setTitle(previewPane.getTitle()); 100: return; 101: } 102: 103: if (PreviewPane.STATUS_TEXT_PROPERTY.equals(propertyName) || 104: PreviewPane.STATUS_TYPE_PROPERTY.equals(propertyName)) 105: { 106: statusBar.setStatus(previewPane.getStatusType(), 107: previewPane.getStatusText()); 108: return; 109: } 110: 111: if (PreviewPane.ICON_THEME_PROPERTY.equals(propertyName)) 112: { 113: statusBar.setIconTheme(previewPane.getIconTheme()); 114: return; 115: } 116: 117: if (PreviewPane.PAGINATING_PROPERTY.equals(propertyName)) 118: { 119: if (Boolean.TRUE.equals(evt.getNewValue())) 120: { 121: progressBar.setVisible(true); 122: pageLabel.setVisible(false); 123: statusBar.setStatus(JStatusBar.TYPE_INFORMATION, "Paginating ..."); 124: } 125: else 126: { 127: progressBar.setVisible(false); 128: pageLabel.setVisible(true); 129: statusBar.setStatus(JStatusBar.TYPE_NONE, ""); 130: } 131: progressBar.revalidate(); 132: return; 133: } 134: 135: if (PreviewPane.PAGE_NUMBER_PROPERTY.equals(propertyName) || 136: PreviewPane.NUMBER_OF_PAGES_PROPERTY.equals(propertyName)) 137: { 138: pageLabel.setText(previewPane.getPageNumber() + "/" + previewPane.getNumberOfPages()); 139: return; 140: } 141: 142: if (PreviewPane.CLOSED_PROPERTY.equals(propertyName)) 143: { 144: if (previewPane.isClosed()) 145: { 146: setVisible(false); 147: dispose(); 148: } 149: else 150: { 151: setVisible(true); 152: } 153: } 154: } 155: } 156: 157: private PreviewPane previewPane; 158: private JStatusBar statusBar; 159: private ReportProgressBar progressBar; 160: private JLabel pageLabel; 161: 162: /** 163: * Creates a non-modal dialog without a title and without a specified 164: * <code>Frame</code> owner. A shared, hidden frame will be set as the owner 165: * of the dialog. 166: * <p/> 167: * This constructor sets the component's locale property to the value returned 168: * by <code>JComponent.getDefaultLocale</code>. 169: * 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() 176: { 177: init(); 178: } 179: 180: /** 181: * Creates a non-modal dialog without a title with the specified 182: * <code>Frame</code> as its owner. If <code>owner</code> is 183: * <code>null</code>, a shared, hidden frame will be set as the owner of the 184: * dialog. 185: * <p/> 186: * This constructor sets the component's locale property to the value returned 187: * by <code>JComponent.getDefaultLocale</code>. 188: * 189: * @param owner the <code>Frame</code> from which the dialog is displayed 190: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless() 191: * returns true. 192: * @see java.awt.GraphicsEnvironment#isHeadless 193: * @see javax.swing.JComponent#getDefaultLocale 194: */ 195: public PreviewDialog(final Frame owner) 196: { 197: super(owner); 198: init(); 199: } 200: 201: /** 202: * Creates a modal or non-modal dialog without a title and with the specified 203: * owner <code>Frame</code>. If <code>owner</code> is <code>null</code>, a 204: * shared, hidden frame will be set as the owner of the dialog. 205: * <p/> 206: * This constructor sets the component's locale property to the value returned 207: * by <code>JComponent.getDefaultLocale</code>. 208: * 209: * @param owner the <code>Frame</code> from which the dialog is displayed 210: * @param modal true for a modal dialog, false for one that allows others 211: * windows to be active at the same time 212: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless() 213: * returns true. 214: * @see java.awt.GraphicsEnvironment#isHeadless 215: * @see javax.swing.JComponent#getDefaultLocale 216: */ 217: public PreviewDialog(final Frame owner, final boolean modal) 218: { 219: super(owner, modal); 220: init(); 221: } 222: 223: /** 224: * Creates a non-modal dialog without a title with the specified 225: * <code>Dialog</code> as its owner. 226: * <p/> 227: * This constructor sets the component's locale property to the value returned 228: * by <code>JComponent.getDefaultLocale</code>. 229: * 230: * @param owner the non-null <code>Dialog</code> from which the dialog is 231: * displayed 232: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless() 233: * returns true. 234: * @see java.awt.GraphicsEnvironment#isHeadless 235: * @see javax.swing.JComponent#getDefaultLocale 236: */ 237: public PreviewDialog(final Dialog owner) 238: { 239: super(owner); 240: init(); 241: } 242: 243: /** 244: * Creates a modal or non-modal dialog without a title and with the specified 245: * owner dialog. 246: * <p/> 247: * This constructor sets the component's locale property to the value returned 248: * by <code>JComponent.getDefaultLocale</code>. 249: * 250: * @param owner the non-null <code>Dialog</code> from which the dialog is 251: * displayed 252: * @param modal true for a modal dialog, false for one that allows other 253: * windows to be active at the same time 254: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless() 255: * returns true. 256: * @see java.awt.GraphicsEnvironment#isHeadless 257: * @see javax.swing.JComponent#getDefaultLocale 258: */ 259: public PreviewDialog(final Dialog owner, final boolean modal) 260: { 261: super(owner, modal); 262: init(); 263: } 264: 265: protected void init() 266: { 267: previewPane = new PreviewPane(); 268: statusBar = new JStatusBar(previewPane.getIconTheme()); 269: progressBar = new ReportProgressBar(); 270: progressBar.setVisible(false); 271: 272: pageLabel = new JLabel(); 273: 274: previewPane.addPropertyChangeListener(new PreviewPanePropertyChangeHandler()); 275: 276: final JComponent extensionArea = statusBar.getExtensionArea(); 277: extensionArea.setLayout(new BoxLayout(extensionArea, BoxLayout.X_AXIS)); 278: extensionArea.add(progressBar); 279: extensionArea.add(pageLabel); 280: 281: final JComponent contentPane = new JPanel(); 282: contentPane.setLayout(new BorderLayout()); 283: contentPane.add(previewPane, BorderLayout.CENTER); 284: contentPane.add(statusBar, BorderLayout.SOUTH); 285: setContentPane(contentPane); 286: } 287: 288: public ReportController getReportController() 289: { 290: return previewPane.getReportController(); 291: } 292: 293: public void setReportController(final ReportController reportController) 294: { 295: previewPane.setReportController(reportController); 296: } 297: 298: public IconTheme getIconTheme() 299: { 300: return previewPane.getIconTheme(); 301: } 302: 303: public void setIconTheme(final IconTheme theme) 304: { 305: previewPane.setIconTheme(theme); 306: } 307: 308: public ReportJob getReportJob() 309: { 310: return previewPane.getReportJob(); 311: } 312: 313: public void setReportJob(final ReportJob reportJob) 314: { 315: previewPane.setReportJob(reportJob); 316: } 317: 318: }