Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSSTUDIO-2939 Add property "SVG Rendering Resolution Factor" to the Picture and Symbol widgets #3245

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public class Messages
WidgetProperties_ReadbackPVName,
WidgetProperties_ReadbackPVValue,
WidgetProperties_ResizeBehavior,
WidgetProperties_SVGRenderingResolutionFactor,
WidgetProperties_RingColor,
WidgetProperties_RingWidth,
WidgetProperties_Rotation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public boolean configureFromXML(final ModelReader model_reader, final Widget wid
public static final WidgetPropertyDescriptor<Boolean> propStretch =
newBooleanPropertyDescriptor(WidgetPropertyCategory.DISPLAY, "stretch_image", Messages.WidgetProperties_StretchToFit);

/** 'svg_rendering_resolution_factor': */
public static final WidgetPropertyDescriptor<Double> propSVGRenderingResolutionFactor =
newDoublePropertyDescriptor(WidgetPropertyCategory.DISPLAY, "svg_rendering_resolution_factor", Messages.WidgetProperties_SVGRenderingResolutionFactor);

/**
* An opacity property. Controlling it from a rule or script works as a
* way to do a simple animation.
Expand All @@ -114,6 +118,7 @@ public boolean configureFromXML(final ModelReader model_reader, final Widget wid
private volatile WidgetProperty<Boolean> stretch_image;
private volatile WidgetProperty<Double> rotation;
private volatile WidgetProperty<Double> opacity;
private volatile WidgetProperty<Double> svgRenderingResolutionFactor;

/** Constructor */
public PictureWidget()
Expand All @@ -129,7 +134,7 @@ protected void defineProperties(final List<WidgetProperty<?>> properties)
properties.add(stretch_image = propStretch.createProperty(this, false));
properties.add(rotation = propRotation.createProperty(this, 0.0));
properties.add(opacity = propOpacity.createProperty(this, 1.0));

properties.add(svgRenderingResolutionFactor = propSVGRenderingResolutionFactor.createProperty(this, 1.0));
}

/** @return 'rotation' property */
Expand All @@ -156,6 +161,11 @@ public WidgetProperty<Double> propOpacity()
return opacity;
}

/** @return 'svgRenderingResolutionFactor' property */
public WidgetProperty<Double> propSVGRenderingResolutionFactor() {
return svgRenderingResolutionFactor;
}

