org.geotoolkit.parameter.AbstractParameterValue Maven / Gradle / Ivy
/*
* Geotoolkit.org - An Open Source Java GIS Toolkit
* http://www.geotoolkit.org
*
* (C) 2012, Open Source Geospatial Foundation (OSGeo)
* (C) 2012, Geomatys
*
* 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;
* version 2.1 of the License.
*
* 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.
*
* This package contains documentation from OpenGIS specifications.
* OpenGIS consortium's work is fully acknowledged here.
*/
package org.geotoolkit.parameter;
import javax.swing.event.ChangeListener;
import org.opengis.parameter.ParameterValue;
import org.opengis.parameter.ParameterDescriptor;
import org.geotoolkit.internal.Listeners;
/**
* The base class of {@link ParameterValue} implementations. This base class provides support
* for {@link ChangeListener} notifications. Those change listeners are not included in the
* serialization neither in {@linkplain #clone() cloned} objects.
*
* {@section Future changes planned for listeners}
* The current implementation leverages the Swing {@link ChangeListener} interface (note that it
* does not cause a large dependency toward the Swing framework). However future Geotk versions
* will implement the JavaFX {@code ObservableValue} interface and replace all Swing
* {@link ChangeListener} by JavaFX {@code ChangeListener} dependencies. This replacement will
* happen on the JDK8 branch. The JDK7 and JDK6 branches will continue to use the Swing listener.
*
* @param The value type.
*
* @author Martin Desruisseaux (Geomatys)
* @version 3.20
*
* @since 3.20
* @module
*/
public abstract class AbstractParameterValue extends AbstractParameter implements ParameterValue {
/**
* Serial number for inter-operability with different versions.
*/
private static final long serialVersionUID = 4166422894375776520L;
/**
* The listeners, or {@code null} if none.
*/
private transient ChangeListener[] listeners;
/**
* Constructs a parameter value from the specified descriptor.
*
* @param descriptor The abstract definition of this parameter.
*/
protected AbstractParameterValue(final ParameterDescriptor descriptor) {
super(descriptor);
}
/**
* Returns the abstract definition of this parameter.
*/
@Override
@SuppressWarnings("unchecked") // Type checked by the constructor.
public ParameterDescriptor getDescriptor() {
return (ParameterDescriptor) super.getDescriptor();
}
/**
* Adds the specified listener to the list of objects to inform when the value changed.
* Notes:
*
* - Change listeners are not serialized
* - Change listeners are not included in {@linkplain #clone() cloned} object.
*
*
* @param listener The listener to add.
*/
public void addChangeListener(final ChangeListener listener) {
listeners = Listeners.addListener(listener, listeners);
}
/**
* Removes the specified listener from the list of objects to inform when the value changed.
*
* @param listener The listener to remove.
*/
public void removeChangeListener(final ChangeListener listener) {
listeners = Listeners.removeListener(listener, listeners);
}
/**
* Informs every listeners that the value changed.
*/
final void fireValueChanged() {
Listeners.fireChanged(this, listeners);
}
/**
* Returns a clone of this parameter. The clone does not include any change listener.
*/
@Override
public AbstractParameterValue clone() {
@SuppressWarnings("unchecked")
final AbstractParameterValue copy = (AbstractParameterValue) super.clone();
copy.listeners = null;
return copy;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy