use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class EllipseWidget method defineProperties.
@Override
protected void defineProperties(final List<WidgetProperty<?>> properties) {
super.defineProperties(properties);
properties.add(line_width = propLineWidth.createProperty(this, 3));
properties.add(line_color = propLineColor.createProperty(this, new WidgetColor(0, 0, 255)));
properties.add(background = propBackgroundColor.createProperty(this, new WidgetColor(30, 144, 255)));
properties.add(transparent = propTransparent.createProperty(this, false));
}
use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class StructuredWidgetPropertyUnitTest method testElementAccess.
@Test
public void testElementAccess() throws Exception {
final PlotWidget widget = new PlotWidget();
final WidgetProperty<String> name1 = widget.propTrace().getElement(0);
final WidgetProperty<String> name2 = widget.propTrace().getElement("pv_name");
assertThat(name1, sameInstance(name2));
WidgetProperty<WidgetColor> color_prop = widget.propTrace().getElement(1);
WidgetColor color = color_prop.getValue();
System.out.println(color);
color_prop = widget.propTrace().getElement(0);
try {
color = color_prop.getValue();
System.out.println(color);
fail("Allowed access to String property as color");
} catch (ClassCastException ex) {
assertThat(ex.getMessage(), containsString("String cannot"));
}
}
use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class ArcWidget method defineProperties.
// By default create an arc with dark blue line, light blue interior, no transparency, 90 degree angle from 0-90
@Override
protected void defineProperties(final List<WidgetProperty<?>> properties) {
super.defineProperties(properties);
properties.add(arc_start = propAngleStart.createProperty(this, 0.0));
properties.add(arc_size = propAngleSize.createProperty(this, 90.0));
properties.add(line_width = propLineWidth.createProperty(this, 3));
properties.add(line_color = propLineColor.createProperty(this, new WidgetColor(0, 0, 255)));
properties.add(background = propBackgroundColor.createProperty(this, new WidgetColor(30, 144, 255)));
properties.add(transparent = propTransparent.createProperty(this, false));
}
use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class ByteMonitorWidget method defineProperties.
@Override
protected void defineProperties(final List<WidgetProperty<?>> properties) {
super.defineProperties(properties);
properties.add(startBit = propStartBit.createProperty(this, 0));
properties.add(numBits = propNumBits.createProperty(this, 8));
properties.add(bitReverse = propBitReverse.createProperty(this, false));
properties.add(horizontal = propHorizontal.createProperty(this, true));
properties.add(square = propSquare.createProperty(this, false));
properties.add(off_color = propOffColor.createProperty(this, new WidgetColor(60, 100, 60)));
properties.add(on_color = propOnColor.createProperty(this, new WidgetColor(60, 255, 60)));
}
use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class RuleToScript method generatePy.
public static String generatePy(final Widget attached_widget, final RuleInfo rule) {
final WidgetProperty<?> prop = attached_widget.getProperty(rule.getPropID());
PropFormat pform = PropFormat.STRING;
if (prop.getDefaultValue() instanceof Number)
pform = PropFormat.NUMERIC;
else if (prop.getDefaultValue() instanceof Boolean)
pform = PropFormat.BOOLEAN;
else if (prop.getDefaultValue() instanceof WidgetColor)
pform = PropFormat.COLOR;
final StringBuilder script = new StringBuilder();
script.append("## Script for Rule: ").append(rule.getName()).append("\n\n");
script.append("from org.csstudio.display.builder.runtime.script import PVUtil\n");
if (pform == PropFormat.COLOR)
script.append("from org.csstudio.display.builder.model.properties import WidgetColor\n");
script.append("\n## Process variable extraction\n");
script.append("## Use any of the following valid variable names in an expression:\n");
final Map<String, String> pvm = pvNameOptions(rule.getPVs().size());
for (Map.Entry<String, String> entry : pvm.entrySet()) {
script.append("## ").append(entry.getKey());
if (entry.getKey().contains("Legacy"))
script.append(" [DEPRECATED]");
script.append("\n");
}
script.append("\n");
// Check which pv* variables are actually used
final Map<String, String> output_pvm = new HashMap<String, String>();
for (ExpressionInfo<?> expr : rule.getExpressions()) {
// Check the boolean expressions.
// In principle, should parse an expression like
// pv0 > 10
// to see if it refers to the variable "pv0".
// Instead of implementing a full parser, we
// just check for "pv0" anywhere in the expression.
// This will erroneously detect a variable reference in
// len("Text with pv0")>4
// which doesn't actually reference "pv0" as a variable,
// but it doesn't matter if the script creates some
// extra variable "pv0" which is then left unused.
String expr_to_check = expr.getBoolExp();
// simply including them in the string to check
if (rule.getPropAsExprFlag())
expr_to_check += " " + expr.getPropVal().toString();
for (Map.Entry<String, String> entry : pvm.entrySet()) {
final String varname = entry.getKey();
if (expr_to_check.contains(varname))
output_pvm.put(varname, entry.getValue());
}
}
// Generate code that reads the required pv* variables from PVs
for (Map.Entry<String, String> entry : output_pvm.entrySet()) script.append(entry.getKey()).append(" = ").append(entry.getValue()).append("\n");
if (pform == PropFormat.COLOR) {
// If property is a color, create variables for all the used colors
script.append("\n## Define Colors\n");
WidgetColor col = (WidgetColor) prop.getValue();
script.append("colorCurrent = ").append("WidgetColor(").append(col.getRed()).append(", ").append(col.getGreen()).append(", ").append(col.getBlue()).append(")\n");
if (!rule.getPropAsExprFlag()) {
int idx = 0;
for (ExpressionInfo<?> expr : rule.getExpressions()) {
if (expr.getPropVal() instanceof WidgetProperty<?>) {
final Object value = ((WidgetProperty<?>) expr.getPropVal()).getValue();
if (value instanceof WidgetColor) {
col = (WidgetColor) value;
script.append("colorVal").append(idx).append(" = ").append("WidgetColor(").append(col.getRed()).append(", ").append(col.getGreen()).append(", ").append(col.getBlue()).append(")\n");
}
}
idx++;
}
}
}
script.append("\n## Script Body\n");
String indent = " ";
final String setPropStr = "widget.setPropertyValue('" + rule.getPropID() + "', ";
int idx = 0;
for (ExpressionInfo<?> expr : rule.getExpressions()) {
script.append((idx == 0) ? "if" : "elif");
script.append(" ").append(javascriptToPythonLogic(expr.getBoolExp())).append(":\n");
script.append(indent).append(setPropStr);
if (rule.getPropAsExprFlag())
script.append(javascriptToPythonLogic(expr.getPropVal().toString())).append(")\n");
else
script.append(formatPropVal((WidgetProperty<?>) expr.getPropVal(), idx, pform)).append(")\n");
idx++;
}
if (idx > 0) {
script.append("else:\n");
script.append(indent).append(setPropStr).append(formatPropVal(prop, -1, pform)).append(")\n");
} else
script.append(setPropStr).append(formatPropVal(prop, -1, pform)).append(")\n");
return script.toString();
}
Aggregations