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: ReportProgressBar.java,v 1.3 2007/04/01 18:49:30 taqua Exp $
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.common;
033
034 import java.text.MessageFormat;
035 import java.util.Locale;
036 import java.util.ResourceBundle;
037 import javax.swing.JProgressBar;
038 import javax.swing.SwingUtilities;
039
040 import org.jfree.report.event.ReportProgressEvent;
041 import org.jfree.report.event.ReportProgressListener;
042 import org.jfree.report.modules.gui.common.GuiCommonModule;
043
044 public class ReportProgressBar extends JProgressBar
045 {
046 private class ScreenUpdateRunnable implements Runnable
047 {
048 private int page;
049 private int activity;
050 private int currentRow;
051
052 public ScreenUpdateRunnable (final int activity,
053 final int currentRow,
054 final int page)
055 {
056 this.activity = activity;
057 this.currentRow = currentRow;
058 this.page = page;
059 }
060
061 public void run ()
062 {
063 //updatePassMessage(activity, currentRow, page);
064 setValue(currentRow);
065 }
066 }
067
068 private class ReportProgressHandler implements ReportProgressListener
069 {
070 public ReportProgressHandler()
071 {
072 }
073
074 public void reportProcessingStarted(ReportProgressEvent event)
075 {
076 postUpdate(event);
077 }
078
079 public void reportProcessingUpdate(ReportProgressEvent event)
080 {
081 postUpdate(event);
082 }
083
084 public void reportProcessingFinished(ReportProgressEvent event)
085 {
086 postUpdate(event);
087 }
088
089 private void postUpdate (ReportProgressEvent event)
090 {
091 final ScreenUpdateRunnable runnable = new ScreenUpdateRunnable
092 (event.getActivity(), event.getRow(), event.getPage());
093 if (SwingUtilities.isEventDispatchThread())
094 {
095 runnable.run();
096 }
097 else
098 {
099 SwingUtilities.invokeLater(runnable);
100 }
101 }
102 }
103
104 /**
105 * The reuseable message format for the page label.
106 */
107 private MessageFormat pageMessageFormatter;
108 /**
109 * The reuseable message format for the pass label.
110 */
111 private MessageFormat currentRowFormatter;
112 /**
113 * a text which describes the layouting process.
114 */
115 private String layoutText;
116 /**
117 * a text that describes the export phase of the report processing.
118 */
119 private String outputText;
120
121 /**
122 * Localised resources.
123 */
124 private ResourceBundle resources;
125
126 /**
127 * Creates a horizontal progress bar that displays a border but no progress string. The
128 * initial and minimum values are 0, and the maximum is 100.
129 *
130 * @see #setOrientation
131 * @see #setBorderPainted
132 * @see #setStringPainted
133 * @see #setString
134 * @see #setIndeterminate
135 */
136 public ReportProgressBar (Locale locale)
137 {
138 setLocale(locale);
139 initialize();
140 }
141
142 /**
143 * Creates a horizontal progress bar that displays a border but no progress
144 * string. The initial and minimum values are 0, and the maximum is 100.
145 *
146 * @see #setOrientation
147 * @see #setBorderPainted
148 * @see #setStringPainted
149 * @see #setString
150 * @see #setIndeterminate
151 */
152 public ReportProgressBar()
153 {
154 setLocale(Locale.getDefault());
155 initialize();
156 }
157
158 private void initialize()
159 {
160 resources = ResourceBundle.getBundle(GuiCommonModule.RESOURCE_BASE_NAME);
161 pageMessageFormatter = new MessageFormat
162 (resources.getString("progress-dialog.page-label"));
163 currentRowFormatter = new MessageFormat
164 (resources.getString("progress-dialog.current-row-label"));
165 }
166 }