/** Creates a new instance of VariationsTableModel */ public VariationsTableModel() { _rows = VariationsFactory.getVariationQuantity(); int maxAdditionalParams = 0; _parameters.ensureCapacity(_rows); _coefficients.ensureCapacity(_rows); for (int i = 0; i < _rows; i++) { _coefficients.add(Double.valueOf(0)); IVariation tmp = VariationsFactory.getVariation(i, Double.valueOf(0)); int parametersQuantity = tmp.getParametersQuantity(); ArrayList<Double> parameters = new ArrayList<>(parametersQuantity); for (int j = 0; j < parametersQuantity; j++) { parameters.add(Double.valueOf(0)); } _parameters.add(parameters); if (maxAdditionalParams < parametersQuantity) { maxAdditionalParams = parametersQuantity; } } _columns = 2 + maxAdditionalParams; }
/** * Returns IVariation object corresponding to the given row. * * @param row row index * @return Variation object */ public IVariation getVariation(int row) { IVariation temp = VariationsFactory.getVariation(row, _coefficients.get(row)); temp.setCoefficient(_coefficients.get(row)); if (temp.getParametersQuantity() > 0) { ArrayList<Double> parTemp = new ArrayList<>(_parameters.get(row)); temp.setParameters(parTemp); } return temp; }
/** * Sets model values according to the given variations * * @param variations variations vector */ public void setVariations(ArrayList<IVariation> variations) { reset(); variations .stream() .forEach( (variation) -> { int row = VariationsFactory.getVariationIndex(variation.getName()); setValueAt(variation.getName(), row, 0); setValueAt(Double.toString(variation.getCoefficient()), row, 1); setValueAt(variation.getParameters(), row, 2); }); }
@Override public Object getValueAt(int row, int col) { if (row < 0 || row >= _rows || col < 0 || col >= _columns) { return null; } else { if (col == 0) { return VariationsFactory.getVariationName(row); } else if (col == 1) { return _coefficients.get(row); } else { int paramIndex = col - 2; ArrayList<Double> additionalParams = _parameters.get(row); if (paramIndex < additionalParams.size()) { return additionalParams.get(paramIndex); } else { return ""; } } } }