/*
* $Id: ColorMap.java,v 1.14 2002/06/14 17:12:25 dwd Exp $
*
* This software is provided by NOAA for full, free and open release. It is
* understood by the recipient/user that NOAA assumes no liability for any
* errors contained in the code. Although this software is released without
* conditions or restrictions in its use, it is expected that appropriate
* credit be given to its author and to the National Oceanic and Atmospheric
* Administration should the software be included by the recipient as an
* element in other product development.
*/
package gov.noaa.pmel.sgt;
import gov.noaa.pmel.util.Range2D;
import gov.noaa.pmel.util.Debug;
import java.awt.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeEvent;
import java.io.Serializable;
/**
* ColorMap
provides a mapping from an index or
* value to a Color
. Several methods of mapping an
* index or value to a Color
are summarized below.
*
*
IndexedColorMap
Color
is determined from an array,
* the index computed from a Transform
.
* TransformColorMap
Color
components
* are computed from Transform
s.
* CLIndexedColorMap
Color
is determined from and array,
* the index computed from a ContourLevels
object.
* CLTransformColorMap
Color
components
* are computed from Transform
s, using
* the index computed from a ContourLevels
* object divided by the maximum index value.
* Color
.
*
* @param val Value
* @return Color
*
*/
abstract public Color getColor(double val);
/**
* Get the current user range for the Transform
s or
* ContourLevel
.
*
* @return user range
*/
abstract public Range2D getRange();
/**
* Test for equality of color maps.
*/
abstract public boolean equals(ColorMap cm);
/**
* Add listener to changes in ColorMap
properties.
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
changes_.addPropertyChangeListener(listener);
}
/**
* Remove listener.
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
changes_.removePropertyChangeListener(listener);
}
public void propertyChange(PropertyChangeEvent evt) {
if(Debug.EVENT) {
System.out.println("ColorMap: " + evt);
System.out.println(" " + evt.getPropertyName());
}
firePropertyChange(evt.getPropertyName(),
evt.getOldValue(),
evt.getNewValue());
}
protected void firePropertyChange(String name, Object oldValue, Object newValue) {
if(batch_) {
modified_ = true;
return;
}
AttributeChangeEvent ace = new AttributeChangeEvent(this, name,
oldValue, newValue,
local_);
changes_.firePropertyChange(ace);
modified_ = false;
}
/**
* Batch the changes to the ColorMap.
*
* @since 3.0
*/
public void setBatch(boolean batch) {
setBatch(batch, true);
}
/**
* Batch the changes to the ColorMap and set local flag.
* Determines whether AttributeChangeEvent
will be set local.
*
* @since 3.0
*/
public void setBatch(boolean batch, boolean local) {
local_ = local;
batch_ = batch;
if(!batch && modified_) firePropertyChange("batch", Boolean.TRUE, Boolean.FALSE);
}
/**
* Is the attribute in batch mode?
*
* @since 3.0
*/
public boolean isBatch() {
return batch_;
}
}