Exemplo n.º 1
0
  /**
   * Returns a best guess for the conversion to use for a given selected column. This will be one of
   * the ones associated with this selector (i.e. one of the ones in the conversion selector or the
   * sole one if there is no conversion selector).
   *
   * @param cinfo column description
   * @return suitable column converter
   */
  private ColumnConverter guessConverter(ColumnInfo cinfo) {

    /* If there is only one permissible converter, return that. */
    if (converter0_ != null) {
      return converter0_;
    }

    /* Otherwise, try to get clever.  This is currently done on a
     * case-by-case basis rather than using an extensible framework
     * because there's a small number (1) of conversions that we know
     * about.  If there were many, a redesign might be in order. */
    String units = info_.getUnitString();
    String cunits = cinfo.getUnitString();
    if (units != null && cunits != null) {
      units = units.toLowerCase();
      cunits = cunits.toLowerCase();
      int nconv = convChooser_.getSize();
      if (units.equals("radian") || units.equals("radians")) {
        if (cunits.startsWith("rad")) {
          for (int i = 0; i < nconv; i++) {
            ColumnConverter conv = (ColumnConverter) convChooser_.getElementAt(i);
            if (conv.toString().toLowerCase().startsWith("rad")) {
              return conv;
            }
          }
        } else if (cunits.startsWith("deg")) {
          for (int i = 0; i < nconv; i++) {
            ColumnConverter conv = (ColumnConverter) convChooser_.getElementAt(i);
            if (conv.toString().toLowerCase().startsWith("deg")) {
              return conv;
            }
          }
        } else if (cunits.startsWith("hour") || cunits.equals("hr") || cunits.equals("hrs")) {
          for (int i = 0; i < nconv; i++) {
            ColumnConverter conv = (ColumnConverter) convChooser_.getElementAt(i);
            if (conv.toString().toLowerCase().startsWith("hour")) {
              return conv;
            }
          }
        } else if (cunits.startsWith("arcmin")) {
          for (int i = 0; i < nconv; i++) {
            ColumnConverter conv = (ColumnConverter) convChooser_.getElementAt(i);
            if (conv.toString().toLowerCase().startsWith("arcmin")) {
              return conv;
            }
          }
        } else if (cunits.startsWith("arcsec")) {
          for (int i = 0; i < nconv; i++) {
            ColumnConverter conv = (ColumnConverter) convChooser_.getElementAt(i);
            if (conv.toString().toLowerCase().startsWith("arcsec")) {
              return conv;
            }
          }
        }
      }
    }

    /* Return null if we haven't found a match yet. */
    return null;
  }
Exemplo n.º 2
0
  /**
   * Constructs a new model for a given table and value type.
   *
   * @param tcModel table model
   * @param info description of the kind of column which is required
   */
  public ColumnSelectorModel(TopcatModel tcModel, ValueInfo info) {
    info_ = info;
    selectionListener_ = new SelectionListener();

    /* Get a suitable model for selection of the unit converter, if
     * appropriate. */
    String units = info.getUnitString();
    ColumnConverter[] converters = ColumnConverter.getConverters(info);
    if (converters.length > 1) {
      converter0_ = null;
      convChooser_ = new DefaultComboBoxModel(converters);
      convChooser_.addListDataListener(selectionListener_);
    } else {
      convChooser_ = null;
      converter0_ = converters[0];
    }

    setTable(tcModel);
  }