/*
 * $Id: GridAttribute.java,v 1.19 2003/08/22 23:02:32 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;

/**
 * Sets the rendering style for grid data.  ColorMap,
 * ContourLevels are GridAttribute properties.
 *
 * @author Donald Denbo
 * @version $Revision: 1.19 $, $Date: 2003/08/22 23:02:32 $
 * @since 1.0
 * @see GridCartesianRenderer
 * @see ContourLevels
 */
public class GridAttribute implements Attribute,
                                      Cloneable,
                                      PropertyChangeListener {
  private transient PropertyChangeSupport changes_ = new PropertyChangeSupport(this);
  // serial version ref 1.18
  private static final long serialVersionUID = 3822340406728567524L;
  private boolean batch_ = false;
  private boolean local_ = true;
  private boolean modified_ = false;
  private String id_ = null;
  /**@shapeType AggregationLink
   * @label cmap*/
  private ColorMap cmap_;
  /**@shapeType AggregationLink
   * @label clev*/
  private ContourLevels clev_;
  private int style_;
  /**
   * Raster style.
   */
  public static final int RASTER = 0;
  /**
   * Area fill style.
   **/
  public static final int AREA_FILL = 1;
  /**
   * Contour line style.
   */
  public static final int CONTOUR = 2;
  /**
   * Raster and Contour style.
   * @since 2.0
   */
  public static final int RASTER_CONTOUR = 3;
  /**
   * Area fill and Contour style.
   * @since 2.0
   */
  public static final int AREA_FILL_CONTOUR = 4;
  /**
   * Default constructor.  Default style is RASTER and
   * default ColorMap is null.
   **/
  public GridAttribute() {
    this(RASTER, null);
  }
  /**
   * GridAttribute constructor for RASTER and
   * AREA_FILL styles.
   *
   * @param style grid style
   * @param cmap ColorMap
   **/
  public GridAttribute(int style,ColorMap cmap) {
    style_ = style;
    cmap_ = cmap;
    if(cmap_ != null) cmap_.addPropertyChangeListener(this);
  }
  /**
   * GridAttribute constructor for CONTOUR style.
   *
   * @param clev ContourLevels
   */
  public GridAttribute(ContourLevels clev) {
    style_ = CONTOUR;
    cmap_ = null;
    clev_ = clev;
  }
  /**
   * Set the ContourLevels.
   * 
Property Change: contourLevels. * * @param clev ContourLevels */ public void setContourLevels(ContourLevels clev) { if(clev_ == null || !clev_.equals(clev)) { ContourLevels tempOld = clev_; clev_ = clev; firePropertyChange("contourLevels", tempOld, clev_); } } /** * Get the ContourLevels. * * @return ContourLevels */ public ContourLevels getContourLevels() { return clev_; } /** * Copy the GridAttribute. * * @return new GridAttribute */ public GridAttribute copy() { GridAttribute newGrid; try { newGrid = (GridAttribute)clone(); } catch (CloneNotSupportedException e) { newGrid = new GridAttribute(); } return newGrid; } /** * Set the grid style. *
Property Change: style. * * @param st grid style **/ public void setStyle(int st) { if(style_ != st) { Integer tempOld = new Integer(style_); style_ = st; firePropertyChange("style", tempOld, new Integer(style_)); } } /** * Get grid style. * * @return grid style **/ public int getStyle() { return style_; } /** * Tests if GridAttribute style is either * RASTER or RASTER_CONTOUR. * @since 2.0 */ public boolean isRaster() { return (style_ == RASTER || style_ == RASTER_CONTOUR); } /** * Tests if GridAttribute style is either * CONTOUR, RASTER_CONTOUR, or AREA_FILL_CONTOUR. * @since 2.0 */ public boolean isContour() { return (style_ == CONTOUR || style_ == RASTER_CONTOUR || style_ == AREA_FILL_CONTOUR); } /** * Tests if GridAttribute style is eigther * AREA_FILL or AREA_FILL_CONTOUR. * @since 2.0 */ public boolean isAreaFill() { return (style_ == AREA_FILL || style_ == AREA_FILL_CONTOUR); } /** * Get the ColorMap. * * @return the ColorMap **/ public ColorMap getColorMap() { return cmap_; } /** * Set the ColorMap. *
Property Change: colorMap. * * @param cmap the ColorMap */ public void setColorMap(ColorMap cmap) { if(cmap_ == null && cmap == null) { return; } else { if(cmap_ != null) cmap_.removePropertyChangeListener(this); if(cmap_ == null || !cmap_.equals(cmap)) { ColorMap tempOld = cmap_; cmap_ = cmap; firePropertyChange("colorMap", tempOld, cmap_); cmap_.addPropertyChangeListener(this); } } } /** * Get a String representation of the * GridAttribute. * * @return String representation */ public String toString() { String name = getClass().getName(); return name.substring(name.lastIndexOf(".")+1); } /** * Add listener to changes in GridAttribute properties. */ public void addPropertyChangeListener(PropertyChangeListener listener) { if(changes_ == null) changes_ = new PropertyChangeSupport(this); changes_.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { changes_.removePropertyChangeListener(listener); } public void propertyChange(PropertyChangeEvent evt) { if(Debug.EVENT) { System.out.println("GridAttribute: " + evt); System.out.println(" " + evt.getPropertyName()); } changes_.firePropertyChange(evt); } /** * @since 3.0 */ public void setId(String id) { id_ = id; } /** * @since 3.0 */ public String getId() { return id_; } 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; } /** * @since 3.0 */ public void setBatch(boolean batch) { setBatch(batch, true); } /** * @since 3.0 */ public void setBatch(boolean batch, boolean local) { local_ = local; batch_ = batch; if(!batch && modified_) firePropertyChange("batch", Boolean.TRUE, Boolean.FALSE); } /** * @since 3.0 */ public boolean isBatch() { return batch_; } }

Ads help maintain this website.