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: * ReportEvent.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.event;
030:
031: import java.util.EventObject;
032:
033: import org.jfree.report.DataRow;
034: import org.jfree.report.ReportDefinition;
035: import org.jfree.report.states.ReportState;
036:
037: /**
038: * Represents a report event.
039: * <p/>
040: * Includes information which {@link org.jfree.report.states.ReportState} generated the event.
041: *
042: * @author Thomas Morgner
043: */
044: public class ReportEvent extends EventObject {
045: /**
046: * The event type constant, that the report initialize event is invoked.
047: */
048: public static final int REPORT_INITIALIZED = 0x01;
049: /**
050: * The event type constant, that the page start event is invoked.
051: */
052: public static final int PAGE_STARTED = 0x02;
053: /**
054: * The event type constant, that the report start event is invoked.
055: */
056: public static final int REPORT_STARTED = 0x04;
057: /**
058: * The event type constant, that a group start event is invoked.
059: */
060: public static final int GROUP_STARTED = 0x08;
061: /**
062: * The event type constant, that the items started event is invoked.
063: */
064: public static final int ITEMS_STARTED = 0x10;
065: /**
066: * The event type constant, that the items advanced event is invoked.
067: */
068: public static final int ITEMS_ADVANCED = 0x20;
069: /**
070: * The event type constant, that the items finished event is invoked.
071: */
072: public static final int ITEMS_FINISHED = 0x40;
073: /**
074: * The event type constant, that a group finished event is invoked.
075: */
076: public static final int GROUP_FINISHED = 0x80;
077: /**
078: * The event type constant, that the report finished event is invoked.
079: */
080: public static final int REPORT_FINISHED = 0x100;
081: /**
082: * The event type constant, that the report done event is invoked.
083: */
084: public static final int REPORT_DONE = 0x200;
085: /**
086: * The event type constant, that the page finished event is invoked.
087: */
088: public static final int PAGE_FINISHED = 0x400;
089: /**
090: * The event type constant, that the page finished event is invoked.
091: *
092: * @deprecated No longer used.
093: */
094: public static final int PAGE_CANCELED = 0x800;
095: /**
096: * The event type constant, that the post group footer state will be processed. This event is never fired.
097: */
098: public static final int POST_GROUP_FOOTER = 0x1000;
099: /**
100: * The event type constant, that the post group header state will be processed. This event is never fired.
101: */
102: public static final int POST_GROUP_HEADER = 0x4000;
103: /**
104: * The event type constant, that the page rollback event is invoked.
105: *
106: * @deprecated No longer used.
107: */
108: public static final int PAGE_ROLLEDBACK = 0x8000;
109:
110: /**
111: * The event type constant, that this event is a prepare event. Use this constant in combination with one of the other
112: * event types to specify which kind of event was prepared.
113: */
114: public static final int PREPARE_EVENT = 0x2000000;
115:
116: /**
117: * A flag that marks the given event as a deep-traversing event. This flag is an indicator, that the event did not
118: * originate in this report, so it propably came from a parent or child report.
119: */
120: public static final int DEEP_TRAVERSING_EVENT = 0x4000000;
121:
122: /**
123: * The event type for this event.
124: */
125: private int type;
126:
127: /**
128: * The state that generated the event in the first place. For master reports this is the same as the event source, for
129: * master-reports receiving events from a sub-report, this is the subreport's report state.
130: */
131: private ReportState originatingState;
132:
133: /**
134: * Creates a new <code>ReportEvent</code>.
135: *
136: * @param state the current state of the processed report (<code>null</code> not permmitted).
137: * @param type the event type for this event object.
138: */
139: public ReportEvent(final ReportState state, final int type) {
140: super (state);
141: if (state == null) {
142: throw new NullPointerException(
143: "ReportEvent(ReportState) : null not permitted.");
144: }
145: if (type <= 0) {
146: throw new IllegalArgumentException(
147: "This is not a valid EventType: " + type);
148: }
149: this .type = type;
150: this .originatingState = state;
151: }
152:
153: /**
154: * Creates a new <code>ReportEvent</code>.
155: *
156: * @param state the current state of the processed report (<code>null</code> not permmitted).
157: * @param originatingState the original state that generated the event.
158: * @param type the event type for this event object.
159: */
160: public ReportEvent(final ReportState state,
161: final ReportState originatingState, final int type) {
162: this (state, type);
163: if (originatingState == null) {
164: throw new NullPointerException(
165: "Originating state can never be null.");
166: }
167: this .originatingState = originatingState;
168: }
169:
170: /**
171: * Returns the event type. The type is made up of a combination of several flags.
172: *
173: * @return the event type.
174: */
175: public int getType() {
176: return type;
177: }
178:
179: /**
180: * Returns the <code>ReportState</code>, which is the source of the event.
181: *
182: * @return the state (never <code>null</code>).
183: */
184: public ReportState getState() {
185: return (ReportState) getSource();
186: }
187:
188: /**
189: * Returns the originating state. The originating state is the state, that generated the event in the first place. For
190: * master reports this is the same as the event source, for master-reports receiving events from a sub-report, this is
191: * the subreport's report state.
192: *
193: * @return the originating state.
194: */
195: public ReportState getOriginatingState() {
196: return originatingState;
197: }
198:
199: /**
200: * Returns the report that generated the event. <P> This is a convenience method that extracts the report from the
201: * report state.
202: *
203: * @return the report.
204: */
205: public ReportDefinition getReport() {
206: return getState().getReport();
207: }
208:
209: /**
210: * Returns the currently assigned dataRow for this event.
211: * <p/>
212: * The {@link DataRow} is used to access the fields of the {@link org.jfree.report.filter.DataSource} and other
213: * functions and expressions within the current row of the report.
214: *
215: * @return the data row.
216: */
217: public DataRow getDataRow() {
218: return getState().getDataRow();
219: }
220:
221: /**
222: * Returns the current function level.
223: *
224: * @return the function level.
225: */
226: public int getLevel() {
227: return getState().getLevel();
228: }
229:
230: /**
231: * Checks, whether the deep-traversing flag is set. An event is deep-traversing, if it did not originate in the
232: * current report.
233: *
234: * @return true, if this is a deep-traversing element, false otherwise.
235: */
236: public boolean isDeepTraversing() {
237: return (type & ReportEvent.DEEP_TRAVERSING_EVENT) == ReportEvent.DEEP_TRAVERSING_EVENT;
238: }
239:
240: /**
241: * Checks, whether this event is a prepare event. Prepare events are fired before the real event is fired and
242: * sometimes simplify the state-management inside complex functions.
243: *
244: * @return true, if this event is a prepare event, false otherwise.
245: */
246: public boolean isPrepareEvent() {
247: return (type & ReportEvent.PREPARE_EVENT) == ReportEvent.PREPARE_EVENT;
248: }
249: }
|