/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

 This library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1 of the
 License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.model;
/**
 * Events of this type are fired by JSCData objects to
 * notify listeners like JSCSymbol objects about changes of
 * various kinds. Instances of this class are constructed via the
 * static valueOf factory methods. 
 * 

* Usage Note:
* The events that are fired by the JSCData objects are intended * for internal communication only. Events do not occur in the EventDispatchingThread. * Clients should rather listen to changes in JSCSymbol objects, especially * if GUI related actions are performed. * * @author Markus Kraetzig */ public class JSCDataEvent { private final JSCData source; private final JSCDataEventTypes type; private final Object newValue; private final Object oldValue; /** * JSCDataEvent constructor. */ private JSCDataEvent( JSCData source, JSCDataEventTypes type, boolean newVal) { this(source, type, new Boolean(!newVal), new Boolean(newVal)); } /** * Creates a JSCDataEvent. * * @param source the source data object * @param type the type of this event * @param oldValue the value before the change * @param newValue the value after the change */ public JSCDataEvent( JSCData source, JSCDataEventTypes type, Object oldValue, Object newValue) { super(); this.source = source; this.type = type; this.oldValue = oldValue; this.newValue = newValue; } /** * Gets the value after the change. * * @return an arbitrary object */ public final Object getNewValue() { return newValue; } /** * Gets the value before the change. * * @return an arbitrary object */ public final Object getOldValue() { return oldValue; } /** * Gets the data object where the event was fired from. * * @return a JSCData object */ public final JSCData getSource() { return source; } /** * Gets the type of this event. * * @return one of JSCDataEventTypes */ public final JSCDataEventTypes getType() { return type; } /** * Gets a string representation of this. * * @return informative string representation */ public String toString() { return super.toString() + " [source:name=" + source.name() + ",type=" + source.type() + ";evttype=" + type + "]"; } /** * Gets an instance of this for events of type JSCDataEventTypes.VALUE_CHANGED. * * @param source the source from which the event is fired * @param oldValue the value before the change * @param newValue the value after the change * * @return a changed event */ public static JSCDataEvent valueOfChanged( JSCData source, Object oldValue, Object newValue) { return new JSCDataEvent( source, JSCDataEventTypes.VALUE_CHANGED, oldValue, newValue); } /** * Gets an instance of this for events of type JSCDataEventTypes.EMPTY_STATE. * * @param source the source from which the event is fired * @param isEmptyNow true if source is empty * @return a cleared event */ public static JSCDataEvent valueOfEmptyState( JSCData source, boolean isEmptyNow) { return new JSCDataEvent( source, JSCDataEventTypes.EMPTY_STATE, isEmptyNow); } /** * Gets the value after the change as a boolean. * * @return true if new value is a Boolean that is true, * false otherwise */ public final boolean isSourceEmpty() { if (newValue instanceof Boolean) return ((Boolean) newValue).booleanValue(); if (newValue == null) return false; // called last to avoid synchronization overhead if possible return source.isEmpty(); } }

Ads help maintain this website.