Search in sources :

Example 1 with RangeRenderer

use of com.serotonin.m2m2.view.text.RangeRenderer in project ma-modules-public by infiniteautomation.

the class TextRendererFactory method updateDataPoint.

/**
 * @param data
 * @param renderer
 */
public static void updateDataPoint(DataPointVO vo, BaseTextRendererModel<?> baseRendererModel) {
    if (baseRendererModel.getType().equals(AnalogRenderer.getDefinition().getName())) {
        AnalogTextRendererModel model = (AnalogTextRendererModel) baseRendererModel;
        AnalogRenderer r = new AnalogRenderer();
        r.setUseUnitAsSuffix(model.isUseUnitAsSuffix());
        r.setUnit(UnitUtil.parseLocal(model.getUnit()));
        r.setRenderedUnit(UnitUtil.parseLocal(model.getRenderedUnit()));
        r.setFormat(model.getFormat());
        r.setSuffix(model.getSuffix());
        vo.setTextRenderer(r);
    } else if (baseRendererModel.getType().equals(BinaryTextRenderer.getDefinition().getName())) {
        BinaryTextRendererModel model = (BinaryTextRendererModel) baseRendererModel;
        BinaryTextRenderer btr = new BinaryTextRenderer();
        btr.setOneColour(model.getOneColour());
        btr.setOneLabel(model.getOneLabel());
        btr.setZeroColour(model.getZeroColour());
        btr.setZeroLabel(model.getZeroLabel());
        vo.setTextRenderer(btr);
    } else if (baseRendererModel.getType().equals(MultistateRenderer.getDefinition().getName())) {
        MultistateRenderer r = new MultistateRenderer();
        MultistateTextRendererModel model = (MultistateTextRendererModel) baseRendererModel;
        r.setMultistateValues(model.getMultistateValues());
        vo.setTextRenderer(r);
    } else if (baseRendererModel.getType().equals(NoneRenderer.getDefinition().getName())) {
        NoneRenderer r = new NoneRenderer();
        vo.setTextRenderer(r);
    } else if (baseRendererModel.getType().equals(PlainRenderer.getDefinition().getName())) {
        PlainTextRendererModel model = (PlainTextRendererModel) baseRendererModel;
        PlainRenderer r = new PlainRenderer();
        r.setUseUnitAsSuffix(model.isUseUnitAsSuffix());
        r.setUnit(UnitUtil.parseLocal(model.getUnit()));
        r.setRenderedUnit(UnitUtil.parseLocal(model.getRenderedUnit()));
        r.setSuffix(model.getSuffix());
        vo.setTextRenderer(r);
    } else if (baseRendererModel.getType().equals(RangeRenderer.getDefinition().getName())) {
        RangeTextRendererModel model = (RangeTextRendererModel) baseRendererModel;
        RangeRenderer r = new RangeRenderer();
        r.setUseUnitAsSuffix(model.isUseUnitAsSuffix());
        r.setUnit(UnitUtil.parseLocal(model.getUnit()));
        r.setRenderedUnit(UnitUtil.parseLocal(model.getRenderedUnit()));
        r.setFormat(model.getFormat());
        r.setRangeValues(model.getRangeValues());
        vo.setTextRenderer(r);
    } else if (baseRendererModel.getType().equals(TimeRenderer.getDefinition().getName())) {
        TimeRenderer r = new TimeRenderer();
        TimeTextRendererModel model = (TimeTextRendererModel) baseRendererModel;
        r.setFormat(model.getFormat());
        r.setConversionExponent(model.getConversionExponent());
        vo.setTextRenderer(r);
    } else {
        throw new ShouldNeverHappenException("Unknown Text Renderer: " + baseRendererModel.getType());
    }
}
Also used : PlainRenderer(com.serotonin.m2m2.view.text.PlainRenderer) NoneRenderer(com.serotonin.m2m2.view.text.NoneRenderer) TimeRenderer(com.serotonin.m2m2.view.text.TimeRenderer) BinaryTextRenderer(com.serotonin.m2m2.view.text.BinaryTextRenderer) MultistateRenderer(com.serotonin.m2m2.view.text.MultistateRenderer) RangeRenderer(com.serotonin.m2m2.view.text.RangeRenderer) AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 2 with RangeRenderer

use of com.serotonin.m2m2.view.text.RangeRenderer in project ma-modules-public by infiniteautomation.

the class TextRendererFactory method createModel.

/**
 * @param vo
 * @return
 */
