Search in sources :

Example 1 with AnalogRenderer

use of com.serotonin.m2m2.view.text.AnalogRenderer 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 AnalogRenderer

use of com.serotonin.m2m2.view.text.AnalogRenderer 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 AnalogRenderer

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

the class InternalDataSourceRT method getIntegerAnalogSuffixRenderer.

private AnalogRenderer getIntegerAnalogSuffixRenderer(String suffix) {
    AnalogRenderer result = new AnalogRenderer();
    result.setUseUnitAsSuffix(false);
    result.setSuffix(suffix);
    result.setFormat("0");
    return result;
}
Also used : AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer)

Example 4 with AnalogRenderer

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

the class InternalMenuItem method maybeCreatePoints.

/**
 */
private void maybeCreatePoints(boolean safe, DataSourceVO<?> vo) {
    Map<String, ValueMonitor<?>> monitors = getAllHomePageMonitors();
    Iterator<String> it = monitors.keySet().iterator();
    while (it.hasNext()) {
        String xid = it.next();
        ValueMonitor<?> monitor = monitors.get(xid);
        if (monitor != null) {
            DataPointVO dp = DataPointDao.instance.getByXid(xid);
            if (dp == null) {
                InternalPointLocatorVO pl = new InternalPointLocatorVO();
                pl.setMonitorId(monitor.getId());
                dp = new DataPointVO();
                dp.setXid(xid);
                dp.setName(monitor.getName().translate(Common.getTranslations()));
                dp.setDataSourceId(vo.getId());
                dp.setDeviceName(vo.getName());
                dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
                dp.defaultTextRenderer();
                dp.setEnabled(true);
                dp.setChartColour("");
                dp.setPointLocator(pl);
                // Use default template
                DataPointPropertiesTemplateVO template = TemplateDao.instance.getDefaultDataPointTemplate(pl.getDataTypeId());
                if (template != null) {
                    template.updateDataPointVO(dp);
                    dp.setTemplateId(template.getId());
                }
                // If we are numeric then we want to log on change
                switch(pl.getDataTypeId()) {
                    case DataTypes.NUMERIC:
                        if (SYSTEM_UPTIME_POINT_XID.equals(xid)) {
                            // This changes every time, so just do an interval instant
                            dp.setLoggingType(LoggingTypes.INTERVAL);
                            dp.setIntervalLoggingPeriodType(Common.TimePeriods.MINUTES);
                            dp.setIntervalLoggingPeriod(5);
                            dp.setIntervalLoggingType(DataPointVO.IntervalLoggingTypes.INSTANT);
                        } else {
                            // Setup to Log on Change
                            dp.setLoggingType(LoggingTypes.ON_CHANGE);
                        }
                        if (dp.getTextRenderer() instanceof AnalogRenderer && !dp.getXid().equals(SYSTEM_UPTIME_POINT_XID)) {
                            // This are count points, no need for decimals.
                            ((AnalogRenderer) dp.getTextRenderer()).setFormat("0");
                        }
                        // No template in use here
                        dp.setTemplateId(null);
                        break;
                }
                ProcessResult result = new ProcessResult();
                dp.validate(result);
                if (!result.getHasMessages()) {
                    if (safe)
                        DataPointDao.instance.saveDataPoint(dp);
                    else
                        Common.runtimeManager.saveDataPoint(dp);
                } else {
                    for (ProcessMessage message : result.getMessages()) {
                        LOG.error(message.toString(Common.getTranslations()));
                    }
                }
            }
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) ValueMonitor(com.infiniteautomation.mango.monitor.ValueMonitor)

Example 5 with AnalogRenderer

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

the class DefaultDataPointPropertiesTemplateFactory method createDefaultNumericTemplate.

protected DataPointPropertiesTemplateVO createDefaultNumericTemplate() {
    DataPointPropertiesTemplateVO defaultNumericPointTemplate = new DataPointPropertiesTemplateVO();
    defaultNumericPointTemplate.setXid(NUMERIC_XID);
    defaultNumericPointTemplate.setName("Numeric");
    defaultNumericPointTemplate.setDefaultTemplate(true);
    defaultNumericPointTemplate.setDataTypeId(DataTypes.NUMERIC);
    defaultNumericPointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
    defaultNumericPointTemplate.setChartColour("");
    defaultNumericPointTemplate.setPlotType(PlotTypes.SPLINE);
    defaultNumericPointTemplate.setLoggingType(LoggingTypes.INTERVAL);
    defaultNumericPointTemplate.setIntervalLoggingPeriod(1);
    defaultNumericPointTemplate.setIntervalLoggingPeriodType(TimePeriods.MINUTES);
    defaultNumericPointTemplate.setIntervalLoggingType(IntervalLoggingTypes.AVERAGE);
    defaultNumericPointTemplate.setDefaultCacheSize(1);
    AnalogRenderer numericTextRenderer = new AnalogRenderer();
    numericTextRenderer.setFormat("0.00");
    defaultNumericPointTemplate.setTextRenderer(numericTextRenderer);
    ImageChartRenderer numericChartRenderer = new ImageChartRenderer();
    numericChartRenderer.setTimePeriod(TimePeriods.DAYS);
    numericChartRenderer.setNumberOfPeriods(1);
    defaultNumericPointTemplate.setChartRenderer(numericChartRenderer);
    return defaultNumericPointTemplate;
}
Also used : AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer)

Aggregations

AnalogRenderer (com.serotonin.m2m2.view.text.AnalogRenderer)6 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)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 RangeRenderer (com.serotonin.m2m2.view.text.RangeRenderer)2 TimeRenderer (com.serotonin.m2m2.view.text.TimeRenderer)2 ValueMonitor (com.infiniteautomation.mango.monitor.ValueMonitor)1 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 ImageChartRenderer (com.serotonin.m2m2.view.chart.ImageChartRenderer)1 NoneRenderer (com.serotonin.m2m2.view.text.NoneRenderer)1 TextRenderer (com.serotonin.m2m2.view.text.TextRenderer)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)1 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)1