Search in sources :

Example 1 with DisplayModel

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;
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) VString(org.diirt.vtype.VString)

Example 2 with DisplayModel

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);
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) Image(javafx.scene.image.Image)

Example 3 with DisplayModel

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;
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 4 with DisplayModel

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;
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) Node(javafx.scene.Node) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 5 with DisplayModel

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();
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayRepresentationUtil.loadDisplayModel(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)

Aggregations

DisplayModel (org.csstudio.display.builder.model.DisplayModel)73 Widget (org.csstudio.display.builder.model.Widget)15 Test (org.junit.Test)10 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)9 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)7 EmbeddedDisplayRepresentationUtil.loadDisplayModel (org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 EmbeddedDisplayWidget (org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)5 Image (javafx.scene.image.Image)4 File (java.io.File)3 InputStream (java.io.InputStream)3 Parent (javafx.scene.Parent)3 Macros (org.csstudio.display.builder.model.macros.Macros)3 PictureWidget (org.csstudio.display.builder.model.widgets.PictureWidget)3 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 Rectangle2D (javafx.geometry.Rectangle2D)2 WidgetFactoryUnitTest (org.csstudio.display.builder.model.WidgetFactoryUnitTest)2 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)2 ModelWriter (org.csstudio.display.builder.model.persist.ModelWriter)2