use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class EmbeddedDisplayRepresentation method backgroundChanged.
private void backgroundChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
final DisplayModel content_model = active_content_model.get();
if (model_widget.propTransparent().getValue()) {
inner_background = TRANSPARENT_BACKGROUND;
// Reinstall the frame in edit mode. Scroll is unusable, so make it with inner
if (toolkit.isEditMode())
inner_border = EDIT_BORDER;
} else {
if (content_model == null)
inner_background = Background.EMPTY;
else
inner_background = new Background(new BackgroundFill(JFXUtil.convert(content_model.propBackgroundColor().getValue()), CornerRadii.EMPTY, Insets.EMPTY));
// TODO Haven't found perfect way to set the 'background' color
// of the embedded content.
// Setting the 'inner' background will sometimes leave a gray section in the right and or bottom edge
// of the embedded content if the container is (much) larger than the content
// The scroll pane background can only be set via style,
// and then shines through on the outside of the scrollbars
// scroll.setStyle("-fx-control-inner-background: " + JFXUtil.webRGB(content_model.propBackgroundColor().getValue()) +
// "; -fx-background: " + JFXUtil.webRGB(content_model.propBackgroundColor().getValue()));
inner_border = Border.EMPTY;
}
dirty_background.mark();
toolkit.scheduleUpdate(this);
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class ExampleModels method createModel.
/**
* @return {@link DisplayModel}
*/
public static DisplayModel createModel() {
final DisplayModel model = new DisplayModel();
model.setPropertyValue(CommonWidgetProperties.propWidth, 1400);
model.setPropertyValue(CommonWidgetProperties.propHeight, 20 * 50);
for (int i = 0; i < 200; ++i) {
final int x = 0 + (i / 20) * 132;
final int y = 0 + (i % 20) * 50;
final GroupWidget group = new GroupWidget();
group.setPropertyValue(CommonWidgetProperties.propName, "Group " + i);
group.setPropertyValue(CommonWidgetProperties.propX, x);
group.setPropertyValue(CommonWidgetProperties.propY, y);
group.setPropertyValue(CommonWidgetProperties.propWidth, 125);
group.setPropertyValue(CommonWidgetProperties.propHeight, 53);
final LabelWidget label = new LabelWidget();
label.setPropertyValue(CommonWidgetProperties.propName, "Label " + i);
label.setPropertyValue(CommonWidgetProperties.propX, 0);
label.setPropertyValue(CommonWidgetProperties.propY, 4);
label.setPropertyValue(CommonWidgetProperties.propWidth, 15);
label.setPropertyValue(CommonWidgetProperties.propHeight, 15);
label.setPropertyValue(CommonWidgetProperties.propText, Integer.toString(i));
group.runtimeChildren().addChild(label);
// For SWT implementation, rect. is not 'transparent',
// so needs to be behind text
final RectangleWidget rect = new RectangleWidget();
rect.setPropertyValue(CommonWidgetProperties.propName, "Rect " + i);
rect.setPropertyValue(CommonWidgetProperties.propX, 10);
rect.setPropertyValue(CommonWidgetProperties.propY, 0);
rect.setPropertyValue(CommonWidgetProperties.propWidth, 80);
rect.setPropertyValue(CommonWidgetProperties.propHeight, 19);
rect.setPropertyValue(CommonWidgetProperties.propScripts, Arrays.asList(new ScriptInfo("../org.csstudio.display.builder.runtime.test/examples/fudge_width.py", true, new ScriptPV("noise"))));
group.runtimeChildren().addChild(rect);
final TextUpdateWidget text = new TextUpdateWidget();
text.setPropertyValue(CommonWidgetProperties.propName, "Text " + i);
text.setPropertyValue(CommonWidgetProperties.propX, 30);
text.setPropertyValue(CommonWidgetProperties.propY, 4);
text.setPropertyValue(CommonWidgetProperties.propWidth, 45);
text.setPropertyValue(CommonWidgetProperties.propHeight, 15);
text.setPropertyValue(CommonWidgetProperties.propPVName, "ramp");
group.runtimeChildren().addChild(text);
model.runtimeChildren().addChild(group);
}
return model;
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class ExampleModels method main.
public static void main(String[] args) throws Exception {
final DisplayModel model = createModel();
final ModelWriter writer = new ModelWriter(new FileOutputStream("example.opi"));
try {
writer.writeModel(model);
} finally {
writer.close();
}
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class EmbeddedDisplayRepresentationUtil method createErrorModel.
/**
* @param message Error message
* @return DisplayModel that shows the message
*/
private static DisplayModel createErrorModel(final Widget model_widget, final String message) {
final LabelWidget info = new LabelWidget();
info.propText().setValue(message);
info.propForegroundColor().setValue(WidgetColorService.getColor(NamedWidgetColors.ALARM_DISCONNECTED));
// Size a little smaller than the widget to fill but not require scrollbars
final int wid = model_widget.propWidth().getValue() - 2;
final int hei = model_widget.propHeight().getValue() - 2;
info.propWidth().setValue(wid);
info.propHeight().setValue(hei);
final DisplayModel error_model = new DisplayModel();
error_model.propWidth().setValue(wid);
error_model.propHeight().setValue(hei);
error_model.runtimeChildren().addChild(info);
error_model.setUserData(DisplayModel.USER_DATA_EMBEDDING_WIDGET, model_widget);
return error_model;
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class EmbeddedDisplayRepresentationUtil method reduceDisplayModelToGroup.
/**
* Reduce display model to content of one named group
* @param display_file Name of the display file
* @param model Model loaded from that file
* @param group_name Name of group to use
*/
private static void reduceDisplayModelToGroup(final Widget model_widget, final DisplayModel model, final DisplayAndGroup display_and_group) {
final String group_name = display_and_group.getGroupName();
final List<Widget> children = model.runtimeChildren().getValue();
// Find all groups with desired name.
// Could just loop to get the first matching group,
// but finding all and logging them helps to debug displays.
final List<Widget> groups = children.parallelStream().filter(child -> child instanceof GroupWidget && child.getName().equals(group_name)).collect(Collectors.toList());
// Expect exactly one
if (groups.size() != 1)
logger.log(Level.WARNING, "Expected one group named '" + group_name + "' in '" + display_and_group.getDisplayFile() + "', found " + groups);
// If no group found, use the complete display
if (groups.size() <= 0)
return;
// Replace display with just the content of that group
final GroupWidget group = (GroupWidget) groups.get(0);
model.runtimeChildren().setValue(group.runtimeChildren().getValue());
// Group model correction - use group background color, not the display background color
model.propBackgroundColor().setValue(group.propBackgroundColor().getValue());
// If the group is transparent, see if the embedding widget can also be
if (group.propTransparent().getValue())
model_widget.checkProperty(CommonWidgetProperties.propTransparent).ifPresent(trans -> trans.setValue(true));
// Not removing children from 'group', since group will be GC'ed anyway.
shrinkModelToWidgets(model);
}
Aggregations