public static BaseTextRendererModel<?> createModel(DataPointVO vo) {
    TextRenderer renderer = vo.getTextRenderer();
    // For when a VO is created that has no renderer
    if (renderer == null)
        return new NoneTextRendererModel();
    if (renderer.getTypeName().equals(AnalogRenderer.getDefinition().getName())) {
        AnalogRenderer r = (AnalogRenderer) renderer;
        AnalogTextRendererModel model = new AnalogTextRendererModel(r.isUseUnitAsSuffix(), UnitUtil.formatLocal(r.getUnit()), UnitUtil.formatLocal(r.getRenderedUnit()), r.getFormat(), r.getSuffix());
        return model;
    } else if (renderer.getTypeName().equals(BinaryTextRenderer.getDefinition().getName())) {
        BinaryTextRendererModel model = new BinaryTextRendererModel();
        BinaryTextRenderer btr = (BinaryTextRenderer) renderer;
        model.setOneColour(btr.getOneColour());
        model.setOneLabel(btr.getOneLabel());
        model.setZeroColour(btr.getZeroColour());
        model.setZeroLabel(btr.getZeroLabel());
        return model;
    } else if (renderer.getTypeName().equals(MultistateRenderer.getDefinition().getName())) {
        MultistateRenderer r = (MultistateRenderer) renderer;
        MultistateTextRendererModel model = new MultistateTextRendererModel(r.getMultistateValues());
        return model;
    } else if (renderer.getTypeName().equals(NoneRenderer.getDefinition().getName())) {
        return new NoneTextRendererModel();
    }
    if (renderer.getTypeName().equals(PlainRenderer.getDefinition().getName())) {
        PlainRenderer r = (PlainRenderer) renderer;
        PlainTextRendererModel model = new PlainTextRendererModel(r.isUseUnitAsSuffix(), UnitUtil.formatLocal(r.getUnit()), UnitUtil.formatLocal(r.getRenderedUnit()), r.getSuffix());
        return model;
    } else if (renderer.getTypeName().equals(RangeRenderer.getDefinition().getName())) {
        RangeRenderer r = (RangeRenderer) renderer;
        RangeTextRendererModel model = new RangeTextRendererModel(r.isUseUnitAsSuffix(), UnitUtil.formatLocal(r.getUnit()), UnitUtil.formatLocal(r.getRenderedUnit()), r.getFormat(), r.getRangeValues());
        return model;
    } else if (renderer.getTypeName().equals(TimeRenderer.getDefinition().getName())) {
        TimeRenderer r = (TimeRenderer) renderer;
        TimeTextRendererModel model = new TimeTextRendererModel(r.getFormat(), r.getConversionExponent());
        return model;
    } else {
        throw new ShouldNeverHappenException("Unknown Text Renderer: " + renderer.getDef().getName());
    }
}
Also used : PlainRenderer(com.serotonin.m2m2.view.text.PlainRenderer) TimeRenderer(com.serotonin.m2m2.view.text.TimeRenderer) BinaryTextRenderer(com.serotonin.m2m2.view.text.BinaryTextRenderer) MultistateRenderer(com.serotonin.m2m2.view.text.MultistateRenderer) RangeRenderer(com.serotonin.m2m2.view.text.RangeRenderer) AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) BinaryTextRenderer(com.serotonin.m2m2.view.text.BinaryTextRenderer) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Example 3 with RangeRenderer

use of com.serotonin.m2m2.view.text.RangeRenderer in project ma-core-public by infiniteautomation.

the class DataPointEditDwr method setRangeRenderer.

@DwrPermission(user = true)
public void setRangeRenderer(String format, List<RangeValue> values) {
    RangeRenderer r = new RangeRenderer(format);
    for (RangeValue v : values) r.addRangeValues(v.getFrom(), v.getTo(), v.getText(), v.getColour());
    setTextRenderer(r);
}
Also used : RangeRenderer(com.serotonin.m2m2.view.text.RangeRenderer) RangeValue(com.serotonin.m2m2.view.text.RangeValue) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

RangeRenderer (com.serotonin.m2m2.view.text.RangeRenderer)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 AnalogRenderer (com.serotonin.m2m2.view.text.AnalogRenderer)2 BinaryTextRenderer (com.serotonin.m2m2.view.text.BinaryTextRenderer)2 MultistateRenderer (com.serotonin.m2m2.view.text.MultistateRenderer)2 PlainRenderer (com.serotonin.m2m2.view.text.PlainRenderer)2 TimeRenderer (com.serotonin.m2m2.view.text.TimeRenderer)2 NoneRenderer (com.serotonin.m2m2.view.text.NoneRenderer)1 RangeValue (com.serotonin.m2m2.view.text.RangeValue)1 TextRenderer (com.serotonin.m2m2.view.text.TextRenderer)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1