1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/lgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: PassageEvent.java 2226 2012-02-02 19:25:21Z dmsmith $
21   */
22  package org.crosswire.jsword.passage;
23  
24  import java.util.EventObject;
25  
26  /**
27   * Defines an event that encapsulates changes to a Passage. For many operations
28   * on a Passage, calculating the extent of the changes is hard. In these cases
29   * we default the range to Gen 1:1-Rev 22:21
30   * 
31   * @see gnu.lgpl.License for license details.<br>
32   *      The copyright to this program is held by it's authors.
33   * @author Joe Walker [joe at eireneh dot com]
34   */
35  public class PassageEvent extends EventObject {
36  
37      /**
38       * Indicates what kind of change happened to a Passage.
39       */
40      public enum EventType {
41          /**
42           * Identifies one or more changes in the lists contents.
43           */
44         CHANGED,
45  
46          /**
47           * Identifies the addition of one or more contiguous items to the list
48           */
49         ADDED,
50  
51          /**
52           * Identifies the removal of one or more contiguous items from the list
53           */
54          REMOVED,
55      }
56  
57      /**
58       * Constructs a PassageEvent object.
59       * 
60       * @param source
61       *            the source Object (typically <code>this</code>)
62       * @param versesChanged
63       *            an int specifying VERSES_CHANGED, VERSES_ADDED, VERSES_REMOVED
64       * @param lower
65       *            an int specifying the bottom of a range
66       * @param upper
67       *            an int specifying the top of a range
68       */
69      public PassageEvent(Object source, EventType versesChanged, Verse lower, Verse upper) {
70          super(source);
71  
72          this.type = versesChanged;
73          this.lower = lower;
74          this.upper = upper;
75      }
76  
77      /**
78       * Returns the event type. The possible values are:
79       * <ul>
80       * <li>VERSES_CHANGED
81       * <li>VERSES_ADDED
82       * <li>VERSES_REMOVED
83       * </ul>
84       * 
85       * @return an int representing the type value
86       */
87      public EventType getType() {
88          return type;
89      }
90  
91      /**
92       * Returns the lower index of the range. For a single element, this value is
93       * the same as that returned by {@link #getUpperIndex()}.
94       * 
95       * @return an int representing the lower index value
96       */
97      public Verse getLowerIndex() {
98          return lower;
99      }
100 
101     /**
102      * Returns the upper index of the range. For a single element, this value is
103      * the same as that returned by {@link #getLowerIndex()}.
104      * 
105      * @return an int representing the upper index value
106      */
107     public Verse getUpperIndex() {
108         return upper;
109     }
110 
111     /**
112      * The type of change
113      */
114     private EventType type;
115 
116     /**
117      * The lowest numbered element to have changed
118      */
119     private Verse lower;
120 
121     /**
122      * The highest numbered element to have changed
123      */
124     private Verse upper;
125 
126     /**
127      * Serialization ID
128      */
129     private static final long serialVersionUID = 3906647492467898675L;
130 }
131