use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class SymbolRepresentation method resolveImageFile.
public static String resolveImageFile(SymbolWidget widget, String imageFileName) {
try {
String expandedFileName = MacroHandler.replace(widget.getMacrosOrProperties(), imageFileName);
// Resolve new image file relative to the source widget model (not 'top'!).
// Get the display model from the widget tied to this representation.
final DisplayModel widgetModel = widget.getDisplayModel();
// Resolve the image path using the parent model file path.
return ModelResourceUtil.resolveResource(widgetModel, expandedFileName);
} catch (Exception ex) {
logger.log(Level.WARNING, "Failure resolving image path: {0} [{1}].", new Object[] { imageFileName, ex.getMessage() });
return null;
}
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class PictureRepresentation method contentChanged.
private void contentChanged(final WidgetProperty<String> property, final String old_value, final String new_value) {
// Imagine if updateChanges executes here. Mark is cleared and image updated before new image loaded.
// Subsequent Scheduled image update would not happen.
String base_path = new_value;
// String base_path = model_widget.displayFile().getValue();
// System.out.println("Picture Representation content changes to " + base_path + " on " + Thread.currentThread().getName());
boolean load_failed = false;
try {
// Expand macros in the file name
final String expanded_path = MacroHandler.replace(model_widget.getMacrosOrProperties(), base_path);
// Resolve new image file relative to the source widget model (not 'top'!)
// Get the display model from the widget tied to this representation
final DisplayModel widget_model = model_widget.getDisplayModel();
// Resolve the image path using the parent model file path
img_path = ModelResourceUtil.resolveResource(widget_model, expanded_path);
} catch (Exception e) {
System.out.println("Failure resolving image path from base path: " + base_path);
e.printStackTrace();
load_failed = true;
}
if (!load_failed) {
try {
// Open the image from the stream created from the resource file
img_loaded = new Image(ModelResourceUtil.openResourceStream(img_path));
native_ratio = img_loaded.getWidth() / img_loaded.getHeight();
} catch (Exception ex) {
logger.log(Level.WARNING, "Failure loading image file:" + img_path, ex);
load_failed = true;
}
}
if (load_failed) {
final String dflt_img = PictureWidget.default_pic;
try {
// Open the image from the stream created from the resource file
img_loaded = new Image(ModelResourceUtil.openResourceStream(dflt_img));
native_ratio = img_loaded.getWidth() / img_loaded.getHeight();
} catch (Exception ex) {
logger.log(Level.WARNING, "Failure loading default image file:" + img_path, ex);
}
}
// Resize/reorient in case we are preserving aspect ratio and changed native_ratio
dirty_style.mark();
// Switch to the new image
dirty_content.mark();
toolkit.scheduleUpdate(this);
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class BoolButtonRepresentation method loadImage.
private ImageView loadImage(final String path) {
if (path.isEmpty())
return null;
try {
// Resolve image file relative to the source widget model (not 'top'!)
final DisplayModel widget_model = model_widget.getDisplayModel();
final String resolved = ModelResourceUtil.resolveResource(widget_model, path);
return new ImageView(new Image(ModelResourceUtil.openResourceStream(resolved)));
} catch (Exception ex) {
logger.log(Level.WARNING, model_widget + " cannot load image", ex);
}
return null;
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class JFXBaseRepresentation method getJFXNode.
/**
* @param widget Widget
* @return JFX node used to represent the widget
*/
public static Node getJFXNode(final Widget widget) {
if (widget instanceof DisplayModel) {
// Display doesn't have a representation.
// Find one of its widgets, then use its parent node
final DisplayModel model = (DisplayModel) widget;
final List<Widget> children = model.getChildren();
if (children.isEmpty())
return null;
return getJFXNode(children.get(0)).getParent();
}
final JFXBaseRepresentation<Node, Widget> representation = widget.getUserData(Widget.USER_DATA_REPRESENTATION);
if (representation == null)
throw new NullPointerException("Missing representation for " + widget);
return representation.jfx_node;
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class EmbeddedDisplayRepresentation method dispose.
@Override
public void dispose() {
// When the file name is changed, updatePendingDisplay()
// will atomically update the active_content_model,
// represent the new model, and then set runtimePropEmbeddedModel.
//
// Fetching the embedded model from active_content_model
// could dispose a representation that hasn't been represented, yet.
// Fetching the embedded model from runtimePropEmbeddedModel
// could fail to dispose what's just now being represented.
//
// --> Very unlikely to happen because runtime has been stopped,
// so nothing is changing the file name right now.
final DisplayModel em = active_content_model.getAndSet(null);
model_widget.runtimePropEmbeddedModel().setValue(null);
if (inner != null && em != null)
toolkit.disposeRepresentation(em);
inner = null;
super.dispose();
}
Aggregations