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

Rectangle: Use either legacy "line" or "border" #2205

Merged
merged 1 commit into from
Apr 7, 2022
Merged
Changes from all 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
@@ -1,6 +1,12 @@

package org.csstudio.display.builder.model.widgets;

import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propLineColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propLineStyle;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propLineWidth;

import java.util.Optional;

import org.csstudio.display.builder.model.Widget;
import org.csstudio.display.builder.model.WidgetConfigurator;
import org.csstudio.display.builder.model.persist.NamedWidgetColors;
Expand All @@ -9,11 +15,6 @@
import org.phoebus.framework.persistence.XMLUtil;
import org.w3c.dom.Element;

import java.util.Optional;

import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.*;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propLineColor;

/**
* A helper class for handling the outline "line" property or widgets
*/
Expand All @@ -29,7 +30,6 @@ public class OutlineSupport {
*/
public static void handleLegacyBorder(final Widget widget, final Element xml) throws Exception
{

// Style tends to be a number, but could also be "None".
final Optional<String> style_text = XMLUtil.getChildString(xml, "border_style");
if (!style_text.isPresent())
Expand All @@ -42,6 +42,15 @@ public static void handleLegacyBorder(final Widget widget, final Element xml) th
return;
}

// There is a "border" configuration.
// Is there also a "line" configuration?
if (XMLUtil.getChildDouble(xml, "line_width").orElse(-1.0) >
XMLUtil.getChildDouble(xml, "border_width").orElse(-1.0))
{
// Ignore the smaller "border", use "line"
return;
}

final int style;
try
{
Expand All @@ -53,6 +62,11 @@ public static void handleLegacyBorder(final Widget widget, final Element xml) th

final Optional<Integer> xml_width = XMLUtil.getChildInteger(xml, "border_width");

// If there's a border_color, use that for the line_color
Element el = XMLUtil.getChildElement(xml, "border_color");
if (el != null)
widget.getProperty(propLineColor).readFromXML(null, el);

switch (style)
{
case 0: // NONE
Expand All @@ -69,35 +83,30 @@ public static void handleLegacyBorder(final Widget widget, final Element xml) th
xml_width.ifPresent(w -> {
widget.getProperty(propLineWidth).setValue(w);
});
widget.getProperty(propLineColor).setValue(WidgetColorService.getColor(NamedWidgetColors.TEXT));
break;
case 8: // DOTTED
widget.getProperty(propLineStyle).setValue(LineStyle.DOT);
xml_width.ifPresent(w -> {
widget.getProperty(propLineWidth).setValue(w);
});
widget.getProperty(propLineColor).setValue(WidgetColorService.getColor(NamedWidgetColors.TEXT));
break;
case 9: // DASHED
widget.getProperty(propLineStyle).setValue(LineStyle.DASH);
xml_width.ifPresent(w -> {
widget.getProperty(propLineWidth).setValue(w);
});
widget.getProperty(propLineColor).setValue(WidgetColorService.getColor(NamedWidgetColors.TEXT));
break;
case 10: // DASH_DOT
widget.getProperty(propLineStyle).setValue(LineStyle.DASHDOT);
xml_width.ifPresent(w -> {
widget.getProperty(propLineWidth).setValue(w);
});
widget.getProperty(propLineColor).setValue(WidgetColorService.getColor(NamedWidgetColors.TEXT));
break;
case 11: // DASH_DOT_DOT
widget.getProperty(propLineStyle).setValue(LineStyle.DASHDOTDOT);
xml_width.ifPresent(w -> {
widget.getProperty(propLineWidth).setValue(w);
});
widget.getProperty(propLineColor).setValue(WidgetColorService.getColor(NamedWidgetColors.TEXT));
break;
}
}
Expand Down