/*
* $Id: TransformColorMap.java,v 1.6 2002/06/12 18:47:26 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 sgtplot;
import java.awt.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeEvent;
import sgtplot.util.Debug;
import sgtplot.util.Range2D;
/**
* TransformColorMap provides a mapping from a value
* to a Color.
*
* @author Donald Denbo
* @version $Revision: 1.6 $, $Date: 2002/06/12 18:47:26 $
* @since 2.0
*/
public class TransformColorMap extends ColorMap
implements Cloneable, PropertyChangeListener,
TransformColor, TransformAccess {
/**
* Red Transform
* @supplierCardinality 0..1
* @clientRole rTrans_
* @link aggregationByValue
*/
private Transform rTrans_ = null;
/**
* Green Transform
* @supplierCardinality 0..1
* @clientRole gTrans_
* @link aggregationByValue
*/
private Transform gTrans_ = null;
/**
* Blue Transform
* @supplierCardinality 0..1
* @clientRole bTrans_
* @link aggregationByValue
*/
private Transform bTrans_ = null;
/**
* Initialize the color map to use red, green, and blue transforms. Sets up
* ColorMap for TRANSFORM access.
* Each Transform should have identical user
* ranges. The physical range will be set to 0.0 to 1.0 for each
* color component.
*
* @see Transform
*/
public TransformColorMap(Transform rTrans,Transform gTrans,Transform bTrans) {
rTrans_ = rTrans;
rTrans_.setRangeP(0.0, 1.0);
gTrans_ = gTrans;
gTrans_.setRangeP(0.0, 1.0);
bTrans_ = bTrans;
bTrans_.setRangeP(0.0, 1.0);
}
/**
* Create a copy of the ColorMap object.
*/
public ColorMap copy() {
ColorMap newMap;
try {
newMap = (ColorMap)clone();
} catch (CloneNotSupportedException e) {
newMap = null;
}
return newMap;
}
/**
* Get a Color. Returns a Color by
* one of four methods. INDEXED, TRANSFORM,
* LEVEL_INDEXED, and LEVEL_TRANSFORM.
*
* @param val Value
* @return Color
*
*/
public Color getColor(double val) {
double ival = val;
float red = (float)rTrans_.getTransP(ival);
float green = (float)gTrans_.getTransP(ival);
float blue = (float)bTrans_.getTransP(ival);
return new Color(red, green, blue);
}
/**
* Set the user range for all the Transforms.
*
*/
public void setRange(Range2D range) {
rTrans_.setRangeU(range);
gTrans_.setRangeU(range);
bTrans_.setRangeU(range);
}
/**
* Get the current user range for the Transforms.
*
* @return user range
*/
public Range2D getRange() {
return rTrans_.getRangeU();
}
/**
* Set the color Transforms.
*
Property Change: redColorTransform,
* greenColorTransform, and
* blueColorTransform.
*
* @param rTrans red Transform
* @param gTrans green Transform
* @param bTrans blue Transform
*/
public void setColorTransforms(Transform rTrans,
Transform gTrans,
Transform bTrans) {
if(!rTrans_.equals(rTrans) ||
!gTrans_.equals(gTrans) ||
!bTrans_.equals(bTrans)) {
if(rTrans_ != null) rTrans_.removePropertyChangeListener(this);
if(gTrans_ != null) gTrans_.removePropertyChangeListener(this);
if(bTrans_ != null) bTrans_.removePropertyChangeListener(this);
Transform tempOld = rTrans_;
rTrans_ = rTrans;
rTrans_.setRangeP(0.0, 1.0);
firePropertyChange("redColorTransform",
tempOld,
rTrans_);
tempOld = gTrans_;
gTrans_ = gTrans;
gTrans_.setRangeP(0.0, 1.0);
firePropertyChange("greenColorTransform",
tempOld,
gTrans_);
tempOld = bTrans_;
bTrans_ = bTrans;
bTrans_.setRangeP(0.0, 1.0);
firePropertyChange("blueColorTransform",
tempOld,
bTrans_);
rTrans_.addPropertyChangeListener(this);
gTrans_.addPropertyChangeListener(this);
bTrans_.addPropertyChangeListener(this);
}
}
/**
* Set the red color Transform
*/
public void setRedTransform(Transform red) {
rTrans_ = red;
}
/**
* Get the red color Transform.
*
* @return red Transform
*/
public Transform getRedTransform() {
return rTrans_;
}
/**
* Set the green color Transform
*/
public void setGreenTransform(Transform green) {
gTrans_ = green;
}
/**
* Get the green color Transform.
*
* @return green Transform
*/
public Transform getGreenTransform() {
return gTrans_;
}
/**
* Set the blue color Transform
*/
public void setBlueTransform(Transform blue) {
bTrans_ = blue;
}
/**
* Get the blue color Transform.
*
* @return blue Transform
*/
public Transform getBlueTransform() {
return bTrans_;
}
public boolean equals(ColorMap cm) {
if(cm == null || !(cm instanceof TransformColorMap)) return false;
if(!(rTrans_.equals(((TransformColorMap)cm).rTrans_) &&
gTrans_.equals(((TransformColorMap)cm).gTrans_) &&
bTrans_.equals(((TransformColorMap)cm).bTrans_))) return false;
return true;
}
}
Ads help maintain this website.