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 */ 031 032 package org.jfree.report.modules.gui.swing.preview; 033 034 import java.awt.BorderLayout; 035 import java.awt.Dialog; 036 import java.awt.Frame; 037 import java.beans.PropertyChangeEvent; 038 import java.beans.PropertyChangeListener; 039 import javax.swing.BoxLayout; 040 import javax.swing.JComponent; 041 import javax.swing.JDialog; 042 import javax.swing.JLabel; 043 import javax.swing.JMenu; 044 import javax.swing.JMenuBar; 045 import javax.swing.JPanel; 046 047 import org.jfree.report.flow.ReportJob; 048 import org.jfree.report.modules.gui.common.IconTheme; 049 import org.jfree.report.modules.gui.swing.common.JStatusBar; 050 import org.jfree.report.modules.gui.swing.common.ReportProgressBar; 051 052 /** 053 * Creation-Date: 11.11.2006, 19:35:16 054 * 055 * @author Thomas Morgner 056 */ 057 public class PreviewDialog extends JDialog 058 { 059 private class PreviewPanePropertyChangeHandler 060 implements PropertyChangeListener 061 { 062 private PreviewPanePropertyChangeHandler() 063 { 064 } 065 066 /** 067 * This method gets called when a bound property is changed. 068 * 069 * @param evt A PropertyChangeEvent object describing the event source and 070 * the property that has changed. 071 */ 072 073 public void propertyChange(final PropertyChangeEvent evt) 074 { 075 final String propertyName = evt.getPropertyName(); 076 if (PreviewPane.MENU_PROPERTY.equals(propertyName)) 077 { 078 // Update the menu 079 final JMenu[] menus = previewPane.getMenu(); 080 if (menus != null && menus.length > 0) 081 { 082 final JMenuBar menuBar = new JMenuBar(); 083 for (int i = 0; i < menus.length; i++) 084 { 085 final JMenu menu = menus[i]; 086 menuBar.add(menu); 087 } 088 setJMenuBar(menuBar); 089 } 090 else 091 { 092 setJMenuBar(null); 093 } 094 return; 095 } 096 097 if (PreviewPane.TITLE_PROPERTY.equals(propertyName)) 098 { 099 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 }