@Override
public WidgetConfigurator getConfigurator(final Version persisted_version)
throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public Widget createWidget ( ) {
/** Property */
public static final WidgetPropertyDescriptor<String> propFallbackSymbol = newFilenamePropertyDescriptor (WidgetPropertyCategory.BEHAVIOR, "fallback_symbol", Messages.WidgetProperties_FallbackSymbol);
public static final WidgetPropertyDescriptor<Boolean> propRunActionsOnMouseClick = newBooleanPropertyDescriptor (WidgetPropertyCategory.BEHAVIOR, "run_actions_on_mouse_click", Messages.WidgetProperties_RunActionsOnMouseClick);
/** 'svg_rendering_resolution_factor': */
public static final WidgetPropertyDescriptor<Double> propSVGRenderingResolutionFactor = newDoublePropertyDescriptor(WidgetPropertyCategory.DISPLAY, "svg_rendering_resolution_factor", Messages.WidgetProperties_SVGRenderingResolutionFactor);


/** 'items' property: list of items (string properties) for combo box */
public static final ArrayWidgetProperty.Descriptor<WidgetProperty<String> > propSymbols = new ArrayWidgetProperty.Descriptor< >(
Expand Down Expand Up @@ -121,6 +124,7 @@ public Widget createWidget ( ) {
private volatile WidgetProperty<String> fallbackSymbol;
private volatile WidgetProperty<WidgetColor> disconnectOverlayColor;
private volatile WidgetProperty<Boolean> run_actions_on_mouse_click;
private volatile WidgetProperty<Double> svgRenderingResolutionFactor;

/** Returns 'symbol' property: element for list of 'symbols' property */
private static WidgetPropertyDescriptor<String> propSymbol( int index ) {
Expand Down Expand Up @@ -225,6 +229,11 @@ public WidgetProperty<Boolean> propRunActionsOnMouseClick() {
return run_actions_on_mouse_click;
}

/** @return 'svgRenderingResolutionFactor' property */
public WidgetProperty<Double> propSVGRenderingResolutionFactor() {
return svgRenderingResolutionFactor;
}

@Override
protected void defineProperties ( final List<WidgetProperty<?>> properties ) {

Expand All @@ -243,6 +252,7 @@ protected void defineProperties ( final List<WidgetProperty<?>> properties ) {
properties.add(enabled = propEnabled.createProperty(this, true));
properties.add(preserve_ratio = propPreserveRatio.createProperty(this, true));
properties.add(fallbackSymbol = propFallbackSymbol.createProperty(this, DEFAULT_SYMBOL));
properties.add(svgRenderingResolutionFactor = propSVGRenderingResolutionFactor.createProperty(this, 1.0));
WidgetColor alarmInvalidColor =
WidgetColorService.getColor(NamedWidgetColors.ALARM_INVALID);
WidgetColor defaultDisconnectedOverlayColor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ WidgetProperties_Skin=Skin
WidgetProperties_Square=Square
WidgetProperties_StartFromZero=Start From Zero
WidgetProperties_StretchToFit=Stretch to Fit
WidgetProperties_SVGRenderingResolutionFactor=SVG Rendering Resolution Factor
WidgetProperties_Symbol=Symbol
WidgetProperties_Symbols=Symbols
WidgetProperties_SymbolValue=Text Symbol value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class PictureRepresentation extends JFXBaseRepresentation<ImageView, Pict
/** Change the image size, rotation or preserve_ratio */
private final DirtyFlag dirty_style = new DirtyFlag();
private final UntypedWidgetPropertyListener styleChangedListener = this::styleChanged;
private final UntypedWidgetPropertyListener svgRenderingResolutionFactorChangedListener = this::svgRenderingResolutionFactorChanged;
private final WidgetPropertyListener<String> contentChangedListener = this::contentChanged;

private volatile Image img_loaded;
Expand Down Expand Up @@ -96,6 +97,7 @@ protected void registerListeners()
model_widget.propStretch().addUntypedPropertyListener(styleChangedListener);
model_widget.propRotation().addUntypedPropertyListener(styleChangedListener);
model_widget.propOpacity().addUntypedPropertyListener(styleChangedListener);
model_widget.propSVGRenderingResolutionFactor().addUntypedPropertyListener(svgRenderingResolutionFactorChangedListener);
// styleChanged() will be called by contentChanged()

model_widget.propFile().addPropertyListener(contentChangedListener);
Expand All @@ -117,6 +119,7 @@ protected void unregisterListeners()
model_widget.propRotation().removePropertyListener(styleChangedListener);
model_widget.propOpacity().removePropertyListener(styleChangedListener);
model_widget.propFile().removePropertyListener(contentChangedListener);
model_widget.propSVGRenderingResolutionFactor().removePropertyListener(svgRenderingResolutionFactorChangedListener);
super.unregisterListeners();
}

Expand All @@ -126,6 +129,12 @@ private void styleChanged(final WidgetProperty<?> property, final Object old_val
toolkit.scheduleUpdate(this);
}

private void svgRenderingResolutionFactorChanged(final WidgetProperty<?> property, final Object oldValue, Object newValue) {
// Update the rendered SVG:
contentChanged(model_widget.propFile(), model_widget.propFile().getValue(), model_widget.propFile().getValue());
}


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.
Expand Down Expand Up @@ -262,10 +271,23 @@ else if (h_prime < pic_h)
* @param height
* @return An {@link Image} or <code>null</code>.
*/
private void loadSVG(String fileName, double width, double height){

private void loadSVG(String fileName, double width, double height) {
String imageFileName = resolveImageFile(fileName);
img_loaded = SVGHelper.loadSVG(imageFileName, width, height);

double svg_rendering_resolution_factor = model_widget.propSVGRenderingResolutionFactor().getValue();

double renderingWidth;
double renderingHeight;
if (!Double.isNaN(svg_rendering_resolution_factor) && svg_rendering_resolution_factor > 0) {
renderingWidth = svg_rendering_resolution_factor * width;
renderingHeight = svg_rendering_resolution_factor * height;
} else {
logger.log(Level.WARNING, "The SVG Rendering Factor is not set to a value greater than 0.0! Setting it to 1.0.");
renderingWidth = width;
renderingHeight = height;
}

img_loaded = SVGHelper.loadSVG(imageFileName, renderingWidth, renderingHeight);
if(img_loaded == null){
loadDefaultImage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class SymbolRepresentation extends RegionBaseRepresentation<StackPane, Sy
private final UntypedWidgetPropertyListener contentListener = this::contentChanged;
private final UntypedWidgetPropertyListener geometryListener = this::geometryChanged;
private final UntypedWidgetPropertyListener styleListener = this::styleChanged;
private final UntypedWidgetPropertyListener svgRenderingResolutionFactorChangedListener = this::svgRenderingResolutionFactorChanged;
private final WidgetPropertyListener<VType> valueListener = this::valueChanged;
private final WidgetPropertyListener<List<WidgetProperty<String>>> symbolsListener = this::symbolsChanged;
private final WidgetPropertyListener<Integer> indexListener = this::initialIndexChanged;
Expand Down Expand Up @@ -610,6 +611,7 @@ protected void registerListeners()
model_widget.propEnabled().addUntypedPropertyListener(styleListener);
model_widget.propShowIndex().addUntypedPropertyListener(styleListener);
model_widget.propTransparent().addUntypedPropertyListener(styleListener);
model_widget.propSVGRenderingResolutionFactor().addUntypedPropertyListener(svgRenderingResolutionFactorChangedListener);

if (!toolkit.isEditMode())
model_widget.runtimePropValue().addPropertyListener(valueListener);
Expand Down Expand Up @@ -639,6 +641,7 @@ protected void unregisterListeners()
model_widget.propEnabled().removePropertyListener(styleListener);
model_widget.propShowIndex().removePropertyListener(styleListener);
model_widget.propTransparent().removePropertyListener(styleListener);
model_widget.propSVGRenderingResolutionFactor().removePropertyListener(svgRenderingResolutionFactorChangedListener);

if (!toolkit.isEditMode())
model_widget.runtimePropValue().removePropertyListener(valueListener);
Expand Down Expand Up @@ -788,6 +791,11 @@ void setSymbolSize ( double width, double height, boolean preserveRatio ) {
}
}

private void svgRenderingResolutionFactorChanged(final WidgetProperty<?> property, final Object oldValue, Object newValue) {
// Update the rendered SVG:
symbolChanged(null, null, null);
}

private void styleChanged ( final WidgetProperty<?> property, final Object oldValue, final Object newValue ) {
dirtyStyle.mark();
toolkit.scheduleUpdate(this);
Expand Down Expand Up @@ -1027,7 +1035,20 @@ void resize(double width, double height, boolean preserveRatio){
* @return An {@link Image} or <code>null</code>.
*/
Image loadSVG(final String imageFileName, double width, double height){
return SVGHelper.loadSVG(imageFileName, width, height);
double svg_rendering_resolution_factor = model_widget.propSVGRenderingResolutionFactor().getValue();

double renderingWidth;
double renderingHeight;
if (!Double.isNaN(svg_rendering_resolution_factor) && svg_rendering_resolution_factor > 0) {
renderingWidth = svg_rendering_resolution_factor * width;
renderingHeight = svg_rendering_resolution_factor * height;
} else {
logger.log(Level.WARNING, "The SVG Rendering Factor is not set to a value greater than 0.0! Setting it to 1.0.");
renderingWidth = width;
renderingHeight = height;
}

return SVGHelper.loadSVG(imageFileName, renderingWidth, renderingHeight);
}
}
}
Loading