Package simtools.ui

Source Code of simtools.ui.DoubleValueMapper$DoubleValueMapperTableModel

package simtools.ui;

import java.util.Iterator;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.JDialog;

import simtools.data.DataSource;


public class DoubleValueMapper extends GenericMapper {


  /**
   *
   */
  private static final long serialVersionUID = 6584365544886433242L;

  public static ResourceBundle resources = ResourceFinder.get(DoubleValueMapper.class);

  protected int doubleIndex = 0;

  /** The text mappers are application global */
  public static Vector doubleValueMappers;
  static{
    doubleValueMappers = new Vector();
  }


  public DoubleValueMapper() {
    super();
  }
 
 
  /**
   * @param name
   */
  public DoubleValueMapper(String name) {
    super(name);
  }

 
  /**
   * If the mapper already exists in the list, update its values
   * Otherwise add it to the list of existing mappers
   * @param m, the mapper to update
   * @return
   */
  public static DoubleValueMapper updateDoubleValueMapper(DoubleValueMapper m) {
      DoubleValueMapper ret = DoubleValueMapper.getDoubleMapper(m.toString());

      if (ret ==null){
          doubleValueMappers.add(m);
          ret = m;
      }
      return ret;
  }
   
  /**
   * Method <b>getDoubleMapper<\b> returns mapper linked to specified name
   * return null if no mapper were found
   * @param name
   * @return
   */
  public static DoubleValueMapper getDoubleMapper(String id) {
    if (doubleValueMappers != null) {
      for (Iterator it = doubleValueMappers.iterator(); it.hasNext(); ) {
        DoubleValueMapper sm = (DoubleValueMapper)it.next();
        if ((sm.toString()!=null) && (sm.toString().equals(id)))
          return sm;
      }
    }
    return null;
  }
 

  /**
   * Realizes the mapping, and returns a Double object for this data source and index
   * @param ds The data source to map
   * @param index The index in the data source (may be used, or not)
   * @return a Double object
   */
  public Double getDouble(DataSource ds, long index) {
    return (Double)getMapping(ds,index);
  }

  public Double getDouble(DataSource ds) {
    return (Double)getMapping(ds);
  }

  public Double getDouble(Object value) {
    return (Double)getMapping(value);
  }

  public void setDefaultDouble(Double defaultValue) {
    super.setDefaultValue(defaultValue);
  }

  public Double getDefaultDouble() {
    return (Double)super.getDefaultValue();
  }
 
  /** Associate a Double with a value */
  public void setDouble(Object value, Double doublevalue) {
    setMapping(value,doublevalue);
  }

  /** Associate a string with a double value interval (bounds included) */
  public void setDouble(double minvalue, double maxvalue, Double doublevalue) {
    setMapping(minvalue, true, maxvalue, true, doublevalue);
  }

  /** Associate a string with a double value interval. Interval bounds are specified */
  public void setDouble(double minvalue, boolean boundedMin, double maxvalue, boolean boundedMax, Double doublevalue) {
    setMapping(minvalue,boundedMin,maxvalue,boundedMax,doublevalue);
  }

  /** Associate a string with a double value infinite range (bound included).
   * @param isMore if true, the interval is x &gt;= value, else it is x &lt;= value
   */
  public void setDouble(boolean isMore, double value, Double doublevalue) {
    setMapping(isMore, value, true, doublevalue);
  }

  /** Associate a string with a double value infinite range.
   * @param isMore if true, the interval is x &gt;= value, else it is x &lt;= value
   */
  public void setDouble(boolean isMore, double value, boolean boundIncluded, Double doublevalue) {
    setMapping(isMore, value, boundIncluded, doublevalue);
  }

  /** Associate a string with a long value interval (bounds included) */
  public void setDouble(long minvalue, long maxvalue, Double doublevalue) {
    setMapping(minvalue, true, maxvalue, true, doublevalue);
  }

  /** Associate a string with a long value interval. Interval bounds are specified */
  public void setDouble(long minvalue, boolean boundedMin, long maxvalue, boolean boundedMax, Double doublevalue) {
    setMapping(minvalue,boundedMin,maxvalue,boundedMax,doublevalue);
  }

  /** Associate a string with a long value infinite range (bound included).
   * @param isMore if true, the interval is x &gt;= value, else it is x &lt;= value
   */
  public void setDouble(boolean isMore, long value, Double doublevalue) {
    setMapping(isMore, value, true, doublevalue);
  }

  /** Associate a string with a long value infinite range.
   * @param isMore if true, the interval is x &gt;= value, else it is x &lt;= value
   */
  public void setDouble(boolean isMore, long value, boolean boundIncluded, Double doublevalue) {
    setMapping(isMore, value, boundIncluded, doublevalue);
  }

  /** Associate a string with a String value interval (bounds included) */
  public void setDouble(String minvalue, String maxvalue, Double doublevalue) {
    setMapping(minvalue, true, maxvalue, true, doublevalue);
  }

  /** Associate a string with a String value interval. Interval bounds are specified */
  public void setDouble(String minvalue, boolean boundedMin, String maxvalue, boolean boundedMax, Double doublevalue) {
    setMapping(minvalue,boundedMin,maxvalue,boundedMax,doublevalue);
  }

  /** Associate a string with a String value infinite range (bound included).
   * @param isMore if true, the interval is x &gt;= value, else it is x &lt;= value
   */
  public void setDouble(boolean isMore, String value, Double doublevalue) {
    setMapping(isMore, value, true, doublevalue);
  }

  /** Associate a string with a String value infinite range.
   * @param isMore if true, the interval is x &gt;= value, else it is x &lt;= value
   */
  public void setDouble(boolean isMore, String value, boolean boundIncluded, Double doublevalue) {
    setMapping(isMore, value, boundIncluded, doublevalue);
  }


  public MapperTableModel createModel() {
    return new DoubleValueMapperTableModel();
  }
 
  protected class DoubleValueMapperTableModel extends MapperTableModel {
   
    public Class getColumnClass(int c) {
      if (c==1) return Double.class;
      return super.getColumnClass(c);
    }

    public String getColumnName(int col) {
      if (col==1) return resources.getString("Value");
      return super.getColumnName(col);
    }

    public boolean isCellEditable(int row, int col) {
      if (col==1) return true;
      return super.isCellEditable(row, col);
    }
  }
 
  protected Object createNewValue() {
    return new Double(doubleIndex++);
  }
 
  public static DoubleValueMapper createDoubleValueMapperDialog(JDialog owner) {
    DoubleValueMapper cm = new DoubleValueMapper();
    cm.editDialog(owner);
    return cm;
  }
 
 

  public static void main(String[] args) {
//    GenericMapper cm = new GenericMapper();
    DoubleValueMapper cm = new DoubleValueMapper();
    cm.setMapping(new Long(3),new Double(1));
    cm.setMapping(new Long(4),new Double(2));
    cm.setMapping(5,10,new Double(3));
    cm.setMapping(8,20,new Double(1));
    cm.setMapping(-18,7,new Double(5));
    cm.editDialog(new JDialog());
    System.exit(0);   
  }

 
}
TOP

Related Classes of simtools.ui.DoubleValueMapper$DoubleValueMapperTableModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.