Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@ public Convert_activeBarClass(final EdmConverter converter, final Widget parent,
convertColor(r.getBgColor(), widget.propBackgroundColor());
widget.propHorizontal().setValue(!"vertical".equals(r.getOrientation()));
widget.propPVName().setValue(convertPVName(r.getIndicatorPv()));

widget.propScaleVisible().setValue(r.isShowScale());
widget.propLimitsFromPV().setValue(r.isLimitsFromDb());
if (!r.isLimitsFromDb() && r.getMax() > r.getMin())
{
widget.propMinimum().setValue(r.getMin());
widget.propMaximum().setValue(r.getMax());
}

// EDM precision 0 usually means "not set"
if (r.getPrecision() > 0)
widget.propPrecision().setValue(r.getPrecision());

// EDM only knows border on/off
if (r.isBorder())
widget.propBorderWidth().setValue(1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
import org.csstudio.display.builder.model.properties.RulesWidgetProperty;
import org.csstudio.display.builder.model.properties.ScriptsWidgetProperty;
import org.csstudio.display.builder.model.properties.WidgetClassProperty;
import org.csstudio.display.builder.model.widgets.ProgressBarWidget;
import org.csstudio.display.builder.model.widgets.ThermometerWidget;
import org.csstudio.display.builder.representation.Preferences;
import org.csstudio.display.builder.representation.javafx.FilenameSupport;
import org.phoebus.ui.color.NamedWidgetColor;
import org.phoebus.ui.color.WidgetColor;
Expand Down Expand Up @@ -148,6 +151,25 @@ public boolean hasFocus() {
return has_focus;
}

/** Some widgets can be drawn by the stock JavaFX renderer or by an
* RTTank based one that adds a scale, selected via preference.
* Properties that only the RTTank renderer honours are hidden while
* the stock renderer is in use, so the panel only lists what has
* an effect.
*
* @param property Property about to be listed
* @return {@code true} if the property has no effect with the current renderer
*/
private static boolean unusedByCurrentRenderer(final WidgetProperty<?> property) {
if (property.getWidget() instanceof ProgressBarWidget)
return !Preferences.progressbar_scale_mode
&& ProgressBarWidget.SCALE_MODE_PROPS.contains(property.getName());
if (property.getWidget() instanceof ThermometerWidget)
return !Preferences.thermometer_scale_mode
&& ThermometerWidget.SCALE_MODE_PROPS.contains(property.getName());
return false;
}

void fill(final UndoableActionManager undo,
final Collection<WidgetProperty<?>> properties,
final List<Widget> other) {
Expand All @@ -163,6 +185,9 @@ void fill(final UndoableActionManager undo,
if (property instanceof WidgetClassProperty && class_mode)
continue;

if (unusedByCurrentRenderer(property))
continue;

// Start of new category that needs to be shown?
if (property.getCategory() != category) {
category = property.getCategory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public class Messages
WidgetProperties_BorderAlarmSensitive,
WidgetProperties_BorderColor,
WidgetProperties_BorderWidth,
WidgetProperties_BulbSize,
WidgetProperties_CellColors,
WidgetProperties_Class,
WidgetProperties_ColorHiHi,
Expand Down Expand Up @@ -241,6 +242,7 @@ public class Messages
WidgetProperties_HourTickMarkColor,
WidgetProperties_HourTickMarkVisible,
WidgetProperties_Increment,
WidgetProperties_InnerPadding,
WidgetProperties_InitialIndex,
WidgetProperties_Insets,
WidgetProperties_Interactive,
Expand Down Expand Up @@ -326,6 +328,7 @@ public class Messages
WidgetProperties_ShowLoLo,
WidgetProperties_ShowMinorTicks,
WidgetProperties_PerpendicularTickLabels,
WidgetProperties_ShowScaleLabels,
WidgetProperties_ShowOK,
WidgetProperties_ShowScale,
WidgetProperties_ShowUnits,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015-2022 Oak Ridge National Laboratory.
* Copyright (c) 2015-2026 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -8,15 +8,11 @@
package org.csstudio.display.builder.model.widgets;

import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propBackgroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propFillColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHorizontal;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propLimitsFromPV;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMaximum;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMinimum;
import static org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.propLogscale;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.csstudio.display.builder.model.Version;
import org.csstudio.display.builder.model.Widget;
Expand All @@ -34,12 +30,41 @@
import org.w3c.dom.Element;

/** Widget that displays a progress bar
*
* <p>Extends {@link ScaledPVWidget} so the bar offers the same range,
* scale and alarm limit properties as the {@link TankWidget}.
* The scale related properties only take effect with the RTTank based
* renderer, see {@link #SCALE_MODE_PROPS}.
*
* <p>Existing {@code .bob} files load unchanged: {@code fill_color},
* {@code background_color}, {@code horizontal}, {@code limits_from_pv},
* {@code minimum}, {@code maximum} and {@code log_scale} keep their
* XML names. Older Phoebus versions ignore the new properties.
*
* @author Kay Kasemir
* @author Amanda Carpenter
* @author Heredie Delvalle - CLS, scale support
*/
@SuppressWarnings("nls")
public class ProgressBarWidget extends PVWidget
public class ProgressBarWidget extends ScaledPVWidget
{
/** Properties that only have an effect with the RTTank based renderer
* ({@code progressbar_scale_mode=true}).
*
* <p>The property editor hides these while the stock JavaFX renderer
* is in use. Properties that both renderers honour, like the range,
* {@code horizontal}, {@code log_scale}, fill and background color,
* are not listed here.
*/
public static final Set<String> SCALE_MODE_PROPS = Set.of(
"format", "precision", "font", "foreground_color",
"scale_visible", "show_minor_ticks", "show_scale_labels",
"opposite_scale_visible", "perpendicular_tick_labels",
"inner_padding", "tank_border_width",
"alarm_limits_from_pv", "show_alarm_limits",
"level_lolo", "level_low", "level_high", "level_hihi",
"minor_alarm_color", "major_alarm_color");

/** Widget descriptor */
public static final WidgetDescriptor WIDGET_DESCRIPTOR =
new WidgetDescriptor("progressbar", WidgetCategory.MONITOR,
Expand All @@ -55,7 +80,7 @@
}
};

/** Widget configurator to read legacy *.opi files*/
/** Widget configurator to read legacy *.opi files */
private static class ProgressBarConfigurator extends WidgetConfigurator
{
public ProgressBarConfigurator(final Version xml_version)
Expand All @@ -82,14 +107,18 @@
bar.propY().setValue(bar.propY().getValue() + reduce);
bar.propHeight().setValue(bar.propHeight().getValue() - reduce);
}
// Do use space below where BOY placed markers for the bar itself.
// In the future, there could be a scale.

final Element el = XMLUtil.getChildElement(xml, "color_fillbackground");
if (el != null)
bar.propBackgroundColor().readFromXML(model_reader, el);

// Create text update for the value indicator
// BOY names that differ from ours. level_hihi and level_lolo match.
readLegacyElement(model_reader, xml, "show_scale", bar.propScaleVisible());
readLegacyElement(model_reader, xml, "scale_font", bar.propFont());
readLegacyElement(model_reader, xml, "level_hi", bar.propLevelHigh());
readLegacyElement(model_reader, xml, "level_lo", bar.propLevelLow());

// Create a companion TextUpdate widget for the BOY value label.
if (XMLUtil.getChildBoolean(xml, "show_label").orElse(true))
{
final Document doc = xml.getOwnerDocument();
Expand All @@ -116,6 +145,14 @@

return true;
}

private static void readLegacyElement(final ModelReader model_reader, final Element xml,

Check warning on line 149 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/ProgressBarWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaC2QEyXxfo69GIqpzbf&open=AaC2QEyXxfo69GIqpzbf&pullRequest=3930
final String name, final WidgetProperty<?> property) throws Exception
{
final Element element = XMLUtil.getChildElement(xml, name);
if (element != null)
property.readFromXML(model_reader, element);
}
}

@Override
Expand All @@ -125,37 +162,24 @@
return new ProgressBarConfigurator(persisted_version);
}

private volatile WidgetProperty<Boolean> limits_from_pv;
private volatile WidgetProperty<Double> minimum;
private volatile WidgetProperty<Double> maximum;
private volatile WidgetProperty<Boolean> log_scale;
private volatile WidgetProperty<WidgetColor> fill_color;
private volatile WidgetProperty<WidgetColor> background_color;
private volatile WidgetProperty<Boolean> horizontal;
private volatile WidgetProperty<Boolean> horizontal;
private volatile WidgetProperty<Integer> inner_padding;

Check warning on line 167 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/ProgressBarWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "inner_padding" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaC2QEyXxfo69GIqpzbg&open=AaC2QEyXxfo69GIqpzbg&pullRequest=3930

/** Constructor */
public ProgressBarWidget()
{
super(WIDGET_DESCRIPTOR.getType());
super(WIDGET_DESCRIPTOR.getType(), 100, 20);
}

@Override
protected void defineProperties(final List<WidgetProperty<?>> properties)
{
super.defineProperties(properties);
properties.add(fill_color = propFillColor.createProperty(this, new WidgetColor(60, 255, 60)));
defineScaleLookProperties(properties, false, false);
properties.add(background_color = propBackgroundColor.createProperty(this, new WidgetColor(250, 250, 250)));
properties.add(limits_from_pv = propLimitsFromPV.createProperty(this, true));
properties.add(minimum = propMinimum.createProperty(this, 0.0));
properties.add(maximum = propMaximum.createProperty(this, 100.0));
properties.add(log_scale = propLogscale.createProperty(this, false));
properties.add(horizontal = propHorizontal.createProperty(this, true));
}

/** @return 'fill_color' property */
public WidgetProperty<WidgetColor> propFillColor()
{
return fill_color;
properties.add(horizontal = propHorizontal.createProperty(this, true));
properties.add(inner_padding = propInnerPadding.createProperty(this, 3));

Check warning on line 182 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/ProgressBarWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract the assignment out of this expression.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaC2QEyXxfo69GIqpzbe&open=AaC2QEyXxfo69GIqpzbe&pullRequest=3930
}

/** @return 'background_color' property */
Expand All @@ -164,33 +188,15 @@
return background_color;
}

/** @return 'limits_from_pv' property */
public WidgetProperty<Boolean> propLimitsFromPV()
{
return limits_from_pv;
}

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

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

/** @return 'log_scale' property */
public WidgetProperty<Boolean> propLogScale()
{
return log_scale;
}

/** @return 'horizontal' property */
public WidgetProperty<Boolean> propHorizontal()
{
return horizontal;
}

/** @return 'inner_padding' property */
public WidgetProperty<Integer> propInnerPadding()

Check failure on line 198 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/ProgressBarWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename method "propInnerPadding" to prevent any misunderstanding/clash with field "propInnerPadding" defined in superclass "org.csstudio.display.builder.model.widgets.ScaledPVWidget".

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaC1sBSYi7fsNIaXLAqr&open=AaC1sBSYi7fsNIaXLAqr&pullRequest=3930
{
return inner_padding;
}
}
Loading
Loading