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: * PreviewInternalFrame.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 java.beans.PropertyVetoException;
037: import javax.swing.BoxLayout;
038: import javax.swing.JComponent;
039: import javax.swing.JInternalFrame;
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.JFreeReport;
046: import org.jfree.report.modules.gui.common.IconTheme;
047: import org.jfree.report.modules.gui.commonswing.JStatusBar;
048: import org.jfree.report.modules.gui.commonswing.ReportProgressBar;
049: import org.jfree.report.modules.gui.commonswing.RequestFocusHandler;
050:
051: /**
052: * Creation-Date: 11.11.2006, 19:35:09
053: *
054: * @author Thomas Morgner
055: */
056: public class PreviewInternalFrame extends JInternalFrame {
057: private class PreviewPanePropertyChangeHandler implements
058: PropertyChangeListener {
059:
060: protected PreviewPanePropertyChangeHandler() {
061: }
062:
063: /**
064: * This method gets called when a bound property is changed.
065: *
066: * @param evt A PropertyChangeEvent object describing the event source and
067: * the property that has changed.
068: */
069:
070: public void propertyChange(final PropertyChangeEvent evt) {
071: final String propertyName = evt.getPropertyName();
072: if (PreviewPane.MENU_PROPERTY.equals(propertyName)) {
073: // Update the menu
074: final JMenu[] menus = previewPane.getMenu();
075: if (menus != null && menus.length > 0) {
076: final JMenuBar menuBar = new JMenuBar();
077: for (int i = 0; i < menus.length; i++) {
078: final JMenu menu = menus[i];
079: menuBar.add(menu);
080: }
081: setJMenuBar(menuBar);
082: } else {
083: setJMenuBar(null);
084: }
085: return;
086: }
087:
088: if (PreviewPane.TITLE_PROPERTY.equals(propertyName)) {
089: setTitle(previewPane.getTitle());
090: return;
091: }
092:
093: if (PreviewPane.STATUS_TEXT_PROPERTY.equals(propertyName)
094: || PreviewPane.STATUS_TYPE_PROPERTY
095: .equals(propertyName)) {
096: statusBar.setStatus(previewPane.getStatusType(),
097: previewPane.getStatusText());
098: return;
099: }
100:
101: if (PreviewPane.ICON_THEME_PROPERTY.equals(propertyName)) {
102: statusBar.setIconTheme(previewPane.getIconTheme());
103: return;
104: }
105:
106: if (PreviewPane.PAGINATING_PROPERTY.equals(propertyName)) {
107: if (Boolean.TRUE.equals(evt.getNewValue())) {
108: progressBar.setOnlyPagination(true);
109: progressBar.setVisible(true);
110: pageLabel.setVisible(false);
111: } else {
112: progressBar.setOnlyPagination(true);
113: progressBar.setVisible(false);
114: pageLabel.setVisible(true);
115: }
116: progressBar.revalidate();
117: return;
118: }
119:
120: if (PreviewPane.PAGE_NUMBER_PROPERTY.equals(propertyName)
121: || PreviewPane.NUMBER_OF_PAGES_PROPERTY
122: .equals(propertyName)) {
123: pageLabel.setText(previewPane.getPageNumber()
124: + "/" + previewPane.getNumberOfPages()); //$NON-NLS-1$
125: return;
126: }
127:
128: if (PreviewPane.CLOSED_PROPERTY.equals(propertyName)) {
129: if (previewPane.isClosed()) {
130: try {
131: setClosed(true);
132: } catch (PropertyVetoException e) {
133: // Ignored ..
134: }
135: dispose();
136: } else {
137: setVisible(true);
138: }
139: }
140: }
141: }
142:
143: private static class TriggerPaginationListener extends
144: ComponentAdapter {
145: private PreviewPane pane;
146:
147: public TriggerPaginationListener(final PreviewPane pane) {
148: this .pane = pane;
149: }
150:
151: /**
152: * Invoked when the component has been made visible.
153: */
154: public void componentShown(final ComponentEvent e) {
155: if (pane.isDeferredRepagination()) {
156: pane.startPagination();
157: }
158: }
159: }
160:
161: private PreviewPane previewPane;
162:
163: private JStatusBar statusBar;
164:
165: private ReportProgressBar progressBar;
166:
167: private JLabel pageLabel;
168:
169: /**
170: * Creates a non-modal dialog without a title and without a specified
171: * <code>Frame</code> owner. A shared, hidden frame will be set as the owner
172: * of the dialog.
173: * <p/>
174: * This constructor sets the component's locale property to the value returned
175: * by <code>JComponent.getDefaultLocale</code>.
176: *
177: * @throws java.awt.HeadlessException if GraphicsEnvironment.isHeadless()
178: * returns true.
179: * @see java.awt.GraphicsEnvironment#isHeadless
180: * @see javax.swing.JComponent#getDefaultLocale
181: */
182: public PreviewInternalFrame() {
183: init();
184: }
185:
186: /**
187: * Constructs a new frame that is initially invisible.
188: * <p/>
189: * This constructor sets the component's locale property to the value returned by
190: * <code>JComponent.getDefaultLocale</code>.
191: *
192: * @see java.awt.GraphicsEnvironment#isHeadless
193: * @see java.awt.Component#setSize
194: * @see java.awt.Component#setVisible
195: * @see javax.swing.JComponent#getDefaultLocale
196: */
197: public PreviewInternalFrame(final JFreeReport report) {
198: init();
199: setReportJob(report);
200: }
201:
202: protected void init() {
203: addComponentListener(new RequestFocusHandler());
204:
205: previewPane = new PreviewPane();
206: previewPane.setDeferredRepagination(true);
207: addComponentListener(new TriggerPaginationListener(previewPane));
208: statusBar = new JStatusBar(previewPane.getIconTheme());
209:
210: progressBar = new ReportProgressBar();
211: progressBar.setVisible(false);
212: previewPane.addReportProgressListener(progressBar);
213:
214: pageLabel = new JLabel();
215: previewPane
216: .addPropertyChangeListener(new PreviewInternalFrame.PreviewPanePropertyChangeHandler());
217:
218: final JComponent extensionArea = statusBar.getExtensionArea();
219: extensionArea.setLayout(new BoxLayout(extensionArea,
220: BoxLayout.X_AXIS));
221: extensionArea.add(progressBar);
222: extensionArea.add(pageLabel);
223:
224: final JComponent contentPane = new JPanel();
225: contentPane.setLayout(new BorderLayout());
226: contentPane.add(previewPane, BorderLayout.CENTER);
227: contentPane.add(statusBar, BorderLayout.SOUTH);
228: setContentPane(contentPane);
229:
230: updateMenu(previewPane.getMenu());
231: setTitle(previewPane.getTitle());
232: statusBar.setIconTheme(previewPane.getIconTheme());
233: statusBar.setStatus(previewPane.getStatusType(), previewPane
234: .getStatusText());
235: }
236:
237: private void updateMenu(final JMenu[] menus) {
238: if (menus != null && menus.length > 0) {
239: final JMenuBar menuBar = new JMenuBar();
240: for (int i = 0; i < menus.length; i++) {
241: final JMenu menu = menus[i];
242: menuBar.add(menu);
243: }
244: setJMenuBar(menuBar);
245: } else {
246: setJMenuBar(null);
247: }
248: }
249:
250: public ReportController getReportController() {
251: return previewPane.getReportController();
252: }
253:
254: public void setReportController(
255: final ReportController reportController) {
256: previewPane.setReportController(reportController);
257: }
258:
259: public IconTheme getIconTheme() {
260: return previewPane.getIconTheme();
261: }
262:
263: public void setIconTheme(final IconTheme theme) {
264: previewPane.setIconTheme(theme);
265: }
266:
267: public JFreeReport getReportJob() {
268: return previewPane.getReportJob();
269: }
270:
271: public void setReportJob(final JFreeReport reportJob) {
272: previewPane.setReportJob(reportJob);
273: }
274:
275: public void dispose() {
276: super .dispose();
277: previewPane.setClosed(true);
278: }
279:
280: protected PreviewPane getPreviewPane() {
281: return previewPane;
282: }
283:
284: public boolean isToolbarFloatable() {
285: return previewPane.isToolbarFloatable();
286: }
287:
288: public void setToolbarFloatable(final boolean toolbarFloatable) {
289: previewPane.setToolbarFloatable(toolbarFloatable);
290: }
291:
292: public double getZoom() {
293: return previewPane.getZoom();
294: }
295:
296: public void setZoom(final double zoom) {
297: previewPane.setZoom(zoom);
298: }
299: }
|