Search in sources :

Example 1 with ColorModelRange

use of org.knime.core.data.property.ColorModelRange in project knime-core by knime.

the class ColorExtractNodeModel method extractColorTable.

private DataTable extractColorTable(final DataTableSpec colorSpec) throws InvalidSettingsException {
    // first column has column handler (convention in ColorHandlerPO)
    ColorHandler clrHdl = colorSpec.getColumnSpec(0).getColorHandler();
    final ColorModel model = clrHdl.getColorModel();
    if (model.getClass() == ColorModelNominal.class) {
        ColorModelNominal nom = (ColorModelNominal) model;
        return extractColorTable(nom);
    } else if (model.getClass() == ColorModelRange.class) {
        ColorModelRange range = (ColorModelRange) model;
        return extractColorTable(range);
    } else {
        throw new InvalidSettingsException("Unknown ColorModel class: " + model.getClass());
    }
}
Also used : ColorModelRange(org.knime.core.data.property.ColorModelRange) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ColorModel(org.knime.core.data.property.ColorHandler.ColorModel) ColorModelNominal(org.knime.core.data.property.ColorModelNominal) ColorHandler(org.knime.core.data.property.ColorHandler)

Example 2 with ColorModelRange

use of org.knime.core.data.property.ColorModelRange in project knime-core by knime.

the class ColorManager2NodeModel method createRangeColorHandler.

private static final ColorHandler createRangeColorHandler(final DataCell lower, final DataCell upper, final Map<DataCell, ColorAttr> map) {
    assert map.size() == 2;
    Color c0 = map.get(MIN_VALUE).getColor();
    Color c1 = map.get(MAX_VALUE).getColor();
    double d0 = Double.NaN;
    if (lower != null && !lower.isMissing() && lower.getType().isCompatible(DoubleValue.class)) {
        d0 = ((DoubleValue) lower).getDoubleValue();
    }
    double d1 = Double.NaN;
    if (upper != null && !upper.isMissing() && upper.getType().isCompatible(DoubleValue.class)) {
        d1 = ((DoubleValue) upper).getDoubleValue();
    }
    return new ColorHandler(new ColorModelRange(d0, c0, d1, c1));
}
Also used : ColorModelRange(org.knime.core.data.property.ColorModelRange) DoubleValue(org.knime.core.data.DoubleValue) Color(java.awt.Color) ColorHandler(org.knime.core.data.property.ColorHandler)

Aggregations

ColorHandler (org.knime.core.data.property.ColorHandler)2 ColorModelRange (org.knime.core.data.property.ColorModelRange)2 Color (java.awt.Color)1 DoubleValue (org.knime.core.data.DoubleValue)1 ColorModel (org.knime.core.data.property.ColorHandler.ColorModel)1 ColorModelNominal (org.knime.core.data.property.ColorModelNominal)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1