[569] | 1 | /* |
---|
| 2 | * $Id: ColorMap.java,v 1.14 2002/06/14 17:12:25 dwd Exp $ |
---|
| 3 | * |
---|
| 4 | * This software is provided by NOAA for full, free and open release. It is |
---|
| 5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
| 6 | * errors contained in the code. Although this software is released without |
---|
| 7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
| 8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
| 9 | * Administration should the software be included by the recipient as an |
---|
| 10 | * element in other product development. |
---|
| 11 | */ |
---|
| 12 | package gov.noaa.pmel.sgt; |
---|
| 13 | |
---|
| 14 | import gov.noaa.pmel.util.Range2D; |
---|
| 15 | import gov.noaa.pmel.util.Debug; |
---|
| 16 | |
---|
| 17 | import java.awt.*; |
---|
| 18 | import java.beans.PropertyChangeListener; |
---|
| 19 | import java.beans.PropertyChangeSupport; |
---|
| 20 | import java.beans.PropertyChangeEvent; |
---|
| 21 | import java.io.Serializable; |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * <code>ColorMap</code> provides a mapping from an index or |
---|
| 25 | * value to a <code>Color</code>. Several methods of mapping an |
---|
| 26 | * index or value to a <code>Color</code> are summarized below. <br> |
---|
| 27 | * |
---|
| 28 | * <DL> |
---|
| 29 | * <DT><CODE>IndexedColorMap</CODE></DT> |
---|
| 30 | * <DD><CODE>Color</CODE> is determined from an array, |
---|
| 31 | * the index computed from a <CODE>Transform</CODE>. |
---|
| 32 | * <DT><CODE>TransformColorMap</CODE></DT> |
---|
| 33 | * <DD>Red, green, blue <CODE>Color</CODE> components |
---|
| 34 | * are computed from <CODE>Transform</CODE>s. |
---|
| 35 | * <DT><CODE>CLIndexedColorMap</CODE></DT> |
---|
| 36 | * <DD><CODE>Color</CODE> is determined from and array, |
---|
| 37 | * the index computed from a <CODE>ContourLevels</CODE> object. |
---|
| 38 | * <DT><CODE>CLTransformColorMap</CODE></DT> |
---|
| 39 | * <DD>Red, green, blue <CODE>Color</CODE> components |
---|
| 40 | * are computed from <CODE>Transform</CODE>s, using |
---|
| 41 | * the index computed from a <CODE>ContourLevels</CODE> |
---|
| 42 | * object divided by the maximum index value. |
---|
| 43 | * </DL> |
---|
| 44 | * |
---|
| 45 | * |
---|
| 46 | * @author Donald Denbo |
---|
| 47 | * @version $Revision: 1.14 $, $Date: 2002/06/14 17:12:25 $ |
---|
| 48 | * @since 1.0 |
---|
| 49 | */ |
---|
| 50 | abstract public class ColorMap implements Cloneable, PropertyChangeListener, Serializable { |
---|
| 51 | private PropertyChangeSupport changes_ = new PropertyChangeSupport(this); |
---|
| 52 | protected boolean batch_ = false; |
---|
| 53 | protected boolean local_ = true; |
---|
| 54 | protected boolean modified_ = false; |
---|
| 55 | abstract public ColorMap copy(); |
---|
| 56 | /** |
---|
| 57 | * Get a <code>Color</code>. |
---|
| 58 | * |
---|
| 59 | * @param val Value |
---|
| 60 | * @return Color |
---|
| 61 | * |
---|
| 62 | */ |
---|
| 63 | abstract public Color getColor(double val); |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * Get the current user range for the <code>Transform</code>s or |
---|
| 67 | * <code>ContourLevel</code>. |
---|
| 68 | * |
---|
| 69 | * @return user range |
---|
| 70 | */ |
---|
| 71 | abstract public Range2D getRange(); |
---|
| 72 | /** |
---|
| 73 | * Test for equality of color maps. |
---|
| 74 | */ |
---|
| 75 | abstract public boolean equals(ColorMap cm); |
---|
| 76 | /** |
---|
| 77 | * Add listener to changes in <code>ColorMap</code> properties. |
---|
| 78 | */ |
---|
| 79 | public void addPropertyChangeListener(PropertyChangeListener listener) { |
---|
| 80 | changes_.addPropertyChangeListener(listener); |
---|
| 81 | } |
---|
| 82 | /** |
---|
| 83 | * Remove listener. |
---|
| 84 | */ |
---|
| 85 | public void removePropertyChangeListener(PropertyChangeListener listener) { |
---|
| 86 | changes_.removePropertyChangeListener(listener); |
---|
| 87 | } |
---|
| 88 | public void propertyChange(PropertyChangeEvent evt) { |
---|
| 89 | if(Debug.EVENT) { |
---|
| 90 | System.out.println("ColorMap: " + evt); |
---|
| 91 | System.out.println(" " + evt.getPropertyName()); |
---|
| 92 | } |
---|
| 93 | firePropertyChange(evt.getPropertyName(), |
---|
| 94 | evt.getOldValue(), |
---|
| 95 | evt.getNewValue()); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | protected void firePropertyChange(String name, Object oldValue, Object newValue) { |
---|
| 99 | if(batch_) { |
---|
| 100 | modified_ = true; |
---|
| 101 | return; |
---|
| 102 | } |
---|
| 103 | AttributeChangeEvent ace = new AttributeChangeEvent(this, name, |
---|
| 104 | oldValue, newValue, |
---|
| 105 | local_); |
---|
| 106 | changes_.firePropertyChange(ace); |
---|
| 107 | modified_ = false; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /** |
---|
| 111 | * Batch the changes to the ColorMap. |
---|
| 112 | * |
---|
| 113 | * @since 3.0 |
---|
| 114 | */ |
---|
| 115 | public void setBatch(boolean batch) { |
---|
| 116 | setBatch(batch, true); |
---|
| 117 | } |
---|
| 118 | /** |
---|
| 119 | * Batch the changes to the ColorMap and set local flag. |
---|
| 120 | * Determines whether <code>AttributeChangeEvent</code> will be set local. |
---|
| 121 | * |
---|
| 122 | * @since 3.0 |
---|
| 123 | */ |
---|
| 124 | public void setBatch(boolean batch, boolean local) { |
---|
| 125 | local_ = local; |
---|
| 126 | batch_ = batch; |
---|
| 127 | if(!batch && modified_) firePropertyChange("batch", Boolean.TRUE, Boolean.FALSE); |
---|
| 128 | } |
---|
| 129 | /** |
---|
| 130 | * Is the attribute in batch mode? |
---|
| 131 | * |
---|
| 132 | * @since 3.0 |
---|
| 133 | */ |
---|
| 134 | public boolean isBatch() { |
---|
| 135 | return batch_; |
---|
| 136 | } |
---|
| 137 | } |
---|