use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class TextEntryRepresentation method updateChanges.
@Override
public void updateChanges() {
super.updateChanges();
if (dirty_size.checkAndClear())
jfx_node.setPrefSize(model_widget.propWidth().getValue(), model_widget.propHeight().getValue());
if (dirty_style.checkAndClear()) {
final StringBuilder style = new StringBuilder(100);
style.append("-fx-text-fill:");
JFXUtil.appendWebRGB(style, model_widget.propForegroundColor().getValue()).append(";");
// http://stackoverflow.com/questions/27700006/how-do-you-change-the-background-color-of-a-textfield-without-changing-the-border
final WidgetColor back_color = active ? active_color : model_widget.propBackgroundColor().getValue();
style.append("-fx-control-inner-background: ");
JFXUtil.appendWebRGB(style, back_color).append(";");
jfx_node.setStyle(style.toString());
jfx_node.setFont(JFXUtil.convert(model_widget.propFont().getValue()));
// Enable if enabled by user and there's write access
final boolean enabled = model_widget.propEnabled().getValue() && model_widget.runtimePropPVWritable().getValue();
// Don't disable the widget, because that would also remove the
// context menu etc.
// Just apply a style that matches the disabled look.
jfx_node.setEditable(enabled);
Styles.update(jfx_node, Styles.NOT_ENABLED, !enabled);
}
if (active)
return;
if (dirty_content.checkAndClear())
jfx_node.setText(value_text);
}
use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class TextUpdateRepresentation method updateChanges.
@Override
public void updateChanges() {
super.updateChanges();
if (dirty_style.checkAndClear()) {
final RotationStep rotation = model_widget.propRotationStep().getValue();
final int width = model_widget.propWidth().getValue(), height = model_widget.propHeight().getValue();
switch(rotation) {
case NONE:
jfx_node.setPrefSize(width, height);
if (was_ever_transformed)
jfx_node.getTransforms().clear();
break;
case NINETY:
jfx_node.setPrefSize(height, width);
jfx_node.getTransforms().setAll(new Rotate(-rotation.getAngle()), new Translate(-height, 0));
was_ever_transformed = true;
break;
case ONEEIGHTY:
jfx_node.setPrefSize(width, height);
jfx_node.getTransforms().setAll(new Rotate(-rotation.getAngle()), new Translate(-width, -height));
was_ever_transformed = true;
break;
case MINUS_NINETY:
jfx_node.setPrefSize(height, width);
jfx_node.getTransforms().setAll(new Rotate(-rotation.getAngle()), new Translate(0, -width));
was_ever_transformed = true;
break;
}
if (model_widget.propTransparent().getValue())
// No fill
jfx_node.setBackground(null);
else {
final Color color = JFXUtil.convert(model_widget.propBackgroundColor().getValue());
jfx_node.setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY)));
}
if (jfx_node instanceof Label) {
final Label label = (Label) jfx_node;
Color color = JFXUtil.convert(model_widget.propForegroundColor().getValue());
label.setTextFill(color);
label.setFont(JFXUtil.convert(model_widget.propFont().getValue()));
label.setAlignment(pos);
label.setWrapText(model_widget.propWrapWords().getValue());
} else {
final TextArea area = (TextArea) jfx_node;
final StringBuilder style = new StringBuilder(100);
style.append("-fx-text-fill:");
JFXUtil.appendWebRGB(style, model_widget.propForegroundColor().getValue()).append(";");
// http://stackoverflow.com/questions/27700006/how-do-you-change-the-background-color-of-a-textfield-without-changing-the-border
final WidgetColor back_color = model_widget.propBackgroundColor().getValue();
style.append("-fx-control-inner-background: ");
JFXUtil.appendWebRGB(style, back_color).append(";");
area.setStyle(style.toString());
area.setFont(JFXUtil.convert(model_widget.propFont().getValue()));
// Alignment (pos) not supported
area.setWrapText(model_widget.propWrapWords().getValue());
}
}
if (dirty_content.checkAndClear()) {
if (jfx_node instanceof Label)
((Label) jfx_node).setText(value_text);
else
((TextArea) jfx_node).setText(value_text);
}
}
use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class StructuredWidgetPropertyUnitTest method testStructuredWidgetProperty.
@Test
public void testStructuredWidgetProperty() throws Exception {
final PlotWidget widget = new PlotWidget();
System.out.println(widget + " trace:");
for (WidgetProperty<?> trace_element : widget.getPropertyValue(propTrace)) System.out.println(trace_element);
// Structure elements are always in XML, even with default value
widget.propTrace().getValue().get(0).setValueFromObject("position");
String xml = ModelWriter.getXML(Arrays.asList(widget));
System.out.println(xml);
assertThat(xml, containsString("<trace>"));
assertThat(xml, containsString("position"));
assertThat(xml, containsString("color"));
final WidgetProperty<WidgetColor> color = widget.propTrace().getElement(1);
color.setValue(new WidgetColor(255, 255, 0));
xml = ModelWriter.getXML(Arrays.asList(widget));
System.out.println(xml);
assertThat(xml, containsString("color"));
// Read back from XML
WidgetFactory.getInstance().addWidgetType(PlotWidget.WIDGET_DESCRIPTOR);
final DisplayModel model = ModelReader.parseXML(xml);
System.out.println(model);
assertThat(model.getChildren().size(), equalTo(1));
assertThat(model.getChildren().get(0).getType(), equalTo("plot"));
final PlotWidget copy = (PlotWidget) model.getChildren().get(0);
System.out.println(copy);
System.out.println(copy.getProperties());
final WidgetProperty<String> pv_name = copy.propTrace().getElement(0);
System.out.println(pv_name);
assertThat(pv_name.getValue(), equalTo("position"));
}
use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class RulesTest method testColorRule.
/**
* Rule that uses color
*/
@Test
public void testColorRule() throws Exception {
final LabelWidget widget = new LabelWidget();
final WidgetProperty<WidgetColor> color = widget.propForegroundColor().clone();
color.setValue(new WidgetColor(1, 2, 3));
final RuleInfo rule = new RuleInfo("Color", "foreground_color", false, Arrays.asList(new RuleInfo.ExprInfoValue<WidgetColor>("pv0 > 10", color)), Arrays.asList(new ScriptPV("Whatever")));
System.out.println(rule);
final String script = RuleToScript.generatePy(widget, rule);
System.out.println(script);
// Script must create variables for colors
assertThat(script, containsString("colorVal"));
}
use of org.csstudio.display.builder.model.properties.WidgetColor in project org.csstudio.display.builder by kasemir.
the class XMLUtil method getChildColor.
/**
* Given a parent element, locate color value of a child node.
*
* @param parent Parent element.
* @param name Name of child element.
* @return Value of child element, or empty result.
*/
public static Optional<WidgetColor> getChildColor(final Element parent, final String name) {
final Element child = getChildElement(parent, name);
if (child != null) {
Element colorElement = XMLUtil.getChildElement(child, XMLTags.COLOR);
if (colorElement == null) {
return Optional.empty();
}
WidgetColor color = null;
String colorName = colorElement.getAttribute(XMLTags.NAME);
try {
int red = getAttribute(colorElement, XMLTags.RED);
int green = getAttribute(colorElement, XMLTags.GREEN);
int blue = getAttribute(colorElement, XMLTags.BLUE);
String alphaString = colorElement.getAttribute(XMLTags.ALPHA);
int alpha = alphaString.isEmpty() ? 255 : Integer.parseInt(alphaString);
if (colorName.isEmpty()) {
// Plain color
color = new WidgetColor(red, green, blue, alpha);
} else {
color = WidgetColorService.getColors().resolve(new NamedWidgetColor(colorName, red, green, blue, alpha));
}
} catch (Exception ex) {
// Older legacy files had no red/green/blue info for named colors
logger.log(Level.WARNING, "Line " + XMLUtil.getLineInfo(child), ex);
if (colorName.isEmpty()) {
color = WidgetColorService.getColor(NamedWidgetColors.TEXT);
} else {
color = WidgetColorService.getColor(colorName);
}
}
return (color == null) ? Optional.empty() : Optional.of(color);
} else {
return Optional.empty();
}
}
Aggregations