/* * $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
*
Red, green, blue Color components * are computed from Transforms. *
CLIndexedColorMap
*
Color is determined from and array, * the index computed from a ContourLevels object. *
CLTransformColorMap
*
Red, green, blue Color components * are computed from Transforms, using * the index computed from a ContourLevels * object divided by the maximum index value. *
* * * @author Donald Denbo * @version $Revision: 1.14 $, $Date: 2002/06/14 17:12:25 $ * @since 1.0 */ abstract public class ColorMap implements Cloneable, PropertyChangeListener, Serializable { private PropertyChangeSupport changes_ = new PropertyChangeSupport(this); protected boolean batch_ = false; protected boolean local_ = true; protected boolean modified_ = false; abstract public ColorMap copy(); /** * Get a Color. * * @param val Value * @return Color * */ abstract public Color getColor(double val); /** * Get the current user range for the Transforms 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_; } }