001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org 019 */ 020 021package org.biojava.utils; 022 023import java.util.EventObject; 024 025/** 026 * Event which encapsulates a change in any mutable BioJava object. 027 * 028 * @author Thomas Down 029 * @author Matthew Pocock 030 * @author Greg Cox 031 * @since 1.1 032 */ 033public class ChangeEvent extends EventObject { 034 private final ChangeType type; 035 private final Object change; 036 private final Object previous; 037 private final ChangeEvent chain; 038 039 /** 040 * Construct a ChangeEvent with no change details. 041 * 042 * @param source The object being changed. 043 * @param type The type of change being made. 044 */ 045 public ChangeEvent(Object source, ChangeType type) { 046 this(source, type, null, null, null); 047 } 048 049 /** 050 * 051 * Construct a ChangeEvent specifying a new value for 052 * a property, or an object to be added to a collection. 053 * 054 * @param source The object being changed. 055 * @param type The type of change being made. 056 * @param change The new value of the property being changed. 057 */ 058 public ChangeEvent( 059 Object source, 060 ChangeType type, 061 Object change 062 ) { 063 this(source, type, change, null, null); 064 } 065 066 /** 067 * 068 * Construct a ChangeEvent specifying a new value for 069 * a property, and giving the previous value. 070 * 071 * @param source The object being changed. 072 * @param type The type of change being made. 073 * @param change The new value of the property being changed. 074 * @param previous The old value of the property being changed. 075 */ 076 public ChangeEvent( 077 Object source, 078 ChangeType type, 079 Object change, 080 Object previous 081 ) { 082 this(source, type, change, previous, null); 083 } 084 085 /** 086 * 087 * Construct a ChangeEvent to be fired because another ChangeEvent has 088 * been received from a property object. 089 * 090 * @param source The object being changed. 091 * @param type The type of change being made. 092 * @param change The new value of the property being changed. 093 * @param previous The old value of the property being changed. 094 * @param chain The event which caused this event to be fired. 095 */ 096 public ChangeEvent( 097 Object source, 098 ChangeType type, 099 Object change, 100 Object previous, 101 ChangeEvent chain 102 ) { 103 super(source); 104 this.type = type; 105 this.change = change; 106 this.previous = previous; 107 this.chain = chain; 108 } 109 110 /** 111 * Find the type of this event. 112 * 113 * @return The Type value 114 */ 115 public ChangeType getType() { 116 return type; 117 } 118 119 /** 120 * 121 * Return an object which is to be the new value of some property, 122 * or is to be added to a collection. May return <code>null</code> 123 * is this is not meaningful. 124 * 125 * @return The Change value 126 */ 127 public Object getChange() { 128 return change; 129 } 130 131 /** 132 * 133 * Return the old value of a property being changed. May return 134 * <code>null</code> is this is not meaningful. 135 * 136 * @return The Previous value 137 */ 138 public Object getPrevious() { 139 return previous; 140 } 141 142 /** 143 * 144 * Return the event which caused this to be fired, or <code>null</code> 145 * if this change was not caused by another event. 146 * 147 * @return The ChainedEvent value 148 */ 149 public ChangeEvent getChainedEvent() { 150 return chain; 151 152 } 153 154 public String toString() { 155 return 156 super.toString() + 157 "[" + 158 "type:" + getType() + 159 ", change: " + getChange() + 160 ", previous: " + getPrevious() + 161 ", chainedEvent: " + getChainedEvent() + 162 "]"; 163 } 164}