Skip to content

Commit

Permalink
Merge pull request #2205 from ControlSystemStudio/rect_line_2203
Browse files Browse the repository at this point in the history
Rectangle: Use either legacy "line" or "border"
  • Loading branch information
shroffk authored Apr 7, 2022
2 parents 272047a + 20fabc6 commit a189362
Showing 1 changed file with 20 additions and 11 deletions.
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

0 comments on commit a189362

Please sign in to comment.