<commit_before>package org.csstudio.sds.behavior.desy;

import java.util.HashMap;
import java.util.Map;

import org.csstudio.sds.components.model.BargraphModel;
import org.csstudio.sds.cosyrules.color.Alarm;
import org.csstudio.sds.eventhandling.AbstractBehavior;
import org.csstudio.sds.model.AbstractWidgetModel;
import org.csstudio.sds.model.LabelModel;
import org.csstudio.sds.util.ColorAndFontUtil;
import org.epics.css.dal.context.ConnectionState;
import org.epics.css.dal.simple.AnyData;
import org.epics.css.dal.simple.MetaData;
import org.epics.css.dal.simple.Severity;

/**
 * Default DESY-Behaviour for the {@link BargraphModel} widget.
 * 
 * @author <NAME>
 * 
 */
public class BargraphBehavior extends AbstractBehavior<BargraphModel> {
	private Map<org.epics.css.dal.context.ConnectionState, String> colorsByConnectionState;

	private Map<ConnectionState, Boolean> transparencyByConnectionState;

	public BargraphBehavior() {
		colorsByConnectionState = new HashMap<ConnectionState, String>();
		colorsByConnectionState.put(ConnectionState.INITIAL, ColorAndFontUtil.toHex(255, 168, 222));
		colorsByConnectionState.put(ConnectionState.CONNECTED, ColorAndFontUtil.toHex(120, 120, 120));
		colorsByConnectionState.put(ConnectionState.CONNECTION_LOST, ColorAndFontUtil.toHex(255, 9, 163));

		transparencyByConnectionState = new HashMap<ConnectionState, Boolean>();
		transparencyByConnectionState.put(ConnectionState.CONNECTED, true);
		transparencyByConnectionState.put(ConnectionState.CONNECTION_LOST, false);
		transparencyByConnectionState.put(ConnectionState.INITIAL, false);
	}

	@Override
	protected String[] doGetInvisiblePropertyIds() {
		return new String[] { BargraphModel.PROP_MIN, BargraphModel.PROP_MAX, BargraphModel.PROP_HIHI_LEVEL, BargraphModel.PROP_HI_LEVEL,
				BargraphModel.PROP_LOLO_LEVEL, BargraphModel.PROP_LO_LEVEL, BargraphModel.PROP_DEFAULT_FILL_COLOR,
				BargraphModel.PROP_FILLBACKGROUND_COLOR, BargraphModel.PROP_FILL, BargraphModel.PROP_TRANSPARENT };

	}

	@Override
	protected void doInitialize(BargraphModel widget) {

	}

	@Override
	protected void doProcessValueChange(BargraphModel widget, AnyData anyData) {
		System.out.println(anyData.getMetaData());
		
		// .. fill level (influenced by current value)
		widget.setPropertyValue(BargraphModel.PROP_FILL, anyData.doubleValue());

		// .. fill color (influenced by severity)
		Severity severity = anyData.getSeverity();
		if (severity != null) {
			widget.setPropertyValue(BargraphModel.PROP_DEFAULT_FILL_COLOR, determineColorBySeverity(severity));
		}
	}

	@Override
	protected void doProcessConnectionStateChange(BargraphModel widget, org.epics.css.dal.context.ConnectionState connectionState) {
		// .. change color
		String color = colorsByConnectionState.get(connectionState);
		if (color != null) {
			widget.setPropertyValue(BargraphModel.PROP_FILLBACKGROUND_COLOR, color);
		}

		// .. change transparency
		Boolean transparent = transparencyByConnectionState.get(connectionState);

		if (transparent != null) {
			widget.setPropertyValue(BargraphModel.PROP_TRANSPARENT, transparent);
		}
	}

