001 /*
002 * $Id: ProbeEvent.java,v 1.11 2012/02/19 17:35:48 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2012
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 *
012 * All Rights Reserved
013 *
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.
016 *
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 *
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
025 * GNU Lesser Public License for more details.
026 *
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program. If not, see http://www.gnu.org/licenses.
029 */
030
031 package edu.wisc.ssec.mcidasv.probes;
032
033 import java.util.EventObject;
034
035 import edu.wisc.ssec.mcidasv.util.Contract;
036
037 /**
038 * This class captures a change to a probe and stores both the previous and
039 * current (as of the event's creation) changed values.
040 */
041 @SuppressWarnings("serial")
042 public class ProbeEvent<T> extends EventObject {
043
044 /**
045 * Previous value of the probe.
046 */
047 private final T oldValue;
048
049 /**
050 * Current value of the probe.
051 */
052 private final T newValue;
053
054 /**
055 * Generated when a {@link ReadoutProbe} changes either its position,
056 * color, or visibility. Currently stores either position, color, or
057 * visibility both before and after the change.
058 *
059 * @param source Probe that generated this event.
060 * @param oldValue Old value of the probe.
061 * @param newValue New value of the probe.
062 *
063 * @throws NullPointerException if any parameters are {@code null}.
064 */
065 public ProbeEvent(final ReadoutProbe source, final T oldValue, final T newValue) {
066 super(source);
067
068 Contract.notNull(source, "Events cannot originate from a null source object");
069 Contract.notNull(oldValue, "Old value cannot be null");
070 Contract.notNull(newValue, "New value cannot be null");
071
072 this.oldValue = oldValue;
073 this.newValue = newValue;
074 }
075
076 public ReadoutProbe getProbe() {
077 return (ReadoutProbe)getSource();
078 }
079
080 /**
081 * Returns the value of the probe before this event was generated.
082 *
083 * @return Previous probe value.
084 */
085 public T getOldValue() {
086 return oldValue;
087 }
088
089 /**
090 * Returns the current (as of this event) value of the probe.
091 *
092 * @return Current probe value.
093 */
094 public T getNewValue() {
095 return newValue;
096 }
097
098 /**
099 * Returns a brief summary of this event. Please note that this format is
100 * subject to change.
101 *
102 * @return String that looks like {@code [ProbeEvent@HASHCODE: source=...,
103 * oldValue=..., newValue=...]}.
104 */
105 @Override public String toString() {
106 return String.format("[ProbeEvent@%x: source=%s, oldValue=%s, newValue=%s]", hashCode(), source, oldValue, newValue);
107 }
108 }