KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreereport > helper > YieldReportListener


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12 */

13 /**
14  * ========================================
15  * <libname> : a free Java <foobar> library
16  * ========================================
17  *
18  * Project Info: http://www.jfree.org/liblayout/
19  * Project Lead: Thomas Morgner;
20  *
21  * (C) Copyright 2005, by Object Refinery Limited and Contributors.
22  *
23  * This library is free software; you can redistribute it and/or modify it under the terms
24  * of the GNU Lesser General Public License as published by the Free Software Foundation;
25  * either version 2.1 of the License, or (at your option) any later version.
26  *
27  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
28  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29  * See the GNU Lesser General Public License for more details.
30  *
31  * You should have received a copy of the GNU Lesser General Public License along with this
32  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
33  * Boston, MA 02111-1307, USA.
34  *
35  * ---------
36  * YieldReportListener.java
37  * ---------
38  *
39  * Original Author: Thomas Morgner;
40  * Contributors: -;
41  *
42  * $Id: Anchor.java,v 1.3 2005/02/23 21:04:29 taqua Exp $
43  *
44  * Changes
45  * -------------------------
46  * 01.10.2006 : Initial version
47  */

48 package org.pentaho.plugin.jfreereport.helper;
49
50 import org.jfree.report.event.RepaginationListener;
51 import org.jfree.report.event.RepaginationState;
52
53 /**
54  * Creation-Date: 01.10.2006, 16:44:20
55  *
56  * @author Thomas Morgner
57  */

58 public class YieldReportListener implements RepaginationListener {
59   private int rate;
60
61   private transient int lastCall;
62
63   private transient int lastPage;
64
65   public YieldReportListener() {
66     rate = 50;
67   }
68
69   public YieldReportListener(final int rate) {
70     this.rate = rate;
71   }
72
73   public int getRate() {
74     return rate;
75   }
76
77   public void setRate(final int rate) {
78     this.rate = rate;
79   }
80
81   public void repaginationUpdate(RepaginationState repaginationState) {
82     final int currentRow = repaginationState.getCurrentRow();
83     final int thisCall = currentRow % rate;
84     final int page = repaginationState.getPage();
85
86     if (page != lastPage) {
87       Thread.yield();
88     } else if (thisCall != lastCall) {
89       Thread.yield();
90     }
91     lastCall = thisCall;
92     lastPage = page;
93   }
94 }
95
Popular Tags