Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -99,7 +99,7 @@ public void readFromXML(final ModelReader model_reader, final Element property_x
{ // Current format: <font name="Name" family="Liberation Sans" style="BOLD" size="18" />
name = font_el.getAttribute(XMLTags.NAME);
family = font_el.getAttribute(FAMILY);
style = WidgetFontStyle.valueOf(font_el.getAttribute(STYLE));
style = WidgetFontStyle.safeValueOf(font_el.getAttribute(STYLE));
size = Double.parseDouble(font_el.getAttribute(SIZE));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import org.csstudio.display.builder.model.Messages;

import java.util.logging.Level;
import java.util.logging.Logger;

/** Description of a font style
* @author Kay Kasemir
*/
Expand All @@ -26,7 +29,7 @@

private final String name;

private WidgetFontStyle(final String name)
WidgetFontStyle(final String name)
{
this.name = name;
}
Expand All @@ -36,4 +39,20 @@
{
return name;
}

/**
* Returns the WidgetFontStyle corresponding to the given name.
* If the name does not match any enum constant, returns REGULAR.
*
* @param name The name of the font style
* @return The corresponding WidgetFontStyle, or REGULAR if not found
*/
public static WidgetFontStyle safeValueOf(String name) {
try {
return WidgetFontStyle.valueOf(name);
} catch (IllegalArgumentException e) {
Logger.getLogger(WidgetFontStyle.class.getName()).log(Level.WARNING, "Cannot find WidgetFontStyle : " + name, e);

Check warning on line 54 in app/display/model/src/main/java/org/csstudio/display/builder/model/properties/WidgetFontStyle.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Lambda should be used to defer string concatenation.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaDJHJtc_0NkOF2kyxfb&open=AaDJHJtc_0NkOF2kyxfb&pullRequest=3934
return REGULAR;
}
}
}
Loading