	@Override
	protected void doProcessMetaDataChange(BargraphModel widget, AnyData anyData) {
		MetaData meta = anyData.getMetaData();

		if (meta != null) {
			System.out.println("(MIN) = Meta.getDisplayLow()="+meta.getDisplayLow());
			System.out.println("(MAX) = Meta.getDisplayHigh()="+meta.getDisplayHigh());
			System.out.println("(HIHI) = Meta.getAlarmHigh()="+meta.getAlarmHigh());
			System.out.println("(HI) = Meta.getWarnHigh()="+meta.getWarnHigh());<commit_msg>improved new property view sections<commit_after>package org.csstudio.sds.behavior.desy;

import java.util.HashMap;
import java.util.Map;

import org.csstudio.sds.components.model.BargraphModel;
import org.csstudio.sds.cosyrules.color.Alarm;
import org.csstudio.sds.eventhandling.AbstractBehavior;
import org.csstudio.sds.model.AbstractWidgetModel;
import org.csstudio.sds.model.LabelModel;
import org.csstudio.sds.util.ColorAndFontUtil;
import org.epics.css.dal.context.ConnectionState;
import org.epics.css.dal.simple.AnyData;
import org.epics.css.dal.simple.MetaData;
import org.epics.css.dal.simple.Severity;

/**
 * Default DESY-Behaviour for the {@link BargraphModel} widget.
 * 
 * @author <NAME>
 * 
 */
public class BargraphBehavior extends AbstractBehavior<BargraphModel> {
	private Map<org.epics.css.dal.context.ConnectionState, String> colorsByConnectionState;

	private Map<ConnectionState, Boolean> transparencyByConnectionState;

	public BargraphBehavior() {
		colorsByConnectionState = new HashMap<ConnectionState, String>();
		colorsByConnectionState.put(ConnectionState.INITIAL, ColorAndFontUtil.toHex(255, 168, 222));
		colorsByConnectionState.put(ConnectionState.CONNECTED, ColorAndFontUtil.toHex(120, 120, 120));
		colorsByConnectionState.put(ConnectionState.CONNECTION_LOST, ColorAndFontUtil.toHex(255, 9, 163));

		transparencyByConnectionState = new HashMap<ConnectionState, Boolean>();
		transparencyByConnectionState.put(ConnectionState.CONNECTED, true);
		transparencyByConnectionState.put(ConnectionState.CONNECTION_LOST, false);
		transparencyByConnectionState.put(ConnectionState.INITIAL, false);
	}

	@Override
	protected String[] doGetInvisiblePropertyIds() {
		return new String[] { BargraphModel.PROP_MIN, BargraphModel.PROP_MAX, BargraphModel.PROP_HIHI_LEVEL, BargraphModel.PROP_HI_LEVEL,
				BargraphModel.PROP_LOLO_LEVEL, BargraphModel.PROP_LO_LEVEL, BargraphModel.PROP_DEFAULT_FILL_COLOR,
				BargraphModel.PROP_FILLBACKGROUND_COLOR, BargraphModel.PROP_FILL, BargraphModel.PROP_TRANSPARENT };

	}

	@Override
	protected void doInitialize(BargraphModel widget) {

	}

	@Override
	protected void doProcessValueChange(BargraphModel widget, AnyData anyData) {
		System.out.println(anyData.getMetaData());
		
		// .. fill level (influenced by current value)
		widget.setPropertyValue(BargraphModel.PROP_FILL, anyData.doubleValue());

		// .. fill color (influenced by severity)
		Severity severity = anyData.getSeverity();
		if (severity != null) {
			widget.setPropertyValue(BargraphModel.PROP_DEFAULT_FILL_COLOR, determineColorBySeverity(severity));
		}
	}

	@Override
	protected void doProcessConnectionStateChange(BargraphModel widget, org.epics.css.dal.context.ConnectionState connectionState) {
		// .. change color
		String color = colorsByConnectionState.get(connectionState);
		if (color != null) {
			widget.setPropertyValue(BargraphModel.PROP_FILLBACKGROUND_COLOR, color);
			widget.setPropertyValue(AbstractWidgetModel.PROP_BORDER_COLOR, color);
		}

		// .. change transparency
		Boolean transparent = transparencyByConnectionState.get(connectionState);

		if (transparent != null) {
			widget.setPropertyValue(BargraphModel.PROP_TRANSPARENT, transparent);
		}
	}

	@Override
	protected void doProcessMetaDataChange(BargraphModel widget, AnyData anyData) {
		MetaData meta = anyData.getMetaData();

		if (meta != null) {
			System.out.println("(MIN) = Meta.getDisplayLow()="+meta.getDisplayLow());
			System.out.println("(MAX) = Meta.getDisplayHigh()="+meta.getDisplayHigh());
			System.out.println("(HIHI) = Meta.getAlarmHigh()="+meta.getAlarmHigh());
			System.out.println("(HI) = Meta.getWarnHigh()="+meta.getWarnHigh());
{'fraction_non_alphanumeric': 0.11181667586968526, 'fraction_numerical': 0.006902263942573164, 'mean_word_length': 6.303427419354839, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4946198', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2290, 'n_words': 355}